Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Use one Deploy Studio server with images on many servers' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use one Deploy Studio server with images on many servers
Authored by: applebit on Mar 03, '09 09:18:53AM
The script below selects a server based on subnet. Also, with certain subnets, it will select 1 of 4 image servers (based off of the second) to load balance image servers.

Next it will select what image the machine runs based on processor. We use 10.4 where we can, and 10.5 only on machines that require 10.5. You will of course have to modify the code to work with your environment.

Run this as a login hook for best results (as I have designed this to run as root)

#!/bin/sh
set -xv; exec 1>/Library/Logs/in.log 2>&1
#preferredserverusername='deploystudio'
#preferredserverpassword='d3p!0y$tuDi0'
allservers="serverFQDN1.org serverFQDN2.org serverFQDN3.org serverFQDN4.org serverFQDN5.org serverFQDN6.org serverFQDN7.org serverFQDN8.org"
#rm -rf /Volumes/images/Masters/HFS/
rm -f /Volumes/images/Masters/HFS/image.dmg
rmdir /Volumes/images/Masters/HFS/
rmdir /Volumes/images/Masters/
rmdir /Volumes/images/
mkdir -p /Volumes/images/Masters/HFS/




/usr/bin/osascript -e "set volume 7"

# set the screensaver
defaults -currentHost write com.apple.screensaver idleTime 300



# add 'dstudio' user to list of administrators
dscl . append /Groups/admin users dstudio



#mount images volume
SubNet=$(/sbin/ifconfig | /usr/bin/grep "inet 10." | /usr/bin/sed "s/./ . /g" | /usr/bin/awk {'print $4'})

case "$SubNet" in
108)
preferredserver=serverFQDN1.org;;
110)
preferredserver=serverFQDN2.org;;
111)
preferredserver=serverFQDN3.org;;
*)
sec=$(date +%S)
if [[ "$(echo 00,01,05,09,13,17,21,25,29,33,37,41,45,49,53,57 | grep $sec)" != "" ]]; then preferredserver=serverFQDN4.org
elif [[ "$(echo 02,06,10,14,18,22,26,30,34,38,42,46,50,54,58 | grep $sec)" != "" ]]; then preferredserver=serverFQDN5.org
elif [[ "$(echo 03,07,11,15,19,23,27,31,35,39,43,47,51,55,59 | grep $sec)" != "" ]]; then preferredserver=serverFQDN6.org
elif [[ "$(echo 04,08,12,16,20,24,28,32,36,40,44,48,52,56,60 | grep $sec)" != "" ]]; then preferredserver=serverFQDN7.org
fi
echo $preferredserver;;
esac

if [[ "$preferredserverusername" != "" ]]; then
preferredserverauthentication="$preferredserverusername:$preferredserverpassword@"
fi

allservers="$preferredserver $(echo $allservers | sed "s/$preferredserver//g")"

mountsuccess=1
for selectserver in $allservers; do
if [[ "$mountsuccess" != "0" ]]; then
/sbin/umount /Volumes/real_images/
/bin/rmdir /Volumes/real_images/
/sbin/umount /Volumes/images/
/bin/rmdir /Volumes/images/
sudo mkdir /Volumes/real_images && sudo /sbin/mount_afp -o nobrowse afp://$preferredserverauthentication$selectserver/images /Volumes/real_images
mountsuccess=$? # once it has mounted a good volume, exit out of the loop (only mount first volume it can)
if [[ "$mountsuccess" == "0" ]]; then
mountedserver=$selectserver
fi
fi
done

if [ ! -e /Volumes/real_images/Masters/ ]; then
/usr/bin/osascript -e 'tell application "System Events"' -e 'activate' -e "display alert "nNo image servers could be mounted.nnnPlease contact District Technology to resolve this issue.nn" giving up after 90" -e 'end tell'
else




# This will set the appropriate image to restore from based on computer
if [[ "$(system_profiler SPHardwareDataType | grep 'Model Identifier' | grep 'PowerMac')" != "" ]]; then # this is a Power PC Computer
ln -s /Volumes/real_images/Masters/HFS/Standard-10.4-PPC.dmg /Volumes/images/Masters/HFS/image.dmg
else
# the is an intel machine - see if this is a computer that can run 10.4 and if so, set it to do so
machinemodel=$(system_profiler SPHardwareDataType | grep 'Model Identifier' | awk {'print $3'})
for fn in "MacPro2,1" "MacPro1,1,Quad" "MacPro1,1" "iMac6,1" "iMac5,1" "iMac5,2" "MacBookPro2,1" "MacBookPro2,2" "MacBookPro3,1" "Macmini1,1" "Macmini2,1" "MacBook1,1" "MacBookPro1,2" "MacBookPro1,1" "iMac4,2" "iMac4,1" "MacBook2,1"; do
if [[ "$fn" == "$machinemodel" ]]; then
ln -s /Volumes/real_images/Masters/HFS/Standard-10.4-x86.dmg /Volumes/images/Masters/HFS/image.dmg
else
ln -s /Volumes/real_images/Masters/HFS/Standard-10.5.dmg /Volumes/images/Masters/HFS/image.dmg
fi
done
fi
# /usr/bin/osascript -e 'tell application "System Events"' -e 'activate' -e "display alert "n$mountedserver server mounted.nn" giving up after 90" -e 'end tell' &

fi

---
Jon McCullough
Systems Support Specialist


[ Reply to This | # ]