Hi,
i am trying to script the final step in our onboarding process, where the user is presented with a list of Locations to chose, and once selected, the script will pull the serial number and rename the machine the location-serialnumber
I'm 90% sure I have it right but i am getting echo errors when testing in CodeRunner... and i'd appreciate some extra eyes / advice....
#!/bin/bash
#/usr/local/bin/dialog
# Pull device serial number for lookup
serialNumber=$(ioreg -c IOPlatformExpertDevice -d 2 | awk -F\\" '/IOPlatformSerialNumber/{print $(NF-1)}')
nserialNumber=${serialNumber}
#Specify variables for swiftDialog
dialogInstalled="/usr/local/bin/dialog"
downloadDialog="https://github.com/swiftDialog/swiftDialog/releases/download/v2.5.1/dialog-2.5.1-4775.pkg"
pathToDownload="/usr/local/dialog"
pathToPackage="/usr/local/dialog/dialog-2.5.1-4775.pkg"
#Check if swiftDialog is installed
if [ -e "$dialogInstalled" ];then
echo "Dialog Is installed"
else
echo "Dialog is not installed"
echo "Creating download directory at $pathToDownload"
mkdir $pathToDownload
echo "Downloading swiftDialog from $downloadDialog"
curl -L $downloadDialog -o $pathToPackage
echo "Installing swift Dialog"
installer -pkg $pathToPackage -target /
wait
fi
location=$(/usr/local/bin/dialog -s --icon /usr/local/images/duck.icns --blurscreen --title "Welcome to swiftDialog" --message "Hi There {username}. <br>Please choose your current location" --selecttitle "Select Location",required --selectvalues "Barcelona, Camden, Cape Town, Durban, Florida, Gold Coast, Gothenburg, IOM, Ipswich, Kyiv, Malaga, Pretoria, Richmond, Stockholm, Sydney" | grep "SelectedOption" | awk -F " : " '{print $NF}' | tr -d '"')
#selection
#
case ${location} in
Barcelona)
invCode='SBA';;
Camden)
invCode='UCA';;
'Cape Town')
invCode='ZCT';;
Durban)
invCode='ZFP';;
Florida)
invCode='ORL';;
'Gold Coast')
invCode='ADI';;
Gothenburg)
invCode='SGB';;
IOM)
invCode='DIL';;
Ipswich)
invCode='UIP';;
Kyiv)
invCode='UKK';;
Malaga)
invCode='SMA';;
Pretoria)
invCode='ZPT';;
Richmond)
invCode='MHL';;
Stockholm)
invCode='SST';;
Sydney)
invCode='ADS';;
esac
echo "Selection was $location setting prefix to $invCode"
computerName="$invCode-$nserialNumber"
echo "Computer Name: $computerName"
echo "Setting computer name to $computerName"
/usr/sbin/scutil --set ComputerName "$computerName"
/usr/sbin/scutil --set LocalHostName "$computerName"
/usr/sbin/scutil --set HostName "$computerName"
dscacheutil -flushcache
/usr/local/bin/jamf recon
exit 0