From 491b7ea8e166dbff12dbbbfd32db33f07c338df7 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Fri, 26 Jul 2024 15:39:41 +0100 Subject: [PATCH] JAL-3631 Added verbose and quiet options, and matched vmoptions with installer. Provenance of options added. --- utils/install4j/macos-install-jalview.sh | 74 ++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 19 deletions(-) diff --git a/utils/install4j/macos-install-jalview.sh b/utils/install4j/macos-install-jalview.sh index b91f9ca..8cb7980 100755 --- a/utils/install4j/macos-install-jalview.sh +++ b/utils/install4j/macos-install-jalview.sh @@ -15,6 +15,8 @@ usage() { echo " -c channel (with -d) Download from channel. Should be one of 'release', 'test-release', 'develop' (defaults to 'release')." 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 "" echo " Advanced options:" echo "" @@ -43,6 +45,8 @@ CHANNEL="release" DMGFILE="" INSTALLERNAME="$(basename $0)" APPLICATIONFOLDER="/Applications" +VERBOSE=0 +QUIET=0 USERAPPDIRTEMPLATE="" DISABLEUSERAPPDIR=0 DISABLEALLUPDATES=0 @@ -51,8 +55,12 @@ DISABLEROOTCHECK=0 USETEMPDIR="" TMP="/tmp" +CURLOPT="" +RSYNCOPT="" +HDIUTILOPT="" + # set options -while getopts "hdi:a:u:c:USPR" opt; do +while getopts "hdi:a:vqu:c:USPR" opt; do case ${opt} in h) usage @@ -74,6 +82,18 @@ while getopts "hdi:a:u:c:USPR" opt; do a) APPLICATIONFOLDER="${OPTARG}" ;; + v) + VERBOSE=1 + CURLOPT="-v" + RSYNCOPT="-v" + HDIUTILOPT="-verbose" + ;; + q) + QUIET=1 + CURLOPT="-s" + RSYNCOPT="-q" + HDIUTILOPT="-quiet" + ;; u) USERAPPDIRTEMPLATE="${OPTARG}" ;; @@ -99,6 +119,12 @@ while getopts "hdi:a:u:c:USPR" opt; do esac done +myecho() { + if [ "${QUIET}" != 1 ]; then + echo $1 + fi +} + # no -d or -i arguments if [ "${DOWNLOAD}" = 0 -a -z "${DMGFILE}" ]; then usage @@ -114,7 +140,7 @@ fi # check channel case "$CHANNEL" in release|test-release|develop) - echo "Using channel ${CHANNEL}" + myecho "Using channel ${CHANNEL}" ;; *) echo "-c channel must be one of 'release', 'test-release' or 'develop'" @@ -138,7 +164,7 @@ esac # dir for downloads and volume mount TEMPDIR=$(mktemp -d -p "${TMP}" -t "${INSTALLERNAME%.sh}_${CHANNEL}") -echo "Using directory '${TEMPDIR}' to download/mount disk image" +myecho "Using directory '${TEMPDIR}' to download/mount disk image" FILEBASE="${TEMPDIR}/jalview-${CHANNEL}-latest-macos-${JARCH}" VOLUMEDIR="${FILEBASE}.vol" @@ -148,15 +174,15 @@ if [ "${DOWNLOAD}" = 1 ]; then URL="https://www.jalview.org/downloads/${CHANNEL}/installer/macos-${JARCH}" - echo "Downloading '${URL}' to '${DMGFILE}'" - curl -f -L -o "${DMGFILE}" "${URL}" + myecho "Downloading '${URL}' to '${DMGFILE}'" + curl ${CURLOPT} -f -L -o "${DMGFILE}" "${URL}" [ $? != 0 ] && echo "Could not download '$URL' to '$DMGFILE'" && exit 6 - SHA256=$( curl -f -s -L "${URL}.sha256" ) + SHA256=$( curl ${CURLOPT} -f -s -L "${URL}.sha256" ) [ $? != 0 ] && echo "Could not download '$URL.sha256'" && exit 7 CHECK=$( shasum -a 256 "${DMGFILE}" | cut -d" " -f1 ) if [ "${CHECK}" = "${SHA256}" ]; then - echo "Downloaded file '$DMGFILE' checksum matches downloaded checksum '$SHA256'" + myecho "Downloaded file '$DMGFILE' checksum matches downloaded checksum '$SHA256'" else echo "Downloaded file '$DMGFILE' checksum does not match downloaded checksum '$SHA256'" exit 8 @@ -164,7 +190,7 @@ if [ "${DOWNLOAD}" = 1 ]; then fi # mount the DMG image -hdiutil attach -mountpoint "${VOLUMEDIR}" "${DMGFILE}" +hdiutil attach ${HDIUTILOPT} -mountpoint "${VOLUMEDIR}" "${DMGFILE}" [ $? != 0 ] && echo "Could not mount '${DMGFILE}' on mount point '${VOLUMEDIR}'" && exit 9 # difficult to use a wildcard for a non-user-readable folder without inserting sudo directly into the command @@ -193,7 +219,7 @@ done [ -z "${APPNAME}" ] && echo "Could not find suitable Jalview\*.app in the volume '${VOLUMEDIR}'" && exit 11 # rsync .app from mounted volume to application folder -rsync -avh --delete "${VOLUMEDIR}/${APPNAME}" "${APPLICATIONFOLDER}/" +rsync ${RSYNCOPT} -ah --delete "${VOLUMEDIR}/${APPNAME}" "${APPLICATIONFOLDER}/" [ $? != 0 ] && echo "Possible problem when rsyncing '${APP}' to '${APPLICATIONFOLDER}'" && exit 12 EXIT=0 @@ -201,13 +227,13 @@ declare -a WARNINGS=() addwarning() { W=$1 N=$2 - echo "$W" + myecho "$W" WARNINGS=( "${WARNINGS[@]}" "$W" ) [ "${EXIT}" = 0 ] && EXIT=$N } # unmount the DMG image -hdiutil detach "${VOLUMEDIR}" || addwarning "Possible problem when unmounting/deleting '${VOLUMEDIR}'. I'm continuing the install but you should look at it later." 13 +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 @@ -216,9 +242,19 @@ fi rmdir "${TEMPDIR}" VMOPTIONS="${APPLICATIONFOLDER}/${APPNAME}/Contents/vmoptions.txt" + +VMOPTIONS_START="" +if [ -e "${VMOPTIONS}" ]; then + while IFS= read -r line; do + VMOPTIONS_START="${VMOPTIONS_START}${line}"$'\n' + if [ "${line}" != "${line/Jalview/}" ]; then # i.e. $line contains "Jalview" + break + fi + done < "${VMOPTIONS}" +fi + VMOPTIONS_COMMENT=$( cat << EOM -# -# Jalview specific options below +# Jalview options added by $( basename $0 ) at $( date +"%F %T") EOM ) @@ -277,7 +313,7 @@ EOM ) fi -printf "%s\n%s\n%s\n%s\n" "${VMOPTIONS_COMMENT}" "${VMOPTIONS_USERAPPDIR}" "${VMOPTIONS_USERAPPDIRPATH}" "${VMOPTIONS_UPDATES}" >> "${VMOPTIONS}" || addwarning "Possible problem adding options to '${VMOPTIONS}'" 14 +printf "%s\n%s\n%s\n%s\n%s\n" "${VMOPTIONS_START}" "${VMOPTIONS_COMMENT}" "${VMOPTIONS_USERAPPDIR}" "${VMOPTIONS_USERAPPDIRPATH}" "${VMOPTIONS_UPDATES}" > "${VMOPTIONS}" || addwarning "Possible problem adding options to '${VMOPTIONS}'" 14 # set a global path in /etc/paths.d if [ "${DISABLEGLOBALPATH}" != 1 ]; then @@ -291,12 +327,12 @@ fi # show accumulated warnings if [ "${#WARNINGS[@]}" != 0 ]; then - echo "-----------------" - echo "Installation complete." - echo "Warnings summary:" - printf -- '- %s\n' "${WARNINGS[@]}" + myecho "-----------------" + myecho "Installation complete." + myecho "Warnings summary:" + myecho $( printf -- '- %s\n' "${WARNINGS[@]}" ) else - echo "Successful installation!" + myecho "Successful installation!" fi exit $EXIT -- 1.7.10.2