67 lines
1.7 KiB
Bash
67 lines
1.7 KiB
Bash
#!/bin/bash
|
|
|
|
##########################################################################
|
|
# Shellscript : Set Asset Tag
|
|
# Author : Andreas Vogel | Jobst Heinermann
|
|
# Copyright : © macenterprise gmbh, 2019
|
|
# Source : https://www.jamf.com/jamf-nation/discussions/24664/script-to-prompt-for-computer-names
|
|
##########################################################################
|
|
|
|
|
|
#Variabeln
|
|
ToUpdateApp="testting"
|
|
JamfPolicy="123"
|
|
|
|
loggedInUser=$(stat -f%Su /dev/console)
|
|
loggedInUID=$(id -u $loggedInUser)
|
|
|
|
# Abfrage, dass nicht ROOT angemeldet ist
|
|
if [[ "$loggedInUser" != "root" ]] && [[ "$loggedInUser" != "_mbsetup" ]]; then
|
|
|
|
## Create local script
|
|
cat << EOF > /private/tmp/update_message.sh
|
|
|
|
#!/bin/bash
|
|
|
|
buttonClicked=\$(osascript -e 'button returned of (display dialog "$ToUpdateApp muss aktualisiert werden. Anschliessend wird der Rechner neu gestartet." buttons {"Update","Cancel"} default button 1)')
|
|
|
|
echo "\${buttonClicked}" > /private/tmp/update_message.txt
|
|
|
|
EOF
|
|
|
|
|
|
## Make script executable
|
|
/bin/chmod +x /private/tmp/update_message.sh
|
|
|
|
## Run the script as logged in user
|
|
/bin/launchctl asuser "$loggedInUID" sudo -iu "$loggedInUser" "/private/tmp/update_message.sh"
|
|
|
|
## Get the new name from the local file
|
|
update_message=$(cat /tmp/update_message.txt)
|
|
|
|
if [ "$update_message" == "Update" ]; then
|
|
echo "$update_message"
|
|
## Set Asset Tag
|
|
|
|
jamf recon
|
|
|
|
## Remove local script
|
|
rm -f /private/tmp/update_message.sh
|
|
rm -f /private/tmp/update_message.txt
|
|
|
|
exit 0
|
|
else
|
|
echo "Update wurde vom User abgebrochen"
|
|
|
|
## Remove local script
|
|
rm -f /private/tmp/update_message.sh
|
|
rm -f /private/tmp/update_message.txt
|
|
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "No-one logged in. Exiting"
|
|
exit 0
|
|
fi
|
|
|