From c82ce9640fe644f4e544b7ae70468308d602cdd3 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Mon, 3 Oct 2022 23:55:22 -0700 Subject: [PATCH] util: clean up dedupe and pass program inline --- notwa-util/dedupe | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/notwa-util/dedupe b/notwa-util/dedupe index 6e44317..62da551 100755 --- a/notwa-util/dedupe +++ b/notwa-util/dedupe @@ -1,31 +1,16 @@ #!/usr/bin/env sh -: \ - && complain() - { : \ - && printf '\033[1m%s\033[m: %s\n' >&2 dedupe "$*" \ - ;} \ -\ - && { : \ - && [ -d /tmp ] \ - || { complain "/tmp must be mounted"; exit 72 ;} \ - ;} \ -\ - && f="$(mktemp)" \ -\ - && { : \ - && [ -s "$f" ] \ - || { : \ - && cat >"$f" <<'EOF' +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&2 dedupe "$*" ;} \ + && { [ -d /tmp ] || { complain "/tmp must be mounted"; exit 72 ;} ;} \ && h=0 && { [ "$1" != --hard ] || shift && h=1 ;} \ && cd "$1" && shift && D="$1" && shift && t="$(mktemp)" \ && { [ $# -eq 0 ] || sha256sum >"$t" "$@" ;} \ && find ! -type d -exec sha256sum {} + >>"$t~" \ && sort -k2, <"$t~" >>"$t" \ - && awk -v D="$D" -v h="$h" -F' ' -f "$f" <"$t" \ + && awk -v D="$D" -v h="$h" -F' ' "$program" <"$t" \ ;