From 09ee24b49cf67aa945f38e3c47ab26dc86632199 Mon Sep 17 00:00:00 2001 From: pvincent Date: Thu, 30 Oct 2025 18:55:56 +0400 Subject: [PATCH] pct-info --- README.md | 9 +-------- bin/pct-info | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ install.sh | 27 +++++++------------------- 3 files changed, 61 insertions(+), 28 deletions(-) create mode 100755 bin/pct-info diff --git a/README.md b/README.md index eef962e..e9e048b 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,7 @@ mostly command-line utilities. ## how-to install -> one-liner style - ```bash -curl https://git.artcode.re/miaou/miaou-proxmox/raw/branch/main/install.sh | bash -s # NON-INTERACTIVE +curl -s https://git.artcode.re/miaou/miaou-proxmox/raw/branch/main/install.sh | bash ``` -> change default storage interactively - -```bash -/opt/miaou-proxmox/install.sh -``` diff --git a/bin/pct-info b/bin/pct-info new file mode 100755 index 0000000..a5541d9 --- /dev/null +++ b/bin/pct-info @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +# CONSTANTS + +BASEDIR=$(dirname "$0") + +# FUNCTIONS + +function usage { + echo "usage: $(basename "$0") < list-bridges | list-zfs-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 +} + +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 + ;; + esac +} + + +# MAIN + +set -Eue +parse_options $* +assert_command +perform diff --git a/install.sh b/install.sh index 90bc50b..3abca32 100755 --- a/install.sh +++ b/install.sh @@ -65,27 +65,14 @@ function choose_default { mapfile -t storages <<< $(pvesm status | grep zfspool | cut -d' ' -f1) - if [[ ! "$-" =~ i ]]; then - # non-interactive, default to first item - interactive=false - storage_disk="${storages[0]}" - echo '----------------------------------------------------' - echo "first TYPE=ZFSPOOL found: $storage_disk" - echo 'to change, please launch one more time: `/opt/miaou-proxmox/install.sh`' - echo '----------------------------------------------------' - else - # interactive, ask for default - interactive=true - PS3="Choose default storage number: " - echo "TYPE=ZFSPOOL STORAGE LIST:" - echo "--------------------------" - select storage_disk in "${storages[@]}"; do - [[ -n $storage_disk ]] && break - done - fi + PS3="Choose default storage number: " + echo "TYPE=ZFSPOOL STORAGE LIST:" + echo "--------------------------" + select storage_disk in "${storages[@]}"; do + [[ -n $storage_disk ]] && break + done cat > $CONFIG_FILE <