Browse Source

pct-info list-dir-pools

main
pvincent 3 weeks ago
parent
commit
3b71a220cd
  1. 76
      bin/pct-default
  2. 44
      bin/pct-info

76
bin/pct-default

@ -2,7 +2,7 @@
# CONSTANTS
BASEDIR=$(dirname "$0")
BASEDIR=$(dirname "$0")
DEFAULT_CONFIG="$BASEDIR/../config/default.conf"
ARG1="${1:-}"
@ -13,29 +13,29 @@ function usage {
}
function parse_options {
COMMAND=show
while [[ $# -gt 0 ]]; do
case "$1" in
--edit)
COMMAND=edit
;;
--config)
COMMAND=config
;;
--help | -h)
usage && exit 0
;;
*)
echo >&2 "Unknown option: $1" && usage && exit 2
;;
esac
shift 1 # Move to the next argument
done
COMMAND=show
while [[ $# -gt 0 ]]; do
case "$1" in
--edit)
COMMAND=edit
;;
--config)
COMMAND=config
;;
--help | -h)
usage && exit 0
;;
*)
echo >&2 "Unknown option: $1" && usage && exit 2
;;
esac
shift 1 # Move to the next argument
done
}
function show_defaults {
[[ ! -f $DEFAULT_CONFIG ]] && echo >&2 "config file missing: $DEFAUL_CONFIG" && exit 3
[[ ! -f $DEFAULT_CONFIG ]] && echo >&2 "config file missing: $DEFAULT_CONFIG" && exit 3
source "$DEFAULT_CONFIG"
echo "STORAGE_DISK=$STORAGE_DISK"
@ -63,11 +63,11 @@ function choose_from_selection {
echo "$2:"
echo -----------------
PS3="Choose number: "
select chosen in "${selection[@]}"; do
[[ -n $chosen ]] && break
done < /dev/tty
done </dev/tty
}
function choose_default {
@ -77,11 +77,13 @@ function choose_default {
swap='2G'
cpu=$(compute_cpu_cores)
mapfile -t storages <<< $(pct-info list-zfs-pools)
choose_from_selection storages "TYPE=ZFSPOOL STORAGE LIST"
mapfile -t storages <<<$(pct-info list-zfs-pools)
local pool_type=ZFS
[[ "${#storages[@]}" == 0 ]] && mapfile -t storages <<<$(pct-info list-dir-pools) && pool_type=DIR
choose_from_selection storages "TYPE=$pool_type STORAGE LIST"
storage_disk=$chosen
mapfile -t bridges <<< $(pct-info list-bridges)
mapfile -t bridges <<<$(pct-info list-bridges)
choose_from_selection bridges "BRIDGE LIST"
bridge=$chosen
@ -97,20 +99,20 @@ EOF
function perform {
case "$COMMAND" in
show)
show_defaults
;;
edit)
editor $DEFAULT_CONFIG
;;
config)
choose_default
;;
esac
show)
show_defaults
;;
edit)
editor $DEFAULT_CONFIG
;;
config)
choose_default
;;
esac
}
# MAIN
set -Eue
parse_options $*
parse_options $*
perform

44
bin/pct-info

@ -2,30 +2,30 @@
# CONSTANTS
BASEDIR=$(dirname "$0")
BASEDIR=$(dirname "$0")
# FUNCTIONS
function usage {
echo "usage: $(basename "$0") < list-bridges | list-zfs-pools >"
echo "usage: $(basename "$0") { list-bridges | list-zfs-pools | list-dir-pools }"
}
function parse_options {
while [[ $# -gt 0 ]]; do
case "$1" in
'list-bridges'|'list-zfs-pools')
COMMAND=$1
;;
--help | -h)
usage && exit 0
;;
*)
echo >&2 "Unknown option: $1" && usage && exit 2
;;
esac
shift 1 # Move to the next argument
done
while [[ $# -gt 0 ]]; do
case "$1" in
list-bridges | list-zfs-pools | list-dir-pools)
COMMAND=$1
;;
--help | -h)
usage && exit 0
;;
*)
echo >&2 "Unknown option: $1" && usage && exit 2
;;
esac
shift 1 # Move to the next argument
done
}
function assert_command {
@ -35,16 +35,20 @@ function assert_command {
function perform {
case "$COMMAND" in
'list-bridges')
list-bridges)
pvesh get /nodes/$(hostname)/network --output-format json | jq -r '.[] | select(.type == "bridge") | .iface'
;;
'list-zfs-pools')
list-zfs-pools)
pvesm status | grep zfspool | cut -d' ' -f1
;;
list-dir-pools)
# "^\w+\s+dir\s+" means Type=dir
pvesm status | grep -P "^\w+\s+dir\s+" | cut -d' ' -f1
;;
esac
}
# MAIN
set -Eue

Loading…
Cancel
Save