86 lines
2.6 KiB
Bash
Executable File
86 lines
2.6 KiB
Bash
Executable File
#!/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.
|
|
|
|
|
|
################################# Function #################################
|
|
MessageBox() {
|
|
osascript <<EOT
|
|
tell app "System Events"
|
|
with timeout of 300 seconds
|
|
button returned of (display dialog "$1" buttons {"$3"} default button 1 with title "$2")
|
|
end timeout
|
|
end tell
|
|
EOT
|
|
}
|
|
|
|
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 ############################################
|
|
# Die Applicationen werden über den "find" Befehl gesucht
|
|
|
|
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/..$//')
|
|
|
|
|
|
################################# Dialoge ############################################
|
|
|
|
# Warnung über den Sachverhalt
|
|
MessageBox \
|
|
"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"." \
|
|
"Warning" \
|
|
"OK"
|
|
|
|
# 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" \
|
|
"Cancel" \
|
|
"OK" \
|
|
"$arrayChoice")"
|
|
|
|
# Ist keine Auswahl getroffen, wird das Script ohne Fehler beendet
|
|
if [[ "$changeApplication" == "" ]]
|
|
then
|
|
unset changeApplication
|
|
exit 0
|
|
fi
|
|
|
|
# Ausführung der Auswahl
|
|
rm -rf $changeApplication
|
|
|
|
|
|
unset changeApplication
|