stargazing/auto-update

49 lines
2.1 KiB
Text
Raw Normal View History

#!/usr/bin/env sh
note() { printf >&2 '\033[1m%s\033[0m\n' "$*" ;}
2022-10-13 12:36:11 -07:00
latest() { : \
2022-10-13 12:36:11 -07:00
&& url="${1?missing argument}" \
&& { [ "${url#"https://github.com/"}" = "$url" ] \
&& re='/commit/' || re='/spoofed_commit_check/' \
;} \
&& curl $flags "$url" | grep -F "$re" | grep -Eo '[0-9a-f]{40}' \
;}
2022-10-13 12:36:11 -07:00
any=0 flags="-L --no-progress-meter" n="$(printf '\n.')" n="${n%.}" \
df=Dockerfile gh='https://github.com/' sr='https://git.sr.ht/~' \
&& set -- \
cosmo COSMO_COMMIT ${gh}jart/cosmopolitan \
cosmo-kuroko KUROKO_COMMIT ${gh}kuroko-lang/kuroko \
cosmo-muon MUON_COMMIT ${sr}lattis/muon \
cosmo-perl PERL_COMMIT ${gh}G4Vi/perl5/tree/cosmo \
cosmo-python PYTHON_COMMIT ${gh}ahgamut/cpython/tree/cosmo_py311 \
cosmo-yices KISSAT_COMMIT ${gh}BrunoDutertre/kissat \
cosmo-yices YICES_COMMIT ${gh}SRI-CSL/yices2 \
&& me="$(readlink -f "$0")" && cd "${me%/*}" \
&& while [ $# != 0 ] \
;do dir="$1" tag="$2" url="$3" \
&& { shift && shift && shift || { note 'incomplete triplet'; exit 70 ;} ;} \
2022-10-05 08:19:05 -07:00
&& { [ -d "$dir" ] && [ -f "$dir/$df" ] && [ -s "$dir/$df" ] \
|| { note "missing $df, skipping $dir ($tag)"; continue ;} \
;} \
2022-10-12 07:22:31 -07:00
&& grep -Fq "$tag=" "$dir/$df" \
&& ours="$(grep -F "$tag=" "$dir/$df" | cut -d= -f2-)" \
&& theirs="$(latest "$url")" ours="${ours%%$n*}" theirs="${theirs%%$n*}" \
2022-10-12 07:22:31 -07:00
&& if [ ${#theirs} = 0 ] \
;then note "failed to retrieve update for $dir ($tag)" \
;elif [ "$ours" != "$theirs" ] \
;then any=1 && note "updating $dir ($tag)" \
&& other="${tag%_COMMIT}_SHA256" && tgz="${url%/}" \
&& tgz="${tgz%%/tree/*}" && tgz="$tgz/archive/$theirs.tar.gz" \
&& { sum="$(curl $flags "$tgz" | sha256sum - | awk '{print $1}')" \
2022-10-12 07:22:31 -07:00
&& notwa-util/shed "$dir/$df" "s/$tag=$ours/$tag=$theirs/g" \
&& notwa-util/shed "$dir/$df" "s/$other=.*/$other=$sum/g" \
;} \
|| note "failed to apply update for $dir ($tag)" \
2022-10-12 07:22:31 -07:00
;fi \
|| note "failed to determine update for $dir ($tag)" \
;done \
&& { [ $any = 1 ] || note "no new updates" ;} \
;