112 lines
3.9 KiB
Bash
112 lines
3.9 KiB
Bash
#!/bin/bash
|
|
|
|
##########################################################################
|
|
# Shellscript : Dynamisches Script, zur Weiterverarbeitung mehrerer Variablen
|
|
# Autor : Andreas Vogel, macenterprise gmbh, 10.12.2019
|
|
##########################################################################
|
|
|
|
################################# Description #################################
|
|
# Das Script an dem für "find" gesetztem Ort.
|
|
# Beispiel: ApplicationVersion=$(find /Library/Java/JavaVirtualMachines -type d -name '*.jdk' -prune -print)
|
|
# Die gefundenen Ergebnisse werden dann als auswählbare Variablen ausgegeben.
|
|
# Diese Auswahl kann dann weiterverarbeitet werden.
|
|
|
|
################################# unset #################################
|
|
unset changeApplication
|
|
unset listChoice
|
|
unset ApplicationVersion
|
|
unset AllApplications
|
|
unset arrayChoice
|
|
|
|
################################# Function #################################
|
|
listChoice() {
|
|
osascript <<EOT
|
|
tell app "System Events"
|
|
with timeout of 300 seconds
|
|
choose from list every paragraph of "$5" with title "$2" with prompt "$1" OK button name "$4" cancel button name "$3"
|
|
end timeout
|
|
end tell
|
|
EOT
|
|
}
|
|
|
|
################################# Variablen ############################################
|
|
|
|
jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
|
|
jamf="/usr/local/bin/jamf"
|
|
|
|
# INGIcon
|
|
WarningIcon="/Library/Application Support/JAMF/ING/France_road_sign_A14.svg.png"
|
|
SuccessfulIcon="/Library/Application Support/JAMF/ING/ok-1976099_640.png"
|
|
|
|
ApplicationVersion=$(find /Library/Java/JavaVirtualMachines -type d -name '*.jdk' -prune -print)
|
|
AllApplications=()
|
|
arrayChoice=()
|
|
AllApplications+=($ApplicationVersion)
|
|
|
|
# Erstellung einer Auswahl
|
|
for item in ${AllApplications[@]}
|
|
do
|
|
arrayChoice+=$"${item}\n"
|
|
done
|
|
arrayChoice=$(echo $arrayChoice |sed 's/..$//')
|
|
|
|
################################# Texte ############################################
|
|
WarningMessage="Die im nächsten Fenster getroffene Wahl wird ohne eine weitere Prüfung gelöscht. Bitte die sorgfältig auswählen.
|
|
Vorgang kann nur mit „Cancel“ abgebrochen werden.
|
|
|
|
The choice made in the next window will be deleted without further examination. Please select the carefully.
|
|
Operation can only be canceled with „Cancel“."
|
|
|
|
FailedMessage="Die Auswahl konnte nicht gelöscht werden. Falls das Problem weiterhin besteht, wende dich an dem Client_Service_Mac.
|
|
|
|
The selection could not be deleted. If the problem persists, contact the Client_Service_Mac."
|
|
|
|
SuccessfulMessage="Erfolgreich beendet.
|
|
|
|
Completed successfully."
|
|
|
|
################################# Dialoge ############################################
|
|
|
|
# Warnung über den Sachverhalt
|
|
HELPER=$("$jamfHelper" -windowType utility -icon "$WarningIcon" -title "Warning" -description "$WarningMessage" -button1 "OK" -button2 "Cancel" -cancelButton "2" -defaultButton 2)
|
|
echo "Exit Code: $HELPER"
|
|
|
|
if [ "$HELPER" == "0" ]
|
|
then
|
|
|
|
# Dialog: Hier wird die Liste erstellt, in der der User eine Auswahlt tätigen kann.
|
|
changeApplication="$(listChoice \
|
|
"Wähle die zu löschende Java Version aus:
|
|
|
|
Choose to delete Java version: " \
|
|
"Triff deine Wahl / Make your choice" \
|
|
"Cancel" \
|
|
"OK" \
|
|
"$arrayChoice")"
|
|
|
|
if [[ "$changeApplication" == "false" ]]
|
|
then
|
|
unset changeApplication
|
|
exit 0
|
|
|
|
else
|
|
|
|
if rm -rf $changeApplication
|
|
then
|
|
|
|
printf HELPER=$("$jamfHelper" -windowType utility -icon "$SuccessfulIcon" -title "Completed successfully" -description "$SuccessfulMessage" -button1 "OK" -defaultButton 1)
|
|
echo "Exit Code: Die Auswahl "$changeApplication" wurde erfolgreich gelöscht."
|
|
unset changeApplication
|
|
|
|
else
|
|
|
|
printf HELPER=$("$jamfHelper" -windowType utility -icon "$WarningIcon" -title "Error" -description "$FailedMessage" -button1 "OK" -defaultButton 1)
|
|
echo "Exit Code: Die Auswahl "$changeApplication" konnte nicht gelöscht werden. "
|
|
unset changeApplication
|
|
|
|
fi
|
|
exit 0
|
|
fi
|
|
|
|
exit 0
|
|
fi |