stargazing/auto-update

49 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env sh
note() { printf >&2 '\033[1m%s\033[0m\n' "$*" ;}
latest() { : \
&& 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}' \
;}
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-bootstrap 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 ;} ;} \
&& { [ -d "$dir" ] && [ -f "$dir/$df" ] && [ -s "$dir/$df" ] \
|| { note "missing $df, skipping $dir ($tag)"; continue ;} \
;} \
&& grep -Fq "$tag=" "$dir/$df" \
&& ours="$(grep -F "$tag=" "$dir/$df" | cut -d= -f2-)" \
&& theirs="$(latest "$url")" ours="${ours%%$n*}" theirs="${theirs%%$n*}" \
&& 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}')" \
&& 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)" \
;fi \
|| note "failed to determine update for $dir ($tag)" \
;done \
&& { [ $any = 1 ] || note "no new updates" ;} \
;