87 lines
3.1 KiB
Bash
Executable File
87 lines
3.1 KiB
Bash
Executable File
#!/bin/bash
|
|
##########################################################################
|
|
# Script : Patch Policy
|
|
# Quelle : https://github.com/IBM/mac-ibm-notifications
|
|
##########################################################################
|
|
|
|
set -x
|
|
|
|
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
|
|
|
|
################ Check Inventory #########################################
|
|
# jamf recon 2&> /dev/null
|
|
|
|
################ Varialen ################################################
|
|
#JSSURL="$4"
|
|
#JSSUSER="$5"
|
|
#JSSPASSWORD="$6"
|
|
#JSS_Category="19"
|
|
|
|
JSSURL="https://macenterprise.jamfcloud.com/JSSResource"
|
|
JSSUSER="API_User"
|
|
JSSPASSWORD="Nextenterprise#1612"
|
|
|
|
FilePath="/Library/Application Support/Updates/patch.xml"
|
|
UDID=$(system_profiler SPHardwareDataType | grep UUID | awk '" " { print $NF }')
|
|
|
|
if [[ ! -e "$FilePath" ]]; then
|
|
echo "Making working directory at $FilePath"
|
|
mkdir -p "$FilePath"
|
|
fi
|
|
|
|
################ Checking the available updates ##########################
|
|
# Check whether updates are available for the device.
|
|
Request=$(/usr/bin/curl -u $JSSUSER:$JSSPASSWORD --tlsv1.2 -H "Accept: application/xml" "$JSSURL/computermanagement/udid/$UDID/subset/policies" -X GET > "$FilePath")
|
|
Update_Count=$(grep -c "patch_app_updates" "${FilePath}")
|
|
|
|
# Update_Count="3"
|
|
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
|
|
|
|
################ Customized Notifier #####################################
|
|
Plural=Plural_${UserLanguage}
|
|
Notifier_Path="/Applications/IBM Notifier.app/Contents/MacOS/IBM Notifier"
|
|
Type="popup"
|
|
Icon_Path="/Library/Application Support/Next Enterprise/Next_logo_48x48.png"
|
|
|
|
Bar_Title_en="Update${!Plural}Available"
|
|
Title_en="Software Update${!Plural}Available"
|
|
Description_en="You have ${Update_Count} update${!Plural}available in the Self Service."
|
|
Button_1_en="Cancel"
|
|
Button_2_en="Update"
|
|
|
|
Bar_Title_de="Update${!Plural}verfügbar"
|
|
Title_de="Software Update${!Plural}verfügbar"
|
|
Description_de="Es sind ${Update_Count} update${!Plural}im Self Service Verfügung."
|
|
Button_1_de="Abbrechen"
|
|
Button_2_de="Update"
|
|
|
|
Bar_Title=Bar_Title_${UserLanguage}
|
|
Title=Title_${UserLanguage}
|
|
Description=Description_${UserLanguage}
|
|
Button_1=Button_1_${UserLanguage}
|
|
Button_2=Button_2_${UserLanguage}
|
|
|
|
|
|
ButtonClicked=$("sudo" "-u" "${CurrentUser}" "${Notifier_Path}" "-type" "${Type}" "-bar_title" "${!Bar_Title}" "-title" "${!Title}" "-subtitle" "${!Description}" "-icon_path" "${Icon_Path}" "-always_on_top" "-main_button_label" "${!Button_1}" "-secondary_button_label" "${!Button_2}"; echo $?)
|
|
|
|
if [[ "$ButtonClicked" -eq 2 ]]; then
|
|
jamf policy -event patch_app_updates
|
|
exit 0
|
|
# open "jamfselfservice://content?action=category&id=${JSS_Category}"
|
|
fi |