move shell functions to a separate library file

This commit is contained in:
Connor Olding 2023-05-19 20:52:28 -07:00
parent f5fefd06a8
commit edd88ab5e3
2 changed files with 56 additions and 54 deletions

View File

@ -1,60 +1,7 @@
#!/usr/bin/env sh
announce() { : \
&& printf >&2 ' \033[1m\033[7m <-- \033[0m\033[1m ' \
&& printf >&2 ' %30s %-30s ' "$1" "$2" \
&& printf >&2 ' \033[1m\033[7m --> \033[0m\n' \
;}
yes_retrieve() { : \
&& local ok=1 out= g= image="${1?missing argument}" && shift \
&& [ -d out ] && out="$(realpath out)" \
&& for f in "$@" \
;do announce retrieving "$f" \
&& g="out/${f##*/}" && { ! [ -e "$g" ] || mv "$g" "$g~" ;} || return \
;done \
&& podman run -v="$out":/out --rm --entrypoint /bin/busybox "localhost/$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 \
&& announce building "$t" \
&& podman build -t "$t" "./$t" "$@" \
;}
build_simple() { : \
&& for f in simple/*.Dockerfile \
;do t="${f%.*}" t=${t##*/} \
&& announce '(simple) packaging' "$t" \
&& podman build -t "$t" -f "$f" simple \
|| return \
;done \
;}
build_base() { : \
&& sed 's/\bcosmo-bootstrap\b/cosmo-all/g' \
<cosmo-dist/Dockerfile >cosmo-dist/all.Dockerfile \
&& build cosmo-dist -f cosmo-dist/all.Dockerfile \
&& build cosmo-base \
;}
: \
&& me="$(readlink -f "$0")" && cd "${me%/*}" && { [ -d out ] || mkdir out ;} \
&& . ./lib.sh \
&& : \
\
`# phase 1` \

55
lib.sh Normal file
View File

@ -0,0 +1,55 @@
#!/usr/bin/false
announce() { : \
&& printf >&2 ' \033[1m\033[7m <-- \033[0m\033[1m ' \
&& printf >&2 ' %30s %-30s ' "$1" "$2" \
&& printf >&2 ' \033[1m\033[7m --> \033[0m\n' \
;}
yes_retrieve() { : \
&& local ok=1 out= g= image="${1?missing argument}" && shift \
&& [ -d out ] && out="$(realpath out)" \
&& for f in "$@" \
;do announce retrieving "$f" \
&& g="out/${f##*/}" && { ! [ -e "$g" ] || mv "$g" "$g~" ;} || return \
;done \
&& podman run -v="$out":/out --rm --entrypoint /bin/busybox "localhost/$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 \
&& announce building "$t" \
&& podman build -t "$t" "./$t" "$@" \
;}
build_simple() { : \
&& for f in simple/*.Dockerfile \
;do t="${f%.*}" t=${t##*/} \
&& announce '(simple) packaging' "$t" \
&& podman build -t "$t" -f "$f" simple \
|| return \
;done \
;}
build_base() { : \
&& sed 's/\bcosmo-bootstrap\b/cosmo-all/g' \
<cosmo-dist/Dockerfile >cosmo-dist/all.Dockerfile \
&& `# sed -i 's/#&& find o/ \&\& find o/' cosmo-dist/all.Dockerfile` \
&& build cosmo-dist -f cosmo-dist/all.Dockerfile \
&& build cosmo-base \
;}