From aab52e30a230884c0a055d071d98b1449417ebc8 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Mon, 26 May 2025 12:57:39 +0200 Subject: [PATCH] test --- misc/vm-core.func | 35 +++++++++ vm/debian-vm.sh | 30 -------- vm/umbrel-os-vm.sh | 184 ++++----------------------------------------- 3 files changed, 48 insertions(+), 201 deletions(-) diff --git a/misc/vm-core.func b/misc/vm-core.func index ac23993..9b5cca3 100644 --- a/misc/vm-core.func +++ b/misc/vm-core.func @@ -396,3 +396,38 @@ exit_script() { echo -e "\n${CROSS}${RD}User exited script${CL}\n" exit } + +set_description() { + DESCRIPTION=$( + cat < + + Logo + + +

${NSAPP} VM

+ +

+ + spend Coffee + +

+ + + + GitHub + + + + Discussions + + + + Issues + + +EOF + ) + qm set "$VMID" -description "$DESCRIPTION" >/dev/null + +} diff --git a/vm/debian-vm.sh b/vm/debian-vm.sh index a49cb5f..f88a595 100644 --- a/vm/debian-vm.sh +++ b/vm/debian-vm.sh @@ -360,37 +360,7 @@ qm set $VMID \ -scsi0 ${DISK1_REF},${DISK_CACHE}${THIN}size=${DISK_SIZE} \ -boot order=scsi0 \ -serial0 socket >/dev/null -DESCRIPTION=$( - cat < - - Logo - -

${NSAPP} VM

- -

- - spend Coffee - -

- - - - GitHub - - - - Discussions - - - - Issues - - -EOF -) -qm set "$VMID" -description "$DESCRIPTION" >/dev/null if [ -n "$DISK_SIZE" ]; then msg_info "Resizing disk to $DISK_SIZE GB" qm resize $VMID scsi0 ${DISK_SIZE} >/dev/null diff --git a/vm/umbrel-os-vm.sh b/vm/umbrel-os-vm.sh index 10fbf01..61f6f97 100644 --- a/vm/umbrel-os-vm.sh +++ b/vm/umbrel-os-vm.sh @@ -5,18 +5,10 @@ # License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE source /dev/stdin <<<$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/api.func) +source <(curl -fsSL https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main/misc/vm-core.func) +load_functions -function header_info() { - clear - cat <<"EOF" - __ __ __ __ ____ _____ _ ____ ___ - / / / /___ ___ / /_ ________ / / / __ \/ ___/ | | / / |/ / - / / / / __ `__ \/ __ \/ ___/ _ \/ / / / / /\__ \ | | / / /|_/ / -/ /_/ / / / / / / /_/ / / / __/ / / /_/ /___/ / | |/ / / / / -\____/_/ /_/ /_/_.___/_/ \___/_/ \____//____/ |___/_/ /_/ - -EOF -} +APP="Umbrel OS VM" header_info echo -e "\n Loading..." GEN_MAC=02:$(openssl rand -hex 5 | awk '{print toupper($0)}' | sed 's/\(..\)/\1:/g; s/.$//') @@ -26,38 +18,6 @@ NSAPP="umbrel-os-vm" var_os="umbrel-os" var_version="n.d." -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -HA=$(echo "\033[1;34m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") - -CL=$(echo "\033[m") -BOLD=$(echo "\033[1m") -BFR="\\r\\033[K" -HOLD=" " -TAB=" " - -CM="${TAB}✔️${TAB}${CL}" -CROSS="${TAB}✖️${TAB}${CL}" -INFO="${TAB}💡${TAB}${CL}" -OS="${TAB}🖥️${TAB}${CL}" -CONTAINERTYPE="${TAB}📦${TAB}${CL}" -DISKSIZE="${TAB}💾${TAB}${CL}" -CPUCORE="${TAB}🧠${TAB}${CL}" -RAMSIZE="${TAB}🛠️${TAB}${CL}" -CONTAINERID="${TAB}🆔${TAB}${CL}" -HOSTNAME="${TAB}🏠${TAB}${CL}" -BRIDGE="${TAB}🌉${TAB}${CL}" -GATEWAY="${TAB}🌐${TAB}${CL}" -DEFAULT="${TAB}⚙️${TAB}${CL}" -MACADDRESS="${TAB}🔗${TAB}${CL}" -VLANTAG="${TAB}🏷️${TAB}${CL}" -CREATING="${TAB}🚀${TAB}${CL}" -ADVANCED="${TAB}🧩${TAB}${CL}" THIN="discard=on,ssd=1," set -e trap 'error_handler $LINENO "$BASH_COMMAND"' ERR @@ -74,35 +34,15 @@ function error_handler() { cleanup_vmid } -function get_valid_nextid() { - local try_id - try_id=$(pvesh get /cluster/nextid) - while true; do - if [ -f "/etc/pve/qemu-server/${try_id}.conf" ] || [ -f "/etc/pve/lxc/${try_id}.conf" ]; then - try_id=$((try_id + 1)) - continue - fi - if lvs --noheadings -o lv_name | grep -qE "(^|[-_])${try_id}($|[-_])"; then - try_id=$((try_id + 1)) - continue - fi - break - done - echo "$try_id" -} - -function cleanup_vmid() { - if qm status $VMID &>/dev/null; then - qm stop $VMID &>/dev/null - qm destroy $VMID &>/dev/null - fi -} - -function cleanup() { - popd >/dev/null - post_update_to_api "done" "none" - rm -rf $TEMP_DIR -} +get_valid_nextid +cleanup_vmid +cleanup +post_update_to_api "done" "none" +[[ -n "${TEMP_DIR:-}" && -d "$TEMP_DIR" ]] && rm -rf "$TEMP_DIR" +check_root +pve_check +arch_check +ssh_check TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null @@ -112,70 +52,6 @@ else header_info && echo -e "${CROSS}${RD}User exited script${CL}\n" && exit fi -function msg_info() { - local msg="$1" - echo -ne "${TAB}${YW}${HOLD}${msg}${HOLD}" -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR}${CM}${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR}${CROSS}${RD}${msg}${CL}" -} - -function check_root() { - if [[ "$(id -u)" -ne 0 || $(ps -o comm= -p $PPID) == "sudo" ]]; then - clear - msg_error "Please run this script as root." - echo -e "\nExiting..." - sleep 2 - exit - fi -} - -function pve_check() { - if ! pveversion | grep -Eq "pve-manager/8\.[1-4](\.[0-9]+)*"; then - msg_error "${CROSS}${RD}This version of Proxmox Virtual Environment is not supported" - echo -e "Requires Proxmox Virtual Environment Version 8.1 or later." - echo -e "Exiting..." - sleep 2 - exit - fi -} - -function arch_check() { - if [ "$(dpkg --print-architecture)" != "amd64" ]; then - echo -e "\n ${INFO}${YWB}This script will not work with PiMox! \n" - echo -e "\n ${YWB}Visit https://github.com/asylumexp/Proxmox for ARM64 support. \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} - -function ssh_check() { - if command -v pveversion >/dev/null 2>&1; then - if [ -n "${SSH_CLIENT:+x}" ]; then - if whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "SSH DETECTED" --yesno "It's suggested to use the Proxmox shell instead of SSH, since SSH can create issues while gathering variables. Would you like to proceed with using SSH?" 10 62; then - echo "you've been warned" - else - clear - exit - fi - fi - fi -} - -function exit_script() { - clear - echo -e "\n${CROSS}${RD}User exited script${CL}\n" - exit -} - function default_settings() { VMID=$(get_valid_nextid) FORMAT=",efitype=4m" @@ -401,10 +277,6 @@ function start_script() { advanced_settings fi } -check_root -arch_check -pve_check -ssh_check start_script post_to_api_vm @@ -489,37 +361,7 @@ qm set $VMID \ -serial0 socket >/dev/null qm set $VMID --agent enabled=1 >/dev/null -DESCRIPTION=$( - cat < - - Logo - - -

Docker VM

- -

- - spend Coffee - -

- - - - GitHub - - - - Discussions - - - - Issues - - -EOF -) -qm set "$VMID" -description "$DESCRIPTION" >/dev/null +set_description if [ -n "$DISK_SIZE" ]; then msg_info "Resizing disk to $DISK_SIZE GB"