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 ""
INSTALLERNAME="$(basename $0)"
APPLICATIONFOLDER="/Applications"
VERBOSE=0
+YES=0
QUIET=0
USERAPPDIRTEMPLATE=""
DISABLEUSERAPPDIR=0
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
RSYNCOPT="-v"
HDIUTILOPT="-verbose"
;;
+ y)
+ YES=1
+ ;;
q)
QUIET=1
CURLOPT="-s"
RSYNCOPT="-q"
HDIUTILOPT="-quiet"
+ YES=1
;;
u)
USERAPPDIRTEMPLATE="${OPTARG}"
myecho() {
if [ "${QUIET}" != 1 ]; then
- echo $1
+ echo "* $1"
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
# 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=""
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
[ -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"
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
# -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
EOM
)
else
+ myecho "- User-space updates enabled"
VMOPTIONS_USERAPPDIR=$( cat << EOM
#
# Uncomment the following line to disable user-space updates
# -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.
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.
# -Dsilent=noupdate
if [ "${DISABLEALLUPDATES}" = 1 ]; then
+ myecho "- All automatic updates DISABLED"
VMOPTIONS_UPDATES=$( cat << EOM
#
# Comment out the following line to enable updates
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
# 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
myecho "-----------------"
myecho "Installation complete."
myecho "Warnings summary:"
- myecho $( printf -- '- %s\n' "${WARNINGS[@]}" )
+ myecho "$( printf -- '- %s\n' "${WARNINGS[@]}" )"
else
myecho "Successful installation!"
fi