-
Notifications
You must be signed in to change notification settings - Fork 10
/
di-arq.sh
executable file
·152 lines (98 loc) · 3.71 KB
/
di-arq.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
#!/usr/bin/env zsh -f
# Purpose: download and install Arq 7
#
# From: Timothy J. Luoma
# Mail: luomat at gmail dot com
# Date: 2021-02-03
[[ -e "$HOME/.path" ]] && source "$HOME/.path"
[[ -e "$HOME/.config/di/defaults.sh" ]] && source "$HOME/.config/di/defaults.sh"
# this is installed via .pkg so will always end up in /Applications/
INSTALL_TO="/Applications/Arq.app"
NAME="$0:t:r"
JSON_FEED_URL='https://www.arqbackup.com/download/arqbackup/arq7_update.json'
INFO=($(curl -sfLS "${JSON_FEED_URL}" \
| egrep '"(url|version)"' \
| sort \
| awk -F'"' '//{print $4}'))
URL="$INFO[1]"
LATEST_VERSION="$INFO[2]"
# If any of these are blank, we cannot continue
if [ "$INFO" = "" -o "$URL" = "" -o "$LATEST_VERSION" = "" ]
then
echo "$NAME: Error: bad data received:
INFO: $INFO
LATEST_VERSION: $LATEST_VERSION
URL: $URL
" >>/dev/stderr
exit 1
fi
###############################################################################################
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="${DOWNLOAD_DIR_ALTERNATE-$HOME/Downloads}/${${INSTALL_TO:t:r}// /}-${${LATEST_VERSION}// /}_${${LATEST_BUILD}// /}.pkg"
RELEASE_NOTES_TXT="$FILENAME:r.txt"
RELEASE_NOTES_HTML="$FILENAME:r.html"
if [[ -e "${RELEASE_NOTES_TXT}" ]]
then
cat "${RELEASE_NOTES_TXT}"
else
if (( $+commands[lynx] ))
then
# has full history of v7 updates
RELEASE_NOTES_URL='https://www.arqbackup.com/download/arqbackup/arq7_release_notes.html'
TEMPFILE="${TMPDIR-/tmp/}${NAME}.${TIME}.$$.$RANDOM.txt"
curl -sfLS "${RELEASE_NOTES_URL}" > "$RELEASE_NOTES_HTML"
fgrep '<h1>' "${RELEASE_NOTES_HTML}" | cat -n > "${TEMPFILE}"
AWK_NUMBER=$(fgrep "${LATEST_VERSION}" "${TEMPFILE}" | awk '{print $1}')
RELEASE_NOTES=$(awk "/<h1>/{i++}i==$AWK_NUMBER" "${RELEASE_NOTES_HTML}" \
| lynx -dump -width='10000' -display_charset=UTF-8 \
-assume_charset=UTF-8 -pseudo_inlines -stdin -nomargins \
| sed 's#^[ ]*##g' )
echo "${RELEASE_NOTES}\n\nSource: ${RELEASE_NOTES_URL}\nVersion: ${LATEST_VERSION}\nURL: ${URL}" \
| tee "${RELEASE_NOTES_TXT}"
fi
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
[[ ! -e "$FILENAME" ]] && echo "$NAME: $FILENAME does not exist." && exit 0
[[ ! -s "$FILENAME" ]] && echo "$NAME: $FILENAME is zero bytes." && rm -f "$FILENAME" && exit 0
egrep -q '^Local sha256:$' "$FILENAME:r.txt" 2>/dev/null
EXIT="$?"
if [ "$EXIT" = "1" -o ! -e "$FILENAME:r.txt" ]
then
(cd "$FILENAME:h" ; \
echo "\n\nLocal sha256:" ; \
shasum -a 256 "$FILENAME:t" \
) >>| "$FILENAME:r.txt"
fi
###############################################################################################
if (( $+commands[pkginstall.sh] ))
then
# use 'pkginstall.sh' if it exists
pkginstall.sh "$FILENAME"
else
# fall back to either `sudo installer` or macOS's installer app
sudo /usr/sbin/installer -verbose -pkg "$FILENAME" -dumplog -target / -lang en 2>&1 \
|| open -b com.apple.installer "$FILENAME"
fi
exit 0
#EOF