diff options
| author | Martin Fischer <martin@push-f.com> | 2026-01-25 20:04:30 +0100 |
|---|---|---|
| committer | Martin Fischer <martin@push-f.com> | 2026-01-25 20:09:08 +0100 |
| commit | dc6b8f5ba8298f3ad1f04eee1f2c82183b9ed28c (patch) | |
| tree | ab836e468ff897cfb82c56dc83d249c24357d026 | |
| parent | 075645b7dbebf565cf4cf8c269c760ceb2a27d5d (diff) | |
break: replace sreplace with atomic sputmain
| -rw-r--r-- | README.md | 2 | ||||
| -rwxr-xr-x | scripts/sput | 17 | ||||
| -rwxr-xr-x | scripts/sreplace | 17 |
3 files changed, 18 insertions, 18 deletions
@@ -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 <local_dir> <ssh_dest> <remote_parent>" + 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 <local_dir> <ssh_dest> <remote_dir>" - 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 -" |
