60 lines
1.6 KiB
Bash
60 lines
1.6 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
|
|
|
|
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 << EOD > /private/tmp/asset_tag.sh
|
|
#!/bin/bash
|
|
|
|
TAG=\$(/usr/bin/osascript -e 'tell application "System Events" to set TAG to text returned of (display dialog "Bitte aktualisiere dein Asset Tag / die Inventarnummer. Diese findest du auf der Unterseite deines MacBooks. Die Nummer beginnt mit 61.... oder 91..." default answer "" buttons {"OK"} default button 1 with icon 2)')
|
|
|
|
echo "\${TAG}" > /private/tmp/asset_tag.txt
|
|
|
|
EOD
|
|
|
|
## Make script executable
|
|
/bin/chmod +x /private/tmp/asset_tag.sh
|
|
|
|
## Run the script as logged in user
|
|
/bin/launchctl asuser "$loggedInUID" sudo -iu "$loggedInUser" "/private/tmp/asset_tag.sh"
|
|
|
|
## Get the new name from the local file
|
|
asset_tag=$(cat /tmp/asset_tag.txt)
|
|
|
|
if [ ! -z "$asset_tag" ]; then
|
|
echo "$asset_tag"
|
|
## Set Asset Tag
|
|
jamf recon -assetTag "$asset_tag"
|
|
|
|
## Remove local script
|
|
rm -f /private/tmp/asset_tag.sh
|
|
|
|
exit 0
|
|
else
|
|
echo "No name was found to rename to"
|
|
|
|
## Remove local script
|
|
rm -f /private/tmp/asset_tag.sh
|
|
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "No-one logged in. Exiting"
|
|
exit 0
|
|
fi
|
|
|