| eric_csm |
 |
Monday, July 14 2008 @ 05:54 am MDT (Read 5193 times) |
|
|
|
Status: offline
Registered: 04/17/08
Posts: 13
|
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
|
| |
|
|
| Patrick Fergus |
 |
Monday, July 14 2008 @ 09:13 am MDT |
|
|

Moderator
Status: offline
Registered: 12/13/07
Posts: 283
|
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: /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup Leopard: /usr/sbin/systemsetup To figure out the available time zones: $systemSetupLocation -listtimezones To set the time zone: $systemSetupLocation -settimezone $desiredTimeZone To enable NTP: $systemSetupLocation -setnetworktimeserver my.time.server.com
$systemSetupLocation -setusingnetworktime on - Patrick
|
| |
|
|
| eric_csm |
 |
Monday, July 14 2008 @ 09:46 am MDT |
|
|
|
Status: offline
Registered: 04/17/08
Posts: 13
|
Thanks Patrick,
does this code look allright to you?
#!/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
|
| |
|
|
| Patrick Fergus |
 |
Monday, July 14 2008 @ 11:40 am MDT |
|
|

Moderator
Status: offline
Registered: 12/13/07
Posts: 283
|
Looks reasonable to me.
- Patrick
|
| |
|
|
| eric_csm |
 |
Wednesday, July 16 2008 @ 09:35 am MDT |
|
|
|
Status: offline
Registered: 04/17/08
Posts: 13
|
To avoid running the package on startup, following the example provided by Pete Akins in http://www.afp548.com/forum/viewtopic.php?showtopic=20328, I have created a package with the following modified files:
/private/etc/hostconfig
AFPSERVER=-NO-
AUTHSERVER=-NO-
AUTOMOUNT=-YES-
NFSLOCKS=-AUTOMATIC-
NISDOMAIN=-NO-
TIMESYNC=-YES-
QTSSERVER=-NO-
WEBSERVER=-NO-
SMBSERVER=-NO-
SNMPSERVER=-NO-
/private/etc/ntp.conf
server.time.euro.apple.com
/Resources/postflight.sh
#!/bin/sh
ln -s /usr/share/zoneinfo/Europe/Dublin "$3/etc/localtime"
exit 0
I will test the build tonight and let you know if it works.
Eric
|
| |
|
|
| eric_csm |
 |
Monday, July 21 2008 @ 09:57 am MDT |
|
|
|
Status: offline
Registered: 04/17/08
Posts: 13
|
update, 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.
#!/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"
|
| |
|
|
| Patrick Fergus |
 |
Monday, July 21 2008 @ 10:16 am MDT |
|
|

Moderator
Status: offline
Registered: 12/13/07
Posts: 283
|
Your postflight is probably the reason it isn't working. As written above,you have ln -s /usr/share/zoneinfo/Europe/Dublin "$3/etc/localtime" That creates the symlink on the startup disk, which won't work as part of an InstaDMG CustomPKG. This probably will work better: ln -s "$3/usr/share/zoneinfo/Europe/Dublin" "$3/etc/localtime" - Patrick
|
| |
|
|
| eric_csm |
 |
Tuesday, July 22 2008 @ 03:33 am MDT |
|
|
|
Status: offline
Registered: 04/17/08
Posts: 13
|
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
## Set timezone by creating a symbolic link
ln -sf "${target_volume}/usr/share/zoneinfo/${timezone}" "${target_volume}/etc/localtime"
Use this one:
## Set timezone by creating a symbolic link
ln -sf "/usr/share/zoneinfo/${timezone}" "${target_volume}/etc/localtime"
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.
|
| |
|
|
| Patrick Fergus |
 |
Tuesday, July 22 2008 @ 12:05 pm MDT |
|
|

Moderator
Status: offline
Registered: 12/13/07
Posts: 283
|
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, some people have had issues with payload-free packages unless they give installer a file to install somewhere.
- Patrick
|
| |
|
|
| arekdreyer |
 |
