-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdi-appzapper.sh
executable file
·188 lines (140 loc) · 4.74 KB
/
di-appzapper.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env zsh -f
# Purpose: Download and install the latest version of AppZapper
#
# From: Timothy J. Luoma
# Mail: luomat at gmail dot com
# Date: 2018-07-17
NAME="$0:t:r"
INSTALL_TO='/Applications/AppZapper.app'
HOMEPAGE="https://www.appzapper.com"
DOWNLOAD_PAGE="https://www.appzapper.com"
SUMMARY="Everybody loves the drag and drop nature of OS X. Drag an app into your applications folder, and it's installed. You'd think it would be that easy to delete an app — just a matter of dragging it to the trash. It's not. Apps install support files that generate clutter. Introducing AppZapper. Simply drag one or more apps onto AppZapper. Then, watch as it finds the extra files and lets you delete them with one click. Zap!"
if [[ -e "$HOME/.path" ]]
then
source "$HOME/.path"
fi
# I don't think there's ever going to be a 2.0.4 or later
# so I'm just hard-coding this in
LATEST_VERSION='2.0.3'
URL='https://iusethis.luo.ma/appzapper/AppZapper-2.0.3.zip'
## if you need to use the app for
## Mac OS X versions 10.8, 10.7, or back to 10.6.2
# URL='https://appzapper.com/downloads/AppZapper2.0.1.zip'
# LATEST_VERSION='2.0.1'
if [[ -e "$INSTALL_TO" ]]
then
INSTALLED_VERSION="$(defaults read "$INSTALL_TO/Contents/Info" CFBundleShortVersionString)"
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
[[ ! -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
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
## The app does not seem to be under active development. If that changes, the following might be useful.
## For now, it's just reference
##
# XML_FEED="https://www.appzapper.com/az2appcast.xml"
#
# RELEASE_NOTES_URL='https://www.appzapper.com/az2sparklenotes.html'
#
# INFO=($(curl -sfL "$XML_FEED" \
# | tr -s ' ' '\012' \
# | egrep 'sparkle:version=|url=' \
# | head -2 \
# | sort \
# | awk -F'"' '/^/{print $2}'))
#
# 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
#
# ## 2018-07-17 - as of this writing, the XML_FEED only shows version 2.0.1 but the website shows 2.0.2
# ## I don't know if the app will ever be updated in the future, so
# ## if we get 2.0.1 from the XML_FEED, we're going to silently replace it with 2.0.2
#
# if [[ "$LATEST_VERSION" == "2.0.1" ]]
# then
#
# URL="https://appzapper.com/downloads/appzapper202.zip"
#
# LATEST_VERSION="2.0.2"
#
# fi
#
# if (( $+commands[lynx] ))
# then
#
# ( echo "$NAME: Release Notes for $INSTALL_TO:t:r ($LATEST_VERSION):" ;
# lynx -dump -nomargins -width='10000' -assume_charset=UTF-8 -pseudo_inlines "$RELEASE_NOTES_URL" ;
# echo "\nSource: <$RELEASE_NOTES_URL>" ) | tee "$FILENAME:r.txt"
#
# fi
#
#EOF