SHA256
Compare commits
2
Commits
73202f5e3b
...
01c299e242
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
01c299e242
|
||
|
|
56b619372d
|
@@ -1,5 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
function usage() {
|
function usage() {
|
||||||
local full=${1:-false}
|
local full=${1:-false}
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
@@ -181,24 +183,27 @@ function may_select() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function select_group() {
|
function select_group() {
|
||||||
local groups
|
local groups raw
|
||||||
readarray -t groups < <(get_group_names)
|
raw=$(get_group_names) || { echo "Error: failed to query PBS!" >&2; return 1; }
|
||||||
(( ${#groups[@]} == 0 )) && return 2
|
[ -z "$raw" ] && return 2
|
||||||
|
readarray -t groups <<< "$raw"
|
||||||
|
|
||||||
PS3="Snapshot group [1-${#groups[@]}]: "
|
PS3="Snapshot group [1-${#groups[@]}]: "
|
||||||
GROUP=$(may_select "$1" "${groups[@]}") || { echo "Error: invalid group" >&2; return 1; }
|
GROUP=$(may_select "$1" "${groups[@]}") || { echo "Error: invalid group" >&2; return 1; }
|
||||||
}
|
}
|
||||||
|
|
||||||
function select_snapshot_and_archive() {
|
function select_snapshot_and_archive() {
|
||||||
local snapshots archives
|
local snapshots archives raw
|
||||||
readarray -t snapshots < <(get_snapshot_names)
|
raw=$(get_snapshot_names) || { echo "Error: failed to query PBS!" >&2; return 1; }
|
||||||
(( ${#snapshots[@]} == 0 )) && return 2
|
[ -z "$raw" ] && return 2
|
||||||
|
readarray -t snapshots <<< "$raw"
|
||||||
|
|
||||||
PS3="Snapshot [1-${#snapshots[@]}]: "
|
PS3="Snapshot [1-${#snapshots[@]}]: "
|
||||||
SNAPSHOT=$(may_select "$1" "${snapshots[@]}") || { echo "Error: invalid snapshot" >&2; return 1; }
|
SNAPSHOT=$(may_select "$1" "${snapshots[@]}") || { echo "Error: invalid snapshot" >&2; return 1; }
|
||||||
|
|
||||||
readarray -t archives < <(get_snapshot_files "$SNAPSHOT")
|
raw=$(get_snapshot_files "$SNAPSHOT") || { echo "Error: failed to query PBS!" >&2; return 1; }
|
||||||
(( ${#archives[@]} == 0 )) && return 3
|
[ -z "$raw" ] && return 3
|
||||||
|
readarray -t archives <<< "$raw"
|
||||||
|
|
||||||
PS3="Archive [1-${#archives[@]}]: "
|
PS3="Archive [1-${#archives[@]}]: "
|
||||||
ARCHIVE=$(may_select "$2" "${archives[@]}") || { echo "Error: invalid archive" >&2; return 1; }
|
ARCHIVE=$(may_select "$2" "${archives[@]}") || { echo "Error: invalid archive" >&2; return 1; }
|
||||||
@@ -355,9 +360,10 @@ case "$action" in
|
|||||||
target=${args[2]}
|
target=${args[2]}
|
||||||
|
|
||||||
if [ -z "$target" ]; then
|
if [ -z "$target" ]; then
|
||||||
|
[ ! -t 0 ] && echo "Error: no target path given and stdin is not a terminal" >&2 && exit 1
|
||||||
while [ -z "$target" ]; do
|
while [ -z "$target" ]; do
|
||||||
echo -n "Target path: "
|
echo -n "Target path: "
|
||||||
read -r target
|
! read -r target && [ -z "$target" ] && echo "Error: no target path given" >&2 && exit 1
|
||||||
[ -d "$target" ] && break
|
[ -d "$target" ] && break
|
||||||
echo -e "\nError: $target: no such directory\n" >&2
|
echo -e "\nError: $target: no such directory\n" >&2
|
||||||
target=''
|
target=''
|
||||||
|
|||||||
Reference in New Issue
Block a user