summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2023-05-21 20:24:22 -0400
committerAndrew Cady <d@jerkface.net>2023-05-21 20:24:22 -0400
commit32d0a60024f0549f85250f565f126a6ffa39c11b (patch)
tree76949af17c955a47e269359d71b10a61b8f0cc63
parent729b61170638365c04458963018edea1ca067e7e (diff)
move config file to /etc
-rwxr-xr-xgo.sh23
1 files changed, 19 insertions, 4 deletions
diff --git a/go.sh b/go.sh
index 23d06d0..65aa592 100755
--- a/go.sh
+++ b/go.sh
@@ -1,5 +1,12 @@
1#!/bin/bash 1#!/bin/bash
2MAX_AGE_SECONDS=60 2MAX_AGE_SECONDS=60
3CONFIG_DIR=/etc/btrfs-backup/remotes
4
5die()
6{
7 printf 'Error: %s\n' "$*" >&2
8 exit 1
9}
3 10
4read_config() 11read_config()
5{ 12{
@@ -45,13 +52,20 @@ check_user_is_root
45 52
46if [ $# = 1 ] 53if [ $# = 1 ]
47then 54then
48 config_file=$1 55 case "$1" in
56 '' ) die 'config file name is blank' ;;
57 */*) die 'config file name must not contain "/"' ;;
58 *.json) ;;
59 *) die "config file name must end in '.json'" ;;
60 esac
61 config_file=$CONFIG_DIR/$1
62 config_file_temp=$CONFIG_DIR/.$1~tmp
49else 63else
50 echo "Usage: $0 <config.json>" >&2 64 echo "Usage: $0 <config.json>" >&2
51 exit 1 65 exit 1
52fi 66fi
53 67
54[ -r "$config_file" ] 68[ -r "$config_file" ] || die "config file does not exist: $config_file"
55exec 3<>"$config_file" 69exec 3<>"$config_file"
56flock -n 3 70flock -n 3
57declare -A config 71declare -A config
@@ -86,8 +100,9 @@ then
86fi 100fi
87 101
88btrfs send ${remote_head:+ -p "$remote_head"} -- "$local_head" | pv | btrfs receive -- "$dst" 102btrfs send ${remote_head:+ -p "$remote_head"} -- "$local_head" | pv | btrfs receive -- "$dst"
89jq --arg h "$local_head" '. | .head=$h' <"$config_file" >."$config_file"~tmp 103jq --arg h "$local_head" '. | .head=$h' <"$config_file" >"$config_file_temp"
90mv -T -- ."$config_file"~tmp "$config_file" 104# TODO: btrfs subvolume delete "$remote_head" but first check for other config files!
105mv -T -- "$config_file_temp" "$config_file"
91 106
92### OK, basic idea: 107### OK, basic idea:
93# 108#