Hi Everyone,
Can anybody tell why this script isn't working? As part of our deployment, we're trying to name the computers and set whether it's a Faculty or Student machine. If it's Faculty, we enter the Faculty user. If it's Student, it just sets the Department as "Student".
Oddly, it seems to go right to "You must enter a Computer Name please try again" (without even prompting to enter it first). It then skips the Machine Type part, and is defaulting to Faculty Machine (which then prompts to enter the Faculty user).
For another wrinkle, it seems to work as expected when we do it from Terminal, but as part of the deployment, it skips around.
Any help would be greatly appreciated!
#!/bin/bash
###
#
#Computer Name Setup
#
###
# Loop until valid input is entered or Cancel is pressed.
while :
do
computerName=$(osascript -e 'Tell application "System Events" to display dialog "Computer Name" default answer ""' -e 'text returned of result' 2>/dev/null)
#if (( $? ));
# then exit 1; fi # Abort, if user pressed Cancel.
computerName=$(echo "$computerName" | sed 's/^ *//' | sed 's/ *$//') # Trim leading and trailing whitespace.
computerName=$(echo "$computerName" | sed 's/ /-/g') # Replace spaces with -
if [ -z "$computerName" ]
then
# The user left the name blank
osascript -e 'Tell application "System Events" to display alert "You must enter a computer name. Please try again" as warning' >/dev/null
# Continue loop to prompt again.
else
# Valid input: exit loop and continue.
break
fi
done
computerType=$(osascript -e 'return choose from list {"Students", "Faculty-Staff"} with title "Machine Type" with prompt "Please select machine type" default items "Students" empty selection allowed false' 2>/dev/null)
#if [ "$computerType" = "false" ]] ;
# then exit 1; fi # Abort, if user pressed Cancel.
if [ "$computerType" = "Students" ]
then
#sets computer department to student in JamfPro
echo $computerType
sudo jamf recon -department $computerType
sleep 7
else
userName=$(osascript -e 'Tell application "System Events" to display dialog "Enter Faculty/Staff User Name" default answer ""' -e 'text returned of result' 2>/dev/null)
echo $userName
sudo jamf recon -endUsername $userName
sleep 7
fi
/usr/sbin/scutil --set ComputerName ${computerName}
/usr/sbin/scutil --set LocalHostName ${computerName}
/usr/sbin/scutil --set HostName ${computerName}
exit 0