Browse Source

pct-info

main
pvincent 2 days ago
parent
commit
09ee24b49c
  1. 9
      README.md
  2. 53
      bin/pct-info
  3. 27
      install.sh

9
README.md

@ -5,14 +5,7 @@ mostly command-line utilities.
## how-to install ## how-to install
> one-liner style
```bash ```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
```

53
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

27
install.sh

@ -65,27 +65,14 @@ function choose_default {
mapfile -t storages <<< $(pvesm status | grep zfspool | cut -d' ' -f1) 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 <<EOF cat > $CONFIG_FILE <<EOF
INTERACTIVE=$interactive
STORAGE_DISK=\${STORAGE_DISK:-$storage_disk} STORAGE_DISK=\${STORAGE_DISK:-$storage_disk}
STORAGE_SIZE=\${STORAGE_SIZE:-$storage_size} STORAGE_SIZE=\${STORAGE_SIZE:-$storage_size}
MEMORY=\${MEMORY:-$memory} MEMORY=\${MEMORY:-$memory}
@ -97,7 +84,7 @@ EOF
function initialize { function initialize {
mkdir -p /opt/miaou-proxmox/config mkdir -p /opt/miaou-proxmox/config
if [[ ! -f $CONFIG_FILE ]] || ! grep -q 'INTERACTIVE=true' $CONFIG_FILE; then
if [[ ! -f $CONFIG_FILE ]]; then
choose_default choose_default
echo '------------------------' echo '------------------------'
echo 'successfully configured!' echo 'successfully configured!'

Loading…
Cancel
Save