Friday, August 08 2008 @ 11:34 am MDT |
|
|

Help Desk
Status: offline
Registered: 01/04/01
Posts: 48
|
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.
|
| |
|
|
| typofonic |
 |
Tuesday, December 16 2008 @ 01:46 pm MST |
|
|

Help Desk
Status: offline
Registered: 09/01/08
Posts: 41
|
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
--
Anders, Denmark
|
| |
|
|
| MacTroll |
 |
Tuesday, December 16 2008 @ 02:45 pm MST |
|
|

Admin
Status: offline
Registered: 01/04/01
Posts: 2871
|
FWIW, and not entirely related here... I think you can set timezone via MCX...
Changing the world, one server at a time.
Joel Rennich
|
| |
|
|
| Patrick Fergus |
 |
Thursday, December 18 2008 @ 03:19 pm MST |
|
|

Moderator
Status: offline
Registered: 12/13/07
Posts: 283
|
Quote by: typofonicHi arekdreyer,
Could you post your script? I have some problems making it check "Use Network Timeserver" in the preferences using a postfight script.
- Anders ######
Try this: /usr/sbin/systemsetup -setnetworktimeserver ntpserver.company.com
/usr/sbin/systemsetup -setusingnetworktime on 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
|
| |
|
|
| typofonic |
 |
Sunday, December 21 2008 @ 01:48 pm MST |
|
|

Help Desk
Status: offline
Registered: 09/01/08
Posts: 41
|
Quote by: MacTrollFWIW, and not entirely related here... I think you can set timezone via MCX...
How exactly is this done. Can it be done without MacOS X Server?
--
Anders, Denmark
|
| |
|
|
| jasonpgignac |
 |
Monday, December 22 2008 @ 07:44 pm MST |
|
|

End User
Status: offline
Registered: 12/28/07
Posts: 24
|
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.
|
| |
|
|
| Patrick Fergus |
 |
Tuesday, December 23 2008 @ 03:29 pm MST |
|
|

Moderator
Status: offline
Registered: 12/13/07
Posts: 283
|
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
|
| |
|
|
| typofonic |
 |
Tuesday, January 13 2009 @ 09:11 am MST |
|
|

Help Desk
Status: offline
Registered: 09/01/08
Posts: 41
|
Thanks for all of your help. I managed to set the TimeZone and NTP!
Now the only thing missing is changing the Format in the International pane of System Preferences to Danish... Hmm
- Anders
--
Anders, Denmark
|
| |
|
|
| aaronwyatt |
 |
