Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tjluoma committed Aug 23, 2019
1 parent da07474 commit cb813c5
Showing 1 changed file with 133 additions and 0 deletions.
133 changes: 133 additions & 0 deletions di-precize.sh
@@ -0,0 +1,133 @@
#!/bin/zsh -f
# Purpose: Precize – looks deep into files, bundles and folders to show their full size including extended attributes, provides macOS Bookmarks and volfs paths as enduring file references, and detailed information contained in Bookmarks and Aliases
#
# From: Timothy J. Luoma
# Mail: luomat at gmail dot com
# Date: 2019-08-23

NAME="$0:t:r"

if [[ -e "$HOME/.path" ]]
then
source "$HOME/.path"
else
PATH='/usr/local/scripts:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin'
fi

HOMEPAGE='https://eclecticlight.co/taccy-signet-precize-alifix-utiutility-alisma/'

INSTALL_TO='/Applications/Precize.app'

TEMPFILE="${TMPDIR-/tmp}/${NAME}.$$.$RANDOM.plist"

curl -sfLS "https://raw.githubusercontent.com/hoakleyelc/updates/master/eclecticapps.plist" > "$TEMPFILE" || exit 1

LATEST_VERSION=$(/usr/libexec/PlistBuddy -c print "$TEMPFILE" | egrep -B1 -i ' Precize$' | awk '{print $NF}' | head -1)

URL=$(/usr/libexec/PlistBuddy -c print "$TEMPFILE" | egrep -A1 -i ' Precize$' | awk '{print $NF}' | tail -1)

if [[ -e "$INSTALL_TO" ]]
then

INSTALLED_VERSION=$(defaults read "${INSTALL_TO}/Contents/Info" CFBundleShortVersionString)

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)"
exit 0
fi

echo "$NAME: Outdated: $INSTALLED_VERSION vs $LATEST_VERSION"

FIRST_INSTALL='no'

else

FIRST_INSTALL='yes'
fi

FILENAME="$HOME/Downloads/${${INSTALL_TO:t:r}// /}-${LATEST_VERSION}.zip"

echo "$NAME: Downloading '$URL' to '$FILENAME':"

curl --continue-at - --fail --location --output "$FILENAME" "$URL"

EXIT="$?"

## exit 22 means 'the file was already fully downloaded'
[ "$EXIT" != "0" -a "$EXIT" != "22" ] && echo "$NAME: Download of $URL failed (EXIT = $EXIT)" && exit 0

[[ ! -e "$FILENAME" ]] && echo "$NAME: $FILENAME does not exist." && exit 0

[[ ! -s "$FILENAME" ]] && echo "$NAME: $FILENAME is zero bytes." && rm -f "$FILENAME" && exit 0

UNZIP_TO=$(mktemp -d "${TMPDIR-/tmp/}${NAME}-XXXXXXXX")

echo "$NAME: Unzipping '$FILENAME' to '$UNZIP_TO':"

ditto -xk --noqtn "$FILENAME" "$UNZIP_TO"

EXIT="$?"

if [[ "$EXIT" == "0" ]]
then
echo "$NAME: Unzip successful"
else
# failed
echo "$NAME failed (ditto -xkv '$FILENAME' '$UNZIP_TO')"

exit 1
fi

if [[ -e "$INSTALL_TO" ]]
then

pgrep -xq "$INSTALL_TO:t:r" \
&& LAUNCH='yes' \
&& osascript -e "tell application \"$INSTALL_TO:t:r\" to quit"

echo "$NAME: Moving existing (old) '$INSTALL_TO' to '$HOME/.Trash/'."

mv -vf "$INSTALL_TO" "$HOME/.Trash/$INSTALL_TO:t:r.$INSTALLED_VERSION.app"

EXIT="$?"

if [[ "$EXIT" != "0" ]]
then

echo "$NAME: failed to move existing $INSTALL_TO to $HOME/.Trash/"

exit 1
fi
fi

echo "$NAME: Moving new version of '$INSTALL_TO:t' (from '$UNZIP_TO') to '$INSTALL_TO'."

# Move the file out of the folder
# note that the '/*/' is to go inside whatever subfolder is created
# this is something all 'eclecticapps' apps do but most other apps do not
mv -vn "${UNZIP_TO}"/*/"$INSTALL_TO:t" "$INSTALL_TO"

EXIT="$?"

if [[ "$EXIT" = "0" ]]
then

echo "$NAME: Successfully installed '$UNZIP_TO/$INSTALL_TO:t' to '$INSTALL_TO'."

else
echo "$NAME: Failed to move '$UNZIP_TO/$INSTALL_TO:t' to '$INSTALL_TO'."

exit 1
fi

[[ "$LAUNCH" = "yes" ]] && open -a "$INSTALL_TO"

exit 0
#EOF

0 comments on commit cb813c5

Please sign in to comment.