Advertisement
adamchilcott

byodTasks.sh

Aug 21st, 2017
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.89 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. ########################
  4. # Automate Student Tasks
  5. ########################
  6.  
  7. while true; do
  8.  
  9. cat << BANNER
  10.  
  11. ###################################
  12. # 1. Configure Student Wi-Fi
  13. # 2. Configure Printing
  14. # 3. Install MS Office For Students
  15. # 4. Drop Back To The Shell
  16. ###################################
  17.  
  18. BANNER
  19.  
  20. printf "Please Select An Option: "
  21. read -r userOption
  22.  
  23. case $userOption in
  24.  
  25. "1")
  26. declare wifiDevice
  27. wifiDevice=$(/usr/sbin/networksetup -listallhardwareports | awk '/^Hardware Port: Wi-Fi/,/^Ethernet Address/' | head -2 | tail -1 | cut -c 9-)
  28. declare wifiSSID='Avondale'
  29. declare wifiSecurity='WPA2E'
  30. declare ssidIndex='0'
  31. networksetup -setairportpower "$wifiDevice" off
  32. networksetup -removepreferredwirelessnetwork "$wifiDevice" "$wifiSSID"
  33. networksetup -addpreferredwirelessnetworkatindex "$wifiDevice" "$wifiSSID" "$ssidIndex" "$wifiSecurity"
  34. networksetup -setairportpower "$wifiDevice" on
  35. ;;
  36.  
  37. "2")
  38. declare tempMountPoint='/tmp/mnt/'
  39. declare serverName='lmpr0801.avondale.edu.au'
  40. declare dmgLocation='lmpr0801.avondale.edu.au/PCClient/mac/'
  41. declare dmgFile='MAC DRIVER.dmg'
  42. declare pkgLocation='/Volumes/Fuji Xerox PS Plug-in Installer/Fuji Xerox PS Plug-in Installer.pkg'
  43. declare dmgVolume='/Volumes/Fuji Xerox PS Plug-in Installer'
  44.  
  45. ##############################
  46. # Create Temporary Mount Point
  47. ##############################
  48. mkdir "$tempMountPoint"
  49.  
  50. #####################################
  51. # Add Remote Server To Users KeyChain
  52. #####################################
  53. find /Users -maxdepth 1 -type d | more
  54. printf "Please Enter Your System UserName: "
  55. read -r systemUser
  56. printf "Please Enter Your System Password: "
  57. read -r -s systemPass
  58. security unlock-keychain -p "$systemPass" "/Users/$systemUser/Library/Keychains/login.keychain"
  59. printf "\n"
  60. printf "Please Enter Your Avondale UserName e.g. s14054524: "
  61. read -r userName
  62. printf "Please Enter Your Avondale Password: "
  63. read -r -s userPass
  64. security add-internet-password -l "$serverName" -a "$userName" -w "$userPass" -D "internet password" -r "smb " -s "$serverName" -T "/System/Library/CoreServices/NetAuthAgent.app/Contents/MacOS/NetAuthSysAgent"
  65.  
  66. #####################
  67. # Mount Remote Server
  68. #####################
  69. mount -t smbfs //"$userName"@"$dmgLocation" "$tempMountPoint"
  70.  
  71. #############
  72. # Mount *.dmg
  73. #############
  74. hdiutil attach "$tempMountPoint$dmgFile"
  75.  
  76. ###############
  77. # Install *.pkg
  78. ###############
  79. installer -pkg "$pkgLocation" -target /
  80.  
  81. ####################
  82. # Configure Printers
  83. ####################
  84. declare printerName='MyPrintQueue'
  85. declare printerURI='smb://LMPR0801.avondale.edu.au/MyPrintQueue'
  86. declare printerDescription='MyPrintQueue'
  87. declare printerLocation='MyPrintQueue'
  88. declare printerModel='/Library/Printers/PPDs/Contents/Resources/FX DocuCentre-V C4475 T2 PS.gz'
  89.  
  90. ####################
  91. # Configure Queue(s)
  92. ####################
  93. lpadmin\
  94.  -x "$printerName"
  95.  
  96. lpadmin\
  97.  -p "$printerName"\
  98.  -E \
  99.  -v "$printerURI"\
  100.  -D "$printerDescription"\
  101.  -L "$printerLocation"\
  102.  -m "$printerModel"
  103.  
  104. ###########################
  105. # Configure PaperCut Client
  106. ###########################
  107. declare pcclientLocal='/Applications/PCClient.app'
  108. declare pcclientRemote='/tmp/mnt/PCClient.app'
  109.  
  110. killall "JavaAppLauncher"
  111. rm -r "/Applications/PCClient.app"
  112. rm -r "$HOME/Library/Preferences/PCClient/config.properties"
  113. rm -r "$HOME/Library/Preferences/PCClient/pc-auth.cookie"
  114. ditto -v "$pcclientRemote" "$pcclientLocal"
  115. chown -R root:wheel "$pcclientLocal"
  116. chmod -R 775 "$pcclientLocal"
  117. chmod -R +x "$pcclientLocal"
  118.  
  119. ##########
  120. # Clean-Up
  121. ##########
  122. hdiutil detach -force "$dmgVolume"
  123. sleep .5
  124. umount -f "$tempMountPoint"
  125.  
  126. #prinf "Please Enter Your System User: "
  127. #read -r systemUser
  128. #su "$systemUser" -c open $pcclientLocal
  129. ;;
  130.  
  131. "3")
  132. ################################
  133. # Install MS Office For Students
  134. ################################
  135. printf "Please Enter The USB Volume Name e.g. SANDISK: "
  136. read -r usbName
  137. declare pkgLocation='packages.d'
  138. declare pkgFile='Microsoft_Office_2016_15.37.17081500_Installer.pkg'
  139. ditto -v "/Volumes/$usbName/$pkgLocation/$pkgFile" /tmp
  140. installer -pkg "/tmp/$pkgFile" -target /
  141. ;;
  142.  
  143. "4")
  144. exit
  145. ;;
  146. *) prinf "Invalid Option";;
  147.  
  148. esac
  149.  
  150. done
  151.  
  152. #############
  153. # START NOTES
  154. #############
  155.  
  156. # 2-clause license ("Simplified BSD License" or "FreeBSD License")
  157. #
  158. # Copyright © 2018, Adam Brian Chilcott
  159. # All rights reserved.
  160. #
  161. # Redistribution and use in source and binary forms, with or without
  162. # modification, are permitted provided that the following conditions are met:
  163. #
  164. # 1. Redistributions of source code must retain the above copyright notice, this
  165. # list of conditions and the following disclaimer.
  166. # 2. Redistributions in binary form must reproduce the above copyright notice,
  167. # this list of conditions and the following disclaimer in the documentation
  168. # and/or other materials provided with the distribution.
  169. #
  170. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  171. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  172. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  173. # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  174. # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  175. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  176. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  177. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  178. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  179. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  180. #
  181. # The views and conclusions contained in the software and documentation are those
  182. # of the authors and should not be interpreted as representing official policies,
  183. # either expressed or implied, of the FreeBSD Project.
  184.  
  185. ###########
  186. # END NOTES
  187. ###########
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement