OS Imaging


I am not sure which forum to post this in, or if I should post it in more than one. Since, ultimately, it has to do with the OS i chose this one.

I have a rather complex problem I am working on. First, a little bit of background so you can all better understand the situation:
I am the technology director for a Mac-based public school district in Maine. I am ultimately responsible for about 1100 machines (in 7 buildings), with the possibility of adding close to 200 for next year.

I have a total technology support staff for the district of 5 people (one is a lab monitor that is gifted with ability to effectively tropubleshoot and a more than substantial amount of knowledge, another is in charge of managing the paperwork and repairs on the 600 units that are owned by the state, the remaining three are the official tech support department) so an imaging solution is a must for us, but none has ever been attempted here before.

I want my imaging solution to be based on the state laptop program’s imaging solution in one very important way: packages.
This process will involve both AppleScript and BASH scripting and I am hoping that this community can help me tweak my ideas for efficiency and make the overall imaging process flawless.

Here is the outline of what I want to do, but I am not entirely sure of all the steps:

  1. Netboot (I am having trouble getting netboot enabled on my OSX 10.4 server, but I have not had a lot of time to track down the proble, which I am sure is a check box somewhere that I missed) to a generic, stripped OS.
  2. The generic, stripped OS immediately runs a script (see below for existing code and logic).
  3. the script backs up the user data in ~/Documents, ~/Desktop and /PowerGrade folders to the server
  4. Install the appropirate OS version for the hardware. if OS Version is “MLTI” it skips steps 5-7)
  5. loop through a system modifications folder and installs every .pkg file in it
  6. loop through an appications folder and installs every .pkg file in it
  7. loop through an optional packages folder and installs every package in there (there will be flag for this, if yes, then do this step, otherwise skip it… each package has the selection criteria for it’s own installation as part of the preflight script)
  8. if image type is MLTI loop through the MLTI folder for packages.
  9. restore the user’s data
  10. restart to new image on local machine.

Also, if anyone has some really cool ideas for an educational environment, please let me know so i can work on making them a reality. I have no problems with sharing the final imaging concept and related products (including a how-to and code) with any person or place that helps me make it all work before August 1 (so I can get it running and in place before the school year starts).

I have not yet had a chance to test some aspects of this script as I have not yet set up the imaging source location. I fear (for bandwidth’s sake) I may have to set up the entire thing in each building and have only a central place for all machines to access info.txt (see script) and have the machines point to the local server for all the packages and images (then I will need a way to synchronize those directories from building to building… eventually).

I know the rules say to compile the applescript before posting, but this is a BASH script so I have not compiled it since they do not get compiled (if they do, please tell me how! :slight_smile: )
Here is the imager script as I currently have it (BASH):

#this script runs the full re-image, including backup and recovery of all user data stored in conventional locations.

#how do I get this script to run? minimal OS on netboot image with script as startup item?

# gets current location (note sure if this is needed)

#Gets MACAddress
MACAddress=`ifconfig | grep -A 3 en0 | grep ether | awk '{print $2}'`

### gets username
UserName=`curl -s $UpdateAddress/info.txt | grep $MACaddress | awk '{print $6}'`

### gets long name
Name=`curl -s $UpdateAddress/info.txt | grep $MACaddress | awk '{print $7}'`

### gets OS version
OSVersion=`curl -s $UpdateAddress/info.txt | grep $MACaddress | awk '{print $9}'`

###gets model type
Model=`curl -s $UpdateAddress/info.txt | grep $MACaddress | awk '{print $11}'`

# gets Location name
Location=`curl -s $UpdateAddress/info.txt | grep $MACaddress | awk '{print $XYZ}'` #XYZ to be replaced with column number

### Sets Image Type
ImageType=$Model & "-" & $OSVersion

### optional packages: yes or no?
OptionalPkg=`curl -s $UpdateAddress/info.txt | grep $MACaddress | awk '{print $10}'`

