#!/usr/bin/env bash # CONSTANTS BASEDIR=$(dirname "$0") # FUNCTIONS function usage { 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 | 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 { [[ -z ${COMMAND:-} ]] && usage && exit 3 true } function perform { case "$COMMAND" in list-bridges) pvesh get /nodes/$(hostname)/network --output-format json | jq -r '.[] | select(.type == "bridge") | .iface' ;; 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 parse_options $* assert_command perform