summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2023-05-21 21:14:55 -0400
committerAndrew Cady <d@jerkface.net>2023-05-21 21:14:55 -0400
commit021338e619b2cb6a07dc07a600c95c08e8c2de29 (patch)
tree8eacef86fdf62e1e20fa99ab071b1b3b1b25ae2e
parent264a3f9f300844ba8e33cdefb890a2794e4bca7d (diff)
use "ssh localhost" to access local system; support ssh to other systems
-rwxr-xr-xgo.sh13
1 files changed, 12 insertions, 1 deletions
diff --git a/go.sh b/go.sh
index 7487dfa..5e9b537 100755
--- a/go.sh
+++ b/go.sh
@@ -38,6 +38,11 @@ get_age()
38 echo $((now - then)) 38 echo $((now - then))
39} 39}
40 40
41btrfs_receive()
42{
43 ssh -- "${1%%:*}" btrfs receive -- "${1#*:}"
44}
45
41set -e 46set -e
42check_dependencies 47check_dependencies
43check_user_is_root 48check_user_is_root
@@ -67,6 +72,12 @@ src=${config[source]}
67dst=${config[destination]} 72dst=${config[destination]}
68remote_head=${config[head]} 73remote_head=${config[head]}
69 74
75case "$dst" in
76 *:/*) ;;
77 /*) dst=localhost:$dst ;;
78 *) die "Invalid destination: $dst" ;;
79esac
80
70is_subvolume "$src" 81is_subvolume "$src"
71 82
72if [ "$(get_age "$remote_head")" -le "$MAX_AGE_SECONDS" ] 83if [ "$(get_age "$remote_head")" -le "$MAX_AGE_SECONDS" ]
@@ -78,7 +89,7 @@ else
78 btrfs subvolume snapshot -r -- "$src" "$new_snapshot" 89 btrfs subvolume snapshot -r -- "$src" "$new_snapshot"
79fi 90fi
80 91
81btrfs send ${remote_head:+ -p "$remote_head"} -- "$new_snapshot" | pv | btrfs receive -- "$dst" 92btrfs send ${remote_head:+ -p "$remote_head"} -- "$new_snapshot" | pv | btrfs_receive "$dst"
82jq --arg h "$new_snapshot" '. | .head=$h' <"$config_file" >"$config_file_temp" 93jq --arg h "$new_snapshot" '. | .head=$h' <"$config_file" >"$config_file_temp"
83mv -T -- "$config_file_temp" "$config_file" 94mv -T -- "$config_file_temp" "$config_file"
84 95