-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdi-clarify.sh
executable file
·121 lines (85 loc) · 2.87 KB
/
di-clarify.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env zsh -f
# Purpose: Download and install latest version of http://www.clarify-it.com/
#
# From: Timothy J. Luoma
# Mail: luomat at gmail dot com
# Date: 2015-12-04
NAME="$0:t:r"
INSTALL_TO='/Applications/Clarify.app'
HOMEPAGE="http://www.clarify-it.com/"
DOWNLOAD_PAGE="http://www.clarify-it.com/download/mac"
SUMMARY="Clarify 2 _was_ a Faster, Simpler Alternative to Screen Recording."
if [[ -e "$HOME/.path" ]]
then
source "$HOME/.path"
fi
## 2018-07-17 this feed seemed to be outdated
#XML_FEED='http://www.bluemangolearning.com/download/clarify/2_0/auto_update/release/clarify_appcast.xml'
##
## 2018-07-17 found new feed via find_appcast
XML_FEED="https://s3.amazonaws.com/files.clarify-it.com/v2/updaters/release/appcast.xml"
INFO=($(curl -sfL "$XML_FEED" \
| tr -s ' ' '\012' \
| egrep 'sparkle:shortVersionString=|url=' \
| head -2 \
| sort \
| awk -F'"' '/^/{print $2}'))
# "Sparkle" will always come before "url" because of "sort"
LATEST_VERSION="$INFO[1]"
URL="$INFO[2]"
# If any of these are blank, we should not continue
if [ "$INFO" = "" -o "$LATEST_VERSION" = "" -o "$URL" = "" ]
then
echo "$NAME: Error: bad data received:
INFO: $INFO
LATEST_VERSION: $LATEST_VERSION
URL: $URL
"
exit 1
fi
if [[ -e "$INSTALL_TO" ]]
then
INSTALLED_VERSION=`defaults read "$INSTALL_TO/Contents/Info" CFBundleShortVersionString 2>/dev/null || echo '0'`
if [[ "$LATEST_VERSION" == "$INSTALLED_VERSION" ]]
then
echo "$NAME: Up-To-Date ($INSTALLED_VERSION)"
exit 0
fi
autoload is-at-least
is-at-least "$LATEST_VERSION" "$INSTALLED_VERSION"
if [ "$?" = "0" ]
then
echo "$NAME: Installed version ($INSTALLED_VERSION) is ahead of official version $LATEST_VERSION"
exit 0
fi
echo "$NAME: Outdated (Installed = $INSTALLED_VERSION vs Latest = $LATEST_VERSION)"
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
if [[ -e "$INSTALL_TO" ]]
then
## Quit app, if running
# pgrep -xq "Clarify" \
# && LAUNCH='yes' \
# && osascript -e 'tell application "Clarify" to quit'
# move installed version to trash
mv -vf "$INSTALL_TO" "$HOME/.Trash/$INSTALL_TO:t:r.$INSTALLED_VERSION.app"
fi
echo "$NAME: Installing $FILENAME to $INSTALL_TO:h/"
# Extract from the .zip file and install (this will leave the .zip file in place)
ditto --noqtn -xk "$FILENAME" "$INSTALL_TO:h/"
EXIT="$?"
if [ "$EXIT" = "0" ]
then
echo "$NAME: Installation of $INSTALL_TO was successful."
[[ "$LAUNCH" == "yes" ]] && open -a "$INSTALL_TO"
else
echo "$NAME: Installation of $INSTALL_TO failed (ditto \$EXIT = $EXIT)\nThe downloaded file can be found at $FILENAME."
exit 1
fi
exit 0
#EOF