Tuesday, March 31 2009 @ 01:21 pm MDT |
|
|
|
Status: offline
Registered: 05/23/07
Posts: 10
|
In the interest of sharing what we've done, I use the following in a first boot script:
###########################
# Configure the Time Zone #
###########################
# link the localtime file in /private/etc/ to your time zone /usr/share/zoneinfo:
/bin/ln -s -f /usr/share/zoneinfo/US/Eastern /private/etc/localtime
# Configure the GlobalPreferences file with the exact city you live in:
# clear out the array in case default info is hanging around:
/usr/libexec/PlistBuddy -c "Delete :com.apple.TimeZonePref.Last_Selected_City" /Library/Preferences/.GlobalPreferences.plist
# recreate the array for selected city:
/usr/libexec/PlistBuddy -c "Add :com.apple.TimeZonePref.Last_Selected_City array" /Library/Preferences/.GlobalPreferences.plist
# add lat, long, zone, country, city, etc.:
/usr/libexec/PlistBuddy -c "Add :com.apple.TimeZonePref.Last_Selected_City:0 string 42.333336" /Library/Preferences/.GlobalPreferences.plist
/usr/libexec/PlistBuddy -c "Add :com.apple.TimeZonePref.Last_Selected_City:1 string -71.083336" /Library/Preferences/.GlobalPreferences.plist
/usr/libexec/PlistBuddy -c "Add :com.apple.TimeZonePref.Last_Selected_City:2 string 6" /Library/Preferences/.GlobalPreferences.plist
/usr/libexec/PlistBuddy -c "Add :com.apple.TimeZonePref.Last_Selected_City:3 string 'US/Eastern'" /Library/Preferences/.GlobalPreferences.plist
/usr/libexec/PlistBuddy -c "Add :com.apple.TimeZonePref.Last_Selected_City:4 string 'US'" /Library/Preferences/.GlobalPreferences.plist
/usr/libexec/PlistBuddy -c "Add :com.apple.TimeZonePref.Last_Selected_City:5 string Boston" /Library/Preferences/.GlobalPreferences.plist
/usr/libexec/PlistBuddy -c "Add :com.apple.TimeZonePref.Last_Selected_City:6 string U.S.A." /Library/Preferences/.GlobalPreferences.plist
/usr/libexec/PlistBuddy -c "Add :com.apple.TimeZonePref.Last_Selected_City:7 string Boston" /Library/Preferences/.GlobalPreferences.plist
/usr/libexec/PlistBuddy -c "Add :com.apple.TimeZonePref.Last_Selected_City:8 string U.S.A." /Library/Preferences/.GlobalPreferences.plist
#################################
# Set network time server prefs #
#################################
# There are three parts to configuring network time services:
# 1) set the ntp server
# 2) turn on autosync in the legacy /private/etc/hostconfig file (this file will be going away in later versions of Mac OS X)
# 3) set the ntpd launch daemon to "enabled"
###
# set the network time server:
/bin/echo "server time.domain.edu" > /private/etc/ntp.conf
# make a backup of the hostconfig file before editing:
/bin/cp /private/etc/hostconfig /private/tmp/hostconfig.backup
# now set the hostconfig settings to autosync with the network time:
/usr/bin/sed 's/^TIMESYNC=-NO-$/TIMESYNC=-YES-/' /private/tmp/hostconfig.backup > /private/etc/hostconfig
# now delete the key which disables the ntpd daemon and keeps it from running at boot:
/usr/libexec/PlistBuddy -c "Delete :Disabled" /System/Library/LaunchDaemons/org.ntp.ntpd.plist
# and now kickstart the service incase its not already loaded:
/bin/launchctl load /System/Library/LaunchDaemons/org.ntp.ntpd.plist
|
| |
|
|
| typofonic |
 |
Wednesday, April 01 2009 @ 10:46 am MDT |
|
|

Help Desk
Status: offline
Registered: 09/01/08
Posts: 41
|
Wow, Aaron!
Thanks a lot for sharing. Will try it out!
- Anders
--
Anders, Denmark
|
| |
|
|
| Patrick Fergus |
 |
Friday, April 03 2009 @ 10:12 am MDT |
|
|

Moderator
Status: offline
Registered: 12/13/07
Posts: 283
|
aaronwyatt,
Nice script. A couple quick comments:
- You could probably bake most (if not all) of that into a CustomPKG and place it into the image at InstaDMG runtime.
- But if you're going to run it at first startup, you can use systemsetup to set the time zone, but systemsetup won't work on non-startup disks. See the "timezone" entries in the systemsetup man page.
- And if you're going to run it at first startup, systemsetup can also set up NTP for you. Se the "timeserver" entries in the systemsetup man page.
The systemsetup man page is here or available in a Terminal near you.
You've essentially done 95% of the work to get your modifications working at InstaDMG runtime, but you're running it at first boot. However, if you've already vetted everything the above suggestions are probably busywork.
- Patrick
|
| |
|
|
| typofonic |
 |
Sunday, May 24 2009 @ 05:40 am MDT |
|
|

