From: Ben Soares Date: Wed, 31 Jul 2024 15:37:17 +0000 (+0100) Subject: JAL-3631 Add a (by-passable) confirmation and improved output to the macos-install... X-Git-Tag: Release_2_11_4_0~17^2~3^2~1 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=1c4f202571e7d356d1eb73126d6721daba164d1e;p=jalview.git JAL-3631 Add a (by-passable) confirmation and improved output to the macos-install-jalview.sh script, with some corrections --- diff --git a/utils/install4j/macos-install-jalview.sh b/utils/install4j/macos-install-jalview.sh index eba1e2b..6ff696c 100755 --- a/utils/install4j/macos-install-jalview.sh +++ b/utils/install4j/macos-install-jalview.sh @@ -16,7 +16,8 @@ usage() { echo " -i filename Use filename as DMG image file instead of downloading." echo " -a folder Install the application .app bundle in folder (default '/Applications')." echo " -v Verbose output." - echo " -q No output other than errors." + echo " -y Assume 'yes' to confirmation." + echo " -q No output other than errors. Assumes -y." echo "" echo " Advanced options:" echo "" @@ -46,6 +47,7 @@ DMGFILE="" INSTALLERNAME="$(basename $0)" APPLICATIONFOLDER="/Applications" VERBOSE=0 +YES=0 QUIET=0 USERAPPDIRTEMPLATE="" DISABLEUSERAPPDIR=0 @@ -57,10 +59,10 @@ TMP="/tmp" CURLOPT="" RSYNCOPT="" -HDIUTILOPT="" +HDIUTILOPT="-quiet" # set options -while getopts "hdi:a:vqu:c:USPR" opt; do +while getopts "hdi:a:vyqu:c:USPR" opt; do case ${opt} in h) usage @@ -88,11 +90,15 @@ while getopts "hdi:a:vqu:c:USPR" opt; do RSYNCOPT="-v" HDIUTILOPT="-verbose" ;; + y) + YES=1 + ;; q) QUIET=1 CURLOPT="-s" RSYNCOPT="-q" HDIUTILOPT="-quiet" + YES=1 ;; u) USERAPPDIRTEMPLATE="${OPTARG}" @@ -121,7 +127,7 @@ done myecho() { if [ "${QUIET}" != 1 ]; then - echo $1 + echo "* $1" fi } @@ -133,7 +139,7 @@ fi # root permissions check if [ "${DISABLEROOTCHECK}" != 1 -a "${EUID}" != 0 ]; then - echo "This script should be run with root permissions, or with -R." + echo "This script should be run with root permissions, or disable this root check with -R." exit 5 fi @@ -164,10 +170,33 @@ esac # dir for downloads and volume mount TEMPDIR=$(mktemp -d -p "${TMP}" -t "${INSTALLERNAME%.sh}_${CHANNEL}") -myecho "Using directory '${TEMPDIR}' to download/mount disk image" +if [ "${DOWNLOAD}" = 1 ]; then + myecho "Using directory '${TEMPDIR}' to download and mount disk image" +else + myecho "Using directory '${TEMPDIR}' to mount disk image" +fi FILEBASE="${TEMPDIR}/jalview-${CHANNEL}-latest-macos-${JARCH}" VOLUMEDIR="${FILEBASE}.vol" +# Confirmation of what's about to happen +if [ "${YES}" != 1 ]; then + if [ "${DOWNLOAD}" = 1 ]; then + myecho "This script will download Jalview from the '${CHANNEL}' channel and install it into the '${APPLICATIONFOLDER}' folder." + else + myecho "This script will install Jalview from the '${DMGFILE}' disk image file into the '${APPLICATIONFOLDER}' folder." + fi + + read -r -p "Continue? [y/N] " response + case $(echo "${response}" | tr '[:upper:]' '[:lower:]') in + yes|y) + myecho "Excellent! Continuing." + ;; + *) + echo "Aborting due to negative confirmation." && exit + ;; + esac +fi + if [ "${DOWNLOAD}" = 1 ]; then DMGFILE="${FILEBASE}.dmg" SHA256="" @@ -190,6 +219,7 @@ if [ "${DOWNLOAD}" = 1 ]; then fi # mount the DMG image +myecho "Mounting disk image '${DMGFILE}' on '${VOLUMEDIR}'" hdiutil attach ${HDIUTILOPT} -mountpoint "${VOLUMEDIR}" "${DMGFILE}" [ $? != 0 ] && echo "Could not mount '${DMGFILE}' on mount point '${VOLUMEDIR}'" && exit 9 @@ -219,26 +249,32 @@ done [ -z "${APPNAME}" ] && echo "Could not find suitable Jalview\*.app in the volume '${VOLUMEDIR}'" && exit 11 # rsync .app from mounted volume to application folder +myecho "Rsyncing '${VOLUMEDIR}/${APPNAME}' to '${APPLICATIONFOLDER}/${APPNAME}'" rsync ${RSYNCOPT} -ah --delete "${VOLUMEDIR}/${APPNAME}" "${APPLICATIONFOLDER}/" [ $? != 0 ] && echo "Possible problem when rsyncing '${APP}' to '${APPLICATIONFOLDER}'" && exit 12 +myecho "Finished rsync" EXIT=0 declare -a WARNINGS=() addwarning() { W=$1 N=$2 - myecho "$W" - WARNINGS=( "${WARNINGS[@]}" "$W" ) + myecho "${W}" + WARNINGS=( "${WARNINGS[@]}" "${W}" ) + # exit with the first warning value [ "${EXIT}" = 0 ] && EXIT=$N } # unmount the DMG image +myecho "Unmounting '${VOLUMEDIR}'" hdiutil detach ${HDIUTILOPT} "${VOLUMEDIR}" || addwarning "Possible problem when unmounting/deleting '${VOLUMEDIR}'. I'm continuing the install but you should look at it later." 13 # delete the image file and temp dir if [ "${DOWNLOAD}" = 1 ]; then + myecho "Deleting downloaded disk image file '${DMGFILE}'" rm "${DMGFILE}" fi +myecho "Removing temporary directory '${TEMPDIR}'" rmdir "${TEMPDIR}" VMOPTIONS="${APPLICATIONFOLDER}/${APPNAME}/Contents/vmoptions.txt" @@ -253,6 +289,11 @@ if [ -e "${VMOPTIONS}" ]; then done < "${VMOPTIONS}" fi +LONGHASH=$( printf %s "${APPLICATIONFOLDER}/${APPNAME}/Contents/Resources/app" | shasum -a 256 -b ) +HASH=${LONGHASH:0:8} +NAME=${APPNAME%.app} + +myecho "Writing vmoptions files '${VMOPTIONS}'" VMOPTIONS_COMMENT=$( cat << EOM # Jalview options added by $( basename $0 ) at $( date +"%F %T") EOM @@ -260,6 +301,7 @@ EOM # -Dnouserdefaultappdir=false if [ "${DISABLEUSERAPPDIR}" = 1 ]; then + myecho "- User-space updates DISABLED" VMOPTIONS_USERAPPDIR=$( cat << EOM # # Comment out the following line to allow user-space updates @@ -267,6 +309,7 @@ if [ "${DISABLEUSERAPPDIR}" = 1 ]; then EOM ) else + myecho "- User-space updates enabled" VMOPTIONS_USERAPPDIR=$( cat << EOM # # Uncomment the following line to disable user-space updates @@ -277,6 +320,7 @@ fi # -Dsetuserappdirpath if [ -z "${USERAPPDIRTEMPLATE}" ]; then + myecho "- Default user-space updates path (~/Library/Application Support/Jalview-Desktop/${NAME}/${HASH})" VMOPTIONS_USERAPPDIRPATH=$( cat << EOM # # Uncomment the below line to set a custom path for user-space updates -- use with caution. @@ -286,6 +330,7 @@ if [ -z "${USERAPPDIRTEMPLATE}" ]; then EOM ) else + myecho "- CUSTOMISED user-space updates path (${USERAPPDIRTEMPLATE})" VMOPTIONS_USERAPPDIRPATH=$( cat << EOM # # The below line sets a custom path for user-space updates -- use with caution. @@ -298,6 +343,7 @@ fi # -Dsilent=noupdate if [ "${DISABLEALLUPDATES}" = 1 ]; then + myecho "- All automatic updates DISABLED" VMOPTIONS_UPDATES=$( cat << EOM # # Comment out the following line to enable updates @@ -305,6 +351,11 @@ if [ "${DISABLEALLUPDATES}" = 1 ]; then EOM ) else + if [ "${DISABLEUSERAPPDIR}" = 1 ]; then + myecho "- Automatic updates enabled in user-space" + else + myecho "- Automatic updates enabled IN INSTALLATION" + fi VMOPTIONS_UPDATES=$( cat << EOM # # Uncomment the following line to also disable all updates @@ -317,11 +368,9 @@ printf "%s\n%s\n%s\n%s\n%s\n" "${VMOPTIONS_START}" "${VMOPTIONS_COMMENT}" "${VMO # set a global path in /etc/paths.d if [ "${DISABLEGLOBALPATH}" != 1 ]; then - LONGHASH=$( printf %s "${APPLICATIONFOLDER}/${APPNAME}/Contents/Resources/app" | shasum -a 256 -b ) - HASH=${LONGHASH:0:8} - NAME=${APPNAME%.app} - US_NAME=${NAME// /_} + US_NAME="${NAME// /_}" PATHFILE="/etc/paths.d/${US_NAME}-${HASH}" + myecho "Writing global PATH to '${PATHFILE}'" echo "${APPLICATIONFOLDER}/${APPNAME}/Contents/MacOS" > "${PATHFILE}" || addwarning "Possible problem writing path file '${PATHFILE}'" 15 fi @@ -330,7 +379,7 @@ if [ "${#WARNINGS[@]}" != 0 ]; then myecho "-----------------" myecho "Installation complete." myecho "Warnings summary:" - myecho $( printf -- '- %s\n' "${WARNINGS[@]}" ) + myecho "$( printf -- '- %s\n' "${WARNINGS[@]}" )" else myecho "Successful installation!" fi