#!/usr/bin/env sh yes_retrieve() { : \ && local ok=1 out= g= image="${1?missing argument}" && shift \ && [ -d out ] && out="$(realpath out)" \ && for f in "$@" \ ;do g="out/${f##*/}" && { ! [ -e "$g" ] || mv "$g" "$g~" ;} || return \ ;done \ && podman run -v="$out":/out --rm --entrypoint /bin/busybox "$image" \ cp -- "$@" "/out/" \ && for f in "$@" \ ;do if g="out/${f##*/}" && [ -e "$g" ] \ ;then ! [ -e "$g~" ] || rm "$g~" || return \ ;else printf 'yes_retrieve: %s\n' "failed to copy file $f to $g"; ok=0 \ ;fi ;done \ && [ $ok = 1 ] \ ;} dbg_retrieve() { : \ && local o=0 container="${1?missing argument}" && shift \ && for f in "$@" \ ;do [ $o = 0 ] && o=1 && set -- "$f" "$f.dbg" || set -- "$f" "$f.dbg" "$@" \ ;done \ && yes_retrieve "$container" "$@" \ ;} build() { : \ && local t="${1?missing argument}" && shift \ && printf >&2 ' \033[1m\033[7m <-- \033[0m\033[1m ' \ && printf >&2 '%22sbuilding %-19s%13s' '' "$t" '' \ && printf >&2 ' \033[1m\033[7m --> \033[0m\n' \ && podman build -t "$t" "$t" "$@" \ ;} : \ && me="$(readlink -f "$0")" && cd "${me%/*}" && { [ -d out ] || mkdir out ;} \ ;: \ `# phase 1` \ && build notwa-util \ `# phase 2` \ && build cosmo-bootstrap \ `# phase 3` \ && build cosmo-all \ && build cosmo-assimilate \ && build cosmo-awk \ && build cosmo-dist \ && build cosmo-sed \ `# phase 4` \ && build cosmo-base \ && for f in simple/*.Dockerfile \ ;do : \ && g="${f%.*}" \ && podman build -t "${g##*/}" "$f" \ ;done \ `# phase 5` \ && build cosmo-kuroko \ && build cosmo-muon \ && build cosmo-perl \ && build cosmo-yices \ `# other stuff` \ && { [ ! -e cosmo-mini ] || build cosmo-mini ;} \ && { [ ! -e cosmo-python311 ] || build cosmo-python311 ;} \ \ && bin=/cosmopolitan/bin \ && yes_retrieve cosmo-base $bin/ape $bin/assimilate.com $bin/awk.com \ $bin/gzip.com $bin/make.com $bin/sed.com $bin/unzip.com $bin/zip.com \ && dbg_retrieve cosmo-kuroko /bin/kuroko.com \ && dbg_retrieve cosmo-muon /bin/muon.com \ && dbg_retrieve cosmo-perl /bin/perl.com \ && yes_retrieve cosmo-unbourne /bin/unbourne.com \ && dbg_retrieve cosmo-yices /bin/kissat.com /bin/yices-sat.com \ /bin/yices-smt.com /bin/yices-smt2.com /bin/yices.com \ ;