diff --git a/misc/build.func b/misc/build.func index 38587512..42e18452 100644 --- a/misc/build.func +++ b/misc/build.func @@ -1,6 +1,7 @@ # Copyright (c) 2021-2025 tteck # Author: tteck (tteckster) # Co-Author: MickLesk +# Co-Author: michelroegl-brunner # License: MIT # https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE @@ -8,7 +9,9 @@ variables() { NSAPP=$(echo ${APP,,} | tr -d ' ') # This function sets the NSAPP variable by converting the value of the APP variable to lowercase and removing any spaces. var_install="${NSAPP}-install" # sets the var_install variable by appending "-install" to the value of NSAPP. INTEGER='^[0-9]+([.][0-9]+)?$' # it defines the INTEGER regular expression pattern. - PVEHOST_NAME=$(hostname) # gets the Proxmox Hostname and sets it to Uppercase + PVEHOST_NAME=$(hostname) # gets the Proxmox Hostname and sets it to Uppercase + DIAGNOSTICS="yes" # sets the DIAGNOSTICS variable to "yes", used for the API call. + METHOD="default" # sets the METHOD variable to "default", used for the API call. } # This function sets various color variables using ANSI escape codes for formatting text in the terminal. @@ -143,10 +146,10 @@ pve_check() { echo -e "Exiting..." sleep 2 exit -fi + fi } -# When a node is running tens of containers, it's possible to exceed the kernel's cryptographic key storage allocations. +# When a node is running tens of containers, it's possible to exceed the kernel's cryptographic key storage allocations. # These are tuneable, so verify if the currently deployment is approaching the limits, advise the user on how to tune the limits, and exit the script. # https://cleveruptime.com/docs/files/proc-key-users | https://docs.kernel.org/security/keys/core.html maxkeys_check() { @@ -222,11 +225,11 @@ get_current_ip() { # Function to update the IP address in the MOTD file update_motd_ip() { MOTD_FILE="/etc/motd" - + if [ -f "$MOTD_FILE" ]; then # Remove existing IP Address lines to prevent duplication sed -i '/IP Address:/d' "$MOTD_FILE" - + IP=$(get_current_ip) # Add the new IP address echo -e "${TAB}${NETWORK}${YW} IP Address: ${GN}${IP}${CL}" >> "$MOTD_FILE" @@ -359,34 +362,34 @@ exit_script() { advanced_settings() { whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox --title "Here is an instructional tip:" "To make a selection, use the Spacebar." 8 58 whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox --title "Default distribution for $APP" "Default is: ${var_os} ${var_version} \n \nIf the default Linux distribution is not adhered to, script support will be discontinued. \n" 10 58 - if [ "$var_os" != "alpine" ]; then + if [ "$var_os" != "alpine" ]; then var_default_os="${var_os}" var_os="" while [ -z "$var_os" ]; do - if [ "$var_default_os" == "debian" ]; then - if var_os=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "DISTRIBUTION" --radiolist "Choose Distribution" 10 58 2 \ - "debian" "" ON \ - "ubuntu" "" OFF \ - 3>&1 1>&2 2>&3); then - if [ -n "$var_os" ]; then - echo -e "${OS}${BOLD}${DGN}Operating System: ${BGN}$var_os${CL}" - fi - else - exit_script + if [ "$var_default_os" == "debian" ]; then + if var_os=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "DISTRIBUTION" --radiolist "Choose Distribution" 10 58 2 \ + "debian" "" ON \ + "ubuntu" "" OFF \ + 3>&1 1>&2 2>&3); then + if [ -n "$var_os" ]; then + echo -e "${OS}${BOLD}${DGN}Operating System: ${BGN}$var_os${CL}" fi + else + exit_script fi - if [ "$var_default_os" == "ubuntu" ]; then - if var_os=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "DISTRIBUTION" --radiolist "Choose Distribution" 10 58 2 \ - "debian" "" OFF \ - "ubuntu" "" ON \ - 3>&1 1>&2 2>&3); then - if [ -n "$var_os" ]; then - echo -e "${OS}${BOLD}${DGN}Operating System: ${BGN}$var_os${CL}" - fi - else - exit_script + fi + if [ "$var_default_os" == "ubuntu" ]; then + if var_os=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "DISTRIBUTION" --radiolist "Choose Distribution" 10 58 2 \ + "debian" "" OFF \ + "ubuntu" "" ON \ + 3>&1 1>&2 2>&3); then + if [ -n "$var_os" ]; then + echo -e "${OS}${BOLD}${DGN}Operating System: ${BGN}$var_os${CL}" fi + else + exit_script fi + fi done fi @@ -394,7 +397,7 @@ advanced_settings() { var_default_version="${var_version}" var_version="" while [ -z "$var_version" ]; do - if [ "$var_default_version" == "11" ]; then + if [ "$var_default_version" == "11" ]; then if var_version=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "DEBIAN VERSION" --radiolist "Choose Version" 10 58 2 \ "11" "Bullseye" ON \ "12" "Bookworm" OFF \ @@ -425,13 +428,13 @@ advanced_settings() { var_default_version="${var_version}" var_version="" while [ -z "$var_version" ]; do - if [ "$var_default_version" == "20.04" ]; then + if [ "$var_default_version" == "20.04" ]; then if var_version=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "UBUNTU VERSION" --radiolist "Choose Version" 10 58 4 \ "20.04" "Focal" ON \ "22.04" "Jammy" OFF \ "24.04" "Noble" OFF \ "24.10" "Oracular" OFF \ - 3>&1 1>&2 2>&3); then + 3>&1 1>&2 2>&3); then if [ -n "$var_version" ]; then echo -e "${OSVERSION}${BOLD}${DGN}Version: ${BGN}$var_version${CL}" fi @@ -444,7 +447,7 @@ advanced_settings() { "22.04" "Jammy" ON \ "24.04" "Noble" OFF \ "24.10" "Oracular" OFF \ - 3>&1 1>&2 2>&3); then + 3>&1 1>&2 2>&3); then if [ -n "$var_version" ]; then echo -e "${OSVERSION}${BOLD}${DGN}Version: ${BGN}$var_version${CL}" fi @@ -452,25 +455,25 @@ advanced_settings() { exit_script fi elif [ "$var_default_version" == "24.04" ]; then - if var_version=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "UBUNTU VERSION" --radiolist "Choose Version" 10 58 4 \ + if var_version=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "UBUNTU VERSION" --radiolist "Choose Version" 10 58 4 \ "20.04" "Focal" OFF \ "22.04" "Jammy" OFF \ "24.04" "Noble" ON \ "24.10" "Oracular" OFF \ - 3>&1 1>&2 2>&3); then + 3>&1 1>&2 2>&3); then if [ -n "$var_version" ]; then echo -e "${OSVERSION}${BOLD}${DGN}Version: ${BGN}$var_version${CL}" fi else exit_script - fi + fi else if var_version=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "UBUNTU VERSION" --radiolist "Choose Version" 10 58 4 \ "20.04" "Focal" OFF \ "22.04" "Jammy" OFF \ "24.04" "Noble" OFF \ "24.10" "Oracular" ON \ - 3>&1 1>&2 2>&3); then + 3>&1 1>&2 2>&3); then if [ -n "$var_version" ]; then echo -e "${OSVERSION}${BOLD}${DGN}Version: ${BGN}$var_version${CL}" fi @@ -485,7 +488,7 @@ advanced_settings() { CT_DEFAULT_TYPE="${CT_TYPE}" CT_TYPE="" while [ -z "$CT_TYPE" ]; do - if [ "$CT_DEFAULT_TYPE" == "1" ]; then + if [ "$CT_DEFAULT_TYPE" == "1" ]; then if CT_TYPE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "CONTAINER TYPE" --radiolist "Choose Type" 10 58 2 \ "1" "Unprivileged" ON \ "0" "Privileged" OFF \ @@ -550,7 +553,6 @@ advanced_settings() { fi done - if CT_ID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" 3>&1 1>&2 2>&3); then if [ -z "$CT_ID" ]; then CT_ID="$NEXTID" @@ -741,14 +743,14 @@ advanced_settings() { if ADV_TAGS=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Custom Tags?[If you remove all, there will be no tags!]" 8 58 ${TAGS} --title "Advanced Tags" 3>&1 1>&2 2>&3); then if [ -n "${ADV_TAGS}" ]; then - ADV_TAGS=$(echo "$ADV_TAGS" | tr -d '[:space:]') - TAGS="${ADV_TAGS}" + ADV_TAGS=$(echo "$ADV_TAGS" | tr -d '[:space:]') + TAGS="${ADV_TAGS}" else TAGS=";" fi - echo -e "${NETWORK}${BOLD}${DGN}Tags: ${BGN}$TAGS${CL}" - else - exit_script + echo -e "${NETWORK}${BOLD}${DGN}Tags: ${BGN}$TAGS${CL}" + else + exit_script fi if [[ "$PW" == -password* ]]; then @@ -771,7 +773,7 @@ advanced_settings() { fi else SSH_AUTHORIZED_KEY="" - fi + fi if (whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then VERB="yes" else @@ -789,6 +791,116 @@ advanced_settings() { fi } +post_to_api() { + local API_URL="http://api.community-scripts.org/upload" + local pve_version="not found" + pve_version=$(pveversion | awk -F'[/ ]' '{print $2}') + + JSON_PAYLOAD=$( + cat </usr/local/community-scripts/diagnostics +DIAGNOSTICS=yes + +#This file is used to store the diagnostics settings for the Community-Scripts API. +#https://github.com/community-scripts/ProxmoxVE/discussions/1836 +#Your diagnostics will be sent to the Community-Scripts API for troubleshooting/statistical purposes. +#You can review the data at https://community-scripts.github.io/ProxmoxVE/data +#If you do not wish to send diagnostics, please set the variable 'DIAGNOSTICS' to "no" in /usr/local/community-scripts/diagnostics, or use the menue. +#This will disable the diagnostics feature. +#To send diagnostics, set the variable 'DIAGNOSTICS' to "yes" in /usr/local/community-scripts/diagnostics, or use the menue. +#This will enable the diagnostics feature. +#The following information will be sent: +#"ct_type" +#"disk_size" +#"core_count" +#"ram_size" +#"verbose" +#"os_type" +#"os_version" +#"hn" +#"disableip6" +#"ssh" +#"tags" +#"nsapp" +#"method" +#"pve_version" +#If you have any concerns, please review the source code at /misc/build.func +EOF + DIAGNOSTICS="yes" + else + cat </usr/local/community-scripts/diagnostics +DIAGNOSTICS=no + +#This file is used to store the diagnostics settings for the Community-Scripts API. +#https://github.com/community-scripts/ProxmoxVE/discussions/1836 +#Your diagnostics will be sent to the Community-Scripts API for troubleshooting/statistical purposes. +#You can review the data at https://community-scripts.github.io/ProxmoxVE/data +#If you do not wish to send diagnostics, please set the variable 'DIAGNOSTICS' to "no" in /usr/local/community-scripts/diagnostics, or use the menue. +#This will disable the diagnostics feature. +#To send diagnostics, set the variable 'DIAGNOSTICS' to "yes" in /usr/local/community-scripts/diagnostics, or use the menue. +#This will enable the diagnostics feature. +#The following information will be sent: +#"ct_type" +#"disk_size" +#"core_count" +#"ram_size" +#"verbose" +#"os_type" +#"os_version" +#"hn" +#"disableip6" +#"ssh" +#"tags" +#"nsapp" +#"method" +#"pve_version" +#If you have any concerns, please review the source code at /misc/build.func +EOF + DIAGNOSTICS="no" + fi + else + DIAGNOSTICS=$(awk -F '=' '/^DIAGNOSTICS/ {print $2}' /usr/local/community-scripts/diagnostics) + + fi + +} + install_script() { pve_check shell_check @@ -796,6 +908,7 @@ install_script() { arch_check ssh_check maxkeys_check + diagnostics_check if systemctl is-active -q ping-instances.service; then systemctl -q stop ping-instances.service @@ -804,12 +917,14 @@ install_script() { timezone=$(cat /etc/timezone) header_info while true; do + CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "SETTINGS" --menu "Choose an option:" \ - 12 50 4 \ + 12 50 5 \ "1" "Default Settings" \ "2" "Default Settings (with verbose)" \ "3" "Advanced Settings" \ - "4" "Exit" --nocancel --default-item "1" 3>&1 1>&2 2>&3) + "4" "Diagnostic Settings" \ + "5" "Exit" --nocancel --default-item "1" 3>&1 1>&2 2>&3) if [ $? -ne 0 ]; then echo -e "${CROSS}${RD} Menu canceled. Exiting.${CL}" @@ -817,35 +932,55 @@ install_script() { fi case $CHOICE in - 1) - header_info - echo -e "${DEFAULT}${BOLD}${BL}Using Default Settings on node $PVEHOST_NAME${CL}" - VERB="no" - base_settings "$VERB" - echo_default - break - ;; - 2) - header_info - echo -e "${DEFAULT}${BOLD}${BL}Using Default Settings on node $PVEHOST_NAME (${SEARCH}Verbose)${CL}" - VERB="yes" - base_settings "$VERB" - echo_default - break - ;; - 3) - header_info - echo -e "${ADVANCED}${BOLD}${RD}Using Advanced Settings on node $PVEHOST_NAME${CL}" - advanced_settings - break - ;; - 4) - echo -e "${CROSS}${RD}Exiting.${CL}" - exit 0 - ;; - *) - echo -e "${CROSS}${RD}Invalid option, please try again.${CL}" + 1) + header_info + echo -e "${DEFAULT}${BOLD}${BL}Using Default Settings on node $PVEHOST_NAME${CL}" + VERB="no" + METHOD="default" + base_settings "$VERB" + echo_default + break + ;; + 2) + header_info + echo -e "${DEFAULT}${BOLD}${BL}Using Default Settings on node $PVEHOST_NAME (${SEARCH}Verbose)${CL}" + VERB="yes" + METHOD="default" + base_settings "$VERB" + echo_default + break + ;; + 3) + header_info + echo -e "${ADVANCED}${BOLD}${RD}Using Advanced Settings on node $PVEHOST_NAME${CL}" + METHOD="advanced" + advanced_settings + break + ;; + 4) + if [[ $DIAGNOSTICS == "yes" ]]; then + if whiptail --backtitle "Proxmox VE Helper Scripts" --title "DIAGNOSTICS SETTINGS" --yesno "Send Diagnostics of LXC Installation?\n\nCurrent setting: ${DIAGNOSTICS}" 10 58 \ + --yes-button "No" --no-button "Back" ; then + DIAGNOSTICS="no" + sed -i 's/^DIAGNOSTICS=.*/DIAGNOSTICS=no/' /usr/local/community-scripts/diagnostics + whiptail --backtitle "Proxmox VE Helper Scripts" --title "DIAGNOSTICS SETTINGS" --msgbox "Diagnostics settings changed to ${DIAGNOSTICS}." 8 58 + fi + else + if whiptail --backtitle "Proxmox VE Helper Scripts" --title "DIAGNOSTICS SETTINGS" --yesno "Send Diagnostics of LXC Installation?\n\nCurrent setting: ${DIAGNOSTICS}" 10 58 \ + --yes-button "Yes" --no-button "Back" ; then + DIAGNOSTICS="yes" + sed -i 's/^DIAGNOSTICS=.*/DIAGNOSTICS=yes/' /usr/local/community-scripts/diagnostics + whiptail --backtitle "Proxmox VE Helper Scripts" --title "DIAGNOSTICS SETTINGS" --msgbox "Diagnostics settings changed to ${DIAGNOSTICS}." 8 58 + fi + fi ;; + 5) + echo -e "${CROSS}${RD}Exiting.${CL}" + exit 0 + ;; + *) + echo -e "${CROSS}${RD}Invalid option, please try again.${CL}" + ;; esac done } @@ -911,7 +1046,7 @@ start() { # This function collects user settings and integrates all the collected information. build_container() { -# if [ "$VERB" == "yes" ]; then set -x; fi + # if [ "$VERB" == "yes" ]; then set -x; fi if [ "$CT_TYPE" == "1" ]; then FEATURES="keyctl=1,nesting=1" @@ -919,6 +1054,9 @@ build_container() { FEATURES="nesting=1" fi + if [[ $DIAGNOSTICS == "yes" ]]; then + post_to_api + fi TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null @@ -1012,7 +1150,7 @@ EOF msg_ok "Started LXC Container" if [ "$var_os" == "alpine" ]; then sleep 3 - pct exec "$CTID" -- /bin/sh -c 'cat </etc/apk/repositories + pct exec "$CTID" -- /bin/sh -c 'cat </etc/apk/repositories http://dl-cdn.alpinelinux.org/alpine/latest-stable/main http://dl-cdn.alpinelinux.org/alpine/latest-stable/community EOF' @@ -1027,7 +1165,8 @@ description() { IP=$(pct exec "$CTID" ip a s dev eth0 | awk '/inet / {print $2}' | cut -d/ -f1) # Generate LXC Description - DESCRIPTION=$(cat < Logo @@ -1055,7 +1194,7 @@ description() { EOF -) + ) # Set Description in LXC pct set "$CTID" -description "$DESCRIPTION"