From 32d0a60024f0549f85250f565f126a6ffa39c11b Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Sun, 21 May 2023 20:24:22 -0400 Subject: move config file to /etc --- go.sh | 23 +++++++++++++++++++---- 1 file 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 @@ #!/bin/bash MAX_AGE_SECONDS=60 +CONFIG_DIR=/etc/btrfs-backup/remotes + +die() +{ + printf 'Error: %s\n' "$*" >&2 + exit 1 +} read_config() { @@ -45,13 +52,20 @@ check_user_is_root if [ $# = 1 ] then - config_file=$1 + case "$1" in + '' ) die 'config file name is blank' ;; + */*) die 'config file name must not contain "/"' ;; + *.json) ;; + *) die "config file name must end in '.json'" ;; + esac + config_file=$CONFIG_DIR/$1 + config_file_temp=$CONFIG_DIR/.$1~tmp else echo "Usage: $0 " >&2 exit 1 fi -[ -r "$config_file" ] +[ -r "$config_file" ] || die "config file does not exist: $config_file" exec 3<>"$config_file" flock -n 3 declare -A config @@ -86,8 +100,9 @@ then fi btrfs send ${remote_head:+ -p "$remote_head"} -- "$local_head" | pv | btrfs receive -- "$dst" -jq --arg h "$local_head" '. | .head=$h' <"$config_file" >."$config_file"~tmp -mv -T -- ."$config_file"~tmp "$config_file" +jq --arg h "$local_head" '. | .head=$h' <"$config_file" >"$config_file_temp" +# TODO: btrfs subvolume delete "$remote_head" but first check for other config files! +mv -T -- "$config_file_temp" "$config_file" ### OK, basic idea: # -- cgit v1.2.3