#!/usr/bin/env zsh -f # Purpose: get the beta of Drafts for Mac # # From: Timothy J. Luoma # Mail: luomat at gmail dot com # Date: 2021-04-09 NAME="$0:t:r" if [[ -e "$HOME/.path" ]] then source "$HOME/.path" fi INSTALL_TO='/Applications/Drafts.app' URL='https://s3-us-west-2.amazonaws.com/downloads.agiletortoise.com/Drafts.app.zip' LATEST_VERSION=$(curl -sfLS "https://config.agiletortoise.com/drafts-mac/beta/build-status.json" \ | awk -F'"' '/latest-version/{print $4}') if [[ "$LATEST_VERSION" == "" ]] then echo "$NAME: '\$LATEST_VERSION' is empty." >>/dev/stderr exit 0 fi if [[ -e "$INSTALL_TO" ]] then INSTALLED_VERSION=$(defaults read "${INSTALL_TO}/Contents/Info" CFBundleVersion) autoload is-at-least is-at-least "$LATEST_VERSION" "$INSTALLED_VERSION" VERSION_COMPARE="$?" if [ "$VERSION_COMPARE" = "0" ] then echo "$NAME: Up-To-Date ($INSTALLED_VERSION vs $LATEST_VERSION)" exit 0 fi echo "$NAME: Beta version $LATEST_VERSION available (Installed version: $INSTALLED_VERSION)." FIRST_INSTALL='no' if [[ -e "${INSTALL_TO}/Contents/_MASReceipt/receipt" ]] then echo "\n\tWARNING! The version of Drafts found at '$INSTALL_TO' is from the Mac App Store.\n '$0' can only install or update the _beta_ version of Drafts.\n If you wish to use the beta, you must first remove the Drafts.app from the Mac App Store.\n Please note that having _both_ versions installed is **HIGHLY DISCOURAGED** and could cause **data loss or corruption**. \n\n\tPlease don't do that." >>/dev/stderr exit 2 fi if [[ ! -w "$INSTALL_TO" ]] then echo "$NAME: '$INSTALL_TO' exists, but you do not have 'write' access to it, therefore you cannot update it." >>/dev/stderr exit 2 fi else FIRST_INSTALL='yes' fi FILENAME="$HOME/Downloads/${${INSTALL_TO:t:r}// /}-${${LATEST_VERSION}// /}.zip" RELEASE_NOTES_TXT="$FILENAME:r.txt" if [[ -e "$RELEASE_NOTES_TXT" ]] then cat "$RELEASE_NOTES_TXT" else if (( $+commands[lynx] )) then RELEASE_NOTES_URL='https://docs.getdrafts.com/beta/changelog-mac' RELEASE_NOTES=$(curl -sfLS "${RELEASE_NOTES_URL}" \ | tidy --tidy-mark no --char-encoding utf8 --wrap 0 --show-errors 0 --indent yes \ --input-xml no --output-xml no --quote-nbsp no --show-warnings no \ --uppercase-attributes no --uppercase-tags no --clean yes --force-output yes \ --join-classes yes --join-styles yes --markup yes --output-xhtml yes --quiet yes \ --quote-ampersand yes --quote-marks yes \ | awk '/