### renames local disk
echo "Checking the name of your local drive, renaming if possible"
for vol in `ls /Volumes/`
        if [-e /Volumes/$vol/System/ then
            mv /Volumes/$vol /Volumes/Macintosh\ HD

#Warns User that documents NOT in the Documents folder or on the Desktop will be lost forever. Allows user to cancel (cancelling sets startup volume to local disk and restarts)
# how do I accomplish this? osascript command does not seem to work.

#copies relevant line from info.txt to /Volumes/Macintosh\ HD/mcahineinfo.txt
curl -s $UpdateAddress/info.txt | grep $MACaddress | /Volumes/Macintosh\ HD/mcahineinfo.txt

### zips all standard data storage locations into files in backup folder
#ideally these files will be unzipped back to their respective locations... how much more difficult is that?
echo "Compressing Your Files"
for user in `ls /Volumes/User/`
        tar czf /Macintosh\ HD/$Username/backup.tar.gz /Volumes/Macintosh\ HD/$user/Documents /Volumes/Macintosh\ HD/$user/Desktop

### this has to loop through for all users installed on the machine. How to do that? for user in /users?
    tar czf /Macintosh\ HD/$Username/PGBackup.tar.gz /Volumes/Macintosh\ HD/Applications/PowerGrade

## backs up bookmarks
    # how to do this?
    #safari bookamrks
    #firefox bookmarks
    #IE favorites

### copies Backup folder to image source location
echo "Backing Up Your Files. This could take awhile"
mkdir $currentlocation/$Username
#is there a better way to do this? would PSync be a better backup solution for the whole /Users/Directory?

#should this be a public directory on the server? what about security of the data during reimage? is this a major concern for the half hour to hour that the process will take?

cp /Volumes/Macintosh\ HD/$Username/backup.tar.gz $destination
cp /Volumes/Macintosh\ HD/$Username/PGBackup.tar.gz $destination

echo "Done backing up files."

### wipes drive
echo "Cleaning drive"
#rm -r /Volumes/Macintosh\ HD/

### OS licensing function runs here. 

echo "Determining OS X Licensing"
#If (-e `curl -s $OSVersion.txt | grep $MACaddress`)
    #do nothing
        LicensesUsed=`curl -s $OSVersion.txt | grep $MACaddress | awk '{print $2}'`
        TotalLicenses=`curl -s $OSVersion.txt | grep $MACaddress | awk '{print $2}'`
        LicensesLeft=$TotalLicenses - LicensesUsed
        if ($LicensesLeft>0)
            #write "," & "$MACAddress" to the end of the MACAddress field
            #Replace LicencesUsed with new value. 
                Case "$OSVersion" in
                        $OSVersion = 10_3
                        #re-run OSLicensFunction
                        $OSVersion = 10_4
                        #re-run OSLicenseFunction
                        #Error out with "No more licenses remain." &Return & " Please contact the Technology Office for assistance"
                        #Message "Your machine is not properly registered with the re-image system. Please contact the technology department for assistance"

echo "Your OS X Version will be: " & $OSVersion

#determines local image server directory

                Case "$Location" in
                        #Message "Your machine is not properly registered with the re-image system. Please contact the technology department for assistance"

echo "Image server set to " & $Location & " imaging directory."

### Determines OS Image  #ImageType is $Model-$OSVersion
if (-e $ImageType.dmg in $Server
        echo "Installing OS X, this could take awhile"
        #run install
        #display dialog "Your computer does not appear to be registered correctly in the imaging system." &Return & "Please inform the Technology Support Staff" Buttons {"OK"} Default Button {"OK"} 

# forks off for MLTI machines
if $ImageType = "MLTI"
    echo "Running MLTI modifications"
    for package in `http://mail.saco.org/ReImage/MLTI`
        echo "package installed"
    if $OptionalPkg = "Yes"
        echo "Installing appropriate optional packages"
        for package in `http://mail.saco.org/ReImage/OptionalPKGs`
            echo "#PackageName installed"
        restart now

### Runs all remaining system packages
#each package in referenced directories contains the qualifying statements in pre-flight script
echo "Running system modifications"
for package in `http://mail.saco.org/ReImage/SystemPKGs`
    echo "package installed"

###installations of applications begins here
echo "Installing Programs"
for package in `http://mail.saco.org/ReImage/Applications`
    echo "#PackageName installed"

#Install optional packages
if $OptionalPkg = "Yes"
    echo "Installing appropriate optional packages"
    for package in `http://mail.saco.org/ReImage/OptionalPKGs`
        echo "#PackageName installed"

###Restoring backed up files to machine
mv $destination/backup.tar.gz /Volumes/Macintosh\ HD/Users/$Username/Desktop/backup.tar.gz
    #restores Firefox and safari bookmarks

#Restores PowerGrade data
if [-e /Volumes/Macintosh\ HD/Applications/PowerGrade then
    tar x $destination/PGBackup.tar.gz /Volumes/Macintosh\ HD/Applications/PowerGrade
    echo "PowerGrade data restored"
        echo "PowerGrade folder not present."
        mkdir  /Volumes/Macintosh\ HD/Applications/PowerGrade
        echo "PowerGrade folder created"
        tar x $destination/PGBackup.tar.gz /Volumes/Macintosh\ HD/Applications/PowerGrade
end if
say "Imaging complete. Restarting computer"
restart now

I too am also interested in some more knowledge on this topic.

You want to do pretty much what I want, except not as exotic. I have a ready made image using the Disk Utility, and currently I NetBoot my lab clients, and then go to each machine, select the image I want to restore to the local volume, restore it, and then restart.

The above steps, involving starting the disk utility, selecting the image, restoring, and then restarting I want to script, to make the imaging process as “hands-off” as possible.