Advertisement
themacdweeb

1stBoot-NewImage.sh

Oct 16th, 2013
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 13.19 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # The Getty "First-Boot" script, ©2013 David Koff
  4. # Allow technicians to input data, set prefs on a new Mac,
  5. # pre-set several variables & then email the ITSLab of a new deployment
  6. #
  7. # Created: 3.5.13
  8. # Last Updated: 6.1.13
  9.  
  10.  
  11. # ---------------------------------------------------------
  12. # variables & directories  (updated Feb2013)
  13. # ---------------------------------------------------------
  14. #--- assignments
  15. SCRIPTNAME=$0
  16. delivasset=$4
  17. removeasset=$5
  18. firstname=$6
  19. lastname=$7
  20. locationcode=$8
  21.  
  22. #--- Set Logging
  23. exec >> "/Library/Logs/Getty Installations.log" 2>&1
  24.  
  25. #--- directories
  26. login="/Library/Preferences/com.apple.loginwindow"
  27. RepoURL="http://xserve-timcook.getty.edu:8088/content/catalogs/others"
  28. MS="/Library/Fonts/Microsoft/"
  29. xProtect_MetaPlist="$3/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/XProtect.meta.plist"
  30. xProtect_Plist="$3/System/Library/LaunchDaemons/com.apple.xprotectupdater.plist"
  31.  
  32. #--- executables
  33. mail="/usr/sbin/postfix"
  34. kickstart="/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart"
  35. PlistBuddy="/usr/libexec/PlistBuddy"
  36.  
  37. #--- computationals
  38. date=`date "+%A %m/%d/%Y"`
  39. time=`systemsetup -gettime`
  40. over500=`dscl . list /Users UniqueID | awk '$2 > 500 { print $1 }'`
  41. admins=`dscl . -read /groups/admin GroupMembership`
  42. firstinitial=`echo $firstname | cut -c1`
  43. hwCheck=`system_profiler | grep "Model Name" | awk '{ print $3 }'`
  44. hwVers=`system_profiler | grep "Model Name" | awk '{ print $3, $4, $5 }'`
  45. osCheck=`sw_vers -productVersion | awk -F . '{print $2}'`
  46. OS=`sw_vers | grep ProductVersion | awk '{ print $2 }'`
  47. ip=`ifconfig | grep "inet 153" | cut -d ' ' -f 2`
  48. serial=`system_profiler | grep "Serial Number (system)" | cut -c 31-43`
  49. enet=`networksetup -listallnetworkservices | grep Ethernet`
  50. USER=`defaults read $login lastUserName`
  51.  
  52. #--- UUID capture
  53. if [[ `ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c27-50` == "00000000-0000-1000-8000-" ]]; then
  54.     MAC_UUID=`ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c51-62 | awk {'print tolower()'}`
  55. elif [[ `ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c27-50` != "00000000-0000-1000-8000-" ]]; then
  56.     MAC_UUID=`ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c27-62`
  57. fi
  58.  
  59.  
  60. #----------------------------------------------------------
  61. #  Timestamp
  62. #----------------------------------------------------------
  63. echo "                                   "
  64. echo "###################################"
  65. echo "##### $SCRIPTNAME"
  66. echo "##### `date "+%A %m/%d/%Y %H:%M"`"
  67. echo "###################################"
  68. echo "                                   "
  69.  
  70.  
  71. echo "
  72. # ---------------------------------------------------------
  73. #  ---------------------- FIXES --------------------------
  74. # ---------------------------------------------------------"
  75.  
  76. echo ""
  77. echo ">>>>>>>>  PREVENT iCLOUD WIZARD FROM RUNNING"
  78. # in any user account
  79. for i in $over500
  80. do
  81.     defaults write /Users/$i/Library/Preferences/com.apple.SetupAssistant DidSeeCloudSetup -bool TRUE
  82.     defaults write /Users/$i/Library/Preferences/com.apple.SetupAssistant LastSeenCloudProductVersion -string '10.8'
  83.     chown "${i}":staff /Users/$i/Library/Preferences/com.apple.SetupAssistant.plist
  84.     echo "iCloud wizard removed from the $i account..."
  85. done
  86.  
  87. #in the user template
  88. for USER_TEMPLATE in "/System/Library/User Template"/*
  89. do
  90.     defaults write "${USER_TEMPLATE}"/Library/Preferences/com.apple.loginwindow -dict#creates a blank file if none exists
  91.     defaults write "${USER_TEMPLATE}"/Library/Preferences/loginwindow -dict#creates a blank file if none exists
  92.     defaults write "${USER_TEMPLATE}"/Library/Preferences/com.apple.SetupAssistant DidSeeCloudSetup -bool TRUE
  93.     defaults write "${USER_TEMPLATE}"/Library/Preferences/com.apple.SetupAssistant LastSeenCloudProductVersion -string '10.8'
  94.     echo "com.apple.SetupAssistant for the $USER_TEMPLATE now won't propmpt for iCloud..."
  95. done
  96.  
  97. echo ""
  98. echo ">>>>>>>>  DISABLE XPROTECT"
  99. if [ -f $LaunchDaemons/com.apple.xprotectupdater.plist ]; then
  100.     echo "x-Protect has been found in $LaunchDaemons and will now be edited and unloaded:"
  101.     $PlistBuddy -c "Delete :JavaWebComponentVersionMinimum" "$xProtect_MetaPlist"
  102.     echo "     Minimum Java Component removed from x-Protect."
  103.     $launchctl unload -w "$xProtect_Plist"
  104.     echo "     x-Protect has been unloaded via launchctl."
  105.     if [ ! -d $LaunchDaemonsDisabled ]; then
  106.         echo ""
  107.         echo "Now creating: $LaunchDaemonsDisabled to store xProtect plist:"
  108.         mkdir -v $LaunchDaemonsDisabled
  109.     else
  110.         echo ""
  111.         echo "$LaunchDaemonsDisabled:"
  112.         echo "     Directory found & emptied."
  113.         echo "     x-Protect moved into that directory:"
  114.         rm -fv $LaunchDaemonsDisabled/*
  115.         mv -v $LaunchDaemons/com.apple.xprotectupdater.plist $LaunchDaemonsDisabled
  116.     fi
  117. else
  118.     echo "x-Protect hasn't been found in: ${LaunchDaemons}"
  119.     if [ -f $LaunchDaemonsDisabled/com.apple.xprotectupdater.plist ]; then
  120.         echo "It has already been moved to: ${LaunchDaemonsDisabled}"
  121.     fi
  122. fi
  123.  
  124. echo ""
  125. echo ">>>>>>>>  FIX ADOBE SUPPORT FOLDER"
  126. for i in $over500
  127. do
  128.     chmod -R 775 /Users/$i/Library/Application\ Support/Adobe
  129.     echo "Fixed Adobe permissions on the $i account..."
  130. done
  131.  
  132. echo ""
  133. echo ">>>>>>>>  FIX FIREFOX BOOKMARKS"
  134. for i in $over500
  135. do
  136.     cd /Users/$i/Library/Application\ Support/Firefox/Profiles/*/
  137.     mv places.sqlite places.sqlite.old
  138.     mv places.sqlite-journal places.sqlite-journal.old
  139.     echo "Firefox bookmarks error is corrected in the $i account..."
  140. done
  141.  
  142. echo ""
  143. echo ">>>>>>>>  FIX DYLD ERRORS"
  144. if [ $osCheck = "6" ]; then
  145.     echo " "
  146.     echo "This Mac is running Snow Leopard & requires updating dyld cache...."
  147.     sudo update_dyld_shared_cache -force
  148. fi
  149.  
  150. echo "
  151. # ---------------------------------------------------------
  152. #  --------------- INITIAL IMAGING SET UPS ---------------
  153. # ---------------------------------------------------------"
  154.  
  155. echo ""
  156. echo ">>>>>>>>  SET COMPUTER NAMES"
  157. scutil --set LocalHostName GT$delivasset-$firstname-$lastname
  158. scutil --set ComputerName GT$delivasset-$firstname-$lastname
  159. scutil --set HostName GT$delivasset-$firstname-$lastname.getty.edu
  160. echo "Computer Name now set to: GT$delivasset-$firstname-$lastname"
  161.  
  162.  
  163. echo ""
  164. echo ">>>>>>>>  SET ACCOUNT LONG NAME"
  165. if [ $firstname = "SHARED" ]; then
  166.     firstname=workstation
  167.     dscl . -create /Users/workstation RealName $firstname
  168.     echo " "
  169.     echo "Workstation account long name has been set to '$firstname'"
  170. else
  171.     dscl . -create /Users/workstation RealName $firstinitial$lastname
  172.     echo " "
  173.     echo "Workstation account long name has been set to '$firstinitial$lastname'"
  174. fi
  175.  
  176. echo ""
  177. echo ">>>>>>>>  SETTING NETWORK PREFS"
  178. networksetup -createlocation Getty populate
  179. networksetup -switchtolocation Getty
  180. networksetup -deletelocation Automatic
  181. networksetup -setnetworkserviceenabled FireWire Off
  182. networksetup -setnetworkserviceenabled "Bluetooth DUN" Off
  183. networksetup -setv6off $enet
  184. echo " "
  185. echo "'Getty' network location created & made active."
  186. echo "Default location 'Automatic' deleted."
  187. echo "FireWire and Bluetooth DUN are disabled."
  188. echo "IPv6 is disabled on all Ethernet ports."
  189.  
  190. echo ""
  191. echo ">>>>>>>>  SETTING ARD FIELDS & SERVICE"
  192. $kickstart -activate -configure -computerinfo -set1 -1 $serial -set2 -2 GT$delivasset -set3 -3 $firstname\ $lastname -set4 -4 $locationcode
  193. echo "ARD fields populated..."
  194. $kickstart -activate
  195. $kickstart -configure -users ard -access -on -privs -DeleteFiles -TextMessages -OpenQuitApps -GenerateReports -RestartShutdown -SendFiles -ChangeSettings -clientopts -setmenuextra -menuextra no -setreqperm -reqperm yes
  196. echo "Getty Standard ARD access prefs are set..."
  197.  
  198. echo ""
  199. echo ">>>>>>>>  SETTING TIME SERVER"
  200. systemsetup -setusingnetworktime on
  201. systemsetup -settimezone America/Los_Angeles
  202. systemsetup -setnetworktimeserver time.getty.edu
  203. echo "time server set to time.getty.edu"
  204.  
  205. echo ""
  206. echo ">>>>>>>>  SETTING SSH"
  207. systemsetup -setremotelogin on
  208. echo "SSH has been turned on."
  209.  
  210. echo ""
  211. echo ">>>>>>>>  SETTING SUS TO REPOSADO"
  212. case `sw_vers -productVersion | awk -F . '{print $2}'` in
  213.   4) URL="${RepoURL}/index-1_production.sucatalog" ;;  
  214.   5) URL="${RepoURL}/index-leopard.merged-1_production.sucatalog" ;;      
  215.   6) URL="${RepoURL}/index-leopard-snowleopard.merged-1_production.sucatalog" ;;  
  216.   7) URL="${RepoURL}/index-lion-snowleopard-leopard.merged-1_production.sucatalog" ;;
  217.   8) URL="${RepoURL}/index-mountainlion-lion-snowleopard-leopard.merged-1_production.sucatalog" ;;  
  218.   *) echo "Unsupported client OS"; exit 1 ;;
  219. esac
  220. defaults write /Library/Preferences/com.apple.SoftwareUpdate CatalogURL "${URL}"
  221. echo "Software Update Server set to PRODUCTION branch at: $URL"
  222.  
  223. echo ""
  224. echo ">>>>>>>>  SET ALL >500 USERS AS ADMIN"
  225. for i in $over500
  226. do
  227.     echo $admins | grep $i
  228.     if [ $? -ne 0 ]; then
  229.         dscl . -append /groups/admin users $i
  230.         echo "The $i account WASN'T administrative but now IS."
  231.     else
  232.         echo "The $i account was already administrative."
  233.     fi
  234. done
  235. echo "Members of the admin group include:"
  236. dscl . -read /groups/admin GroupMembership
  237.  
  238.  
  239. echo ""
  240. echo ">>>>>>>>  SET ALL >500 USERS TO ENABLE JAVA WEB PLUG-INS"
  241. for i in $over500
  242. do
  243.     rm -f /Users/$i/Library/Preferences/ByHost/com.apple.java.JavaPreferences.*
  244.     echo "JavaPrefs plist has been deleted from: $i account"
  245.     echo "The Mac UUID has been set to: $MAC_UUID"
  246.  
  247.     ### ----- Set the "Enable applet plug-in" setting in the Java Preferences for the current user.
  248.  
  249.     $PlistBuddy -c "Delete :GeneralByTask:Any:WebComponentsEnabled" /Users/$USER/Library/Preferences/ByHost/com.apple.java.JavaPreferences.${MAC_UUID}.plist
  250.     $PlistBuddy -c "Add :GeneralByTask:Any:WebComponentsEnabled bool true" /Users/$USER/Library/Preferences/ByHost/com.apple.java.JavaPreferences.${MAC_UUID}.plist
  251.     $PlistBuddy -c "Delete :GeneralByTask:Any:WebComponentsLastUsed" /Users/$USER/Library/Preferences/ByHost/com.apple.java.JavaPreferences.${MAC_UUID}.plist
  252.     $PlistBuddy -c "Add :GeneralByTask:Any:WebComponentsLastUsed real $(( $(date "+%s") - 978307200 ))" /Users/$USER/Library/Preferences/ByHost/com.apple.java.JavaPreferences.${MAC_UUID}.plist
  253.     echo "                                   "
  254. done
  255. echo "Java Web-Apps have been enabled for ALL 500+ users on this Mac."
  256.  
  257. echo "
  258. # ---------------------------------------------------------
  259. #  -------------------- DELETIONS ------------------------
  260. # ---------------------------------------------------------"
  261.  
  262. rm -dr /Applications/Xerox
  263. rm -f /Envelope\ Index
  264. rm -f /10.5.9
  265. rm -f /ppdmgr
  266. ### ----- RESET SYNC SERVICES
  267. rm -dr /Users/workstation/Library/Application\ Support/SyncServices/Local
  268. ### ----- RESET FLASH
  269. rm -dr /Users/workstation/Library/Preferences/Macromedia
  270. ### ----- RESET M$ Fonts
  271. rm -f "$MS"/Arial.ttf
  272. rm -f "$MS"Arial\ Italic.ttf
  273. rm -f "$MS"Arial\ Bold.ttf
  274. rm -f "$MS"Arial\ Bold\ Italic.ttf
  275. rm -f "$MS"Brush\ Script.ttf
  276. rm -f "$MS"Times\ New\ Roman.ttf
  277. rm -f "$MS"Times\ New\ Roman\ Italic.ttf
  278. rm -f "$MS"Times\ New\ Roman\ Bold.ttf
  279. rm -f "$MS"Times\ New\ Roman\ Bold\ Italic.ttf
  280. rm -f "$MS"Verdana.ttf
  281. rm -f "$MS"Verdana\ Italic.ttf
  282. rm -f "$MS"Verdana\ Bold.ttf
  283. rm -f "$MS"Verdana\ Bold\ Italic.ttf
  284. rm -f "$MS"Wingdings.ttf
  285. rm -f "$MS"Wingdings\ 2.ttf
  286. rm -f "$MS"Wingdings\ 3.ttf
  287. echo " "
  288. echo "Conflicting items have been removed."
  289.  
  290. echo "
  291. # ---------------------------------------------------------
  292. #  ------------------ INSTALLATIONS ----------------------
  293. # ---------------------------------------------------------"
  294.  
  295. echo ""
  296. echo ">>>>>>>>  INSTALL ALL SUS PATCHES"
  297. softwareupdate -ia
  298. echo "--------------------------"
  299.  
  300. echo ""
  301. echo ">>>>>>>>  INSTALL MCAFEE AGENT"
  302. /usr/local/VSePO/ePO_keys/install.sh -i
  303. echo "McAfee agent has been installed..."
  304.  
  305. echo "
  306. # ---------------------------------------------------------
  307. #  --------------------- SEND MAIL -----------------------
  308. # ---------------------------------------------------------"
  309. if [ ! -d /Library/Server/Mail/Data/spool ]; then
  310.     echo "Creating Unix mail folder hierarchy to enable sendmail..."
  311.     mkdir -p /Library/Server/Mail/Data/spool
  312.     $mail set-permissions
  313.     $mail reload
  314.     sleep 2
  315. fi
  316.  
  317. if [ $firstname = "workstation" ]; then
  318.     firstname=SHARED
  319. fi
  320.  
  321. $mail start
  322. echo "A new Mac has been deployed. The computer information is as follows:
  323.  
  324. Date: `date "+%m/%d/%Y"`
  325. Time: `date "+%H:%M"`
  326. Delivered: $delivasset
  327. Removed: $removeasset
  328. Name: GT$delivasset-$firstname-$lastname
  329. Type: $hwVers
  330. OS: $OS
  331. IP: $ip" | mail -s "New Mac Deployment: GT$delivasset-$firstname-$lastname" dkoff@getty.edu, cnorris@getty.edu
  332.  
  333. $mail stop
  334.  
  335. #----------------------------------------------------------
  336. #  Wrap-Up
  337. #----------------------------------------------------------
  338.  
  339. # Removes the launchd items and scripts
  340. echo "Pausing 2 seconds before deleting scripts & launch daemons..."
  341. sleep 2
  342. rm -f $0
  343. echo "$0 has now been deleted."
  344. rm -f /Library/LaunchAgents/org.getty.nointerrupt.plist
  345. echo "The jamfHelper LaunchDaemon has been deleted."                                      
  346. killall -m jamfHelper
  347.  
  348.  
  349. echo "                                   "
  350. echo "###################################"
  351. echo "##### End Log"
  352. echo "##### `date "+%A %m/%d/%Y %H:%M"`"
  353. echo "###################################"
  354. echo "                                   "
  355.  
  356. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement