JAMF time server and time zone script. Is there an update to include macOS Monterey 12.4 ?

tcandela
Valued Contributor II

there used to be a section where we can see uploaded scripts and use those scripts if we found any of them useful. I can't find this 'scripts' section, has it been removed?

I downloaded the following script in the past and was wondering if it has been updated for macOS Monterey.  

The script looks to be exiting at the 

if [ $maj -gt 11 ]
then
  echo
  echo "Check OS string format & OS X systemsetup utility for script compatibility with OS X version $osx"
  echo
  exit
fi

 

 

 

#!/bin/sh
####################################################################################################
#
# Copyright (c) 2021, JAMF Software, LLC.  All rights reserved.
#
#       Redistribution and use in source and binary forms, with or without
#       modification, are permitted provided that the following conditions are met:
#               * Redistributions of source code must retain the above copyright
#                 notice, this list of conditions and the following disclaimer.
#               * Redistributions in binary form must reproduce the above copyright
#                 notice, this list of conditions and the following disclaimer in the
#                 documentation and/or other materials provided with the distribution.
#               * Neither the name of the JAMF Software, LLC nor the
#                 names of its contributors may be used to endorse or promote products
#                 derived from this software without specific prior written permission.
#
#       THIS SOFTWARE IS PROVIDED BY JAMF SOFTWARE, LLC "AS IS" AND ANY
#       EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
#       WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
#       DISCLAIMED. IN NO EVENT SHALL JAMF SOFTWARE, LLC BE LIABLE FOR ANY
#       DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
#       (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
#       LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#       ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#       (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
#       SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
####################################################################################################
#
# SUPPORT FOR THIS PROGRAM
#
#       This program is distributed "as is" by JAMF Software, LLC's Resource Kit team. For more
#       information or support for the Resource Kit, please utilize the following resources:
#
#               http://list.jamfsoftware.com/mailman/listinfo/resourcekit
#
#               http://www.jamfsoftware.com/support/resource-kit
#
#       Please reference our SLA for information regarding support of this application:
#
#               http://www.jamfsoftware.com/support/resource-kit-sla
#
####################################################################################################
#
# ABOUT THIS PROGRAM
#
# NAME
#   setTimeServers.sh -- Set a time server.
#
# SYNOPSIS
#   sudo setTimeServer.sh
#   sudo setTimeServer.sh <mountPoint> <computerName> <currentUsername> <timeServer>
#
# DESCRIPTION
#   This script will set a Time Server in the network settings for whichever network interface has
#   been specified.
#
####################################################################################################
#
# HISTORY
#
#   Version: 1.0
#
#   - Created by Tedd Herman on December 29,2008
#
#   Version 2.0
#
#   - Updated by Brock Walters Nov 8 2014
#
#
#   Version 3.0
#
#   - Updated by Jordan Lee Dec 12, 2020
#
####################################################################################################
#
# DEFINE VARIABLES & READ IN PARAMETERS
#
####################################################################################################

# HARDCODED VALUES ARE SET HERE
timeServer=""
timeServer2="tick.usno.navy.mil"

# CHECK TO SEE IF A VALUE WAS PASSED IN PARAMETER 4 AND, IF SO, ASSIGN TO "timeServer"
if [ "$4" != "" ] && [ "$timeServer" == "" ]
then
    timeServer=$4
fi

####################################################################################################
#
# SCRIPT CONTENTS - DO NOT MODIFY BELOW THIS LINE
#
####################################################################################################

osx=$(/usr/bin/defaults read /System/Library/CoreServices/SystemVersion ProductVersion | awk '{print $1}')
maj=$(/usr/bin/defaults read /System/Library/CoreServices/SystemVersion ProductVersion | awk '{print substr($1,1,2)}')
ref=$(/usr/bin/defaults read /System/Library/CoreServices/SystemVersion ProductVersion | awk '{print substr($1,4,2)}')

if [ $maj -gt 11 ]
then
  echo
  echo "Check OS string format & OS X systemsetup utility for script compatibility with OS X version $osx"
  echo
  exit
fi

