meta: make auto-update more robust

This commit is contained in:
Connor Olding 2022-10-12 07:22:31 -07:00
parent 76d6e8213e
commit c98b2c0fa5

View File

@ -27,19 +27,22 @@ latest() { : \
&& { [ -d "$dir" ] && [ -f "$dir/$df" ] && [ -s "$dir/$df" ] \ && { [ -d "$dir" ] && [ -f "$dir/$df" ] && [ -s "$dir/$df" ] \
|| { note "missing $df, skipping $dir ($tag)"; continue ;} \ || { note "missing $df, skipping $dir ($tag)"; continue ;} \
;} \ ;} \
&& ours="$(grep -F "$tag"= "$dir/$df" | grep -Eo '[0-9a-f]{40}')" \ && grep -Fq "$tag=" "$dir/$df" \
&& ours="$(grep -F "$tag=" "$dir/$df" | cut -d= -f2-)" \
&& theirs="$(latest "$url")" ours="${ours%%$n*}" theirs="${theirs%%$n*}" \ && theirs="$(latest "$url")" ours="${ours%%$n*}" theirs="${theirs%%$n*}" \
&& if [ ${#ours} = 0 ] || [ ${#theirs} = 0 ] \ && if [ ${#theirs} = 0 ] \
;then note "failed to retrieve update for $dir ($tag)" \ ;then note "failed to retrieve update for $dir ($tag)" \
;elif [ "$ours" != "$theirs" ] \ ;elif [ "$ours" != "$theirs" ] \
;then any=1 && note "updating $dir ($tag)" \ ;then any=1 && note "updating $dir ($tag)" \
&& other="${tag%_COMMIT}_SHA256" && tgz="${url%/}" \ && other="${tag%_COMMIT}_SHA256" && tgz="${url%/}" \
&& tgz="${tgz%%/tree/*}" && tgz="$tgz/archive/$theirs.tar.gz" \ && tgz="${tgz%%/tree/*}" && tgz="$tgz/archive/$theirs.tar.gz" \
&& { sum="$(curl $flags "$tgz" | sha256sum - | awk '{print $1}')" \ && { sum="$(curl $flags "$tgz" | sha256sum - | awk '{print $1}')" \
&& notwa-util/shed "$dir/$df" "s/$ours/$theirs/g" \ && notwa-util/shed "$dir/$df" "s/$tag=$ours/$tag=$theirs/g" \
&& notwa-util/shed "$dir/$df" "s/$other=.*/$other=$sum/g" \ && notwa-util/shed "$dir/$df" "s/$other=.*/$other=$sum/g" \
;} \ ;} \
|| note "failed to apply update for $dir ($tag)" \ || note "failed to apply update for $dir ($tag)" \
;fi ;done \ ;fi \
|| note "failed to determine update for $dir ($tag)" \
;done \
&& { [ $any = 1 ] || note "no new updates" ;} \ && { [ $any = 1 ] || note "no new updates" ;} \
; ;