Skip to content

Commit dad7e1b

Browse files
authored
simplex-servers-update: download scripts from tag (#1457)
* simplex-servers-update: download scripts from tag * set remote version when re-executing the update script * safeguard variables * additional checks
1 parent 72c2ddc commit dad7e1b

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

scripts/main/simplex-servers-update

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ set -eu
44
# Make sure that PATH variable contains /usr/local/bin
55
PATH="/usr/local/bin:$PATH"
66

7-
# Links to scripts/configs
8-
scripts_url="https://raw.githubusercontent.com/simplex-chat/simplexmq/stable/scripts/main"
9-
scripts_url_systemd_smp="$scripts_url/smp-server.service"
10-
scripts_url_systemd_xftp="$scripts_url/xftp-server.service"
11-
scripts_url_update="$scripts_url/simplex-servers-update"
12-
scripts_url_uninstall="$scripts_url/simplex-servers-uninstall"
13-
scripts_url_stopscript="$scripts_url/simplex-servers-stopscript"
14-
157
# Default installation paths
168
path_bin="/usr/local/bin"
179
path_bin_smp="$path_bin/smp-server"
@@ -139,7 +131,6 @@ check_versions() {
139131

140132
case "$VER" in
141133
latest)
142-
bin_url="https://github.com/simplex-chat/simplexmq/releases/latest/download"
143134
remote_version="$(curl --proto '=https' --tlsv1.2 -sSf -L https://api.github.com/repos/simplex-chat/simplexmq/releases/latest 2>/dev/null | grep -i "tag_name" | awk -F \" '{print $4}')"
144135

145136
if [ -z "$remote_version" ]; then
@@ -152,7 +143,6 @@ check_versions() {
152143
ver_check="https://github.com/simplex-chat/simplexmq/releases/tag/${VER}"
153144

154145
if curl -o /dev/null --proto '=https' --tlsv1.2 -sf -L "${ver_check}"; then
155-
bin_url="https://github.com/simplex-chat/simplexmq/releases/download/${VER}"
156146
remote_version="${VER}"
157147
else
158148
printf "Provided version ${BLU}%s${NC} ${RED}doesn't exist${NC}! Switching to ${BLU}latest${NC}.\n" "${VER}"
@@ -167,6 +157,15 @@ check_versions() {
167157
;;
168158
esac
169159

160+
# Links to scripts/configs
161+
bin_url="https://github.com/simplex-chat/simplexmq/releases/download/${remote_version}"
162+
scripts_url="https://raw.githubusercontent.com/simplex-chat/simplexmq/refs/tags/${remote_version}/scripts/main"
163+
scripts_url_systemd_smp="$scripts_url/smp-server.service"
164+
scripts_url_systemd_xftp="$scripts_url/xftp-server.service"
165+
scripts_url_update="$scripts_url/simplex-servers-update"
166+
scripts_url_uninstall="$scripts_url/simplex-servers-uninstall"
167+
scripts_url_stopscript="$scripts_url/simplex-servers-stopscript"
168+
170169
set +u
171170
for i in smp xftp; do
172171
# Only check local directory where binaries are installed by the script
@@ -261,7 +260,10 @@ download_thing() {
261260
check_pattern="$3"
262261
err_msg="$4"
263262

264-
curl --proto '=https' --tlsv1.2 -sSf -L "$thing" -o "$path"
263+
if ! curl --proto '=https' --tlsv1.2 -sSf -L "$thing" -o "$path"; then
264+
printf "${RED}Something went wrong when downloading ${YLW}%s${NC}: either you don't have connection to Github or you're rate-limited.\n" "$err_msg"
265+
exit 1
266+
fi
265267

266268
type="$(file "$path")"
267269

@@ -270,7 +272,7 @@ download_thing() {
270272
esac
271273

272274
if ! check_sanity "$path" "$check_pattern"; then
273-
printf "${RED}Something went wrong when downloading ${YLW}%s${NC}: either you don't have connection to Github or you're rate-limited.\n" "$err_msg"
275+
printf "${RED}Something went wrong with downloaded ${YLW}%s${NC}: file is corrupted.\n" "$err_msg"
274276
exit 1
275277
fi
276278

@@ -329,14 +331,14 @@ update_misc() {
329331
OLD_IFS="$IFS"
330332

331333
IFS='/'
332-
for script in $msg_scripts_raw; do
334+
for script in ${msg_scripts_raw:-}; do
333335
case "$script" in
334336
update)
335337
printf -- "- Updating update script..."
336338
mv "$path_tmp_bin_update" "$path_bin_update"
337339
printf "${GRN}Done!${NC}\n"
338340
printf -- "- Re-executing Update script..."
339-
exec env UPDATE_SCRIPT_DONE=1 "$path_bin_update" "${selection}"
341+
exec env UPDATE_SCRIPT_DONE=1 VER="$remote_version" "$path_bin_update" "${selection}"
340342
;;
341343
stop)
342344
printf -- "- Updating stopscript script..."
@@ -351,7 +353,7 @@ update_misc() {
351353
esac
352354
done
353355

354-
for service in $msg_services_raw; do
356+
for service in ${msg_services_raw:-}; do
355357
app="${service%%-*}"
356358
eval "path_systemd=\$path_systemd_${app}"
357359
eval "path_tmp_systemd=\$path_tmp_systemd_${app}"
@@ -371,7 +373,7 @@ update_bins() {
371373
OLD_IFS="$IFS"
372374

373375
IFS='/'
374-
for service in $msg_bins_raw; do
376+
for service in ${msg_bins_raw:-}; do
375377
app="${service%%-*}"
376378
eval "local_version=\$local_version_${app}"
377379
eval "bin_url_final=\$bin_url_${app}"
@@ -413,7 +415,7 @@ download_bins() {
413415
OLD_IFS="$IFS"
414416

415417
IFS='/'
416-
for service in $msg_bins_raw; do
418+
for service in ${msg_bins_raw:-}; do
417419
app="${service%%-*}"
418420
eval "local_version=\$local_version_${app}"
419421
eval "bin_url_final=\$bin_url_${app}"

0 commit comments

Comments
 (0)