From 39dc4acfca071df31a5463a10e39603bf2387cb6 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sat, 1 Oct 2022 10:25:02 -0700 Subject: [PATCH] add `shed` utility to apply sed more intelligently --- notwa-util/Dockerfile | 2 +- notwa-util/shed | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 notwa-util/shed diff --git a/notwa-util/Dockerfile b/notwa-util/Dockerfile index f06a6ea..a66b469 100644 --- a/notwa-util/Dockerfile +++ b/notwa-util/Dockerfile @@ -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 diff --git a/notwa-util/shed b/notwa-util/shed new file mode 100644 index 0000000..2dd1f05 --- /dev/null +++ b/notwa-util/shed @@ -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 \ +;