Help Desk
Status: offline
Registered: 09/01/08
Posts: 41
|
Quote by: aaronwyatt
# add lat, long, zone, country, city, etc.:
/usr/libexec/PlistBuddy -c "Add :com.apple.TimeZonePref.Last_Selected_City:0 string 42.333336" /Library/Preferences/.GlobalPreferences.plist
/usr/libexec/PlistBuddy -c "Add :com.apple.TimeZonePref.Last_Selected_City:1 string -71.083336" /Library/Preferences/.GlobalPreferences.plist
/usr/libexec/PlistBuddy -c "Add :com.apple.TimeZonePref.Last_Selected_City:2 string 6" /Library/Preferences/.GlobalPreferences.plist
/usr/libexec/PlistBuddy -c "Add :com.apple.TimeZonePref.Last_Selected_City:3 string 'US/Eastern'" /Library/Preferences/.GlobalPreferences.plist
/usr/libexec/PlistBuddy -c "Add :com.apple.TimeZonePref.Last_Selected_City:4 string 'US'" /Library/Preferences/.GlobalPreferences.plist
/usr/libexec/PlistBuddy -c "Add :com.apple.TimeZonePref.Last_Selected_City:5 string Boston" /Library/Preferences/.GlobalPreferences.plist
/usr/libexec/PlistBuddy -c "Add :com.apple.TimeZonePref.Last_Selected_City:6 string U.S.A." /Library/Preferences/.GlobalPreferences.plist
/usr/libexec/PlistBuddy -c "Add :com.apple.TimeZonePref.Last_Selected_City:7 string Boston" /Library/Preferences/.GlobalPreferences.plist
/usr/libexec/PlistBuddy -c "Add :com.apple.TimeZonePref.Last_Selected_City:8 string U.S.A." /Library/Preferences/.GlobalPreferences.plist
[/code]
Maybe I'm a noob, but could please somebody explain these lines. What does each line refer to?
String 0-2 has numbers and 5 and 7 & 6 and 8 are duplicates.
I'm trying to set up an image localized to Danish.
Any ideas?
--
Anders, Denmark
|
| |
|
|
| alantrewartha |
 |
Monday, May 25 2009 @ 10:48 am MDT |
|
|

Help Desk
Status: offline
Registered: 10/15/08
Posts: 66
|
as an example of putting it in a PKG here's the NTP stuff from our current custom PKG:
timezone='Europe/London'
timeserver=xxxxx
ln -sf "/usr/share/zoneinfo/${timezone}" "$3/etc/localtime" # Set timezone by creating a symbolic link
echo "server ${timeserver} iburst" > "$3/private/etc/ntp.conf" # Create an appropriate ntpd.conf file
sed -i .bak 's/TIMESYNC=-NO-/TIMESYNC=-YES-/' "$3/etc/hostconfig" # Update the hostconfig file to use NTP
as an aside - does anyone know if that iburst setting in the ntp.conf is still valid/useful
|
| |
|
|
| walt |
 |
Friday, May 29 2009 @ 05:22 pm MDT |
|
|

Help Desk
Status: offline
Registered: 11/03/06
Posts: 35
|
If these scripts are being run as first boot scripts it is much easier imho to use the systemsetup command to configure things like NTP or SSH. As opposed to writing scripts that rely on creating symbolic links to the appropriate Time Zone or editing plist files. The command is easy to use and will accomplish setting NTP settings. I will post up my first boot script once I get back to my work computer. In the meantime read about the command here:
http://developer.apple.com/documentation/Darwin/Reference/Manpages/man8/systemsetup.8.html\
Also, as Patrick mentioned above, systemsetup can't be run on on a volume you aren't booted off of. But if you are writing scripts to run on first boot anyway the systemsetup command is much easier to use and requires less code.
Check out my website:
http://mindyourmac.wordpress.com/
|
| |
|
|
| walt |
 |
Monday, June 01 2009 @ 08:15 am MDT |
|
|

