Files
Alte_Skripte/de.ing.Alerter_Notifikation.sh
2026-02-16 15:05:15 +01:00

79 lines
3.0 KiB
Bash

#!/bin/bash
set -x
##########################################################################
# Script : Alerter
# Autor : Andreas Vogel
# Copyright : macenterprise gmbh, 2020
##########################################################################
# Variablen
#
# App_ID="${4}" -> Identifier, mit dem Icon der Alerter startet. Wird keiner bestimmt,
# wird der für den Self Service verwendet. -> Optional
# Message="${5}" -> Text der mit angezeigt wird. Wird kein Text angegeben, wird die Meldung
# "Das Udate steht bereit" angezeigt. -> Optional
# TimeOut="${6}" -> Zeit in Sekunden, wie lange die Meldung angezeigt wird.
# Ohne Angabe, wird der Wert 300 Sekunden gewählt. -> Optional
# Policy_ID="${7}" -> Welche Policy soll ausgeführt werden, wenn "Update Now" gewählt wird.
# Zudem wird die Variable genutzt, um die Policy im Self Service an zu zeigen. -> Pflicht
################################ Alerter Version##########################
macOS_Version=$(sw_vers -productVersion)
if [[ "$macOS_Version" == *"10.15"* ]]
then
alerter_verion=/Library/Application\ Support/JAMF/alerter
else
alerter_verion=/Library/Application\ Support/JAMF/alerter\ 2
fi
echo $alerter_verion
################################ User ####################################
fGetCurrenUser (){
currentUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");'`
# Identify the UID of the logged-in user
currentUserUID=`id -u "$currentUser"`
}
user=$(stat -f '%u %Su' /dev/console | cut -d ' ' -f 2)
################################ Variablen ################################
App_Icon="${4}"
if [[ -z "$App_Icon" ]]; then
App_Icon="/Users/$user/Library/Application Support/com.jamfsoftware.selfservice.mac/Documents/Images/brandingimage.png"
fi
Message="${5}"
if [[ -z "$Message" ]]; then
Message="Das Udate steht bereit"
fi
TimeOut="${6}"
if [[ -z "$TimeOut" ]]; then
TimeOut=10
fi
Policy_ID="${7}"
################################ Ausführung ################################
fGetCurrenUser
Alerter="$(/bin/launchctl asuser "$currentUserUID" "$alerter_verion" -appIcon "$App_Icon" -title "Client Service Mac" -message "$Message" -closeLabel "OK" -actions "Update now","Show in Self Service" -dropdownLabel "Other option" -timeout $TimeOut)"
echo "Alerter Exit Code: $Alerter"
if [ "$Alerter" == "OK" ] || [[ "$Alerter" == "@TIMEOUT" ]]
then
exit 0
elif [ "$Alerter" == "Update now" ]; then
jamf policy -id $Policy_ID
else
if [ "$Alerter" == "Show in Self Service" ] || [[ "$Alerter" == "@CONTENTCLICKED" ]];then
/bin/launchctl asuser "$currentUserUID" sudo -u "$user" /usr/bin/open "jamfselfservice://content?entity=policy&id=$Policy_ID&action=view"
fi
fi