#!/bin/bash ########################################################################## # Script : Patch Policy # Autor : Andreas Vogel NEXT Enterprise GmbH # Quelle : https://github.com/IBM/mac-ibm-notifications ########################################################################## ################ Varialen ################################################ CurrentUser=$(/usr/sbin/scutil <<< "show State:/Users/ConsoleUser" | /usr/bin/awk -F': ' '/[[:space:]]+Name[[:space:]]:/ { if ( $2 != "loginwindow" ) { print $2 }}') Language=$(/usr/libexec/PlistBuddy -c 'print AppleLanguages:0' "/Users/${CurrentUser}/Library/Preferences/.GlobalPreferences.plist") if [[ $Language = de* ]]; then UserLanguage="de" else UserLanguage="en" fi JSSURL="https://macenterprise.jamfcloud.com/JSSResource" JSSUSER="API_User" JSSPASSWORD="Nextenterprise#1612" UDID=$(system_profiler SPHardwareDataType | grep UUID | awk '" " { print $NF }') xsltFile="/tmp/xsltTemplate.xsl" xmlFile="/tmp/fileName.xml" xmlupdates="/tmp/updates.xml" # Writes out an xslt form /bin/cat < "$xsltFile" EOF /usr/bin/curl -u $JSSUSER:$JSSPASSWORD --tlsv1.2 -H "Accept: application/xml" "$JSSURL/computermanagement/udid/$UDID/subset/policies" | xsltproc "$xsltFile" - > $xmlFile Update_Count=$(grep -c "patch_app_updates" "$xmlFile") sed '/patch_app_updates/!d' $xmlFile > $xmlupdates IDs=($(awk '{ print $1 }' $xmlupdates)) ########################################################################## ################ Customized Notifier ##################################### ########################################################################## COUNTER=0 ################ Message ################################################# if [[ "$Update_Count" -eq 1 ]]; then Plural_en=" " Plural_de=" " elif [[ "$Update_Count" -gt 1 ]]; then Plural_en="s " Plural_de="s " else echo "no patches found, exiting" exit 0 fi Plural=Plural_${UserLanguage} Notifier_Path="/Applications/IBM Notifier.app/Contents/MacOS/IBM Notifier" Type_Message="popup" Icon_Path="/Library/Application Support/Next Enterprise/Next_logo_48x48.png" Bar_Title_Message_en="Update${!Plural}Available" Title__Message_en="Software Update${!Plural}Available" Description_Message_en="You have ${Update_Count} update${!Plural}available in the Self Service." Button_1_Message_en="Update" Button_2_Message_en="Cancel" Bar_Title_Message_de="Update${!Plural}verfügbar" Title__Message_de="Software Update${!Plural}verfügbar" Description_Message_de="Es sind ${Update_Count} update${!Plural}im Self Service Verfügung." Button_1_Message_de="Update" Button_2_Message_de="Abbrechen" Bar_Title_Message=Bar_Title_Message_${UserLanguage} Title_Message=Title__Message_${UserLanguage} Description_Message=Description_Message_${UserLanguage} Button_1_Message=Button_1_Message_${UserLanguage} Button_2_Message=Button_2_Message_${UserLanguage} ################ Progress ################################################ Type_Progress="popup" ACCESSORYTYPE="progressbar" Bar_Title_Progress_en="Update" Title_Progress_en="Updating the old app${!Plural}" Description_Progress_en="The update process is in progress. Please wait until all updates have been installed. The process is completely automatic. Please do not restart the device while the message is displayed." ACCESSORYPAYLOAD_en="/percent indeterminate /bottom_message All available updates will be installed....." Update_Inventory_Message_en="Updating Inventory......" Update_Steps_en="Step" Count_Steps_en="of" Update_Progress_Message_en="Update" Bar_Title_Progress_de="Update" Title_Progress_de="Aktualisierung der alten App${!Plural}" Description_Progress_de="Der Aktualisierungsvorgang ist in Arbeit. Bitte warte, bis alle Updates installiert worden sind. Der Vorgang läuft vollständig automatisch ab. Bitte starte das Gerät während die Meldung angezeigt wird, nicht neu." ACCESSORYPAYLOAD_de="/percent indeterminate" Update_Inventory_Message_de="Aktualisierung des Bestandsverzeichnisses....." Update_Steps_de="Schritt" Count_Steps_de="von" Update_Progress_Message_de="Aktuallisiere" Update_Inventory_Message=Update_Inventory_Message_${UserLanguage} Bar_Title_Progress=Bar_Title_Progress_${UserLanguage} Title_Progress=Title_Progress_${UserLanguage} Description_Progress=Description_Progress_${UserLanguage} ACCESSORYPAYLOAD=ACCESSORYPAYLOAD_${UserLanguage} Update_Steps=Update_Steps_${UserLanguage} Count_Steps=Count_Steps_${UserLanguage} Update_Progress_Message=Update_Progress_Message_${UserLanguage} ################ Function ################################################ policy_progress() { pipe_name="pbnota" # FIFO creation and setup process for updating the progress bar find /private/tmp -name "$pipe_name" -delete mkfifo /private/tmp/${pipe_name} exec 5<> /private/tmp/${pipe_name} # IBM Notifier Progress Bar configuration sudo -u "${CurrentUser}" "${Notifier_Path}" \ -type "${Type_Progress}" \ -title "${!Title_Progress}" \ -bar_title "${!Bar_Title_Progress}" \ -subtitle "${!Description_Progress}" \ -icon_path "${Icon_Path}" \ -accessory_view_type "${ACCESSORYTYPE}" \ -always_on_top \ -accessory_view_payload "${!ACCESSORYPAYLOAD}" < /private/tmp/${pipe_name} & for i in ${IDs[@]} do let COUNTER++ PolicyName=$(/usr/bin/curl -u $JSSUSER:$JSSPASSWORD --tlsv1.2 -H "Accept: application/xml" "$JSSURL/policies/id/$i" | xmllint --xpath '/policy/general/name/text()' - 2>/dev/null) echo "/bottom_message ${!Update_Steps} $COUNTER ${!Count_Steps} $Update_Count ${!Update_Progress_Message}: $PolicyName" >&5 jamf policy -id $i -forceNoRecon done } ################ Checking the available updates ########################## ButtonClicked=$("sudo" "-u" "${CurrentUser}" "${Notifier_Path}" "-type" "${Type_Message}" "-bar_title" "${!Bar_Title_Message}" "-title" "${!Title_Message}" "-subtitle" "${!Description_Message}" "-icon_path" "${Icon_Path}" "-always_on_top" "-main_button_label" "${!Button_1_Message}"; echo $?) echo $ButtonClicked if [[ "$ButtonClicked" -eq 0 ]]; then policy_progress fi find /private/tmp -name "$pipe_name" -delete