From 039652c2b918524ae842f995e66e5ee709138e95 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Wed, 5 Oct 2022 04:01:29 -0700 Subject: [PATCH] meta: rewrite auto-update in cursed code style --- auto-update | 83 ++++++++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 43 deletions(-) diff --git a/auto-update b/auto-update index b190ee8..6027e6f 100755 --- a/auto-update +++ b/auto-update @@ -1,48 +1,45 @@ #!/usr/bin/env sh note() { printf >&2 '\033[1m%s\033[0m\n' "$*" ;} +latest() { : \ + && url="${1?huh}" \ + && { [ "${url#"https://github.com/"}" = "$url" ] \ + && re='/commit/' || re='/spoofed_commit_check/' \ + ;} \ + && curl $flags "$url" | grep -F "$re" | grep -Eo '[0-9a-f]{40}' \ + ;} -investigate() { - url="${1?huh}" - [ "${url#"https://github.com/"}" = "$url" ] \ - && re='/commit/' || re='/spoofed_commit_check/' - curl $curlflags "$url" | grep -F "$re" | grep -Eo '[0-9a-f]{40}' -} - -me="$(readlink -f "$0")" && cd "${me%/*}" || exit -curlflags="-L --no-progress-meter" -any=0 -set -- \ -cosmo COSMO_COMMIT https://github.com/jart/cosmopolitan \ -cosmo-kuroko KUROKO_COMMIT https://github.com/kuroko-lang/kuroko \ -cosmo-muon MUON_COMMIT https://git.sr.ht/~lattis/muon \ -cosmo-perl PERL_COMMIT https://github.com/G4Vi/perl5/tree/cosmo \ -cosmo-python PYTHON_COMMIT https://github.com/ahgamut/cpython/tree/cosmo_py311 \ -cosmo-yices KISSAT_COMMIT https://github.com/BrunoDutertre/kissat \ -cosmo-yices YICES_COMMIT https://github.com/SRI-CSL/yices2 \ +: \ + && 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 ;} ;} \ + && if ! [ -d "$dir" ] && ! [ -f "$dir/$df" ] && ! [ -s "$dir/$df" ] \ + ;then note "missing $df, skipping $dir ($tag)"; continue \ + ;fi \ + && ours="$(grep -F "$tag"= "$dir/$df" | grep -Eo '[0-9a-f]{40}')" \ + && theirs="$(latest "$url")" ours="${ours%%$n*}" theirs="${theirs%%$n*}" \ + && if [ ${#ours} = 0 ] || [ ${#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/$ours/$theirs/g" \ + && notwa-util/shed "$dir/$df" "s/$other=.*/$other=$sum/g" \ + ;} \ + || note "failed to apply update for $dir ($tag)" \ + ;fi ;done \ + && { [ $any = 1 ] || note "no new updates" ;} \ ; - -while [ $# != 0 ]; do - dir="$1" tag="$2" url="$3" - shift && shift && shift || { note 'not a multiple of 3!'; exit 255 ;} - if ! [ -d "$dir" -a -f "$dir/Dockerfile" -a -s "$dir/Dockerfile" ]; then - note "missing Dockerfile, skipping $dir ($tag)" - continue - fi - ours="$(grep -F "$tag"= "$dir/Dockerfile" | grep -Eo '[0-9a-f]{40}' | head -n1)" - theirs="$(investigate "$url" | head -n1)" - if [ ${#ours} == 0 -o ${#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 $curlflags "$tgz" | sha256sum - | awk '{print $1}')" \ - && notwa-util/shed "$dir/Dockerfile" "s/$ours/$theirs/g" \ - && notwa-util/shed "$dir/Dockerfile" "s/$other=.*/$other=$sum/g" \ - ;} \ - || note "failed to apply update for $dir ($tag)" - fi -done -[ $any = 1 ] || note "no new updates"