From 5c18d12cbfbbbc8d1371355c7e3c74b1140c814d Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 14 Dec 2020 03:45:59 +0100 Subject: [PATCH] self-upgrading upgrader... getting too meta --- scripts/copyparty-repack.sh | 25 +++++++++++++++++++------ scripts/make-sfx.sh | 0 2 files changed, 19 insertions(+), 6 deletions(-) mode change 100644 => 100755 scripts/copyparty-repack.sh mode change 100644 => 100755 scripts/make-sfx.sh diff --git a/scripts/copyparty-repack.sh b/scripts/copyparty-repack.sh old mode 100644 new mode 100755 index 52171bdd..50d1d6b5 --- a/scripts/copyparty-repack.sh +++ b/scripts/copyparty-repack.sh @@ -1,4 +1,5 @@ #!/bin/bash +repacker=1 set -e # -- download latest copyparty (source.tgz and sfx), @@ -38,10 +39,10 @@ dl_files() { export -f dl_files -# debug: if cache exists, use that instead of bothering github +# if cache exists, use that instead of bothering github cache="$od/.copyparty-repack.cache" [ -e "$cache" ] && - tar -xvf "$cache" || + tar -xf "$cache" || { # get download links from github dl_text https://api.github.com/repos/9001/copyparty/releases/latest | @@ -56,8 +57,7 @@ cache="$od/.copyparty-repack.cache" tr -d '\r' | tr '\n' '\0' | xargs -0 bash -c 'dl_files "$@"' _ - # debug: create cache - #tar -czvf "$cache" * + tar -czf "$cache" * } @@ -70,10 +70,21 @@ mv copyparty-*.tar.gz copyparty-extras/ # unpack the source code ( cd copyparty-extras/ -tar -xvf *.tar.gz +tar -xf *.tar.gz ) +# use repacker from release if that is newer +p_other=copyparty-extras/copyparty-*/scripts/copyparty-repack.sh +other=$(awk -F= 'BEGIN{v=-1} NR<10&&/^repacker=/{v=$NF} END{print v}' <$p_other) +[ $repacker -lt $other ] && + cat $p_other >"$od/$0" && cd "$od" && rm -rf "$td" && exec "$0" "$@" + + +# now drop the cache +rm -f "$cache" + + # fix permissions chmod 755 \ copyparty-extras/sfx-full/* \ @@ -101,7 +112,9 @@ rm -rf copyparty-{0..9}*.*.*{0..9} # and include the repacker itself too -cp -pv "$od/$0" copyparty-extras/ +cp -av "$od/$0" copyparty-extras/ || +cp -av "$0" copyparty-extras/ || +true # create the bundle diff --git a/scripts/make-sfx.sh b/scripts/make-sfx.sh old mode 100644 new mode 100755