Skip to content

Instantly share code, notes, and snippets.

@d1rtyvans
Last active April 6, 2020 15:43
Show Gist options
  • Save d1rtyvans/07cd0bf29ddef489a138e3ed204fe9b2 to your computer and use it in GitHub Desktop.
Save d1rtyvans/07cd0bf29ddef489a138e3ed204fe9b2 to your computer and use it in GitHub Desktop.
Install a MacOS Application from a disk image on the internet
#!/usr/bin/env bash
set -e
APP_NAME="Postgres.app"
APP_DIR="/Applications"
VERSION="2.3.3e"
URL="https://github.com/PostgresApp/PostgresApp/releases/download/v${VERSION}/Postgres-${VERSION}-10-11-12.dmg"
if [ -d $APP_DIR/$APP_NAME ]; then
echo "$APP_NAME is already installed."
read -p "Want to try installing $APP_NAME anyway? [Yn]: " choice
[ "$choice" = 'Y' ] || exit
fi
echo "Downloading $APP_NAME from $URL"
TMPFILE="/tmp/$APP_NAME.dmg"
curl -\# -Lo $TMPFILE $URL
if [ "$choice" = 'Y' ]; then
read -p "Removing $APP_DIR/$APP_NAME... You sure you want this? [Yn]: " choice
[ "$choice" = 'Y' ] || exit
rm -rf $APP_DIR/$APP_NAME
fi
echo "Installing..."
OUTPUT=$(hdiutil mount $TMPFILE)
VOLUME=$(echo ${OUTPUT##* } | xargs) # Get last word in string (volume) and trim leading whitespace
cp -R $VOLUME/$APP_NAME $APP_DIR
echo "Cleaning up..."
hdiutil unmount $VOLUME > /dev/null
rm $TMPFILE
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment