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 ""
DMGFILE=""
INSTALLERNAME="$(basename $0)"
APPLICATIONFOLDER="/Applications"
+VERBOSE=0
+QUIET=0
USERAPPDIRTEMPLATE=""
DISABLEUSERAPPDIR=0
DISABLEALLUPDATES=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
a)
APPLICATIONFOLDER="${OPTARG}"
;;
+ v)
+ VERBOSE=1
+ CURLOPT="-v"
+ RSYNCOPT="-v"
+ HDIUTILOPT="-verbose"
+ ;;
+ q)
+ QUIET=1
+ CURLOPT="-s"
+ RSYNCOPT="-q"
+ HDIUTILOPT="-quiet"
+ ;;
u)
USERAPPDIRTEMPLATE="${OPTARG}"
;;
esac
done
+myecho() {
+ if [ "${QUIET}" != 1 ]; then
+ echo $1
+ fi
+}
+
# no -d or -i arguments
if [ "${DOWNLOAD}" = 0 -a -z "${DMGFILE}" ]; then
usage
# 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'"
# 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"
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
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
[ -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
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
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
)
)
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
# 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