adamchilcott icon

byodTasks.sh

adamchilcott | PRO | 08/22/17 01:22:39 AM UTC | 0 ⭐ | 1097 👁️ | Never ⏰ | []
Bash |

5.89 KB

|

None

|

0 👍

/

0 👎

#!/usr/bin/env bash
 
########################
# Automate Student Tasks
########################
 
while true; do
 
cat << BANNER
 
###################################
# 1. Configure Student Wi-Fi
# 2. Configure Printing
# 3. Install MS Office For Students
# 4. Drop Back To The Shell
###################################
 
BANNER
 
printf "Please Select An Option: "
read -r userOption
 
case $userOption in
 
"1")
declare wifiDevice
wifiDevice=$(/usr/sbin/networksetup -listallhardwareports | awk '/^Hardware Port: Wi-Fi/,/^Ethernet Address/' | head -2 | tail -1 | cut -c 9-)
declare wifiSSID='Avondale'
declare wifiSecurity='WPA2E'
declare ssidIndex='0'
networksetup -setairportpower "$wifiDevice" off
networksetup -removepreferredwirelessnetwork "$wifiDevice" "$wifiSSID"
networksetup -addpreferredwirelessnetworkatindex "$wifiDevice" "$wifiSSID" "$ssidIndex" "$wifiSecurity"
networksetup -setairportpower "$wifiDevice" on
;;
 
"2")
declare tempMountPoint='/tmp/mnt/'
declare serverName='lmpr0801.avondale.edu.au'
declare dmgLocation='lmpr0801.avondale.edu.au/PCClient/mac/'
declare dmgFile='MAC DRIVER.dmg'
declare pkgLocation='/Volumes/Fuji Xerox PS Plug-in Installer/Fuji Xerox PS Plug-in Installer.pkg'
declare dmgVolume='/Volumes/Fuji Xerox PS Plug-in Installer'
 
##############################
# Create Temporary Mount Point
##############################
mkdir "$tempMountPoint"
 
#####################################
# Add Remote Server To Users KeyChain
#####################################
find /Users -maxdepth 1 -type d | more
printf "Please Enter Your System UserName: "
read -r systemUser
printf "Please Enter Your System Password: "
read -r -s systemPass
security unlock-keychain -p "$systemPass" "/Users/$systemUser/Library/Keychains/login.keychain"
printf "\n"
printf "Please Enter Your Avondale UserName e.g. s14054524: "
read -r userName
printf "Please Enter Your Avondale Password: "
read -r -s userPass
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"
 
#####################
# Mount Remote Server
#####################
mount -t smbfs //"$userName"@"$dmgLocation" "$tempMountPoint"
 
#############
# Mount *.dmg
#############
hdiutil attach "$tempMountPoint$dmgFile"
 
###############
# Install *.pkg
###############
installer -pkg "$pkgLocation" -target /
 
####################
# Configure Printers
####################
declare printerName='MyPrintQueue'
declare printerURI='smb://LMPR0801.avondale.edu.au/MyPrintQueue'
declare printerDescription='MyPrintQueue'
declare printerLocation='MyPrintQueue'
declare printerModel='/Library/Printers/PPDs/Contents/Resources/FX DocuCentre-V C4475 T2 PS.gz'
 
####################
# Configure Queue(s)
####################
lpadmin\
 -x "$printerName"
 
lpadmin\
 -p "$printerName"\
 -E \
 -v "$printerURI"\
 -D "$printerDescription"\
 -L "$printerLocation"\
 -m "$printerModel"
 
###########################
# Configure PaperCut Client
###########################
declare pcclientLocal='/Applications/PCClient.app'
declare pcclientRemote='/tmp/mnt/PCClient.app'
 
killall "JavaAppLauncher"
rm -r "/Applications/PCClient.app"
rm -r "$HOME/Library/Preferences/PCClient/config.properties"
rm -r "$HOME/Library/Preferences/PCClient/pc-auth.cookie"
ditto -v "$pcclientRemote" "$pcclientLocal"
chown -R root:wheel "$pcclientLocal"
chmod -R 775 "$pcclientLocal"
chmod -R +x "$pcclientLocal"
 
##########
# Clean-Up
##########
hdiutil detach -force "$dmgVolume"
sleep .5
umount -f "$tempMountPoint"
 
#prinf "Please Enter Your System User: "
#read -r systemUser
#su "$systemUser" -c open $pcclientLocal
;;
 
"3")
################################
# Install MS Office For Students
################################
printf "Please Enter The USB Volume Name e.g. SANDISK: "
read -r usbName
declare pkgLocation='packages.d'
declare pkgFile='Microsoft_Office_2016_15.37.17081500_Installer.pkg'
ditto -v "/Volumes/$usbName/$pkgLocation/$pkgFile" /tmp
installer -pkg "/tmp/$pkgFile" -target /
;;
 
"4")
exit
;;
*) prinf "Invalid Option";;
 
esac
 
done
 
#############
# START NOTES
#############
 
# 2-clause license ("Simplified BSD License" or "FreeBSD License")
#
# Copyright © 2018, Adam Brian Chilcott
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and documentation are those
# of the authors and should not be interpreted as representing official policies,
# either expressed or implied, of the FreeBSD Project.
 
###########
# END NOTES
###########

Comments