Help Desk
Status: offline
Registered: 11/03/06
Posts: 35
|
Here are my scripts. One is the postflight script that is run during the InstaDMG creation process that creates the Launchd item and installs the script. The other is the script that runs on startup. I created these after getting lots of good info and tips from these forums Feel free to modify them.
Postflight script that installs the script and the Launchd item:
#!/bin/sh
# Install startup settings Launchd item and corresponding script.
# Script by Walter Meyer
# Declare 'defaults'and 'PlistBuddy'.
defaults="/usr/bin/defaults"
PlistBuddy="/usr/libexec/PlistBuddy"
# Define directory variables.
PKG_DIR="$1/Contents/Resources"
SCRIPTS_DIR="$3/Library/Scripts"
LAUNCHD_DIR="$3/Library/LaunchDaemons"
# Create scripts directory.
mkdir "${SCRIPTS_DIR}"
# Copy startupssettings.sh script to the scripts directory.
cp "${PKG_DIR}/startupsettings.sh" "${SCRIPTS_DIR}"
# Install Launchd item to /Library/LaunchDaemons. Change com.yourcompany.startupsettings to your orginization.
$defaults write "${LAUNCHD_DIR}/com.yourcompany.startupsettings" Label com.yourcompany.startupsettings
$defaults write "${LAUNCHD_DIR}/com.yourcompany.startupsettings" ProgramArguments -array
$PlistBuddy -c "Add :ProgramArguments:Item\ 1 string /Library/Scripts/startupsettings.sh" "${LAUNCHD_DIR}/com.yourcompany.startupsettings.plist"
$defaults write "${LAUNCHD_DIR}/com.yourcompany.startupsettings" RunAtLoad -bool YES
# Give Launchd item correct permissions.
chown root:wheel "${LAUNCHD_DIR}/com.yourcompany.startupsettings.plist"
chmod 644 "${LAUNCHD_DIR}/com.yourcompany.startupsettings.plist"
exit 0
StartupSettings.sh script:
#!/bin/sh
# System startup script that should be a Launchd startup script, that deletes itself and the launchd item after completion.
# This script turns on NTP and sets NTP server. Also sets Time Zone. Enables ARD and SSH.
# Define 'kickstart' and 'systemsetup' variables, built in OS X script that activates and sets options for ARD.
# Script by Walter Meyer
kickstart="/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart"
systemsetup="/usr/sbin/systemsetup"
#### Begin ARD Configuration ####
# Set options and activate ARD for only our admin user with all privelages. Turn on VNC and set password to yoursupersecurepasswordhere.
# First we have to define specified users with ARD privelages in a separate command. Replace youradminusehere wih your Administrators short-name. More options for kickstart can be found here: http://support.apple.com/kb/HT2370
$kickstart -configure -users youradminuserhere -access -on -privs -all
# The next command configures the other ARD options.
$kickstart -activate -configure -allowAccessFor -specifiedUsers -clientopts -setmenuextra -menuextra yes -setvnclegacy -vnclegacy yes -setvncpw -vncpw yoursupersecurepasswordhere
#### End ARD Configuration ####
#### Begin Time and Network Services Configuration ####
# Replace 'America/New_York' with your time zone. To list time zones in terminal run: sysemsetup -listtimezones. Set your time server by replacing some.timeserver.here.
$systemsetup -settimezone America/New_York -setusingnetworktime on -setnetworktimeserver some.timeserver.here
# Activate WakeOnLAN.
$systemsetup -setwakeonnetworkaccess on
# Activate SSH.
$systemsetup -setremotelogin on
#### End Time and Network Services Configuration ####
# Delete the script and the launchd item.
rm /Library/LaunchDaemons/com.yourcompany.startupsettings.plist
srm "$0"
Check out my website:
http://mindyourmac.wordpress.com/
|
| |
|
|
| typofonic |
 |
Monday, June 01 2009 @ 08:51 am MDT |
|
|

Help Desk
Status: offline
Registered: 09/01/08
Posts: 41
|
Hey Walt,
Thanks for sharing your script! It's really useful with the detailed comments. Do you happen to know how to also change keyboard layout and how to change the Region settings?
/ Anders
--
Anders, Denmark
|
| |
|
|
| truecolor |
 |
Sunday, June 07 2009 @ 06:52 pm MDT |
|
|
|
Status: offline
Registered: 06/07/09
Posts: 1
|
|
| |
|
|