Hello!
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:
- 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.
- The generic, stripped OS immediately runs a script (see below for existing code and logic).
- the script backs up the user data in ~/Documents, ~/Desktop and /PowerGrade folders to the server
- Install the appropirate OS version for the hardware. if OS Version is “MLTI” it skips steps 5-7)
- loop through a system modifications folder and installs every .pkg file in it
- loop through an appications folder and installs every .pkg file in it
- 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)
- if image type is MLTI loop through the MLTI folder for packages.
- restore the user’s data
- 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! )
Here is the imager script as I currently have it (BASH):
#!/bin/sh
#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)
currentlocation=`pwd`
#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/`
do
if [-e /Volumes/$vol/System/ then
mv /Volumes/$vol /Volumes/Macintosh\ HD
done
#
#
#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/`
do
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?
done
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
destination=`pwd`/$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
else
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
$LicensesUsed++
#Replace LicencesUsed with new value.
else
Case "$OSVersion" in
10_2)
$OSVersion = 10_3
#re-run OSLicensFunction
10_3)
$OSVersion = 10_4
#re-run OSLicenseFunction
10_4)
#Error out with "No more licenses remain." &Return & " Please contact the Technology Office for assistance"
exit
*)
#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
Young)
Server="192.168.X.1/Images"
FF)
Server="192.168.X.1/Images"
Burns)
Server="192.168.X.1/Images"
Dayton)
Server="192.168.X.1/Images"
SMS)
Server="192.168.X.1/Images"
HSTP)
Server="192.168.X.1/Images"
CO)
Server="192.168.X.1/Images"
*)
#Message "Your machine is not properly registered with the re-image system. Please contact the technology department for assistance"
exit
esac
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
else
#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`
do
echo "package installed"
done
if $OptionalPkg = "Yes"
echo "Installing appropriate optional packages"
for package in `http://mail.saco.org/ReImage/OptionalPKGs`
do
#PackageName=
echo "#PackageName installed"
done
else
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`
do
echo "package installed"
done
###installations of applications begins here
echo "Installing Programs"
for package in `http://mail.saco.org/ReImage/Applications`
do
#PackageName=
echo "#PackageName installed"
done
#Install optional packages
if $OptionalPkg = "Yes"
echo "Installing appropriate optional packages"
for package in `http://mail.saco.org/ReImage/OptionalPKGs`
do
#PackageName=
echo "#PackageName installed"
done
###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"
else
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