diff options
author | Andrew Cady <d@jerkface.net> | 2023-05-21 20:24:22 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2023-05-21 20:24:22 -0400 |
commit | 32d0a60024f0549f85250f565f126a6ffa39c11b (patch) | |
tree | 76949af17c955a47e269359d71b10a61b8f0cc63 | |
parent | 729b61170638365c04458963018edea1ca067e7e (diff) |
move config file to /etc
-rwxr-xr-x | go.sh | 23 |
1 files changed, 19 insertions, 4 deletions
@@ -1,5 +1,12 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | MAX_AGE_SECONDS=60 | 2 | MAX_AGE_SECONDS=60 |
3 | CONFIG_DIR=/etc/btrfs-backup/remotes | ||
4 | |||
5 | die() | ||
6 | { | ||
7 | printf 'Error: %s\n' "$*" >&2 | ||
8 | exit 1 | ||
9 | } | ||
3 | 10 | ||
4 | read_config() | 11 | read_config() |
5 | { | 12 | { |
@@ -45,13 +52,20 @@ check_user_is_root | |||
45 | 52 | ||
46 | if [ $# = 1 ] | 53 | if [ $# = 1 ] |
47 | then | 54 | then |
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 | ||
49 | else | 63 | else |
50 | echo "Usage: $0 <config.json>" >&2 | 64 | echo "Usage: $0 <config.json>" >&2 |
51 | exit 1 | 65 | exit 1 |
52 | fi | 66 | fi |
53 | 67 | ||
54 | [ -r "$config_file" ] | 68 | [ -r "$config_file" ] || die "config file does not exist: $config_file" |
55 | exec 3<>"$config_file" | 69 | exec 3<>"$config_file" |
56 | flock -n 3 | 70 | flock -n 3 |
57 | declare -A config | 71 | declare -A config |
@@ -86,8 +100,9 @@ then | |||
86 | fi | 100 | fi |
87 | 101 | ||
88 | btrfs send ${remote_head:+ -p "$remote_head"} -- "$local_head" | pv | btrfs receive -- "$dst" | 102 | btrfs send ${remote_head:+ -p "$remote_head"} -- "$local_head" | pv | btrfs receive -- "$dst" |
89 | jq --arg h "$local_head" '. | .head=$h' <"$config_file" >."$config_file"~tmp | 103 | jq --arg h "$local_head" '. | .head=$h' <"$config_file" >"$config_file_temp" |
90 | mv -T -- ."$config_file"~tmp "$config_file" | 104 | # TODO: btrfs subvolume delete "$remote_head" but first check for other config files! |
105 | mv -T -- "$config_file_temp" "$config_file" | ||
91 | 106 | ||
92 | ### OK, basic idea: | 107 | ### OK, basic idea: |
93 | # | 108 | # |