From dc6b8f5ba8298f3ad1f04eee1f2c82183b9ed28c Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Sun, 25 Jan 2026 20:04:30 +0100 Subject: break: replace sreplace with atomic sput --- README.md | 2 +- scripts/sput | 17 +++++++++++++++++ scripts/sreplace | 17 ----------------- 3 files changed, 18 insertions(+), 18 deletions(-) create mode 100755 scripts/sput delete mode 100755 scripts/sreplace diff --git a/README.md b/README.md index 68116c6..9e84c62 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ CMD 50 is a collection of perhaps someday 50 command-line tools. * reset-bg - reset background of [foot] terminal * serve - serve the current directory over HTTP * set-bg - set background of [foot] terminal -* sreplace - OpenSSH secure replace a directory +* sput - atomically replace a directory via OpenSSH TODO: write man pages diff --git a/scripts/sput b/scripts/sput new file mode 100755 index 0000000..d6fe517 --- /dev/null +++ b/scripts/sput @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# Replaces the contents of a remote directory named "current" with the contents of a local directory. + +if [ "$#" -ne 3 ]; then + echo "usage: $0 " + exit 1 +fi +printf -v remote_dir %q "$3" +temp_dir="$remote_dir/$(date +%s)" + +tar cf - -C "$1" . | ssh $2 "set -xe +[ -d $remote_dir/current ] +mkdir $temp_dir +tar xvf - -C $temp_dir +mv -T --exchange $remote_dir/current $temp_dir +rm -r $temp_dir +" diff --git a/scripts/sreplace b/scripts/sreplace deleted file mode 100755 index 3dee6ed..0000000 --- a/scripts/sreplace +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash -# Replaces the contents of a remote directory with the contents of a local directory. - -if [ "$#" -ne 3 ]; then - echo "usage: $0 " - exit 1 -fi -printf -v remote_dir %q "$3" - -cd "$1" -tar cf - . | ssh "$2" "set -xe -TEMP_DIR=\$(mktemp -d) -cd \$TEMP_DIR -tar xvf - -rm -rf $remote_dir -mv \$TEMP_DIR $remote_dir -" -- cgit v1.3.1