util: largely superficial tweaking

This commit is contained in:
Connor Olding 2022-10-04 05:59:38 -07:00
parent 8653d6dd54
commit 9a79aeba8f
2 changed files with 64 additions and 65 deletions

View File

@ -1,17 +1,11 @@
#!/usr/bin/env sh
: \
&& warn() { printf >&2 '\033[1m%s:\033[m %s\n' acquire "$*" ;} \
&& die() { warn "$@"; exit 64 ;} \
&& missing()
{ : \
&& [ ${#3} != 0 ] \
|| { warn "missing a required $1: $2"; ok=0 ;} \
;} \
&& ok=1 from= repo= commit= checksum= \
\
&& if [ "$#" != 0 ] \
;then : \
warn() { printf >&2 '\033[1m%s:\033[m %s\n' acquire "$*" ;}
die() { warn "$@"; exit 64 ;}
missing() { [ ${#3} != 0 ] || { warn "missing a required $1: $2"; ok=0 ;} ;}
argue()
{ : \
&& for arg in "$@" \
;do : \
&& rhs="${arg#*=}" \
@ -66,8 +60,12 @@
&& die "unknown value specified for \"from\": $from" \
;fi \
|| exit \
;fi \
\
;}
ok=1 from= repo= commit= checksum=
: \
&& { [ "$#" == 0 ] || argue "$@" ;} \
&& { [ -d "/tmp" ] || die '/tmp must be mounted (or just exist)' ;} \
&& missing variable dest "$dest" \
&& missing variable local_fn "$local_fn" \

View File

@ -18,10 +18,11 @@ read -r program <<'EOF'
BEGIN{if(!D){print U;exit 64}E=(Q="'")"\"'\""Q;H=(G=".")(F="/");I=" -- "Q;J="[^/]*/";sub(F"?$",F,D)gsub(Q,E,D)}function C(x){if(X=system(x))exit X}{if((p=$2)==B){print V;exit 65}for(r=z=i=d=B;d!=!i;i++){b=a=p;d=sub("/.*",B,a);sub(J,B,p);if(a==G G)e=!sub(J,B,z);else z=a==G?z:b!=a?z a F:z a;if(e||!i&&!a){print W;exit 65}}P=p=!z?H:z;if((o=O[$1])==p)next;gsub(Q,E,P);M=m=D P;gsub("/[^/]+$",B,M);if(!u[M]++)C("mkdir -p"I M Q);if(o){T=split(o,t,F);S=split(p,s,F);for(i=1;t[i]==s[i];i++);for(j=i;j<S;j++)r=r G H;for(j=i;j<T;j++)r=r t[j]F;r=h?o:r t[T];gsub(Q,E,r);C("ln"(h?I D:" -s"I)r"' '"m Q);next}O[$1]=p;C("cp -i"I P"' '"m Q)}
EOF
die() { printf '\033[1mdedupe:\033[m %s\n' >&2 "$2"; exit "$1" ;}
h=0
: \
&& die() { printf '\033[1mdedupe:\033[m %s\n' >&2 "$2"; exit "$1" ;} \
&& while o="${1#-}" && [ "${#o}" != "${#1}" ] && shift \
;do case "$o" in \
(-) break ;; \