diff --git a/bin/pct-create b/bin/pct-create index 43847e9..51c22a7 100755 --- a/bin/pct-create +++ b/bin/pct-create @@ -7,6 +7,7 @@ CONTAINER_NAME=$1 TEMPLATE_DIR=/var/lib/vz/template/cache TAG_NAME=debian13 SSH_PUBKEYS="$BASEDIR/../config/admin.pubkeys" +CONFIG_FILE="$BASEDIR/../config/default.conf" # FUNCTIONS @@ -18,15 +19,6 @@ function debian13_template { ls -1 $TEMPLATE_DIR | grep ^debian-13 } -function show_defaults { - echo -n "STORAGE_DISK=$STORAGE_DISK," - echo -n "STORAGE_SIZE=$STORAGE_SIZE," - echo -n "MEMORY=$MEMORY," - echo -n "SWAP=$SWAP," - echo -n "CPU=$CPU," - echo -} - function convert_human_size_to_megabyte { value=$1 echo "$(numfmt --from=iec-i "$value"i --to-unit=Mi)" | cut -dM -f1 @@ -37,6 +29,14 @@ function convert_human_size_to_gigabyte { echo "$(numfmt --from=iec-i "$value"i --to-unit=Gi)" | cut -dG -f1 } +function optional_public_keys { + if [[ -f $SSH_PUBKEYS ]]; then + echo "--ssh-public-keys $SSH_PUBKEYS" + else + echo + fi +} + function create_container { local new_id=$($BASEDIR/pct-nextid) local template_file="$TEMPLATE_DIR/$(debian13_template)" @@ -56,7 +56,7 @@ function create_container { --net0 name=eth0,bridge=vmbr0,ip=dhcp,firewall=1 \ --start \ --onboot true \ - --ssh-public-keys $SSH_PUBKEYS \ + $(optional_public_keys) \ --unprivileged true \ --features nesting=1 \ @@ -65,7 +65,7 @@ function create_container { } function existing_container { - local vmid=$($BASEDIR/pct-lookup "$CONTAINER_NAME") + local vmid=$($BASEDIR/pct-lookup "$CONTAINER_NAME" 2>/dev/null) if [[ -z $vmid ]]; then false else @@ -78,9 +78,8 @@ function existing_container { set -Eue [[ "$#" -lt 1 ]] && usage && exit 1 -source "$BASEDIR/../config/default.config" +source "$CONFIG_FILE" -# show_defaults existing_container && false || create_container diff --git a/install.sh b/install.sh index 4f610c2..680619d 100755 --- a/install.sh +++ b/install.sh @@ -2,6 +2,7 @@ # CONSTANTS +CONFIG_FILE=/opt/miaou-proxmox/config/default.conf # FUNCTIONS @@ -40,6 +41,63 @@ function install_miaou_proxmox { [[ $status == 'appended' ]] && echo 'successfully installed! please run `source $HOME/.bashrc`' } +function compute_cpu_cores { + cores=$(nproc) + if [[ $cores -ge 16 ]]; then + cores=$(( cores / 4 )) + else + if [[ $cores -ge 4 ]]; then + cores=$(( cores / 2 )) + else + cores=1 + fi + fi + echo $cores +} + +function choose_default { + storage_size='20G' + memory='2G' + swap='2G' + cpu=$(compute_cpu_cores) + + mapfile -t storages <<< $(pvesm status | grep zfspool | cut -d' ' -f1) + 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 <