diff --git a/bin/pct-default b/bin/pct-default index 2da7cfe..604b086 100755 --- a/bin/pct-default +++ b/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 " + 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