aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2026-01-25 20:04:30 +0100
committerMartin Fischer <martin@push-f.com>2026-01-25 20:09:08 +0100
commitdc6b8f5ba8298f3ad1f04eee1f2c82183b9ed28c (patch)
treeab836e468ff897cfb82c56dc83d249c24357d026
parent075645b7dbebf565cf4cf8c269c760ceb2a27d5d (diff)
break: replace sreplace with atomic sputmain
-rw-r--r--README.md2
-rwxr-xr-xscripts/sput17
-rwxr-xr-xscripts/sreplace17
3 files changed, 18 insertions, 18 deletions
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 <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
-"