#!/bin/bash ########################################################################## # Script : Patch Policy # Autor : Andreas Vogel NEXT Enterprise GmbH # Quelle : https://github.com/IBM/mac-ibm-notifications ########################################################################## ################ Clean up ################################################ if [ -f "/tmp/xsltTemplate.xsl" ]; then rm -rf "/tmp/xsltTemplate.xsl" fi if [ -f "/tmp/fileName.xml" ]; then rm -rf "/tmp/fileName.xml" fi if [ -f "/tmp/updates.xml" ]; then rm -rf "/tmp/updates.xml" fi ################ Varialen ################################################ CurrentUser=$(/usr/sbin/scutil <<< "show State:/Users/ConsoleUser" | /usr/bin/awk -F': ' '/[[:space:]]+Name[[:space:]]:/ { if ( $2 != "loginwindow" ) { print $2 }}') RealName=$(dscl . read /Users/$CurrentUser RealName | tail -n1) 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="${4}" User=$(echo "${5}" | base64 --decode) 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 $User --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 Percent=0 Update_Count_Percent=$((Update_Count + 1)) max_counter_read=$((100/Update_Count_Percent)) max_percent=$((max_counter_read * Update_Count_Percent)) max_calculate=$((100 - max_counter_read * Update_Count_Percent)) ################ 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="Hello ${RealName} \n 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="Hallo ${RealName} \n 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 0" 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 0" Update_Inventory_Message_de="Aktualisierung des Bestandsverzeichnisses....." Update_Steps_de="Schritt" Count_Steps_de="von" Update_Progress_Message_de="Aktualisiere" if [[ "$Update_Count" -eq 1 ]]; then Final_Massage_en="The update has been installed. Thanks for the patience." Final_Massage_de="Das Update wurde installiert. Danke für die Geduld." else Final_Massage_en="All updates have been installed. Thanks for the patience." Final_Massage_de="Alle Updates wurden installiert. Danke für die Geduld." fi 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} Final_Massage=Final_Massage_${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} & until [[ "$COUNTER" -ge $Update_Count ]]; do for i in ${IDs[@]} do let COUNTER++ counter_read=$((100/Update_Count_Percent)) Percent=$((Percent + counter_read)) PolicyName=$(/usr/bin/curl -u $User --tlsv1.2 -H "Accept: application/xml" "$JSSURL/policies/id/$i" | xmllint --xpath '/policy/general/name/text()' - 2>/dev/null) echo "/percent $Percent /bottom_message ${!Update_Steps} $COUNTER ${!Count_Steps} $Update_Count ${!Update_Progress_Message}: $PolicyName" >&5 jamf policy -id $i -forceNoRecon done Percent=$((Percent + counter_read + max_calculate)) echo "/percent $Percent /bottom_message ${!Final_Massage} ">&5 done exec 3>&- find /private/tmp -name ${pipe_name} -delete } ################ 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