aboutsummaryrefslogtreecommitdiffstats
path: root/sys/nixpkgs/pkgs/snap-sync-forked
diff options
context:
space:
mode:
authorSoispha <soispha@vhack.eu>2024-02-20 17:21:42 +0100
committerSoispha <soispha@vhack.eu>2024-02-20 17:21:42 +0100
commitf2bdeaed0bcf97a880fe36cfc8a050d1643120b8 (patch)
treeba4fe9c3ddf076529701c0e776ffef2104ac23d5 /sys/nixpkgs/pkgs/snap-sync-forked
parentrefactor(treewide): Add a `.sh` extension to shell scripts (diff)
downloadnixos-config-f2bdeaed0bcf97a880fe36cfc8a050d1643120b8.zip
refactor(treewide): Reformat all files with treefmt
This includes getting all shellscripts to pass shellcheck. To accomplish this, some old scripts were removed
Diffstat (limited to 'sys/nixpkgs/pkgs/snap-sync-forked')
-rwxr-xr-xsys/nixpkgs/pkgs/snap-sync-forked/snap-sync-forked.sh182
1 files changed, 91 insertions, 91 deletions
diff --git a/sys/nixpkgs/pkgs/snap-sync-forked/snap-sync-forked.sh b/sys/nixpkgs/pkgs/snap-sync-forked/snap-sync-forked.sh
index a66f31ae..47230667 100755
--- a/sys/nixpkgs/pkgs/snap-sync-forked/snap-sync-forked.sh
+++ b/sys/nixpkgs/pkgs/snap-sync-forked/snap-sync-forked.sh
@@ -37,12 +37,12 @@ printf "snap-sync comes with ABSOLUTELY NO WARRANTY. This is free software, and
SNAPPER_CONFIG=/etc/sysconfig/snapper
donotify=0
-if ! command -v notify-send &> /dev/null; then
+if ! command -v notify-send &>/dev/null; then
donotify=1
fi
doprogress=0
-if ! command -v pv &> /dev/null; then
+if ! command -v pv &>/dev/null; then
doprogress=1
fi
@@ -73,7 +73,7 @@ trap 'traperror ${LINENO} $? "$BASH_COMMAND" $BASH_LINENO "${FUNCNAME[@]}"' ERR
trap trapkill SIGTERM SIGINT
usage() {
- cat <<EOF
+ cat <<EOF
$name $version
Usage: $name [options]
@@ -100,52 +100,52 @@ sudo=0
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
- -d|--description)
- description="$2"
- shift 2
+ -d | --description)
+ description="$2"
+ shift 2
;;
- -c|--config)
- selected_configs="$2"
- shift 2
+ -c | --config)
+ selected_configs="$2"
+ shift 2
;;
- -u|--UUID)
- uuid_cmdline="$2"
- shift 2
+ -u | --UUID)
+ uuid_cmdline="$2"
+ shift 2
;;
- -s|--subvolid)
- subvolid_cmdline="$2"
- shift 2
+ -s | --subvolid)
+ subvolid_cmdline="$2"
+ shift 2
;;
- -k|--keepold)
- keep="yes"
- shift
+ -k | --keepold)
+ keep="yes"
+ shift
;;
- -n|--noconfirm)
- noconfirm="yes"
- shift
+ -n | --noconfirm)
+ noconfirm="yes"
+ shift
;;
- -h|--help)
- usage
- exit 1
+ -h | --help)
+ usage
+ exit 1
;;
- -q|--quiet)
- donotify=1
- shift
+ -q | --quiet)
+ donotify=1
+ shift
;;
- -r|--remote)
- remote=$2
- shift 2
- ;;
- -p|--port)
- port=$2
- shift 2
- ;;
- --sudo)
- sudo=1
- shift
+ -r | --remote)
+ remote=$2
+ shift 2
;;
- *)
- die "Unknown option: '$key'. Run '$name -h' for valid options."
+ -p | --port)
+ port=$2
+ shift 2
+ ;;
+ --sudo)
+ sudo=1
+ shift
+ ;;
+ *)
+ die "Unknown option: '$key'. Run '$name -h' for valid options."
;;
esac
done
@@ -153,8 +153,8 @@ done
notify() {
for u in $(users | tr ' ' '\n' | sort -u); do
sudo -u "$u" DISPLAY=:0 \
- DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(sudo -u "$u" id -u)/bus" \
- notify-send -a $name "$1" "$2" --icon="dialog-$3"
+ DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(sudo -u "$u" id -u)/bus" \
+ notify-send -a $name "$1" "$2" --icon="dialog-$3"
done
}
@@ -183,12 +183,12 @@ subvolid_cmdline=${subvolid_cmdline:-"5"}
noconfirm=${noconfirm:-"no"}
if [[ -z $remote ]]; then
- if ! command -v rsync &> /dev/null; then
+ if ! command -v rsync &>/dev/null; then
die "--remote specified but rsync command not found"
fi
fi
-if [[ "$uuid_cmdline" != "none" ]]; then
+if [[ $uuid_cmdline != "none" ]]; then
if [[ -z $remote ]]; then
notify_info "Backup started" "Starting backups to $uuid_cmdline subvolid=$subvolid_cmdline..."
else
@@ -227,34 +227,34 @@ declare -a SUBVOLIDS_ARRAY
i=0
for x in $TARGETS; do
- SUBVOLIDS_ARRAY[$i]=$($ssh btrfs subvolume show "$x" | awk '/Subvolume ID:/ { print $3 }')
- TARGETS_ARRAY[$i]=$x
- i=$((i+1))
+ SUBVOLIDS_ARRAY[i]=$($ssh btrfs subvolume show "$x" | awk '/Subvolume ID:/ { print $3 }')
+ TARGETS_ARRAY[i]=$x
+ i=$((i + 1))
done
i=0
disk=-1
disk_count=0
for x in $UUIDS; do
- UUIDS_ARRAY[$i]=$x
- if [[ "$x" == "$uuid_cmdline" && ${SUBVOLIDS_ARRAY[$((i))]} == "$subvolid_cmdline" ]]; then
+ UUIDS_ARRAY[i]=$x
+ if [[ $x == "$uuid_cmdline" && ${SUBVOLIDS_ARRAY[$((i))]} == "$subvolid_cmdline" ]]; then
disk=$i
- disk_count=$((disk_count+1))
+ disk_count=$((disk_count + 1))
fi
- i=$((i+1))
+ i=$((i + 1))
done
-if [[ "${#UUIDS_ARRAY[$@]}" -eq 0 ]]; then
+if [[ ${#UUIDS_ARRAY[$@]} -eq 0 ]]; then
die "No external btrfs subvolumes found to backup to. Run '$name -h' for more options."
fi
-if [[ "$disk_count" -gt 1 ]]; then
+if [[ $disk_count -gt 1 ]]; then
printf "Multiple mount points were found with UUID %s and subvolid %s.\n" "$uuid_cmdline" "$subvolid_cmdline"
disk="-1"
fi
-if [[ "$disk" == -1 ]]; then
- if [[ "$disk_count" == 0 && "$uuid_cmdline" != "none" ]]; then
+if [[ $disk == -1 ]]; then
+ if [[ $disk_count == 0 && $uuid_cmdline != "none" ]]; then
error "A device with UUID $uuid_cmdline and subvolid $subvolid_cmdline was not found to be mounted, or it is not a BTRFS device."
fi
if [[ -z $ssh ]]; then
@@ -264,7 +264,7 @@ if [[ "$disk" == -1 ]]; then
fi
while [[ $disk -lt 0 || $disk -gt $i ]]; do
for x in "${!TARGETS_ARRAY[@]}"; do
- printf "%4s) %s (uuid=%s, subvolid=%s)\n" "$((x+1))" "${TARGETS_ARRAY[$x]}" "${UUIDS_ARRAY[$x]}" "${SUBVOLIDS_ARRAY[$x]}"
+ printf "%4s) %s (uuid=%s, subvolid=%s)\n" "$((x + 1))" "${TARGETS_ARRAY[$x]}" "${UUIDS_ARRAY[$x]}" "${SUBVOLIDS_ARRAY[$x]}"
done
printf "%4s) Exit\n" "0"
read -e -r -p "Enter a number: " disk
@@ -276,7 +276,7 @@ if [[ "$disk" == -1 ]]; then
if [[ $disk == 0 ]]; then
exit 0
fi
- disk=$((disk-1))
+ disk=$((disk - 1))
fi
selected_subvolid="${SUBVOLIDS_ARRAY[$((disk))]}"
@@ -289,7 +289,7 @@ else
printf "The disk is mounted at '%s:%s'.\n" "$remote" "$selected_mnt"
fi
-# shellcheck source=/etc/default/snapper
+# shellcheck source=/dev/null
source "$SNAPPER_CONFIG"
if [[ -z $selected_configs ]]; then
@@ -322,17 +322,17 @@ for x in $selected_configs; do
printf "'noconfirm' option passed. Failed backups will not be deleted.\n"
else
read -e -r -p "Delete failed backup snapshot(s)? (These local snapshots from failed backups are not used.) [y/N]? " delete_failed
- while [[ -n "$delete_failed" && "$delete_failed" != [Yy]"es" &&
- "$delete_failed" != [Yy] && "$delete_failed" != [Nn]"o" &&
- "$delete_failed" != [Nn] ]]; do
+ while [[ -n $delete_failed && $delete_failed != [Yy]"es" &&
+ $delete_failed != [Yy] && $delete_failed != [Nn]"o" &&
+ $delete_failed != [Nn] ]]; do
read -e -r -p "Delete failed backup snapshot(s)? (These local snapshots from failed backups are not used.) [y/N] " delete_failed
- if [[ -n "$delete_failed" && "$delete_failed" != [Yy]"es" &&
- "$delete_failed" != [Yy] && "$delete_failed" != [Nn]"o" &&
- "$delete_failed" != [Nn] ]]; then
+ if [[ -n $delete_failed && $delete_failed != [Yy]"es" &&
+ $delete_failed != [Yy] && $delete_failed != [Nn]"o" &&
+ $delete_failed != [Nn] ]]; then
printf "Select 'y' or 'N'.\n"
fi
done
- if [[ "$delete_failed" == [Yy]"es" || "$delete_failed" == [Yy] ]]; then
+ if [[ $delete_failed == [Yy]"es" || $delete_failed == [Yy] ]]; then
# explicit split list of snapshots (on whitespace) into multiple arguments
# shellcheck disable=SC2046
snapper -c "$x" delete $(snapper -c "$x" list --disable-used-space | awk '/'$name' backup in progress/ {print $1}')
@@ -343,7 +343,7 @@ for x in $selected_configs; do
SNAP_SYNC_EXCLUDE=no
if [[ -f "/etc/snapper/configs/$x" ]]; then
- # shellcheck source=/etc/snapper/config-templates/default
+ # shellcheck source=/dev/null
source "/etc/snapper/configs/$x"
else
die "Selected snapper configuration $x does not exist."
@@ -358,10 +358,10 @@ for x in $selected_configs; do
old_num=$(snapper -c "$x" list --disable-used-space -t single | awk '/'"subvolid=$selected_subvolid, uuid=$selected_uuid"'/ {print $1}')
old_snap=$SUBVOLUME/.snapshots/$old_num/snapshot
- OLD_NUM_ARRAY[$i]=$old_num
- OLD_SNAP_ARRAY[$i]=$old_snap
+ OLD_NUM_ARRAY[i]=$old_num
+ OLD_SNAP_ARRAY[i]=$old_snap
- if [[ -z "$old_num" ]]; then
+ if [[ -z $old_num ]]; then
printf "No backups have been performed for '%s' on this disk.\n" "$x"
read -e -r -p "Enter name of subvolume to store backups, relative to $selected_mnt (to be created if not existing): " mybackupdir
printf "This will be the initial backup for snapper configuration '%s' to this disk. This could take awhile.\n" "$x"
@@ -372,8 +372,8 @@ for x in $selected_configs; do
BACKUPDIR="$selected_mnt/$mybackupdir"
$ssh test -d "$BACKUPDIR" || die "%s is not a directory on %s.\n" "$BACKUPDIR" "$selected_uuid"
fi
- BACKUPDIRS_ARRAY[$i]="$BACKUPDIR"
- MYBACKUPDIR_ARRAY[$i]="$mybackupdir"
+ BACKUPDIRS_ARRAY[i]="$BACKUPDIR"
+ MYBACKUPDIR_ARRAY[i]="$mybackupdir"
printf "Creating new local snapshot for '%s' configuration...\n" "$x"
new_num=$(snapper -c "$x" create --print-number -d "$name backup in progress")
@@ -387,40 +387,40 @@ for x in $selected_configs; do
printf "Will backup %s to %s\n" "$new_snap" "$remote":"$backup_location/snapshot"
fi
- if ($ssh test -d "$backup_location/snapshot") ; then
+ if ($ssh test -d "$backup_location/snapshot"); then
printf "WARNING: Backup directory '%s' already exists. This configuration will be skipped!\n" "$backup_location/snapshot"
printf "Move or delete destination directory and try backup again.\n"
fi
- NEW_NUM_ARRAY[$i]="$new_num"
- NEW_SNAP_ARRAY[$i]="$new_snap"
- NEW_INFO_ARRAY[$i]="$new_info"
- BACKUPLOC_ARRAY[$i]="$backup_location"
+ NEW_NUM_ARRAY[i]="$new_num"
+ NEW_SNAP_ARRAY[i]="$new_snap"
+ NEW_INFO_ARRAY[i]="$new_info"
+ BACKUPLOC_ARRAY[i]="$backup_location"
cont_backup="K"
- CONT_BACKUP_ARRAY[$i]="yes"
+ CONT_BACKUP_ARRAY[i]="yes"
if [[ $noconfirm == "yes" ]]; then
cont_backup="yes"
else
- while [[ -n "$cont_backup" && "$cont_backup" != [Yy]"es" &&
- "$cont_backup" != [Yy] && "$cont_backup" != [Nn]"o" &&
- "$cont_backup" != [Nn] ]]; do
+ while [[ -n $cont_backup && $cont_backup != [Yy]"es" &&
+ $cont_backup != [Yy] && $cont_backup != [Nn]"o" &&
+ $cont_backup != [Nn] ]]; do
read -e -r -p "Proceed with backup of '$x' configuration [Y/n]? " cont_backup
- if [[ -n "$cont_backup" && "$cont_backup" != [Yy]"es" &&
- "$cont_backup" != [Yy] && "$cont_backup" != [Nn]"o" &&
- "$cont_backup" != [Nn] ]]; then
+ if [[ -n $cont_backup && $cont_backup != [Yy]"es" &&
+ $cont_backup != [Yy] && $cont_backup != [Nn]"o" &&
+ $cont_backup != [Nn] ]]; then
printf "Select 'Y' or 'n'.\n"
fi
done
fi
- if [[ "$cont_backup" != [Yy]"es" && "$cont_backup" != [Yy] && -n "$cont_backup" ]]; then
- CONT_BACKUP_ARRAY[$i]="no"
+ if [[ $cont_backup != [Yy]"es" && $cont_backup != [Yy] && -n $cont_backup ]]; then
+ CONT_BACKUP_ARRAY[i]="no"
printf "Not backing up '%s' configuration.\n" "$x"
snapper -c "$x" delete "$new_num"
fi
- i=$((i+1))
+ i=$((i + 1))
done
@@ -429,12 +429,12 @@ printf "\nPerforming backups...\n"
i=-1
for x in $selected_configs; do
- i=$((i+1))
+ i=$((i + 1))
SNAP_SYNC_EXCLUDE=no
if [[ -f "/etc/snapper/configs/$x" ]]; then
- # shellcheck source=/etc/snapper/config-templates/default
+ # shellcheck source=/dev/null
source "/etc/snapper/configs/$x"
else
die "Selected snapper configuration $x does not exist."
@@ -459,14 +459,14 @@ for x in $selected_configs; do
new_info="${NEW_INFO_ARRAY[$i]}"
backup_location="${BACKUPLOC_ARRAY[$i]}"
- if ($ssh test -d "$backup_location/snapshot") ; then
+ if ($ssh test -d "$backup_location/snapshot"); then
printf "ERROR: Backup directory '%s' already exists. Skipping backup of this configuration!\n" "$backup_location/snapshot"
continue
fi
$ssh mkdir -p "$backup_location"
- if [[ -z "$old_num" ]]; then
+ if [[ -z $old_num ]]; then
printf "Sending first snapshot for '%s' configuration...\n" "$x"
if [[ $doprogress -eq 0 ]]; then
btrfs send "$new_snap" | pv | $ssh btrfs receive "$backup_location" &>/dev/null
@@ -522,7 +522,7 @@ done
printf "\nDone!\n"
-if [[ "$uuid_cmdline" != "none" ]]; then
+if [[ $uuid_cmdline != "none" ]]; then
notify_info "Finished" "Backups to $uuid_cmdline complete!"
else
notify_info "Finished" "Backups complete!"