From a4fa4a904ff96b431c4cfc7b66a13ce2520e1958 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Fri, 11 Mar 2022 13:27:18 +0000 Subject: [PATCH 1/1] JAL-3393 improved flexibility of script and updated doc --- doc/README-DMG_creation.md | 7 ++- utils/install4j/mk_ds_store.sh | 127 ++++++++++++++++++++++++++++++++-------- 2 files changed, 106 insertions(+), 28 deletions(-) diff --git a/doc/README-DMG_creation.md b/doc/README-DMG_creation.md index 5ad5e8d..6542b7c 100644 --- a/doc/README-DMG_creation.md +++ b/doc/README-DMG_creation.md @@ -3,17 +3,18 @@ ## New method to make the DS_Store file from scratch (on a Mac) ``` -./utils/install4j/mk_ds_store.sh +./utils/install4j/mk_ds_store.sh --name Jalview [--bgimg ./utils/channels/release/image/jalview_dmg_background.png] [--output ./utils/channels/release/image/jalview_dmg_DS_Store] ``` A script that creates a new DMG with the top level items to be found in a Jalview Installer DMG, mounts the volume, then uses an AppleScript to adjust the background image, size and position of the icons, and appearance of the Finder window. The .DS_Store is then copied out of the volume by the script, the volume unmounted, and all files (in /tmp) tidied up. -To use it, the NAME (of the application, without the `.app` extension) should be set in the script (set to "Jalview"), and the background image that you want to use should be copied to your working directory as `background.png`. +To use it, the NAME (of the application, without the `.app` extension) should be set in the script (set to "Jalview"), and the background image that you want to use should be copied to your working directory as `background.png` (or use the --bgimg option). -Once it is run (only works on a Mac with osascript) it will leave a file Jalview_Installer-DS_Store in your working directory. +Once it is run (only works on a Mac with osascript) it will leave a file Output-DS_Store in your working directory (or use the --output option). +> This script borrows extensively from https://github.com/create-dmg/create-dmg ## Old manual method (possibly instructive) diff --git a/utils/install4j/mk_ds_store.sh b/utils/install4j/mk_ds_store.sh index d08249f..9bbac91 100755 --- a/utils/install4j/mk_ds_store.sh +++ b/utils/install4j/mk_ds_store.sh @@ -1,39 +1,114 @@ #!/usr/bin/env bash -NAME="Jalview" +set -e -TMPNAME="${NAME// /_}_Installer" -APPNAME="${NAME}.app" -DMG="${TMPNAME}.dmg" +if [[ $(uname) != "Darwin" ]]; then + echo "Must be run on a Mac" + exit 1 +fi + +function usage() { + cat < + The application name (without '.app' extension) (mandatory) + --bgimg + Path to your background image (defaults to background.png) + --output + The filename of the resullting .DS_Store (defaults to Output-DS_Store) + -h, --help + This help text + +EOH +exit 0 +} + +# defaults +BACKGROUNDIMG="background.png" +OUTPUTNAME="Output-DS_Store" + +while [[ "${1:0:1}" = "-" ]]; do + case $1 in + --name) + NAME="$2" + shift; shift;; + --bgimg) + BACKGROUNDIMG="$2" + shift; shift;; + --output) + OUTPUTNAME="$2" + shift; shift;; + -h | --help) + usage;; + esac +done + +if [[ -z "$NAME" ]]; then + echo "Must supply a --name Name argument" + exit 1 +fi WDIR=$(pwd) +# make a relative path absolute as we'll be cd-ing to /tmp +if [[ "${BACKGROUNDIMG#/}" = "${BACKGROUNDIMG}" ]]; then + BACKGROUNDIMG="${WDIR}/${BACKGROUNDIMG}" +fi + +# Note that VOLNAME is only for making the DS_Store file in. The final DMG can have a different Volume name +# This temporary VOLNAME can be seen if you do `strings /Volume/Your DMG Name/.DS_Store` on the final .DS_Store +# so we set this to something relatable to the application name. +VOLNAME="${NAME// /_}_Installer" + +APPNAME="${NAME}.app" + +DMG="${VOLNAME}.dmg" +# We set the Applications folder link to " " in the DMG +APPLICATIONSFOLDERLINK=" " + +VOLDIR="/Volumes/${VOLNAME}" +# The directory and filename this temporary volume is mounted from can be seen in `strings .DS_Store` so we move out +# of userspace for generic and security reasons. cd /tmp -mkdir -p "$TMPNAME" -cd "$TMPNAME" +mkdir -p "$VOLNAME" +cd "$VOLNAME" mkdir "$APPNAME" ln -s /Applications " " mkdir .background mkdir .fseventsd -cp "${WDIR}/background.png" .background/background.png +cp "$BACKGROUNDIMG" .background/background.png cd /tmp [ -e "$DMG" ] && rm "$DMG" -hdiutil create -volname "$TMPNAME" -srcfolder "$TMPNAME" -size 1m -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW "$DMG" +hdiutil create -volname "$VOLNAME" -srcfolder "$VOLNAME" -size 1m -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW "$DMG" open "$DMG" sleep 1 -VOL="/Volumes/${TMPNAME}" -#osascript "${WDIR}/set_ds_store.applescript" "$TMPNAME" "$APPNAME" -osascript - "$TMPNAME" "$APPNAME" <