-
Notifications
You must be signed in to change notification settings - Fork 10
/
di-cyberduck.sh
executable file
·211 lines (154 loc) · 5.54 KB
/
di-cyberduck.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env zsh -f
# Purpose: Download and install the latest version of Cyberduck
#
# From: Timothy J. Luoma
# Mail: luomat at gmail dot com
# Date: 2016-01-19
NAME="$0:t:r"
INSTALL_TO="/Applications/Cyberduck.app"
HOMEPAGE="https://cyberduck.io"
DOWNLOAD_PAGE="https://cyberduck.io"
SUMMARY="Cyberduck is a libre server and cloud storage browser with support for FTP, SFTP, WebDAV, Amazon S3, OpenStack Swift, Backblaze B2, Microsoft Azure & OneDrive, Google Drive, and Dropbox."
## This is a more complicated case than usual, because Cyberduck
## has THREE feeds:
## one for _nightly_ releases
## one for _beta_ releases
## one for _stable_ releases
##
## Now, currently, as of 2018-08-13, both of the so-called “nightly”
## and the “beta” feeds actually seem to contain the same information
## but, that might change in the future.
##
## So we have to give people the option of being able to set two
## 'PREFERS_BETAS_FILE' files. The question is, how do we prioritize them?
##
## Well, I made the decision that if someone has created a file for
## _both_ the nightly _and_ the betas, I was going to use the betas
##
## But they could still opt for the betas instead of the nightly
## builds, if they prefer.
## Create _this_ file if you want NIGHTLY builds
PREFERS_BETAS_FILE="$HOME/.config/di/cyberduck-prefer-nightly.txt"
if [[ -e "$PREFERS_BETAS_FILE" ]]
then
XML_FEED="https://version.cyberduck.io/nightly/changelog.rss"
NAME="$NAME (nightly releases)"
else
## Create _this_ file if you want BETA builds
PREFERS_BETAS_FILE="$HOME/.config/di/cyberduck-prefer-betas.txt"
if [[ -e "$PREFERS_BETAS_FILE" ]]
then
NAME="$NAME (beta releases)"
XML_FEED="https://version.cyberduck.io/beta/changelog.rss"
else
XML_FEED="https://version.cyberduck.io/changelog.rss"
fi
fi
RELEASE_NOTES_URL=$(curl -sfL "$XML_FEED" \
| fgrep '<sparkle:releaseNotesLink>' \
| head -1 \
| sed 's#.*<sparkle:releaseNotesLink>##g ; s#</sparkle:releaseNotesLink>##g')
if [[ -e "$HOME/.path" ]]
then
source "$HOME/.path"
fi
INFO=($(curl -sfL "$XML_FEED" \
| tr ' ' '\012' \
| egrep '^(url|sparkle:shortVersionString|sparkle:version)=' \
| sort \
| head -3 \
| awk -F'"' '//{print $2}'))
LATEST_VERSION="$INFO[1]"
LATEST_BUILD="$INFO[2]"
URL="$INFO[3]"
# If any of these are blank, we should not continue
if [ "$INFO" = "" -o "$LATEST_VERSION" = "" -o "$LATEST_BUILD" = "" -o "$URL" = "" ]
then
echo "$NAME: Error: bad data received:\nINFO: $INFO\nLATEST_VERSION: $LATEST_VERSION\nLATEST_BUILD: $LATEST_BUILD\nURL: $URL"
exit 1
fi
if [[ -e "$INSTALL_TO" ]]
then
INSTALLED_VERSION=$(defaults read "${INSTALL_TO}/Contents/Info" CFBundleShortVersionString)
INSTALLED_BUILD=$(defaults read "${INSTALL_TO}/Contents/Info" CFBundleVersion)
autoload is-at-least
is-at-least "$LATEST_VERSION" "$INSTALLED_VERSION"
VERSION_COMPARE="$?"
is-at-least "$LATEST_BUILD" "$INSTALLED_BUILD"
BUILD_COMPARE="$?"
if [ "$VERSION_COMPARE" = "0" -a "$BUILD_COMPARE" = "0" ]
then
echo "$NAME: Up-To-Date ($INSTALLED_VERSION/$INSTALLED_BUILD)"
exit 0
fi
echo "$NAME: Outdated: $INSTALLED_VERSION/$INSTALLED_BUILD vs $LATEST_VERSION/$LATEST_BUILD"
FIRST_INSTALL='no'
if [[ -e "$INSTALL_TO/Contents/_MASReceipt/receipt" ]]
then
echo "$NAME: $INSTALL_TO was installed from the Mac App Store and cannot be updated by this script."
echo " See <https://apps.apple.com/us/app/cyberduck/id409222199?mt=12> or"
echo " <macappstore://apps.apple.com/us/app/cyberduck/id409222199>"
echo " Please use the App Store app to update it: <macappstore://showUpdatesPage?scan=true>"
exit 0
fi
else
FIRST_INSTALL='yes'
fi
FILENAME="$HOME/Downloads/$INSTALL_TO:t:r-${LATEST_VERSION}_${LATEST_BUILD}.zip"
if (( $+commands[lynx] ))
then
( echo "$NAME: Release Notes for $INSTALL_TO:t:r ($LATEST_VERSION/$LATEST_BUILD):" ;
(echo '<ul>';
curl -sfL "${RELEASE_NOTES_URL}" | sed '1,/<ul>/d; /<\/ul>/,$d' ;
echo '</ul>' ) \
| lynx -dump -nomargins -width='10000' -assume_charset=UTF-8 -pseudo_inlines -stdin ;
echo "\nSource: <$RELEASE_NOTES_URL>" ) \
| tee "$FILENAME:r.txt"
fi
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
pgrep -qx "$INSTALL_TO:t:r" && LAUNCH='yes' && killall "$INSTALL_TO:t:r"
mv -f "$INSTALL_TO" "$HOME/.Trash/$INSTALL_TO:t:r.$INSTALLED_VERSION.app"
fi
echo "$NAME: Installing '$FILENAME' to '$INSTALL_TO:h/':"
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
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
exit 0
EOF