if [ "$timeServer" != "" ]
then
    if [ $maj -eq 11 ]
    then
	      echo
        echo "1 Setting network time server to: $timeServer..."
        /usr/sbin/systemsetup -setnetworktimeserver $timeServer
        /usr/sbin/systemsetup -setusingnetworktime on
        echo "server $timeServer2" >> /etc/ntp.conf
        echo
    else 
    	  if [ $ref -lt 5 ]
   	    then
        		echo
        		echo "2 Setting network time server to: $timeServer..."
        		/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup -setnetworktimeserver $timeServer
        		/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup -setusingnetworktime on
        		echo "server $timeServer2" >> /etc/ntp.conf
        		echo
    	else
        		echo
        		echo "3 Setting network time server to: $timeServer..."
        		/usr/sbin/systemsetup -setnetworktimeserver $timeServer
        		/usr/sbin/systemsetup -setusingnetworktime on
        		echo "server $timeServer2" >> /etc/ntp.conf
        		echo
    	fi
    fi
else
    echo
    echo "Error:  The parameter 'timeServer' is blank.  Please specify a time server."
    echo
fi

 

 

 

5 REPLIES 5

mm2270
Legendary Contributor III

Yes, that script section was removed from the new Jamf Nation site. Same with some other items, like 3rd party Extension Attributes and such. I do think most of those scripts still exist somewhere, like on a github page, but I can't seem to find the right location for them now if that's the case. I may not be remembering that correctly anyway.

As for this script and its compatibility with Monterey, you could try it on a test machine. Just comment out the section you already noted.

if [ $maj -gt 11 ]
then
  echo
  echo "Check OS string format & OS X systemsetup utility for script compatibility with OS X version $osx"
  echo
  exit
fi

 

Incidentally, it always amazes me how overly complex some of these scripts are in how they were written. A simple example. This line, which grabs the OS version:

osx=$(/usr/bin/defaults read /System/Library/CoreServices/SystemVersion ProductVersion | awk '{print $1}')

Can be simplified into something like this

osx=$(sw_vers -productVersion)

As well as the 2 lines that follow it. Also, this script still looks for a macOS version that's below 10.5, which is just absurd. If anyone has Macs that are still sporting OS X 10.4 they've got way bigger issues to address.

And that will cause some problems when running this against Monterey. The $ref variable gets the second digit in the OS version string, so for a system on 12.4 it will pull "4". Since it looks for anything 5 or lower, then it will try to run the wrong command on the Mac. I suggest this edit. Change this:

if [ $maj -eq 11 ]

 to

if [ $maj -ge 11 ]

That should allow it to know to run if the OS is 11.x or 12.x.

tcandela
Valued Contributor II

@mm2270  yep, I'll have to manipulate the script so it will run on macOS Catalina and up.

why did JAMF remove the script and extension attributes section??? Those were useful.  People would upload new scripts and EA for others to use.  Why would you remove those sections?  makes no sense.

They try to make the site better but it gets worse after every change.

mm2270
Legendary Contributor III

Hey @tcandela I agree that those sections were useful. Even though I only occasionally looked at them, I know a number of people who missed those sections under the site redesign.

As to why Jamf removed them, honestly I wish I could say, but I don't have any insight into what went on at Jamf when they were discussing what to keep and what to drop when redesigning the community site. But for whatever reason, those got put on the chopping block.

It's possible there was some kind of liability concern by having a place where anyone could post up code for others to download. Unless they have staff vetting those scripts and EAs, there might have been a concern about Jamf being the host for those.

Or, more likely, they just didn't want to bother migrating them over for whatever reason. Sometimes the simplest explanation is the right one.

tcandela
Valued Contributor II

hey, I'm basically just going to comment out

if [ $maj -gt 11 ]
then
  echo
  echo "Check OS string format & OS X systemsetup utility for script compatibility with OS X version $osx"
  echo
  exit
fi

then change it to

if [ $maj -ge 10 ]

then comment out the  rest until it gets to this

if [ "$timeServer" != "" ]
then
    if [ $maj -ge 10 ]
    then
	      echo
        echo "1 Setting network time server to: $timeServer..."
        /usr/sbin/systemsetup -setnetworktimeserver $timeServer
        /usr/sbin/systemsetup -setusingnetworktime on
        echo "server $timeServer2" >> /etc/ntp.conf
        echo
    fi
else
    echo
    echo "Error:  The parameter 'timeServer' is blank.  Please specify a time server."
    echo
fi

 

tcandela
Valued Contributor II

@mm2270  what do you think is causing this error?  the settings for timeserver get applied correctly but I can't figure out the error

 

Screen Shot 2022-08-08 at 12.27.02 PM.png