altosui: open /Library/AltusMetrum on Mac OS X after install
[fw/altos] / altosui / install-macosx
index aced4ab9280748189f137f223b4b72cdb33fc3db..e97a002ae2e08fb4f7a7219efa86b2c4a87c7ae4 100755 (executable)
@@ -1,37 +1,55 @@
 #!/bin/bash
 
+JVM=/Library/Java/JavaVirtualMachines
+dir=`dirname "$0"`
+
 case `id -u` in
     0)
     ;;
     *)
-       # Check for java
-       if [ ! -d /Library/Java/JavaVirtualMachines/ -o `ls /Library/Java/JavaVirtualMachine` == '' ]; then
-           open https://adoptopenjdk.net/
-           osascript -e 'display dialog "Install Java from https://adoptopenjdk.net then click OK" buttons {"Continue"}'
-       fi
-       sudo "$0" "$@"
+       SUDO_ASKPASS="${dir}/ask-pass" sudo -A "$0" "$@"
+       case $? in
+           0)
+           ;;
+           *)
+               osascript -e 'display dialog "Installation failed. Incorrect password?" buttons {"OK"} default button 1 with title "Installation Status"' > /dev/null
+               ;;
+       esac
+       exit 0
        ;;
 esac
 
-dir=`dirname "$0"`
+# Check for java
+if ls "$JVM" | grep -q adopt; then
+    echo "Adopt OpenJDK already present"
+else
+    open https://adoptopenjdk.net/
+    osascript -e 'display dialog "Install Java from https://adoptopenjdk.net then click Continue" buttons {"Continue"} default button 1 with title "Install Java"' >/dev/null
+fi
+
 cd "$dir"
-APP=`echo *.app`
 LIBRARY=/Library/AltusMetrum
-APPLICATIONS=/Applications/
+APPLICATIONS=/Applications
+INSTALLED=
 for file in *; do
-    case "$i" in
+    echo 'Installing' "$file"
+    case "$file" in
        *.app)
-           mkdir -p "$(APPLICATIONS)"
-           if [ -d "$(APPLICATIONS)/$(APP)/." ]; then
-               rm -rf "$(APPLICATIONS)/$(APP)"
+           mkdir -p "${APPLICATIONS}"
+           if [ -d "${APPLICATIONS}/${file}" ]; then
+               rm -rf "${APPLICATIONS}/${file}"
            fi
-           cp -a "$i" "$(APPLICATIONS)/$(APP)"
-           chmod +w "$(APPLICATIONS)/$(APP)"/*
-           xattr -c "$(APPLICATIONS)/$(APP)"/*
+           cp -a "$file" "${APPLICATIONS}/${file}"
+           chmod -R +w "${APPLICATIONS}/${file}"
+           xattr -rc "${APPLICATIONS}/${file}"
+           APP=`basename "$file" .app`
+           INSTALLED="${INSTALLED} ${APP}"
            ;;
        *)
-           mkdir -p "$(LIBRARY)"
-           cp -a "$i" "$(LIBRARY)"
+           mkdir -p "${LIBRARY}"
+           cp -a "$file" "${LIBRARY}"
            ;;
     esac
 done
+open "${LIBRARY}"
+osascript -e 'display dialog "Installation of'"${INSTALLED}"' complete" with title "Installation Complete" buttons {"OK"} default button 1' >/dev/null