Home Forums Software InstaDMG Set timezone and NTP

Viewing 15 posts - 1 through 15 (of 25 total)
  • Author
    Posts
  • #373369
    eric_csm
    Participant

    Hi,

    The settings I would like to apply to my Netrestored instaDMG created image are:

    #time zone
    “Europe/Dublin”

    #time server address
    “time.euro.apple.com”

    Since building an instaDMG is uncharted territory for me I am trying to keep all customizations as Netrestore post-scripts since it makes testing much faster, otherwise I have have to wait +2 hours for building a new instaDMG to test it, while using Netrestore post-scripts changes can be applied and tested almost instantly).

    There may be a need to auto-bind these images to AD in the future, so the NTP time sync should occur before any AD script, login hook, or launchdaemon is executed.

    If setting the timezone and NTP with a Netrestore post-script is not an option I will consider using a different option such as creating an Startup Item pkg, a LaunchDaemon pkg, a payload free pkg with a post-install script or other methods, etc.

    I will really appreciate your views on this as well as any example scripts or .pkgs to accomplish changing the timezone and activating the NTP.

    Many thanks,

    Eric

    #373374
    Patrick Fergus
    Participant

    All the following code has a caveat–it has to be run on the startup disk. It would have to be the postflight script of a payload-free package that installs upon first boot of a freshly booted machine. There are other ways of handling this that edit the image at creation time, but I prefer using the Apple-supported way of handling this. Also, if you have machines in multiple time zones and have some way of the machine figuring out where it is (via IP address, etc) the machine can set itself with the correct time zone upon first startup.

    First, you’ll need SystemSetup. It’s in a different location for Tiger and Leopard:

    Tiger:[code]/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup[/code]Leopard:[code]/usr/sbin/systemsetup[/code]To figure out the available time zones:[code]$systemSetupLocation -listtimezones[/code]To set the time zone:[code]$systemSetupLocation -settimezone $desiredTimeZone[/code]To enable NTP:[code]$systemSetupLocation -setnetworktimeserver my.time.server.com
    $systemSetupLocation -setusingnetworktime on[/code]- Patrick

    #373376
    eric_csm
    Participant

    Thanks Patrick,

    does this code look allright to you?

    [code]

    #!/bin/sh

    ###Postflight script to set time zone and start NTP (Leopard)

    ###Set variables
    systemSetupLocation=”/usr/sbin/systemsetup”
    timeZone=”Europe/Dublin”
    networkTimeServer=”time.euro.apple.com”

    ###Set time zone, set time server, start NTP
    $systemSetupLocation -settimezone $timeZone
    $systemSetupLocation -setnetworktimeserver $networkTimeServer iburst
    $systemSetupLocation -setusingnetworktime on

    [/code]

    #373385
    Patrick Fergus
    Participant

    Looks reasonable to me.

    – Patrick

    #373408
    eric_csm
    Participant

    To avoid running the package on startup, following the example provided by Pete Akins in https://www.afp548.com/forum/viewtopic.php?showtopic=20328, I have created a package with the following modified files:

    /private/etc/hostconfig

    [code]
    AFPSERVER=-NO-
    AUTHSERVER=-NO-
    AUTOMOUNT=-YES-
    NFSLOCKS=-AUTOMATIC-
    NISDOMAIN=-NO-
    TIMESYNC=-YES-
    QTSSERVER=-NO-
    WEBSERVER=-NO-
    SMBSERVER=-NO-
    SNMPSERVER=-NO-
    [/code]

    /private/etc/ntp.conf

    [code]server.time.euro.apple.com[/code]

    /Resources/postflight.sh

    [code]
    #!/bin/sh

    ln -s /usr/share/zoneinfo/Europe/Dublin “$3/etc/localtime”

    exit 0

    [/code]

    I will test the build tonight and let you know if it works.

    Eric

    #373460
    eric_csm
    Participant

    [b]update[/b], packaging the NTP and timezone changes and running it within InstaDMG doesn’t work for me.

    I’ll test with the neat Netrestore post-action script which Geoff Lee kindly sent me this morning.

    [code]

    #!/bin/bash
    ## To be run as a netrestore post-action script ##

    target_volume=${1}
    timezone=’Europe/Dublin’
    timeserver=my.timeserver.ie

    if [ -z “${target_volume}” ]
    then
    echo “No target volume supplied.”
    exit 1
    fi

    ## Remove trailing slash from target_volume (if there is one)
    target_volume=`echo ${target_volume} | sed ‘s/\/$//’`

    ## Set timezone by creating a symbolic link
    ln -sf “${target_volume}/usr/share/zoneinfo/${timezone}” “${target_volume}/etc/localtime”
    if [ $? != 0 ]
    then
    echo “Setting timezone to ${timezone} failed”
    exit 1
    fi

    ## Create an appropriate ntpd.conf file
    echo “server ${timeserver} iburst” > “${target_volume}/private/etc/ntp.conf”
    ## Update the hostconfig file to use NTP
    sed -i .bak ‘s/TIMESYNC=-NO-/TIMESYNC=-YES-/’ “${target_volume}/etc/hostconfig”

    [/code]

    #373461
    Patrick Fergus
    Participant

    Your postflight is probably the reason it isn’t working. As written above,you have[code]ln -s /usr/share/zoneinfo/Europe/Dublin “$3/etc/localtime”[/code]That creates the symlink on the startup disk, which won’t work as part of an InstaDMG CustomPKG. This probably will work better:[code]ln -s “$3/usr/share/zoneinfo/Europe/Dublin” “$3/etc/localtime”[/code]- Patrick

    #373468
    eric_csm
    Participant

    Hi Patrick,

    I’m not sure that’s the case since the symbolic link produces a relative path.

    ln -s “$3/usr/share/zoneinfo/Europe/Dublin” “$3/etc/localtime”

    would create a symlink to /Volumes/Macintosh \HD/usr/share/zoneinfo/Europe/Dublin instead of creating a symlink to /usr/share/zoneinfo/Europe/Dublin

    in my case it looked like the postflight wasn’t executed at all, and I did check if the .sh was executable.

    Going back to the netrestore post-action script, which I prefer in my case since I’m trying to keep as much scripting as I can outside of the InstaDMG build train, I tested with Geoff Lee’s code, provided in my previous post, and it is almost perfect, there is just one line of code to correct here and it applies to the symlink.

    Instead of the line below, which creates a symlink to /Volumes/Macintosh \HD/usr/share/zoneinfo/Europe/Dublin

    [code]## Set timezone by creating a symbolic link
    ln -sf “${target_volume}/usr/share/zoneinfo/${timezone}” “${target_volume}/etc/localtime”[/code]

    Use this one:

    [code]## Set timezone by creating a symbolic link
    ln -sf “/usr/share/zoneinfo/${timezone}” “${target_volume}/etc/localtime”[/code]

    Note that ${target_volume} has been removed.

    I did test and verified with ls -la /etc/l* and now /etc/localtime its symlinked where it should

    Again, thank you all for your input with this issue.

    #373472
    Patrick Fergus
    Participant

    You’re right–my brain still assumes everything acts with the properties of an alias.

    Not to beat on the CustomPKG too much more, but did you install at least some file (even an empty file in /private/tmp/) when creating the payload-free package? IIRC, [i]some[/i] people have had issues with payload-free packages unless they give installer a file to install somewhere.

    – Patrick

    #373690
    arekdreyer
    Member

    As of InstaDMG_1.4b3 (which fixes symlink issues), I include a package SetTimeZoneToChicago.pkg that creates the symbolic link as described in this thread, and it seems to work fine for me.

    #374998
    typofonic
    Participant

    Hi arekdreyer,

    Could you post your script? I have some problems making it check “Use Network Timeserver” in the preferences using a postfight script.

    – Anders

    #375018
    Patrick Fergus
    Participant

    [QUOTE][u]Quote by: typofonic[/u][p]Hi arekdreyer,

    Could you post your script? I have some problems making it check “Use Network Timeserver” in the preferences using a postfight script.

    – Anders[/p][/QUOTE]######

    Try this:[code]/usr/sbin/systemsetup -setnetworktimeserver ntpserver.company.com
    /usr/sbin/systemsetup -setusingnetworktime on[/code]You’re going to need to run this on first boot of a freshly imaged machine, likely installing a payload-free pkg via launchd or SystemStarter. Someone else will probably provide the instructions on how to do this at InstaDMG image creation time (rather than first boot), but I figure if Apple has already provided a way to set this up I’d rather use it than have to cobble it together myself.

    Also, systemsetup can’t set setting on a non-startup disk.

    – Patrick

    #375034
    typofonic
    Participant

    [QUOTE][u]Quote by: MacTroll[/u][p]FWIW, and not entirely related here… I think you can set timezone via MCX…[/p][/QUOTE]

    How exactly is this done. Can it be done without MacOS X Server?

    #375042
    jasonpgignac
    Participant

    Well, you wouldn’t be able to do this as a true ‘payload free pkg’, since you don’t want to run the script right away – you want it to run on first boot. So, the easiest thing to do, at least in my experience, is to just have a pkg, that copies the script to the system, and then copies in a launchd job onto the system. Then, make sure the script logs itself, and that if there is no errors, that it deletes itself, and the launchd job at the end.

    #375045
    Patrick Fergus
    Participant

    The discussions here regarding payload-free packages have been mostly in the frame of running InstaDMG CustomPKGs, but you could use a payload-free package in InstaDMG CustomPKGs, upon first installation, from ARD, via FileWave, etc. The “payload” part has been whether there are files are actually placed on the computer or whether the package exists to only run a script.

    Thanks,

    – Patrick

Viewing 15 posts - 1 through 15 (of 25 total)
  • You must be logged in to reply to this topic.

Comments are closed