Advertisement
themacdweeb

1stBoot-OverTheWireInstallation.sh

Oct 16th, 2013
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 11.44 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # 1st boot script runs as a Launchd startup script,
  4. # then deletes itself after completion. Fixes problems left by Apple.
  5. # Copyright, David Koff 2013© for the J. Paul Getty Trust
  6. #
  7. # Created: 3.15.13
  8. # Last Updated: 5.7.13
  9.  
  10. #----------------------------------------------------------
  11. #   Variables
  12. #----------------------------------------------------------
  13.  
  14. #-----Assignments
  15. SCRIPTNAME=$0
  16. user405=ard
  17.  
  18. #--- Set Logging
  19. exec >> "/Library/Logs/Getty Installations.log" 2>&1
  20.  
  21. #-----Directories & Files
  22. kickstart="/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart"
  23. systemsetup="/usr/sbin/systemsetup"
  24. PlistBuddy="/usr/libexec/PlistBuddy"
  25. login="/Library/Preferences/com.apple.loginwindow"
  26. xProtect_MetaPlist="$3/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/XProtect.meta.plist"
  27. xProtect_Plist="$3/System/Library/LaunchDaemons/com.apple.xprotectupdater.plist"
  28. LaunchDaemons="/System/Library/LaunchDaemons"
  29. LaunchDaemonsDisabled="/System/Library/LaunchDaemonsDisabled"
  30. RepoURL="http://xserve-timcook.getty.edu:8088/content/catalogs/others"
  31.  
  32. #-----Computationals
  33. xProtect=`launchctl list | grep com.apple.xprotectupdater`
  34. over500=`dscl . list /Users UniqueID | awk '$2 > 500 { print $1 }'`
  35. USER=`defaults read $login lastUserName`
  36. MSpid=`ps -ax | grep Microsoft | cut -c 1-5`
  37. macname=`systemsetup -getcomputername | awk '{ print $3 }'`
  38. hwVers=`system_profiler | grep "Model Name" | awk '{ print $3, $4, $5 }'`
  39. OS=`sw_vers | grep ProductVersion | awk '{ print $2 }'`
  40. ip=`ifconfig | grep "inet 153" | cut -d ' ' -f 2`
  41.  
  42. #-----Array
  43. Apps2Quit=( Safari firefox-bin firefox JavaApplicationStub groupwise ) ### use of array allows us to add/subtract titles
  44.  
  45.  
  46. #-----Dynamically Set
  47. if [[ `ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c27-50` == "00000000-0000-1000-8000-" ]]; then
  48.     MAC_UUID=`ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c51-62 | awk {'print tolower()'}`
  49. elif [[ `ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c27-50` != "00000000-0000-1000-8000-" ]]; then
  50.     MAC_UUID=`ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c27-62`
  51. fi
  52.  
  53. #----------------------------------------------------------
  54. #  Timestamp
  55. #----------------------------------------------------------
  56. echo "                                   "
  57. echo "###################################"
  58. echo "##### $SCRIPTNAME"
  59. echo "##### `date "+%A %m/%d/%Y %H:%M"`"
  60. echo "###################################"
  61. echo "                                   "
  62.  
  63. echo "
  64. # ---------------------------------------------------------
  65. #  ---------------------- FIXES --------------------------
  66. # ---------------------------------------------------------"
  67.  
  68. echo ">>>>>>>>  RECREATE ARD ACCOUNT IF BROKEN"
  69. if [ -d /private/var/$user405 ]; then
  70.     echo "the ard directory is already present, no need to recreate..."
  71. else
  72.     mkdir /private/var/$user405
  73. fi
  74. dscl . -create /Users/$user405
  75. dscl . -create /Users/$user405 realname "${user405}"
  76. dscl . -create /Users/$user405 NFSHomeDirectory /private/var/$user405
  77. chown -R $user405 /private/var/$user405
  78. dscl . -passwd /Users/$user405 ma5ter
  79. dscl . -create /Users/$user405 PrimaryGroupID 405
  80. dscl . -create /Users/$user405 UniqueID 405
  81. dscl . -create /Users/$user405 shell /bin/bash
  82. dscl . -append /Groups/admin GroupMembership $user405
  83. defaults write $login Hide500Users -bool TRUE  ### hides this user from user list and user switching
  84. defaults write $login HiddenUsersList -array add $user405 ### hides this user from login screen
  85.  
  86. echo ""
  87. echo ">>>>>>>>  PREVENT iCLOUD WIZARD FROM RUNNING"
  88. # in any user account
  89. for i in $over500
  90. do
  91.     defaults write /Users/$i/Library/Preferences/com.apple.SetupAssistant DidSeeCloudSetup -bool TRUE
  92.     defaults write /Users/$i/Library/Preferences/com.apple.SetupAssistant LastSeenCloudProductVersion -string '10.8'
  93.     chown "${i}":staff /Users/$i/Library/Preferences/com.apple.SetupAssistant.plist
  94.     echo "iCloud wizard removed from the $i account..."
  95. done
  96.  
  97. #in the user template
  98. for USER_TEMPLATE in "/System/Library/User Template"/*
  99. do
  100.     defaults write "${USER_TEMPLATE}"/Library/Preferences/com.apple.loginwindow -dict#creates a blank file if none exists
  101.     defaults write "${USER_TEMPLATE}"/Library/Preferences/loginwindow -dict#creates a blank file if none exists
  102.     defaults write "${USER_TEMPLATE}"/Library/Preferences/com.apple.SetupAssistant DidSeeCloudSetup -bool TRUE
  103.     defaults write "${USER_TEMPLATE}"/Library/Preferences/com.apple.SetupAssistant LastSeenCloudProductVersion -string '10.8'
  104.     echo "com.apple.SetupAssistant for the $USER_TEMPLATE now won't propmpt for iCloud..."
  105. done
  106.  
  107. echo ""
  108. echo ">>>>>>>>  DISABLE XPROTECT"
  109. if [ -f $LaunchDaemons/com.apple.xprotectupdater.plist ]; then
  110.     echo "x-Protect has been found in $LaunchDaemons and will now be edited and unloaded:"
  111.     $PlistBuddy -c "Delete :JavaWebComponentVersionMinimum" "$xProtect_MetaPlist"
  112.     echo "     Minimum Java Component removed from x-Protect."
  113.     $launchctl unload -w "$xProtect_Plist"
  114.     echo "     x-Protect has been unloaded via launchctl."
  115.     if [ ! -d $LaunchDaemonsDisabled ]; then
  116.         echo ""
  117.         echo "Now creating: $LaunchDaemonsDisabled to store xProtect plist:"
  118.         mkdir -v $LaunchDaemonsDisabled
  119.     else
  120.         echo ""
  121.         echo "$LaunchDaemonsDisabled:"
  122.         echo "     Directory found & emptied."
  123.         echo "     x-Protect moved into that directory:"
  124.         rm -fv $LaunchDaemonsDisabled/*
  125.         mv -v $LaunchDaemons/com.apple.xprotectupdater.plist $LaunchDaemonsDisabled
  126.     fi
  127. else
  128.     echo "x-Protect hasn't been found in: $LaunchDaemons"
  129.     if [ -f $LaunchDaemonsDisabled/com.apple.xprotectupdater.plist ]; then
  130.         echo "It has already been moved to: $LaunchDaemonsDisabled"
  131.     fi
  132. fi
  133.  
  134. echo "
  135. # ---------------------------------------------------------
  136. #  ------------ PREFERENCE MODIFICATIONS -----------------
  137. # ---------------------------------------------------------"
  138.  
  139. echo ""
  140. echo ">>>>>>>>  SET PROPER ARD PREFS"
  141. $kickstart -activate
  142. $kickstart -configure -users ard -access -on -privs -DeleteFiles -TextMessages -OpenQuitApps -GenerateReports -RestartShutdown -SendFiles -ChangeSettings -clientopts -setmenuextra -menuextra no -setreqperm -reqperm yes
  143.  
  144. echo ""
  145. echo ">>>>>>>>  SET PROPER SSH PREFS"
  146. $systemsetup -setremotelogin on
  147.  
  148. echo ""
  149. echo ">>>>>>>>  SET PROPER TIME PREFS"
  150. $systemsetup -setusingnetworktime on
  151. $systemsetup -settimezone America/Los_Angeles
  152. $systemsetup -setnetworktimeserver time.getty.edu
  153.  
  154. echo "
  155. #----------------------------------------------------------
  156. # ------------------- INSTALLATIONS ----------------------
  157. #----------------------------------------------------------"
  158.  
  159. echo ""
  160. echo ">>>>>>>>  QUIT COMPETING APPS" #Mar2013
  161. killall "${Apps2Quit[@]}"
  162. kill $MSpid
  163.  
  164. echo ""
  165. echo ">>>>>>>>  QUIT EPO"
  166. sudo launchctl unload /Library/LaunchDaemons/com.mcafee.ssm.ScanManager.plist
  167. sudo /usr/local/McAfee/Antimalware/VSControl stop
  168.  
  169. echo ""
  170. echo ">>>>>>>>  SET TO REPOSADO & RUN INSTALLS"
  171. case `sw_vers -productVersion | awk -F . '{print $2}'` in
  172.   4) URL="${RepoURL}/index-1_production.sucatalog" ;;  
  173.   5) URL="${RepoURL}/index-leopard.merged-1_LabTesters.sucatalog" ;;      
  174.   6) URL="${RepoURL}/index-leopard-snowleopard.merged-1_LabTesters.sucatalog" ;;  
  175.   7) URL="${RepoURL}/index-lion-snowleopard-leopard.merged-1_LabTesters.sucatalog" ;;
  176.   8) URL="${RepoURL}/index-mountainlion-lion-snowleopard-leopard.merged-1_LabTesters.sucatalog" ;;  
  177.   *) echo "Unsupported client OS"; exit 1 ;;
  178. esac
  179. defaults write /Library/Preferences/com.apple.SoftwareUpdate CatalogURL "${URL}"
  180. echo "Software Update Server set to PRODUCTION branch at: $URL"
  181. echo "Now installing Apple updates:"
  182. softwareupdate -ia
  183.  
  184. echo ""
  185. echo ">>>>>>>>  CUSTOM TRIGGER INSTALLATIONS"
  186. echo "Apple updates have installed. Now calling a custom policy to:"
  187. echo "Install Java & Flash"
  188. jamf policy -trigger UpgradeMountainLion
  189.  
  190. echo ""
  191. echo ">>>>>>>>  RESTART EPO"
  192. sudo launchctl load /Library/LaunchDaemons/com.mcafee.ssm.ScanManager.plist
  193. sudo /usr/local/McAfee/Antimalware/VSControl mastart
  194.  
  195. echo "
  196. #----------------------------------------------------------
  197. # ----------------------- JAVA ---------------------------
  198. #----------------------------------------------------------"
  199.  
  200. echo ""
  201. echo ">>>>>>>>  FIX JAVA: CONFIRM PLUG-IN REVERTED TO JSE 6"
  202. echo "Now checking Java SE 6 Status...."
  203. if [ ! -d /Library/Internet\ Plug-Ins/disabled ]; then
  204.     mkdir -pv /Library/Internet\ Plug-Ins/disabled
  205.     mv -v /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin /Library/Internet\ Plug-Ins/disabled
  206.     ln -sf /System/Library/Java/Support/Deploy.bundle/Contents/Resources/JavaPlugin2_NPAPI.plugin /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
  207.     ln -sf /System/Library/Frameworks/JavaVM.framework/Commands/javaws /usr/bin/javaws
  208.     echo "Java reverted to JSE 6 on this Mac..."
  209. else
  210.     echo "The java applet has already been reverted to SE 6 and the newer plug-ins moved."
  211. fi
  212.  
  213. echo ""
  214. echo ">>>>>>>>  ENABLE JAVA PLUG-INS"
  215. for i in $over500
  216. do
  217.     echo "-------------------------------------------------"
  218.     rm -fv /Users/$i/Library/Preferences/ByHost/com.apple.java.JavaPreferences.*
  219.     echo "JavaPrefs plist has been deleted from: $i account"
  220.     echo "The Mac UUID has been set to: $MAC_UUID"
  221.     # Set the "Enable applet plug-in" setting in the Java Preferences for the current user.
  222.     $PlistBuddy -c "Delete :GeneralByTask:Any:WebComponentsEnabled" /Users/$USER/Library/Preferences/ByHost/com.apple.java.JavaPreferences.${MAC_UUID}.plist
  223.     $PlistBuddy -c "Add :GeneralByTask:Any:WebComponentsEnabled bool true" /Users/$USER/Library/Preferences/ByHost/com.apple.java.JavaPreferences.${MAC_UUID}.plist
  224.     $PlistBuddy -c "Delete :GeneralByTask:Any:WebComponentsLastUsed" /Users/$USER/Library/Preferences/ByHost/com.apple.java.JavaPreferences.${MAC_UUID}.plist
  225.     $PlistBuddy -c "Add :GeneralByTask:Any:WebComponentsLastUsed real $(( $(date "+%s") - 978307200 ))" /Users/$USER/Library/Preferences/ByHost/com.apple.java.JavaPreferences.${MAC_UUID}.plist
  226.     echo "                                   "
  227. done
  228. echo "Java Web-Apps have been enabled for ALL 500+ users on this Mac."
  229.  
  230. echo "
  231. #----------------------------------------------------------
  232. # --------------------- SEND EMAIL -----------------------
  233. #----------------------------------------------------------"
  234. if [ ! -d /Library/Server/Mail/Data/spool ]; then
  235.     echo "Creating Unix mail folder hierarchy to enable sendmail..."
  236.     mkdir -p /Library/Server/Mail/Data/spool
  237.     $mail set-permissions
  238.     $mail reload
  239.     sleep 2
  240. fi
  241.  
  242. $mail start
  243. echo "An OTW upgrade has been performed on this Mac. Computer information follows:
  244.  
  245. Date: `date "+%m/%d/%Y"`
  246. Time: `date "+%H:%M"`
  247. Name: $macname
  248. Type: $hwVers
  249. OS: $OS
  250. IP: $ip" | mail -s "OTW Install Notification: $macname" dkoff@getty.edu, cnorris@getty.edu
  251. $mail stop
  252.  
  253. echo ""
  254. echo "e-mail has been sent to ITS Lab SysAdmins."
  255.  
  256. #----------------------------------------------------------
  257. #  Wrap-Up
  258. #----------------------------------------------------------
  259.  
  260. # Removes the launchd items & scripts
  261. sleep 2
  262. rm -f $0
  263. echo "$0 has now been deleted."
  264. rm -f /Library/LaunchDaemons/com.getty.NewOS1stBoot.plist
  265. echo "The 1stBoot LaunchDaemon have been deleted."                                              
  266.  
  267. echo "                                   "
  268. echo "###################################"
  269. echo "##### End Log"
  270. echo "##### `date "+%A %m/%d/%Y %H:%M"`"
  271. echo "###################################"
  272. echo "                                   "
  273.  
  274. /sbin/reboot #force reboot to bake it in
  275.  
  276. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement