Help writing configuration to disk with post-install script...

ega
Contributor III

First I apologize for the length and advanced nature of the questions.
I have been editing a script that will configure or create all the files on a disk, post install, to pre-configure it when booted the first time. The idea is to have a post-install configuration script that runs after a NetInstall with disk format (these can be created with System Image Utility). What I have so far is here:
https://github.com/everetteallen/OSX-No-Boot
This is NOT a first boot script and there is the snag.
The configuration settings normally set by systemsetup, pmset, and createhomedir can not be targeted at a non-booted volume. This narrows me down to the basic tools: defaults, PlistBuddy, dscl, and cat.
Here are my assumptions:
1) we are NOT booted to the volume that is the target of the installer (i.e. we ARE booted from an external disk, netinstall image, key drive, etc or the target volume is on a mounted disk image file)
2) the target volume contains a new, never booted OS X 10.x or newer
3) no first boot script or installer can be used
NOTE: I am not interested in how to get around the assumptions just answers that will work given the assumptions please. I know about First Boot Installer Maker Application and friends but I want avoid the multiple reboots. Besides we should collectively be able to meet the challenge!

So, here are the questions:
a) I need to configure energy saver to never sleep. Normally this would be:
systemsetup -setcomputersleep off
systemsetup -setsleep off
// Restart automatically if the computer freezes or power fails
systemsetup -setrestartfreeze on
systemsetup -setrestartpowerfailure on
systemsetup -setwaitforstartupafterpowerfailure 120
I can see that I need to edit both /Library/Preferences/SystemConfiguration/com.apple.PowerManagement.plist
and
/Library/Preferences/SystemConfiguration/com.apple.AutoWake.plist
Does anyone have working examples of how to make the changes using PlistBuddy or defaults?

2) I need to force custom time server and time zone. Normally this would be:
// Set the time zone
systemsetup -settimezone "America/New_York"
// Enable network time servers
systemsetup -setusingnetworktime on
// Configure a specific NTP server
systemsetup -setnetworktimeserver "time.whatever.domain"
I can:
echo "server time.ncsu.edu" >> /etc/ntp.conf
and cheat a bit with:
defaults write /Library/Preferences/com.apple.timezone.auto Active -bool true
The question is does anyone know what files to write to that will force timezone manually and to use the time server without location services?

3) I want to pre-create the home directories for the 3 users I make with dscl. Normally this would be createhomedir -c -u someuser
I tried setting the user's NFSHomeDirectory value to $3/Users/$whateveruser but createhomedir -u still did not create and populate the folders. I thought about ditto /System/Library/User Template/English.lproj to /Users/$whateveruser (with appropriate chown/chmods) but that misses the changes I make to /System/Library/User Template/Non_localized for iCloud suppression etc.
Question: Does anyone know how to either a) get createhomdir to work on another volume or b) know the commands to use ditto or cp to pre-populate home directories?

Thanks in advance!

2 REPLIES 2

thoule
Valued Contributor II

I don't get why this all needs to be done pre-first boot. These are common tasks done by many with a first boot script. I think you can keep fighting your battle there, but I know I wouldn't be tackling it that way.... If you are going to keep it up, you should be able to prepend your path with /Volumes/NewlyImagedHD/ for the defaults command.

p.s. I think the energy saver stuff might be saved in NVRAM... Look into pmset.

mm2270
Legendary Contributor III

I have to agree with @thoule You haven't provided an explanation of why this all needs to be done in one shot and not in a first run script, other than that you want to avoid any reboots. Understandable, as I would love to not have to do any reboots post imaging as well, but most of the stuff you're looking to do isn't going to be easy to configure on a non boot volume, and I think you won't find too many answers. Its the primary reason why almost anyone doing imaging is using first run scripts, since trying to affect these settings on a non boot volume is very difficult.

You can try looking at CreateUserPkg to see it will work to create user accounts on the non boot volume, although I don't know if it can. It might also require running agains the boot drive.
Copying the user template and then chmod'ing/chown'ing contents sounds unnecessarily complex and like it will lead to a number of problems to me, but you can try it I guess.