SHA256
Compare commits
7
Commits
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
73202f5e3b
|
||
|
|
d243ea1c89
|
||
|
|
0623c6a985
|
||
|
|
4fb949c26e
|
||
|
|
e065ab2cd7
|
||
|
|
7421c8f43e
|
||
|
|
e184d1c92c
|
+2
-2
@@ -20,7 +20,7 @@ function download_files() {
|
||||
shift
|
||||
curl -fsSL --output-dir "$WORK_DIR/" --remote-name "$API_ENDPOINT/raw/$path$query_params"
|
||||
rc=$?
|
||||
if (( $rc != 0 )); then
|
||||
if (( rc != 0 )); then
|
||||
return $rc
|
||||
fi
|
||||
done
|
||||
@@ -42,7 +42,7 @@ chmod o= "$WORK_DIR/config.example"
|
||||
|
||||
"$WORK_DIR/pbc" install
|
||||
rc=$?
|
||||
if (( $rc != 0 )); then
|
||||
if (( rc != 0 )); then
|
||||
echo "Error installing pbc requirements!" >&2
|
||||
exit $rc
|
||||
fi
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
function usage() {
|
||||
full=${1:-false}
|
||||
local full=${1:-false}
|
||||
cat <<EOF
|
||||
Usage: $SCRIPT [-h] [-H] [-c config] command [OPTIONS]
|
||||
|
||||
@@ -80,7 +80,7 @@ function apt_get_install() {
|
||||
echo "Installing $package using package manager ..."
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends "$package" >/dev/null
|
||||
local rc=$?
|
||||
(( $rc != 0 )) && echo "Error installing package!" >&2
|
||||
(( rc != 0 )) && echo "Error installing package!" >&2
|
||||
return $rc
|
||||
}
|
||||
|
||||
@@ -180,16 +180,41 @@ function may_select() {
|
||||
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_DIR=$(dirname "$SCRIPT_PATH")
|
||||
SCRIPT_DIR=$(dirname "$(realpath "$0")")
|
||||
SCRIPT=$(basename "$SCRIPT_PATH")
|
||||
|
||||
PBC=$(command -v proxmox-backup-client)
|
||||
PBC_DOWNLOAD_URL='http://download.proxmox.com/debian/pbs-client/dists/trixie/main/binary-amd64'
|
||||
ETC_DIR="/etc/$SCRIPT"
|
||||
|
||||
FULL_HELP=false
|
||||
full_help=false
|
||||
update_pbc=false
|
||||
|
||||
action=''
|
||||
cfgfile="$ETC_DIR/config"
|
||||
@@ -210,7 +235,7 @@ while (( $# > 0 )); do
|
||||
exit 0
|
||||
;;
|
||||
-H|--full-help)
|
||||
FULL_HELP=true
|
||||
full_help=true
|
||||
;;
|
||||
-*)
|
||||
echo "Error: invalid option: $opt" >&2
|
||||
@@ -225,7 +250,7 @@ while (( $# > 0 )); do
|
||||
elif [ "$action" == "install" ]; then
|
||||
case "$opt" in
|
||||
-u|--update)
|
||||
args+=('true')
|
||||
update_pbc=true
|
||||
;;
|
||||
-*)
|
||||
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
|
||||
fi
|
||||
|
||||
if $FULL_HELP; then
|
||||
if $full_help; then
|
||||
[ -f "$cfgfile" ] && source "$cfgfile"
|
||||
PBC=${PBC:-/usr/local/bin/proxmox-backup-client}
|
||||
full_usage
|
||||
@@ -296,66 +321,38 @@ case "$action" in
|
||||
pbc-list "${args[@]}" || exit $?
|
||||
;;
|
||||
snapshot-list)
|
||||
readarray -t groups < <(get_group_names)
|
||||
(( ${#groups[@]} == 0 )) && echo "no snapshot groups found" && exit 0
|
||||
|
||||
group=${args[0]}
|
||||
args=("${args[@]:1}")
|
||||
|
||||
PS3="Snapshot group [1-${#groups[@]}]: "
|
||||
group=$(may_select "$group" "${groups[@]}")
|
||||
(( $? != 0 )) && echo "Error: invalid group" >&2 && exit 1
|
||||
select_group "${args[0]}"
|
||||
case $? in
|
||||
0) ;;
|
||||
2) echo "no snapshot groups found"; exit 0 ;;
|
||||
*) exit 1 ;;
|
||||
esac
|
||||
|
||||
echo
|
||||
pbc-snapshot-list "$group" "${args[@]}" || exit $?
|
||||
pbc-snapshot-list "$GROUP" "${args[@]:1}" || exit $?
|
||||
;;
|
||||
catalog-shell)
|
||||
readarray -t snapshots < <(get_snapshot_names)
|
||||
(( ${#snapshots[@]} == 0 )) && echo "no snapshots found" && exit 0
|
||||
|
||||
snapshot=${args[0]}
|
||||
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
|
||||
select_snapshot_and_archive "${args[0]}" "${args[1]}"
|
||||
case $? in
|
||||
0) ;;
|
||||
2) echo "no snapshots found"; exit 0 ;;
|
||||
3) echo "no archives found"; exit 0 ;;
|
||||
*) exit 1 ;;
|
||||
esac
|
||||
|
||||
echo
|
||||
pbc-catalog-shell "$snapshot" "$archive" || exit $?
|
||||
pbc-catalog-shell "$SNAPSHOT" "$ARCHIVE" || exit $?
|
||||
;;
|
||||
mount)
|
||||
readarray -t snapshots < <(get_snapshot_names)
|
||||
(( ${#snapshots[@]} == 0 )) && echo "no snapshots found" && exit 0
|
||||
select_snapshot_and_archive "${args[0]}" "${args[1]}"
|
||||
case $? in
|
||||
0) ;;
|
||||
2) echo "no snapshots found"; exit 0 ;;
|
||||
3) echo "no archives found"; exit 0 ;;
|
||||
*) exit 1 ;;
|
||||
esac
|
||||
|
||||
snapshot=${args[0]}
|
||||
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}")
|
||||
target=${args[2]}
|
||||
|
||||
if [ -z "$target" ]; then
|
||||
while [ -z "$target" ]; do
|
||||
@@ -371,30 +368,26 @@ case "$action" in
|
||||
fi
|
||||
|
||||
echo
|
||||
pbc-mount "$snapshot" "$archive" "$target" || exit $?
|
||||
pbc-mount "$SNAPSHOT" "$ARCHIVE" "$target" || exit $?
|
||||
;;
|
||||
install)
|
||||
update=${args[0]:-false}
|
||||
|
||||
(( 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
|
||||
$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
|
||||
apt_get_install jq || exit $?
|
||||
fi
|
||||
|
||||
ETC_DIR="/etc/$SCRIPT"
|
||||
|
||||
if [ ! -d "$ETC_DIR" ]; then
|
||||
echo "Creating config directory $ETC_DIR ..."
|
||||
! mkdir -p "$ETC_DIR" && echo "Error creating directory!" >&2 && exit 3
|
||||
fi
|
||||
|
||||
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 ..."
|
||||
! install -m 0640 "$SCRIPT_DIR/config.example" "$ETC_DIR/config.example" && echo "Error installing file!" >&2 && exit 4
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user