select UUID by command line (#3)
This commit is contained in:
@@ -16,10 +16,10 @@ while [[ $# -gt 0 ]]; do
|
|||||||
description="$2"
|
description="$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
#TODO -u|--UUID)
|
-u|--UUID)
|
||||||
# uuid_cmdline="$2"
|
uuid_cmdline="$2"
|
||||||
# shift
|
shift
|
||||||
# ;;
|
;;
|
||||||
# TODO: add more
|
# TODO: add more
|
||||||
-h|--help)
|
-h|--help)
|
||||||
echo "Usage:"
|
echo "Usage:"
|
||||||
@@ -36,6 +36,7 @@ while [[ $# -gt 0 ]]; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
description=${description:-"latest incremental backup"}
|
description=${description:-"latest incremental backup"}
|
||||||
|
uuid_cmdline=${uuid_cmdline:-"interactive"}
|
||||||
|
|
||||||
if [[ $EUID -ne 0 ]]; then
|
if [[ $EUID -ne 0 ]]; then
|
||||||
printf "Script must be run as root.\n"
|
printf "Script must be run as root.\n"
|
||||||
@@ -51,31 +52,44 @@ UUIDS="$(findmnt -n -v -t btrfs -o UUID --list)"
|
|||||||
declare -a TARGETS_ARRAY
|
declare -a TARGETS_ARRAY
|
||||||
declare -a UUIDS_ARRAY
|
declare -a UUIDS_ARRAY
|
||||||
|
|
||||||
|
i=0
|
||||||
|
disk=-1
|
||||||
|
for x in $UUIDS; do
|
||||||
|
UUIDS_ARRAY[$i]=$x
|
||||||
|
if [[ "$x" == "$uuid_cmdline" ]]; then
|
||||||
|
disk=$i
|
||||||
|
fi
|
||||||
|
i=$((i+1))
|
||||||
|
done
|
||||||
|
|
||||||
i=0
|
i=0
|
||||||
for x in $TARGETS; do
|
for x in $TARGETS; do
|
||||||
TARGETS_ARRAY[$i]=$x
|
TARGETS_ARRAY[$i]=$x
|
||||||
i=$((i+1))
|
i=$((i+1))
|
||||||
done
|
done
|
||||||
i=0
|
|
||||||
for x in $UUIDS; do
|
if [[ "$disk" == -1 ]]; then
|
||||||
UUIDS_ARRAY[$i]=$x
|
if [[ "$uuid_cmdline" != "none" ]]; then
|
||||||
i=$((i+1))
|
printf "A device with UUID $uuid_cmdline was not found to be mounted, or it is not a BTRFS device."
|
||||||
done
|
fi
|
||||||
printf "Select a mounted BTRFS device to backup to.\n"
|
printf "Select a mounted BTRFS device to backup to.\n"
|
||||||
disk=-1
|
disk=-1
|
||||||
while [[ $disk -lt 0 || $disk -gt $i ]]; do
|
while [[ $disk -lt 0 || $disk -gt $i ]]; do
|
||||||
for x in "${!TARGETS_ARRAY[@]}"; do
|
for x in "${!TARGETS_ARRAY[@]}"; do
|
||||||
printf "%s) %s (%s)\n" "$((x+1))" "${UUIDS_ARRAY[$x]}" "${TARGETS_ARRAY[$x]}"
|
printf "%s) %s (%s)\n" "$((x+1))" "${UUIDS_ARRAY[$x]}" "${TARGETS_ARRAY[$x]}"
|
||||||
|
done
|
||||||
|
printf "0) Exit\n"
|
||||||
|
read -r -p "Enter a number: " disk
|
||||||
done
|
done
|
||||||
printf "0) Exit\n"
|
if [[ $disk == 0 ]]; then
|
||||||
read -r -p "Enter a number: " disk
|
exit 0
|
||||||
done
|
fi
|
||||||
if [[ $disk == 0 ]]; then
|
|
||||||
exit 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
selected_uuid="${UUIDS_ARRAY[$((disk-1))]}"
|
selected_uuid="${UUIDS_ARRAY[$((disk-1))]}"
|
||||||
selected_mnt="${TARGETS_ARRAY[$((disk-1))]}"
|
selected_mnt="${TARGETS_ARRAY[$((disk-1))]}"
|
||||||
printf "You selected the disk with UUID %s.\n" "$selected_uuid"
|
printf "You selected the disk with UUID %s.\n" "$selected_uuid"
|
||||||
|
exit 0
|
||||||
|
|
||||||
if [[ -f /etc/conf.d/snapper ]]; then
|
if [[ -f /etc/conf.d/snapper ]]; then
|
||||||
source /etc/conf.d/snapper
|
source /etc/conf.d/snapper
|
||||||
|
|||||||
Reference in New Issue
Block a user