Compare commits

...
7 Commits
2 changed files with 61 additions and 68 deletions
+2 -2
View File
@@ -20,7 +20,7 @@ function download_files() {
shift shift
curl -fsSL --output-dir "$WORK_DIR/" --remote-name "$API_ENDPOINT/raw/$path$query_params" curl -fsSL --output-dir "$WORK_DIR/" --remote-name "$API_ENDPOINT/raw/$path$query_params"
rc=$? rc=$?
if (( $rc != 0 )); then if (( rc != 0 )); then
return $rc return $rc
fi fi
done done
@@ -42,7 +42,7 @@ chmod o= "$WORK_DIR/config.example"
"$WORK_DIR/pbc" install "$WORK_DIR/pbc" install
rc=$? rc=$?
if (( $rc != 0 )); then if (( rc != 0 )); then
echo "Error installing pbc requirements!" >&2 echo "Error installing pbc requirements!" >&2
exit $rc exit $rc
fi fi
+59 -66
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
function usage() { function usage() {
full=${1:-false} local full=${1:-false}
cat <<EOF cat <<EOF
Usage: $SCRIPT [-h] [-H] [-c config] command [OPTIONS] Usage: $SCRIPT [-h] [-H] [-c config] command [OPTIONS]
@@ -80,7 +80,7 @@ function apt_get_install() {
echo "Installing $package using package manager ..." echo "Installing $package using package manager ..."
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends "$package" >/dev/null DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends "$package" >/dev/null
local rc=$? local rc=$?
(( $rc != 0 )) && echo "Error installing package!" >&2 (( rc != 0 )) && echo "Error installing package!" >&2
return $rc return $rc
} }
@@ -180,16 +180,41 @@ function may_select() {
echo "$value" echo "$value"
} }
function select_group() {
local groups
readarray -t groups < <(get_group_names)
(( ${#groups[@]} == 0 )) && return 2
PS3="Snapshot group [1-${#groups[@]}]: "
GROUP=$(may_select "$1" "${groups[@]}") || { echo "Error: invalid group" >&2; return 1; }
}
function select_snapshot_and_archive() {
local snapshots archives
readarray -t snapshots < <(get_snapshot_names)
(( ${#snapshots[@]} == 0 )) && return 2
PS3="Snapshot [1-${#snapshots[@]}]: "
SNAPSHOT=$(may_select "$1" "${snapshots[@]}") || { echo "Error: invalid snapshot" >&2; return 1; }
readarray -t archives < <(get_snapshot_files "$SNAPSHOT")
(( ${#archives[@]} == 0 )) && return 3
PS3="Archive [1-${#archives[@]}]: "
ARCHIVE=$(may_select "$2" "${archives[@]}") || { echo "Error: invalid archive" >&2; return 1; }
}
SCRIPT_PATH=$(realpath -s "$0") SCRIPT_PATH=$(realpath -s "$0")
SCRIPT_DIR=$(dirname "$SCRIPT_PATH") SCRIPT_DIR=$(dirname "$(realpath "$0")")
SCRIPT=$(basename "$SCRIPT_PATH") SCRIPT=$(basename "$SCRIPT_PATH")
PBC=$(command -v proxmox-backup-client) PBC=$(command -v proxmox-backup-client)
PBC_DOWNLOAD_URL='http://download.proxmox.com/debian/pbs-client/dists/trixie/main/binary-amd64' PBC_DOWNLOAD_URL='http://download.proxmox.com/debian/pbs-client/dists/trixie/main/binary-amd64'
ETC_DIR="/etc/$SCRIPT" ETC_DIR="/etc/$SCRIPT"
FULL_HELP=false full_help=false
update_pbc=false
action='' action=''
cfgfile="$ETC_DIR/config" cfgfile="$ETC_DIR/config"
@@ -210,7 +235,7 @@ while (( $# > 0 )); do
exit 0 exit 0
;; ;;
-H|--full-help) -H|--full-help)
FULL_HELP=true full_help=true
;; ;;
-*) -*)
echo "Error: invalid option: $opt" >&2 echo "Error: invalid option: $opt" >&2
@@ -225,7 +250,7 @@ while (( $# > 0 )); do
elif [ "$action" == "install" ]; then elif [ "$action" == "install" ]; then
case "$opt" in case "$opt" in
-u|--update) -u|--update)
args+=('true') update_pbc=true
;; ;;
-*) -*)
echo "Error: invalid option: $opt" >&2 echo "Error: invalid option: $opt" >&2
@@ -252,7 +277,7 @@ if [ -f "$cfgfile" ]; then
(( 8#$perms & 0007 )) && echo "Warning: $cfgfile is readable by others!" >&2 (( 8#$perms & 0007 )) && echo "Warning: $cfgfile is readable by others!" >&2
fi fi
if $FULL_HELP; then if $full_help; then
[ -f "$cfgfile" ] && source "$cfgfile" [ -f "$cfgfile" ] && source "$cfgfile"
PBC=${PBC:-/usr/local/bin/proxmox-backup-client} PBC=${PBC:-/usr/local/bin/proxmox-backup-client}
full_usage full_usage
@@ -296,66 +321,38 @@ case "$action" in
pbc-list "${args[@]}" || exit $? pbc-list "${args[@]}" || exit $?
;; ;;
snapshot-list) snapshot-list)
readarray -t groups < <(get_group_names) select_group "${args[0]}"
(( ${#groups[@]} == 0 )) && echo "no snapshot groups found" && exit 0 case $? in
0) ;;
group=${args[0]} 2) echo "no snapshot groups found"; exit 0 ;;
args=("${args[@]:1}") *) exit 1 ;;
esac
PS3="Snapshot group [1-${#groups[@]}]: "
group=$(may_select "$group" "${groups[@]}")
(( $? != 0 )) && echo "Error: invalid group" >&2 && exit 1
echo echo
pbc-snapshot-list "$group" "${args[@]}" || exit $? pbc-snapshot-list "$GROUP" "${args[@]:1}" || exit $?
;; ;;
catalog-shell) catalog-shell)
readarray -t snapshots < <(get_snapshot_names) select_snapshot_and_archive "${args[0]}" "${args[1]}"
(( ${#snapshots[@]} == 0 )) && echo "no snapshots found" && exit 0 case $? in
0) ;;
snapshot=${args[0]} 2) echo "no snapshots found"; exit 0 ;;
args=("${args[@]:1}") 3) echo "no archives found"; exit 0 ;;
*) exit 1 ;;
PS3="Snapshot [1-${#snapshots[@]}]: " esac
snapshot=$(may_select "$snapshot" "${snapshots[@]}")
(( $? != 0 )) && echo "Error: invalid snapshot" >&2 && exit 1
readarray -t archives < <(get_snapshot_files "$snapshot")
(( ${#archives[@]} == 0 )) && echo "no archives found" && exit 0
archive=${args[0]}
args=("${args[@]:1}")
PS3="Archive [1-${#archives[@]}]: "
archive=$(may_select "$archive" "${archives[@]}")
(( $? != 0 )) && echo "Error: invalid archive" >&2 && exit 1
echo echo
pbc-catalog-shell "$snapshot" "$archive" || exit $? pbc-catalog-shell "$SNAPSHOT" "$ARCHIVE" || exit $?
;; ;;
mount) mount)
readarray -t snapshots < <(get_snapshot_names) select_snapshot_and_archive "${args[0]}" "${args[1]}"
(( ${#snapshots[@]} == 0 )) && echo "no snapshots found" && exit 0 case $? in
0) ;;
2) echo "no snapshots found"; exit 0 ;;
3) echo "no archives found"; exit 0 ;;
*) exit 1 ;;
esac
snapshot=${args[0]} target=${args[2]}
args=("${args[@]:1}")
PS3="Snapshot [1-${#snapshots[@]}]: "
snapshot=$(may_select "$snapshot" "${snapshots[@]}")
(( $? != 0 )) && echo "Error: invalid snapshot" >&2 && exit 1
readarray -t archives < <(get_snapshot_files "$snapshot")
(( ${#archives[@]} == 0 )) && echo "no archives found" && exit 0
archive=${args[0]}
args=("${args[@]:1}")
PS3="Archive [1-${#archives[@]}]: "
archive=$(may_select "$archive" "${archives[@]}")
(( $? != 0 )) && echo "Error: invalid archive" >&2 && exit 1
target=${args[0]}
args=("${args[@]:1}")
if [ -z "$target" ]; then if [ -z "$target" ]; then
while [ -z "$target" ]; do while [ -z "$target" ]; do
@@ -371,30 +368,26 @@ case "$action" in
fi fi
echo echo
pbc-mount "$snapshot" "$archive" "$target" || exit $? pbc-mount "$SNAPSHOT" "$ARCHIVE" "$target" || exit $?
;; ;;
install) install)
update=${args[0]:-false}
(( EUID != 0 )) && echo "Error: installation only works as root!" >&2 && exit 1 (( EUID != 0 )) && echo "Error: installation only works as root!" >&2 && exit 1
install_proxmox_backup_client "$update" || exit $? install_proxmox_backup_client "$update_pbc" || exit $?
if dpkg -s jq &>/dev/null; then if dpkg -s jq &>/dev/null; then
$update && echo "Info: skip update of jq, package is managed by package manager" || echo "Info: jq is already installed" $update_pbc && echo "Info: skip update of jq, package is managed by package manager" || echo "Info: jq is already installed"
else else
apt_get_install jq || exit $? apt_get_install jq || exit $?
fi fi
ETC_DIR="/etc/$SCRIPT"
if [ ! -d "$ETC_DIR" ]; then if [ ! -d "$ETC_DIR" ]; then
echo "Creating config directory $ETC_DIR ..." echo "Creating config directory $ETC_DIR ..."
! mkdir -p "$ETC_DIR" && echo "Error creating directory!" >&2 && exit 3 ! mkdir -p "$ETC_DIR" && echo "Error creating directory!" >&2 && exit 3
fi fi
if [ -f "$SCRIPT_DIR/config.example" ]; then if [ -f "$SCRIPT_DIR/config.example" ]; then
if $update || [ ! -f "$ETC_DIR/config.example" ]; then if $update_pbc || [ ! -f "$ETC_DIR/config.example" ]; then
echo "Install example config to $ETC_DIR/config.example ..." echo "Install example config to $ETC_DIR/config.example ..."
! install -m 0640 "$SCRIPT_DIR/config.example" "$ETC_DIR/config.example" && echo "Error installing file!" >&2 && exit 4 ! install -m 0640 "$SCRIPT_DIR/config.example" "$ETC_DIR/config.example" && echo "Error installing file!" >&2 && exit 4
fi fi