add shed utility to apply sed more intelligently

This commit is contained in:
Connor Olding 2022-10-01 10:25:02 -07:00
parent c3eb9c90ca
commit 39dc4acfca
2 changed files with 12 additions and 1 deletions

View File

@ -3,7 +3,7 @@
FROM alpine:3.16 as partial
# need this for acquire (.tar.xz files):
RUN apk add --no-cache xz
COPY --chmod=0755 acquire cosmocc dedupe quickconf \
COPY --chmod=0755 acquire cosmocc dedupe quickconf shed \
/usr/local/bin/
FROM partial as downloader

11
notwa-util/shed Normal file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env sh
: \
&& f="${1?missing filename}" && shift \
&& for e in "$@" \
;do : \
&& cp "$f" "$f.bak" && sed -i -e "$e" "$f" \
&& { diff -q "$f" "$f.bak" >/dev/null; [ $? = 1 ] ;} \
|| { printf >&2 '\033[91mfailed to apply sed:\033[m\n%s\n' "$e"; exit 1 ;} \
&& rm "$f.bak" || exit \
;done \
;