├── .vscode └── settings.json ├── images ├── UniFi-Networks.png ├── Proxmox-network.png ├── Proxmox-network2.png ├── UniFi-Network-VPN.egress.png ├── UniFi-Devices-Port_Management-pvelan.png └── UniFi-Devices-Port_Management-vpnegress.png ├── .gitattributes ├── .gitmodules ├── shared └── src │ └── pve_host_mount_list ├── src ├── pve_host_setup_hostnameupdate.sh ├── pve_host_setup_boot_delay.sh ├── pve_host_setup_hostname.sh ├── pve_host_toolbox.sh ├── pve_host_setup_lxc_igpu_support.sh ├── pve_host_setup_fail2ban.sh ├── pvetool_ct_updater.sh ├── pve_host_setup_basic.sh ├── pve_host_setup_sshkey.sh ├── pve_host_add_nfs_mounts.sh ├── pve_host_setup_postfix_server.sh ├── pve_host_setup_postfix.sh └── pve_host_add_cifs_mounts.sh ├── pve_host_toolbox.sh ├── README.md └── LICENSE /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cSpell.words": [ 3 | "localdomain" 4 | ] 5 | } -------------------------------------------------------------------------------- /images/UniFi-Networks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahuacate/pve-host/HEAD/images/UniFi-Networks.png -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | * text eol=lf 4 | -------------------------------------------------------------------------------- /images/Proxmox-network.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahuacate/pve-host/HEAD/images/Proxmox-network.png -------------------------------------------------------------------------------- /images/Proxmox-network2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahuacate/pve-host/HEAD/images/Proxmox-network2.png -------------------------------------------------------------------------------- /images/UniFi-Network-VPN.egress.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahuacate/pve-host/HEAD/images/UniFi-Network-VPN.egress.png -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "common"] 2 | path = common 3 | url = https://github.com/ahuacate/common.git 4 | branch = main 5 | -------------------------------------------------------------------------------- /images/UniFi-Devices-Port_Management-pvelan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahuacate/pve-host/HEAD/images/UniFi-Devices-Port_Management-pvelan.png -------------------------------------------------------------------------------- /images/UniFi-Devices-Port_Management-vpnegress.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahuacate/pve-host/HEAD/images/UniFi-Devices-Port_Management-vpnegress.png -------------------------------------------------------------------------------- /shared/src/pve_host_mount_list: -------------------------------------------------------------------------------- 1 | # Mount Category : PVE ES auto mount (0 = yes, 1 = no) 2 | #None:Ignore this share:1 3 | Appdata:Application install folder:0 4 | Audio:Audiobooks and podcasts:0 5 | Backup:PVE LXC settings backup storage:0 6 | Books:Ebooks and Magazines:0 7 | Cloudstorage:Private user cloud storage:0 8 | Docker:Docker storage:0 9 | Downloads:General Download folders:0 10 | Git:GIT folder:1 11 | Homes:Users home folders:1 12 | Music:Music, Albums and Songs:0 13 | Photo:Photographic image collection:0 14 | Public:General public storage folder:0 15 | Timemachine:Apple Time machine folder:1 16 | Transcode:Dedicated Video Transcoding folder:0 17 | Video:All video libraries (i.e movies, series, homevideos):0 18 | #Exit/Finished:Nothing more to add:1 -------------------------------------------------------------------------------- /src/pve_host_setup_hostnameupdate.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ---------------------------------------------------------------------------------- 3 | # Filename: pve_host_setup_hostnameupdate.sh 4 | # Description: Script to change PVE host hostname 5 | # ---------------------------------------------------------------------------------- 6 | 7 | #---- Applying changes to PVE Host 8 | if [ $SET_PVE_HOST_HOSTNAME = 0 ] 9 | then 10 | section "Applying changes to PVE Host" 11 | msg "Applying new hostname to PVE host system..." 12 | hostnamectl set-hostname $PVE_HOSTNAME 13 | msg "Updating new hostname in /etc/hosts file..." 14 | sed -i "s/$HOSTNAME/${PVE_HOSTNAME}/g" /etc/hosts >/dev/null 15 | msg "Updating new hostname in /etc/postfix/main.cf..." 16 | sed -i "s/$HOSTNAME/${PVE_HOSTNAME}/g" /etc/postfix/main.cf >/dev/null 17 | msg "Updating new hostname in /etc/pve/storage.cfg file..." 18 | sed -i "s/$HOSTNAME/${PVE_HOSTNAME}/g" /etc/pve/storage.cfg 2>/dev/null 19 | msg "Waiting for PVE to create a new ${PVE_HOSTNAME} node...\n (be patient, this might take a while!)" 20 | while [ ! -d /etc/pve/nodes/${PVE_HOSTNAME} ]; do sleep 1; done 21 | msg "Creating backup of '$HOSTNAME' configuration files..." 22 | cp -r /etc/pve/nodes/$HOSTNAME . 2>/dev/null 23 | msg "Copying $HOSTNAME configuration files to new $PVE_HOSTNAME node..." 24 | cp $(pwd)/$HOSTNAME/qemu-server/* /etc/pve/nodes/$PVE_HOSTNAME/qemu-server 2>/dev/null 25 | # msg "Copying $HOSTNAME lxc configuration files to new ${PVE_HOSTNAME} node..." 26 | # cp $(pwd)/$HOSTNAME/lxc/* /etc/pve/nodes/${PVE_HOSTNAME}/lxc 2>/dev/null 27 | msg "Removing old $HOSTNAME configuration files from /etc/pve/nodes..." 28 | rm -R /etc/pve/nodes/$HOSTNAME >/dev/null 29 | info "PVE hostname has been updated and set: ${YELLOW}$PVE_HOSTNAME${NC}" 30 | echo 31 | fi 32 | #----------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /src/pve_host_setup_boot_delay.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ---------------------------------------------------------------------------------- 3 | # Filename: pve_host_setup_boot_delay.sh 4 | # Description: Basic mods for Proxmox (PVE) Host machines 5 | # ---------------------------------------------------------------------------------- 6 | 7 | #---- Bash command to run script --------------------------------------------------- 8 | #---- Source ----------------------------------------------------------------------- 9 | #---- Dependencies ----------------------------------------------------------------- 10 | #---- Static Variables ------------------------------------------------------------- 11 | 12 | # Easy Script Section Header Body Text 13 | SECTION_HEAD='PVE Host Boot Delay' 14 | 15 | # Grub parameters (seconds) 16 | grub_timeout=300 17 | grub_timeout_default=5 18 | 19 | #---- Other Variables -------------------------------------------------------------- 20 | #---- Other Files ------------------------------------------------------------------ 21 | #---- Body ------------------------------------------------------------------------- 22 | 23 | #---- Prerequisites 24 | #---- Introduction 25 | 26 | section "Introduction" 27 | 28 | msg_box "#### PLEASE READ CAREFULLY - PVE BOOT DELAY ####\n 29 | This setup script is for adding a boot delay so your NAS and network devices (i.e switches, DNS servers) are up before PVE boots. Our solution is to the edit the 'grub timeout' parameter: 30 | 31 | TASK DESCRIPTION 32 | -- Edit the Grub parameter 'grub timeout' in file '/etc/default/grub' 33 | -- Set the boot delay to 5 minutes ( NAS can be slow to go online ) 34 | 35 | Your Proxmox server now waits 5 minutes before starting the OS, by which time your NAS and network devices (i.e switches, DNS servers) should be operational. There will be no more manual restarting of virtual machines following a power outage." 36 | echo 37 | 38 | msg "Select you option..." 39 | OPTIONS_VALUES_INPUT=( "TYPE01" "TYPE02" "TYPE00") 40 | OPTIONS_LABELS_INPUT=( "Apply a ${grub_timeout} second Grub boot delay (recommended)" "Restore Proxmox default Grub boot delay (${grub_timeout_default} seconds)" "None. Return to the Toolbox" ) 41 | makeselect_input2 42 | singleselect SELECTED "$OPTIONS_STRING" 43 | 44 | if [ "$RESULTS" = 'TYPE01' ] 45 | then 46 | # Set grub boot delay (300) 47 | msg "Setting PVE host boot delay..." 48 | sed -i "s/GRUB_TIMEOUT=.*/GRUB_TIMEOUT=${grub_timeout}/" /etc/default/grub 49 | # Update grub 50 | update-grub 51 | info "PVE host boot delay: ${YELLOW}${grub_timeout}${NC}" 52 | elif [ "$RESULTS" = 'TYPE02' ] 53 | then 54 | # Set grub boot back to default 55 | msg "Setting PVE host boot delay..." 56 | sed -i "s/GRUB_TIMEOUT=.*/GRUB_TIMEOUT=${grub_timeout_default}/" /etc/default/grub 57 | # Update grub 58 | update-grub 59 | info "PVE host boot delay: ${YELLOW}${grub_timeout_default}${NC} (default)" 60 | elif [ "$RESULTS" = 'TYPE00' ] 61 | then 62 | return 63 | fi 64 | 65 | #---- Finish Line ------------------------------------------------------------------ 66 | 67 | section "Completion Status" 68 | msg "Success. Task complete." 69 | echo 70 | #----------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /pve_host_toolbox.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ---------------------------------------------------------------------------------- 3 | # Filename: pve_host_toolbox.sh 4 | # Description: Toolbox Proxmox host 5 | # ---------------------------------------------------------------------------------- 6 | 7 | #---- Bash command to run script --------------------------------------------------- 8 | 9 | #---- Source Github 10 | # bash -c "$(wget -qLO - https://raw.githubusercontent.com/ahuacate/pve-host/main/pve_host_toolbox.sh)" 11 | 12 | #---- Source local Git 13 | # /mnt/pve/nas-01-git/ahuacate/pve-host/pve_host_toolbox.sh 14 | 15 | #---- Installer Vars --------------------------------------------------------------- 16 | # This is a installer script. Only edit the variables in this section. 17 | 18 | # Git server 19 | GIT_SERVER='https://github.com' 20 | # Git user 21 | GIT_USER='ahuacate' 22 | # Git repository 23 | GIT_REPO='pve-host' 24 | # Git branch 25 | GIT_BRANCH='main' 26 | # Git common 27 | GIT_COMMON='0' 28 | 29 | #----------------------------------------------------------------------------------- 30 | # NO NOT EDIT HERE DOWN 31 | #---- Dependencies ----------------------------------------------------------------- 32 | 33 | #---- Check for Internet connectivity 34 | 35 | # List of well-known websites to test connectivity (in case one is blocked) 36 | websites=( "google.com 443" "github.com 443" "cloudflare.com 443" "apple.com 443" "amazon.com 443" ) 37 | # Loop through each website in the list 38 | for website in "${websites[@]}" 39 | do 40 | # Test internet connectivity 41 | nc -zw1 $website > /dev/null 2>&1 42 | # Check the exit status of the ping command 43 | if [ $? = 0 ] 44 | then 45 | # Flag to track if internet connection is up 46 | connection_up=0 47 | break 48 | else 49 | # Flag to track if internet connection is down 50 | connection_up=1 51 | fi 52 | done 53 | # On connection fail 54 | if [ "$connection_up" = 1 ] 55 | then 56 | echo "Checking for internet connectivity..." 57 | echo -e "Internet connectivity status: \033[0;31mDown\033[0m\n\nCannot proceed without a internet connection.\nFix your PVE hosts internet connection and try again..." 58 | echo 59 | exit 0 60 | fi 61 | 62 | #---- Static Variables ------------------------------------------------------------- 63 | 64 | #---- Set Package Installer Temp Dir 65 | 66 | # Set 'rep_temp' dir 67 | REPO_TEMP='/tmp' 68 | # Change to 'repo temp' dir 69 | cd $REPO_TEMP 70 | 71 | #---- Local Repo path (check if local) 72 | 73 | # For local SRC a 'developer_settings.git' file must exist in repo dir 74 | REPO_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P | sed "s/${GIT_USER}.*/$GIT_USER/" )" 75 | 76 | #---- Other Variables -------------------------------------------------------------- 77 | #---- Other Files ------------------------------------------------------------------ 78 | 79 | #---- Package loader 80 | 81 | # Check for local source 82 | if [ -f "$REPO_PATH/common/bash/src/pve_repo_loader.sh" ] && [[ $(sed -n 's/^dev_git_mount=//p' $REPO_PATH/developer_settings.git 2> /dev/null) == '0' ]] 83 | then 84 | # Download Local loader (developer) 85 | source $REPO_PATH/common/bash/src/pve_repo_loader.sh 86 | else 87 | # Download Github loader 88 | wget -qL - https://raw.githubusercontent.com/$GIT_USER/common/main/bash/src/pve_repo_loader.sh -O $REPO_TEMP/pve_repo_loader.sh 89 | chmod +x $REPO_TEMP/pve_repo_loader.sh 90 | source $REPO_TEMP/pve_repo_loader.sh 91 | fi 92 | 93 | #---- Body ------------------------------------------------------------------------- 94 | 95 | #---- Run Installer 96 | 97 | # Run repo toolbox 98 | source $REPO_PATH/$GIT_REPO/src/pve_host_toolbox.sh 99 | #----------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /src/pve_host_setup_hostname.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ---------------------------------------------------------------------------------- 3 | # Filename: pve_host_setup_hostname.sh 4 | # Description: Set (PVE) Host machine hostname 5 | # ---------------------------------------------------------------------------------- 6 | 7 | #---- Bash command to run script --------------------------------------------------- 8 | #---- Source ----------------------------------------------------------------------- 9 | #---- Dependencies ----------------------------------------------------------------- 10 | #---- Static Variables ------------------------------------------------------------- 11 | 12 | # Easy Script Section Header Body Text 13 | SECTION_HEAD='PVE Host Hostname' 14 | 15 | #---- Other Variables -------------------------------------------------------------- 16 | #---- Other Files ------------------------------------------------------------------ 17 | #---- Functions -------------------------------------------------------------------- 18 | 19 | # Check Hostname availability status 20 | function valid_pvehostname() { 21 | local name="$1" 22 | local stat=1 23 | 24 | if [ "$PVE_TYPE" = 1 ] 25 | then 26 | pve_hostname_regex='^(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9]+\-01)$' 27 | elif [ "$PVE_TYPE" = 2 ]; then 28 | pve_hostname_regex='^(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9]+\-[2-9]{2})$' 29 | fi 30 | # Run function 31 | if [[ "$name" =~ ${hostname_regex} ]] && [[ ! $(grep -h -Po 'hostname: \K[^/]*' /etc/pve/lxc/* 2> /dev/null) =~ $name ]] && [[ ! $(grep -h -Po 'name: \K[^/]*' /etc/pve/qemu-server/* 2> /dev/null) =~ $name ]] && [[ ! $name == $(echo $(hostname) | awk '{ print tolower($0) }') ]] && [ ! "$(ping -s 1 -c 2 ${name} > /dev/null; echo $?)" = 0 ] 32 | then 33 | stat=$? 34 | fi 35 | return $stat 36 | } 37 | 38 | #---- Body ------------------------------------------------------------------------- 39 | 40 | #---- Prerequisites 41 | 42 | # Validate conditions 43 | if [[ $(pct list) ]] || [[ $(qm list) ]] || [[ $(pvecm nodes 2>/dev/null | grep $HOSTNAME) ]] 44 | then 45 | msg_box "#### PLEASE READ CAREFULLY - VALIDATE PREREQUISITES ####\n\n$(if [[ $(pct list) ]] || [[ $(qm list) ]]; then echo -e "PVE host '$HOSTNAME' is reporting to be hosting $(qm list | awk 'NR>1 { print $1 }' | wc -l)x virtual machines (VMs) and $(pct list | awk 'NR>1 { print $1 }' | wc -l)x LXC containers (CTs).\n\nIf you want to proceed to configure or make system changes to this PVE host '$HOSTNAME' you must first take the following steps:\n\n FOR SINGLE OR PRIMARY NODES - REMOVE ALL CONTAINERS\n -- Stop all VMs and CTs.\n -- Create a backup archive of all VMs and CTs.\n -- REMOVE all VMs and CTs.\n\nBackup VM archives can be restored through the Proxmox VE web GUI.\n\n"; fi)$(if [[ $(pvecm nodes 2>/dev/null | grep $HOSTNAME) ]]; then echo -e "PVE host '$HOSTNAME' is also reporting as a member of a PVE cluster. To proceed you must first remove this node ( '$HOSTNAME' ) from the PVE cluster.\n\n REMOVE NODE FROM CLUSTER\n -- Migrate all VMs and CTs to another active node.\n -- Remove '$HOSTNAME' from the PVE cluster.\n\n"; fi)Complete the above tasks and try running this script again. PVE hostname remains unchanged." 46 | echo 47 | # Set for other scripts 48 | PVE_HOSTNAME=$HOSTNAME 49 | SET_PVE_HOST_HOSTNAME=1 50 | sleep 3 51 | return 52 | fi 53 | 54 | 55 | #---- Introduction 56 | section "Introduction" 57 | 58 | msg_box "#### PLEASE READ CAREFULLY - PVE HOST CHECKER ####\n 59 | This script changes your $(if [ "$PVE_TYPE" == '1' ]; then echo "primary"; else echo "secondary"; fi) PVE host '$HOSTNAME'. Tasks to be performed include: 60 | 61 | PREREQUISITES BASICS 62 | -- Update Proxmox. 63 | -- Set a new hostname. 64 | $(if [ "$PVE_TYPE" = 1 ]; then echo "-- Primary PVE hosts must be denoted with -01 (i.e must be hostname-01)"; else echo "-- Secondary PVE hosts must be denoted within the range 02 to 09 (i.e hostname-02)."; fi) 65 | 66 | Changing a PVE hostname requires editing many linux system files. The required edits could change with newer Proxmox releases and our edits may no longer work. The user can always reinstall Proxmox and input a valid hostname during the installation." 67 | echo 68 | while true 69 | do 70 | read -p "Do you want to change the current '$HOSTNAME' [y/n]?: " -n 1 -r YN 71 | echo 72 | case $YN in 73 | [Yy]*) 74 | SET_PVE_HOST_HOSTNAME=0 75 | info "The User has chosen to proceed." 76 | echo 77 | break 78 | ;; 79 | [Nn]*) 80 | PVE_HOSTNAME=$HOSTNAME 81 | SET_PVE_HOST_HOSTNAME=1 82 | info "You have chosen to skip this step.\nPVE hostname is set: ${YELLOW}$PVE_HOSTNAME${NC} (Unchanged)." 83 | echo 84 | return 85 | ;; 86 | *) 87 | warn "Error! Entry must be 'y' or 'n'. Try again..." 88 | echo 89 | ;; 90 | esac 91 | done 92 | 93 | #---- Set PVE Search domain 94 | section "Modify PVE host 'hostname'" 95 | 96 | # Set PVE host 'hostname' 97 | # Hostname suggestion only 98 | if [ "$PVE_TYPE" = 1 ] && [[ "$HOSTNAME" =~ ^[A-Za-z]+\-"01"$ ]] 99 | then 100 | PVE_HOSTNAME_VAR01="$HOSTNAME" 101 | elif [ "$PVE_TYPE" = 1 ] && ! [[ "$HOSTNAME" =~ ^[A-Za-z]+\-"01"$ ]] 102 | then 103 | PVE_HOSTNAME_VAR01="pve-01" 104 | elif [ "$PVE_TYPE" = 2 ] && [[ "$HOSTNAME" =~ ^[A-Za-z]+\-0[2-9]{1}$ ]] 105 | then 106 | PVE_HOSTNAME_VAR01="$HOSTNAME" 107 | elif [ "$PVE_TYPE" = 2 ] && ! [[ "$HOSTNAME" =~ ^[A-Za-z]+\-0[2-9]{1}$ ]] 108 | then 109 | PVE_HOSTNAME_VAR01="pve-02" 110 | fi 111 | while true 112 | do 113 | read -p "Enter a new PVE host 'hostname': " -e -i $PVE_HOSTNAME_VAR01 PVE_HOSTNAME 114 | PVE_HOSTNAME=${PVE_HOSTNAME,,} 115 | FAIL_MSG="The $(if [ "$PVE_TYPE" = 1 ]; then echo "primary"; else echo "secondary"; fi) hostname is not valid. A valid $(if [ "$PVE_TYPE" = 1 ]; then echo "primary"; else echo "secondary"; fi) hostname is when all of the following constraints are satisfied:\n 116 | -- it does not exist on the network. 117 | -- it is not in use by any CT or VM. 118 | -- it contains only lowercase characters. 119 | -- it may include numerics, hyphens (-) and periods (.) but not start or end with them. 120 | -- it doesn't contain any other special characters [!#$&%*+_]. 121 | -- it doesn't contain any white space. 122 | -- it conforms to our PVE host naming convention: 123 | $(if [ "$PVE_TYPE" = 1 ]; then echo "-- Primary PVE hosts must be denoted with -01 (i.e must be hostname-01)"; else echo "-- Secondary PVE hosts must be denoted within the range -02/03/04-09 (i.e hostname-02)."; fi)\n 124 | Try again..." 125 | PASS_MSG="PVE Hostname is set: ${YELLOW}$PVE_HOSTNAME${NC}" 126 | valid_pvehostname "$PVE_HOSTNAME" 127 | if [ $? = 0 ] 128 | then 129 | HOSTNAME_FIX=0 130 | info "$PASS_MSG" 131 | echo 132 | break 133 | elif [ ! "$?" = 0 ] 134 | then 135 | warn "$FAIL_MSG" 136 | echo 137 | fi 138 | done 139 | #----------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /src/pve_host_toolbox.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ---------------------------------------------------------------------------------- 3 | # Filename: pve_host_toolbox.sh 4 | # Description: Installer toolbox for Proxmox host setup and configuration 5 | # Note: Custom installer script (do not update with default installer) 6 | #---------------------------------------------------------------------------------- 7 | 8 | #---- Bash command to run script --------------------------------------------------- 9 | 10 | #---- Source Github 11 | # bash -c "$(wget -qLO - https://raw.githubusercontent.com/ahuacate/pve-host/main/pve_host_toolbox.sh)" 12 | 13 | #---- Source local Git 14 | # /mnt/pve/nas-01-git/ahuacate/pve-host/pve_host_toolbox.sh 15 | 16 | #---- Source ----------------------------------------------------------------------- 17 | #---- Dependencies ----------------------------------------------------------------- 18 | #---- Static Variables ------------------------------------------------------------- 19 | 20 | #---- Easy Script Section Header Body Text 21 | SECTION_HEAD="$(echo "$GIT_REPO" | sed -E 's/(\-|\.|\_)/ /' | awk '{print toupper($0)}')" 22 | 23 | #---- Script path variables 24 | DIR="$REPO_TEMP/$GIT_REPO" 25 | SRC_DIR="$DIR/src" 26 | COMMON_DIR="$DIR/common" 27 | COMMON_PVE_SRC_DIR="$DIR/common/pve/src" 28 | SHARED_DIR="$DIR/shared" 29 | TEMP_DIR="$DIR/tmp" 30 | 31 | #---- Other Variables -------------------------------------------------------------- 32 | #---- Other Files ------------------------------------------------------------------ 33 | #---- Functions -------------------------------------------------------------------- 34 | 35 | #---- Installer cleanup 36 | function installer_cleanup () { 37 | rm -R "$REPO_TEMP/$GIT_REPO" &> /dev/null 38 | rm $REPO_TEMP/${GIT_REPO}.tar.gz &> /dev/null 39 | } 40 | 41 | #---- Body ------------------------------------------------------------------------- 42 | 43 | #---- Prerequisites 44 | 45 | # Run Bash Header 46 | source $COMMON_PVE_SRC_DIR/pvesource_bash_defaults.sh 47 | 48 | # Check PVE SMTP status 49 | check_smtp_status 50 | 51 | #---- Identify PVE Host Type 52 | 53 | section "Set PVE host type" 54 | msg_box "#### PLEASE READ CAREFULLY - PVE BUILD TYPE ####\n 55 | We need to determine the type of PVE host being built or updated. There are two types of PVE hosts machines: 56 | 57 | PRIMARY TYPE 58 | -- Primary PVE host is the first Proxmox machine 59 | 60 | -- Primary PVE hostnames are denoted by '-01' 61 | 62 | -- Default hostname is pve-01 63 | 64 | -- Default primary host IPv4 address is 192.168.1.101 65 | 66 | SECONDARY TYPE 67 | -- Secondary PVE hosts are cluster machines 68 | 69 | -- Proxmox requires a minimum of 3x PVE hosts to form a cluster 70 | 71 | -- Secondary PVE hostnames are denoted by '-02' onwards 72 | 73 | -- Default hostname naming convention begins from pve-02 (i.e 03,0x) 74 | 75 | -- Default secondary host IPv4 addresses begin from 192.168.1.102 and upwards." 76 | 77 | # Set PVE Build Type 78 | OPTIONS_VALUES_INPUT=( "TYPE01" "TYPE02" ) 79 | OPTIONS_LABELS_INPUT=( "Primary - Primary PVE host" \ 80 | "Secondary - Secondary PVE host (cluster node)" ) 81 | makeselect_input2 82 | singleselect SELECTED "$OPTIONS_STRING" 83 | if [ "$RESULTS" = 'TYPE01' ] 84 | then 85 | PVE_TYPE=1 86 | export PVE_TYPE=1 87 | elif [ "$RESULTS" = 'TYPE02' ] 88 | then 89 | PVE_TYPE=2 90 | export PVE_TYPE=2 91 | fi 92 | 93 | #---- Run Installer 94 | while true 95 | do 96 | section "Run a PVE Host Add-On task" 97 | 98 | msg_box "The User must select a task to perform. 'PVE Host Basic' is mandatory or required for all hosts. 'PVE Full Build' includes the full suite of Toolbox add-on options.\n\nSelect a Toolbox task or 'None. Exit this installer' to leave." 99 | echo 100 | warn_msg="Only primary PVE hosts can run this add-on task.\nRun another task or select 'None. Exit this installer'. Try again..." 101 | OPTIONS_VALUES_INPUT=( "TYPE01" "TYPE02" "TYPE03" "TYPE04" "TYPE05" "TYPE06" "TYPE07" "TYPE08" "TYPE09" "TYPE00" ) 102 | OPTIONS_LABELS_INPUT=( "PVE Basic - required by all hosts (mandatory)" \ 103 | "PVESM NFS Storage - add NFS PVE storage mounts" \ 104 | "PVESM SMB/CIFS Storage - add SMB/CIFS storage mounts" \ 105 | "PVE Hostname Updater - change a hosts hostname" \ 106 | "Fail2Ban Installer $(if [ "$(dpkg -s fail2ban >/dev/null 2>&1; echo $?)" = 0 ]; then echo "( installed & active )"; else echo "(not installed)"; fi)" \ 107 | "SMTP Email Server Setup $(if [ "$SMTP_STATUS" = 1 ]; then echo "( installed & active )"; else echo "(not installed)"; fi)" \ 108 | "PVE CT updater - mass update all CT OS" \ 109 | "PVE Host Grub boot delay - set the grub boot delay (recommended)" \ 110 | "PVE Intel Amd iGPU LXC support - allow LXC access to CPU iGPU (recommended)" \ 111 | "None. Exit this installer" ) 112 | makeselect_input2 113 | singleselect SELECTED "$OPTIONS_STRING" 114 | 115 | if [ "$RESULTS" = 'TYPE01' ]; then 116 | #---- Configure PVE host - basic 117 | source $REPO_TEMP/$GIT_REPO/src/pve_host_setup_basic.sh 118 | 119 | elif [ "$RESULTS" = 'TYPE02' ]; then 120 | #---- Create PVE Storage mounts (NFS) 121 | if [ "$PVE_TYPE" = 1 ] 122 | then 123 | source $REPO_TEMP/$GIT_REPO/src/pve_host_add_nfs_mounts.sh 124 | else 125 | warn "${warn_msg}" 126 | echo 127 | fi 128 | elif [ "$RESULTS" = 'TYPE03' ]; then 129 | #---- Create PVE Storage mounts (CIFS) 130 | if [ "$PVE_TYPE" = 1 ] 131 | then 132 | source $REPO_TEMP/$GIT_REPO/src/pve_host_add_cifs_mounts.sh 133 | else 134 | warn "${warn_msg}" 135 | echo 136 | fi 137 | elif [ "$RESULTS" = 'TYPE04' ]; then 138 | #---- PVE Hostname edit 139 | source $REPO_TEMP/$GIT_REPO/src/pve_host_setup_hostname.sh 140 | source $REPO_TEMP/$GIT_REPO/src/pve_host_setup_hostnameupdate.sh 141 | elif [ "$RESULTS" = 'TYPE05' ]; then 142 | #---- Install and Configure Fail2ban 143 | source $REPO_TEMP/$GIT_REPO/src/pve_host_setup_fail2ban.sh 144 | elif [ "$RESULTS" = 'TYPE06' ]; then 145 | #---- Configure Email Alerts 146 | source $REPO_TEMP/$GIT_REPO/src/pve_host_setup_postfix_server.sh 147 | elif [ "$RESULTS" = 'TYPE07' ]; then 148 | #---- PVE CT Updater 149 | if [ "$PVE_TYPE" = 1 ] 150 | then 151 | source $REPO_TEMP/$GIT_REPO/src/pvetool_ct_updater.sh 152 | else 153 | warn "${warn_msg}" 154 | echo 155 | fi 156 | elif [ "$RESULTS" = 'TYPE08' ]; then 157 | #---- Configure PVE Host boot delay 158 | source $REPO_TEMP/$GIT_REPO/src/pve_host_setup_boot_delay.sh 159 | elif [ "$RESULTS" = 'TYPE09' ]; then 160 | #---- Configure Intel iGPU support 161 | source $REPO_TEMP/$GIT_REPO/src/pve_host_setup_lxc_igpu_support.sh 162 | elif [ "$RESULTS" = 'TYPE00' ]; then 163 | # Exit installation 164 | msg "You have chosen not to proceed. Aborting. Bye..." 165 | echo 166 | sleep 1 167 | break 168 | fi 169 | # Reset Section Head 170 | SECTION_HEAD='PVE Host Toolbox' 171 | done 172 | 173 | 174 | #---- Finish Line ------------------------------------------------------------------ 175 | 176 | # Cleanup 177 | installer_cleanup 178 | #----------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /src/pve_host_setup_lxc_igpu_support.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ---------------------------------------------------------------------------------- 3 | # Filename: pve_host_setup_lxc_igpu_support.sh 4 | # Description: Source script for setting up host Intel/Amd iGPU support (qsv, VA-API etc) 5 | # ---------------------------------------------------------------------------------- 6 | 7 | #---- Bash command to run script --------------------------------------------------- 8 | 9 | #bash -c "$(wget -qLO - https://raw.githubusercontent.com/ahuacate/pve-host/main/pve_host_toolbox.sh)" 10 | 11 | #---- Source ----------------------------------------------------------------------- 12 | #---- Dependencies ----------------------------------------------------------------- 13 | #---- Static Variables ------------------------------------------------------------- 14 | 15 | # Easy Script Section Header Body Text 16 | SECTION_HEAD='PVE Host Intel or Amd iGPU support' 17 | 18 | # Check for PVE Hostname mod 19 | if [ -z "${HOSTNAME_FIX+x}" ]; then 20 | PVE_HOSTNAME=$HOSTNAME 21 | fi 22 | 23 | # Grub file 24 | grub_file=/etc/default/grub 25 | 26 | #---- Other Variables -------------------------------------------------------------- 27 | #---- Other Files ------------------------------------------------------------------ 28 | #---- Body ------------------------------------------------------------------------- 29 | 30 | #---- Checking PVE Host Prerequisites 31 | 32 | # Check for grub file 33 | if [ ! -e "$grub_file" ]; then 34 | section "Checking grub support" 35 | warn "No grub file detected. Exiting script..." 36 | sleep 1 37 | return 0 38 | fi 39 | 40 | # Check for Intel AMD integrated graphics 41 | if ! lscpu | grep -q -E "Vendor ID:\s*(GenuineIntel|AuthenticAMD)"; then 42 | section "Checking CPU support" 43 | warn "Your CPU vendor is not supported.. Exiting script..." 44 | sleep 1 45 | return 0 46 | fi 47 | 48 | 49 | #---- Introduction 50 | section "Introduction" 51 | 52 | msg_box "#### PLEASE READ CAREFULLY - INTEL/AMD iGPU SUPPORT #### 53 | 54 | To enable your LXCs to utilize your CPUs processors integrated iGPU, such as Intel QuickSync or VA-API, resulting in significantly improved rendering speeds, you must modify the Proxmox host's Grub bootloader file /etc/default/grub. 55 | 56 | Before proceeding, take note of the following considerations: 57 | 58 | 1. Ensure that your hardware supports IOMMU (I/O Memory Management Unit) interrupt remapping, including the CPU and the mainboard. 59 | 2. Check if your Intel or AMD CPU includes a built-in GPU (iGPU). 60 | 2. Familiarize yourself with the functionality of this script by visiting the following resource: https://pve.proxmox.com/wiki/PCI(e)_Passthrough" 61 | echo 62 | while true 63 | do 64 | read -p "Proceed to setup iGPU support with '/etc/default/grub' file edits [y/n]?: " -n 1 -r YN 65 | echo 66 | case $YN in 67 | [Yy]*) 68 | msg "Proceeding..." 69 | echo 70 | break 71 | ;; 72 | [Nn]*) 73 | info "The User has chosen to not to proceed..." 74 | echo 75 | sleep 1 76 | return 0 77 | ;; 78 | *) 79 | warn "Error! Entry must be 'y' or 'n'. Try again..." 80 | echo 81 | ;; 82 | esac 83 | done 84 | 85 | 86 | #---- Intel CPU iGPU 87 | 88 | # Edits for Intel CPUs only 89 | if lscpu | grep -q "Vendor ID:\s*GenuineIntel"; then 90 | # Configuring Intel Low Power Encoders 91 | section "Enable Intel Low-Power Encoders" 92 | 93 | msg "If you have an Intel CPU with a low-power wattage model and QuickSync support, consider enabling low-power encoders. Low-power encoding is a feature available on certain Intel processors, optimizing QuickSync for ultra-efficient video encoding with minimal power consumption." 94 | OPTIONS_VALUES_INPUT=( "TYPE01" "TYPE02" ) 95 | OPTIONS_LABELS_INPUT=( "Disable" "Enable - setup for low-power encoding support" ) 96 | makeselect_input2 97 | singleselect SELECTED "$OPTIONS_STRING" 98 | if [ "$RESULTS" = TYPE01 ]; then 99 | enable_low_power='0' # Disable low power encoders 100 | elif [ "$RESULTS" = TYPE02 ]; then 101 | enable_low_power='1' # Enable low power encoders 102 | fi 103 | 104 | # Update '/etc/default/grub' 105 | eval "$(grep ^GRUB_CMDLINE_LINUX_DEFAULT $grub_file)" 106 | declare -i updated=0 107 | if [[ "${GRUB_CMDLINE_LINUX_DEFAULT}" != *intel_iommu=on* ]]; then 108 | echo "Adding 'intel_iommu=on'" 109 | GRUB_CMDLINE_LINUX_DEFAULT+=" intel_iommu=on" 110 | updated=1 111 | fi 112 | 113 | # if [[ "${GRUB_CMDLINE_LINUX_DEFAULT}" != *i915.enable_guc=2* ]] && [ "$enable_low_power" = 1 ]; then 114 | # echo "Adding 'i915.enable_guc=2'" 115 | # GRUB_CMDLINE_LINUX_DEFAULT+=" i915.enable_guc=2" 116 | # updated=1 117 | # fi 118 | 119 | if (( updated )); then 120 | cp $grub_file ${grub_file}.bk 121 | sed -i -e "s/^GRUB_CMDLINE_LINUX_DEFAULT=.*\$/GRUB_CMDLINE_LINUX_DEFAULT=\"${GRUB_CMDLINE_LINUX_DEFAULT}\"/" $grub_file 122 | update-grub 123 | echo "GRUB configuration updated setting: ${GRUB_CMDLINE_LINUX_DEFAULT}" 124 | echo 125 | fi 126 | 127 | # Enable GUC in Proxmox host 128 | declare -i updated_modprobe=0 129 | modprobe_entries=("options i915 enable_guc=2" "options i915 enable_fbc=1") # Lines to add to /etc/modules 130 | modprobe_file="/etc/modprobe.d/i915.conf" # Path to the /etc/modules file 131 | if [ ! -e "$modprobe_file" ]; then 132 | touch "$modprobe_file" # create mod file if missing 133 | fi 134 | # Check if the modules exist in the file 135 | for entry in "${modprobe_entries[@]}"; do 136 | if ! grep -q "^$entry$" "$modprobe_file"; then 137 | if [ "$enable_low_power" = 0 ] && [[ "$entry" =~ enable_guc ]]; then 138 | continue # Skip if $enable_low_power is disabled 139 | fi 140 | echo "Adding '$entry' to $modprobe_file" 141 | echo "$entry" >> $modprobe_file 142 | updated_modprobe=1 143 | fi 144 | done 145 | 146 | # Check for 'ehl_gux_70.1.1.bin' in /lib/firmware/i915 147 | if [ ! -e '/lib/firmware/i915/ehl_gux_70.1.1.bin' ]; then 148 | wget -q --show-progress -O /lib/firmware/i915/ehl_gux_70.1.1.bin https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/plain/i915/ehl_guc_70.1.1.bin 149 | fi 150 | fi 151 | 152 | 153 | #---- AMD CPU iGPU 154 | 155 | # Edits for AMD CPUs only 156 | if lscpu | grep -q "Vendor ID:\s*AuthenticAMD"; then 157 | # Update '/etc/default/grub' 158 | eval "$(grep ^GRUB_CMDLINE_LINUX_DEFAULT $grub_file)" 159 | declare -i updated=0 160 | if [[ "${GRUB_CMDLINE_LINUX_DEFAULT}" != *amd_iommu=on* ]]; then 161 | echo "Adding 'amd_iommu=on'" 162 | GRUB_CMDLINE_LINUX_DEFAULT+=" amd_iommu=on" 163 | updated=1 164 | fi 165 | 166 | if (( updated )); then 167 | cp $grub_file ${grub_file}.bk 168 | sed -i -e "s/^GRUB_CMDLINE_LINUX_DEFAULT=.*\$/GRUB_CMDLINE_LINUX_DEFAULT=\"${GRUB_CMDLINE_LINUX_DEFAULT}\"/" $grub_file 169 | update-grub 170 | echo "GRUB configuration updated setting: ${GRUB_CMDLINE_LINUX_DEFAULT}" 171 | echo 172 | fi 173 | fi 174 | 175 | #---- Update Kernel modules 176 | msg "Checking kernel modules..." 177 | declare -i updated_kernel=0 178 | modules_to_add=("vfio" "vfio_iommu_type1" "vfio_pci" "vfio_virqfd") # Lines to add to /etc/modules 179 | modules_file="/etc/modules" # Path to the /etc/modules file 180 | # Check if the modules exist in the file 181 | for module in "${modules_to_add[@]}"; do 182 | if ! grep -q "^$module$" "$modules_file"; then 183 | msg "Adding '$module' to $modules_file" 184 | echo "$module" | tee -a "$modules_file" 185 | updated_kernel=1 186 | fi 187 | done 188 | 189 | #---- Perform initramfs refresh 190 | if (( updated_kernel )) || (( updated_modprobe )); then 191 | msg "Refresh your initramfs (only latest kernel)..." 192 | update-initramfs -u -k "$(uname -r)" 193 | fi 194 | 195 | 196 | #---- Reboot 197 | section "Reboot Proxmox host" 198 | 199 | msg "For Grub edits to take effect you must reboot your Proxmox host." 200 | OPTIONS_VALUES_INPUT=( "TYPE01" "TYPE02" ) 201 | OPTIONS_LABELS_INPUT=( "Reboot now - Recommended (must be done)" "Skip - You must reboot at a later stage" ) 202 | makeselect_input2 203 | singleselect SELECTED "$OPTIONS_STRING" 204 | if [ "$RESULTS" = TYPE01 ]; then 205 | msg "Rebooting Proxmox host. Bye..." 206 | sleep 1 207 | reboot 208 | elif [ "$RESULTS" = TYPE02 ]; then 209 | msg "The Grub bootloader changes will take effect after the next reboot." 210 | fi 211 | #----------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /src/pve_host_setup_fail2ban.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ---------------------------------------------------------------------------------- 3 | # Filename: pve_host_setup_fail2ban.sh 4 | # Description: Source script for setting up Fail2Ban 5 | # ---------------------------------------------------------------------------------- 6 | 7 | #---- Bash command to run script --------------------------------------------------- 8 | #---- Source ----------------------------------------------------------------------- 9 | #---- Dependencies ----------------------------------------------------------------- 10 | #---- Static Variables ------------------------------------------------------------- 11 | 12 | # Easy Script Section Header Body Text 13 | SECTION_HEAD='PVE Host Fail2Ban' 14 | 15 | 16 | # Run SMTP check 17 | check_smtp_status 18 | 19 | # Check for PVE Hostname mod 20 | if [ -z "${HOSTNAME_FIX+x}" ] 21 | then 22 | PVE_HOSTNAME=$HOSTNAME 23 | fi 24 | 25 | #---- Other Variables -------------------------------------------------------------- 26 | #---- Other Files ------------------------------------------------------------------ 27 | #---- Body ------------------------------------------------------------------------- 28 | 29 | #---- Install and Configure Fail2Ban 30 | section "Introduction" 31 | 32 | msg_box "#### PLEASE READ CAREFULLY - FAIL2BAN SETUP ####\n 33 | Fail2Ban is an intrusion prevention software framework that protects computer servers from brute-force attacks. 34 | 35 | Most commonly this is used to block selected IP addresses that may belong to hosts that are trying to breach the systems security. It can ban any host IP address that makes too many login attempts or performs any other unwanted action within a time frame defined by the PVE administrator. 36 | 37 | Our default Fail2ban configuration sets the following rule sets: 38 | 39 | -- PVE WEBGUI HTTP(S) ACCESS 40 | Maximum HTTP retry 3 attempts. 41 | PVE HTTP(S) ban time is 1 hour. 42 | If your PVE Postfix SMTP server is configured then Fail2ban will send send email alerts. 43 | 44 | -- PVE EMAIL ALERTS 45 | Send email alerts of banned login attempts. (requires working PVE Postfix SMTP server)" 46 | 47 | echo 48 | while true 49 | do 50 | read -p "Install and/or configure Fail2ban [y/n]?: " -n 1 -r YN 51 | echo 52 | case $YN in 53 | [Yy]*) 54 | info "The User has chosen to proceed." 55 | echo 56 | break 57 | ;; 58 | [Nn]*) 59 | info "You have chosen to skip this step." 60 | echo 61 | return 62 | ;; 63 | *) 64 | warn "Error! Entry must be 'y' or 'n'. Try again..." 65 | echo 66 | ;; 67 | esac 68 | done 69 | 70 | #---- Checking PVE Host Prerequisites 71 | section "Checking Prerequisites" 72 | 73 | # Installing Fail2Ban 74 | if [[ $(dpkg -s fail2ban) ]] 75 | then 76 | msg "Installing fail2ban..." 77 | apt-get install -y fail2ban >/dev/null 78 | info "Fail2ban status: ${GREEN}installed${NC}" 79 | echo 80 | fi 81 | 82 | #---- Configuring Fail2ban 83 | section "Configuring Fail2ban" 84 | 85 | # Checking Postfix SMTP Status 86 | msg "Checking PVE host SMTP email server status for sending Fail2ban alerts..." 87 | EMAIL_RECIPIENT=$(pveum user list | awk -F " │ " '$1 ~ /root@pam/' | awk -F " │ " '{ print $3 }') 88 | if [ "$SMTP_STATUS" = 1 ] 89 | then 90 | while true 91 | do 92 | read -p "Enable Fail2ban email alerts [y/n]?: " -n 1 -r YN 93 | echo 94 | case $YN in 95 | [Yy]*) 96 | info "The User is set to receive Fail2ban alerts by email.\nAll alerts will be sent to: ${YELLOW}$EMAIL_RECIPIENT${NC}" 97 | F2B_EMAIL_ALERTS=0 98 | echo 99 | break 100 | ;; 101 | [Nn]*) 102 | info "You have chosen NOT to configure Fail2ban to send email alerts." 103 | F2B_EMAIL_ALERTS=1 104 | echo 105 | break 106 | ;; 107 | *) 108 | warn "Error! Entry must be 'y' or 'n'. Try again..." 109 | echo 110 | ;; 111 | esac 112 | done 113 | elif [ "$SMTP_STATUS" = 0 ] 114 | then 115 | msg "We cannot determine if the PVE hosts Postfix email server works." 116 | while true 117 | do 118 | read -p "Is the PVE host Postfix email server configured and working [y/n]?: " -n 1 -r YN 119 | echo 120 | case $YN in 121 | [Yy]*) 122 | while true 123 | do 124 | read -p "Enable Fail2ban email alerts [y/n]?: " -n 1 -r YN 125 | echo 126 | case $YN in 127 | [Yy]*) 128 | SMTP_STATUS=1 129 | info "The User set to receive Fail2ban alerts by email.\nAll alerts will be sent to: ${YELLOW}${EMAIL_RECIPIENT}${NC}" 130 | F2B_EMAIL_ALERTS=0 131 | echo 132 | break 2 133 | ;; 134 | [Nn]*) 135 | info "The User has chosen NOT to enable Fail2ban email alerts." 136 | F2B_EMAIL_ALERTS=1 137 | echo 138 | break 2 139 | ;; 140 | *) 141 | warn "Error! Entry must be 'y' or 'n'. Try again..." 142 | echo 143 | ;; 144 | esac 145 | done 146 | ;; 147 | [Nn]*) 148 | info "The User will not receive any Fail2ban email alerts." 149 | F2B_EMAIL_ALERTS=1 150 | echo 151 | break 152 | ;; 153 | *) 154 | warn "Error! Entry must be 'y' or 'n'. Try again..." 155 | echo 156 | ;; 157 | esac 158 | done 159 | fi 160 | 161 | # Configuring Fail2Ban 162 | # Fail2Ban Default Access rulesets 163 | if [ "$F2B_EMAIL_ALERTS" = 0 ] 164 | then 165 | msg "Configuring Fail2Ban default rulesets..." 166 | F2B_DEFAULT_IPWHITELIST="127.0.0.1/8" 167 | info "PVE hosts Fail2ban default ruleset is set:\n Email alerts: ${YELLOW}active${NC}\n Alerts sent to: ${YELLOW}$EMAIL_RECIPIENT${NC}\n IP whitelist: ${YELLOW}$F2B_DEFAULT_IPWHITELIST${NC}" 168 | echo -e "[DEFAULT]\ndestemail = ${EMAIL_RECIPIENT}\nsender = fail2ban@localhost\nsendername = Fail2ban\nmta = mail\naction = %(action_mwl)s\nignoreip = ${F2B_DEFAULT_IPWHITELIST}" > /etc/fail2ban/jail.local 169 | echo 170 | elif [ "$F2B_EMAIL_ALERTS" = 1 ] 171 | then 172 | msg "Configuring Fail2Ban default rulesets..." 173 | info "PVE hosts Fail2ban default ruleset is set:\n IP whitelist: ${YELLOW}127.0.0.1/8${NC}" 174 | echo -e "[DEFAULT]\nignoreip = 127.0.0.1/8" > /etc/fail2ban/jail.local 175 | echo 176 | fi 177 | 178 | # Fail2Ban PVE WebGui HTTP(s) Access rulesets 179 | msg "Configuring Fail2Ban PVE WebGui HTTP(s) access ruleset..." 180 | F2B_HTTP_MAX_RETRY='3' 181 | F2B_HTTP_BANTIME='1' # Hours (Units) 182 | read -p "Confirm your PVE hosts WebGui HTTP(s) port number: " -e -i 8006 F2B_HTTP_PVE_PORT 183 | info "PVE hosts Fail2ban WebGui HTTP(s) ruleset is set:\n WebGui port number: ${YELLOW}$F2B_HTTP_PVE_PORT${NC}\n Max retry number: ${YELLOW}$F2B_HTTP_MAX_RETRY${NC}\n Ban time (seconds): ${YELLOW}$F2B_HTTP_BANTIME${NC}" 184 | echo -e "[proxmox-web-gui]\nenabled = true\nport = https,http,${F2B_HTTP_PVE_PORT}\nfilter = proxmox\nlogpath = /var/log/daemon.log\nmaxretry = ${F2B_HTTP_MAX_RETRY}\nbantime = $(echo $(( ${F2B_HTTP_BANTIME} * 60 * 60 )))" > /etc/fail2ban/jail.d/proxmox-web-gui.local 185 | echo -e "[Definition]\nfailregex = pvedaemon\[.*authentication failure; rhost= user=.* msg=.*\nignoreregex =" > /etc/fail2ban/filter.d/proxmox.conf 186 | echo 187 | 188 | # Fail2Ban SSHd rulesets 189 | msg "Configuring Fail2Ban SSHD access rulesets..." 190 | F2B_SSHD_MAX_RETRY='10' 191 | F2B_SSHD_FINDTIME='60' # Seconds (units) 192 | F2B_SSHD_BANTIME='1' # Hours (Units) 193 | info "PVE hosts SSHD ruleset is set:\n Max retry number: ${YELLOW}$F2B_SSHD_MAX_RETRY${NC}\n Findtime (seconds): ${YELLOW}$F2B_SSHD_FINDTIME${NC}\n Ban time (seconds): ${YELLOW}$F2B_SSHD_BANTIME${NC}" 194 | echo -e "[sshd]\nenabled = true\nport = ssh\nfilter = sshd\nlogpath = /var/log/auth.log\nmaxretry = ${F2B_SSHD_MAX_RETRY}\nfindtime = ${F2B_SSHD_FINDTIME}\nbantime = $(echo $(( ${F2B_SSHD_BANTIME} * 60 * 60 )))" > /etc/fail2ban/jail.d/sshd.local 195 | echo 196 | 197 | # Fail2ban restart 198 | msg "Restarting Fail2ban..." 199 | service fail2ban restart 2>/dev/null 200 | if [ "$(systemctl is-active --quiet fail2ban; echo $?)" = 0 ] 201 | then 202 | info "Fail2ban status: ${GREEN}active${NC} (running)" 203 | echo 204 | elif [ "$(systemctl is-active --quiet fail2ban; echo $?)" = 3 ] 205 | then 206 | info "Fail2ban status: ${RED}inactive${NC} (dead - your intervention is required)" 207 | echo 208 | fi 209 | 210 | #---- Finish Line ------------------------------------------------------------------ 211 | 212 | section "Completion Status" 213 | msg "Success. Task complete." 214 | echo 215 | #----------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /src/pvetool_ct_updater.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ---------------------------------------------------------------------------------- 3 | # Filename: pvetool_ct_updater.sh 4 | # Description: Simple bash script to APT updating Linux LXC/CT CTIDs. 5 | # Stopped CTs will be started, updated and returned to stopped status. 6 | # Running CTs will be updated. 7 | # ---------------------------------------------------------------------------------- 8 | 9 | #---- Bash command to run script --------------------------------------------------- 10 | 11 | #bash -c "$(wget -qLO - https://raw.githubusercontent.com/ahuacate/common/main/pve/tool/pvetool_ct_updater.sh)" 12 | 13 | #---- Source ----------------------------------------------------------------------- 14 | #---- Dependencies ----------------------------------------------------------------- 15 | #---- Static Variables ------------------------------------------------------------- 16 | 17 | # Easy Script Section Header Body Text 18 | SECTION_HEAD='PVE CT Updater' 19 | 20 | # List of CTIDs 21 | ## 1=CTID:2=STATUS (running or stopped):3=NAME (CT name):4=SIZE (CT size used in megabytes) 22 | unset ctid_LIST 23 | while IFS=':' read CTID STATUS NAME 24 | do 25 | ctid_LIST+=( "$CTID:$STATUS:$NAME:$(pct df $CTID | awk '/^rootfs/ { s=substr($4,1,length($4)-1); u=substr($4,length($4)); if(u=="G") $4=sprintf("%.0f",(s*1024)); else if(u=="M") $4=sprintf("%.0f",s); print $4 }')" ) 26 | done < <( pct list | awk 'NR > 1 { OFS = ":"; print $1, $2, $3 }' ) 27 | 28 | # CURRENT_OS='ubuntu' 29 | # if [[ "$CURRENT_OS" == 'ubuntu' ]]; then 30 | # echo hello 31 | # fi 32 | 33 | # Update function 34 | function update_container() { 35 | local CTID="$1" 36 | 37 | msg "Updating CT '$CTID'..." 38 | # to chain commands within one exec we will need to wrap them in bash 39 | if [[ "$CURRENT_OS" == 'ubuntu' ]] 40 | then 41 | # Ubuntu OS 42 | pct exec $CTID -- bash -c "apt-get update -y" 43 | pct exec $CTID -- bash -c "apt-get upgrade -y" 44 | pct exec $CTID -- bash -c "apt-get autoremove -y" 45 | info "Ubuntu CT'$CTID' update status: ${GREEN}success${NC}" 46 | elif [[ "$CURRENT_OS" == 'fedora linux' ]] 47 | then 48 | # Fedora OS 49 | pct exec $CTID -- bash -c "dnf -y upgrade --refresh" 50 | info "Fedora CT '$CTID' update status: ${GREEN}success${NC}" 51 | elif [[ "$CURRENT_OS" == 'centos stream' ]] 52 | then 53 | # Centos OS 54 | pct exec $CTID -- bash -c "yum -y update" 55 | elif [[ "$CURRENT_OS" == 'alpine linux' ]] 56 | then 57 | # Alpine OS 58 | pct exec $CTID -- ash -c "apk update" 59 | pct exec $CTID -- ash -c "apk upgrade --available" 60 | pct exec $CTID -- ash -c "sync" 61 | info "Alpine CT '$CTID' update status: ${GREEN}success${NC}\n ( requires a reboot )" 62 | elif [[ ${CURRENT_OS} =~ (gentoo|unknown) ]] 63 | then 64 | # Unknown & Gentoo OS 65 | msg "User must manually update the CT. Skipping CTID '$CTID'..." 66 | fi 67 | } 68 | 69 | # CT start function 70 | function pct_start_waitloop() { 71 | local CTID="$1" 72 | 73 | if [ "$(pct status $CTID)" = 'status: stopped' ] 74 | then 75 | msg "Starting CT '$CTID'..." 76 | pct start $CTID 77 | msg "Waiting to hear from CT '$CTID'..." 78 | while ! [[ "$(pct status $CTID)" == 'status: running' ]]; do 79 | echo -n . 80 | done 81 | sleep 2 82 | msg "CT '$CTID' status: running" 83 | fi 84 | } 85 | 86 | # Check OS Version 87 | function findCurrentOSType() { 88 | local CTID="$1" 89 | # Determine OS type and shell (ash or bash) 90 | if [[ $(pct exec $CTID 2> /dev/null -- bash -c "echo hello") ]] 91 | then 92 | SHELL='bash' 93 | osType=$(pct exec $CTID -- ${SHELL} -c "uname") 94 | elif [[ $(pct exec $CTID 2> /dev/null -- ash -c "echo hello") ]] 95 | then 96 | SHELL='ash' 97 | osType=$(pct exec $CTID -- ${SHELL} -c "uname") 98 | fi 99 | case "$osType" in 100 | "Darwin") 101 | { 102 | CURRENT_OS='osx' 103 | } ;; 104 | "Linux") 105 | { 106 | # If available, use LSB to identify distribution 107 | if [ "$(pct exec $CTID -- ${SHELL} -c "[ -f /etc/lsb-release -o -f /etc/os-release -o -d /etc/lsb-release.d ] && echo '0' || echo '1'")" = 0 ] 108 | then 109 | DISTRO=$(pct exec $CTID -- ${SHELL} -c "awk -F'=' '/^NAME/{print \$2}' /etc/os-release") 110 | else 111 | DISTRO=$(pct exec $CTID -- ${SHELL} -c "ls -d /etc/[A-Za-z]*[_-][rv]e[lr]* | grep -v "lsb" | cut -d'/' -f3 | cut -d'-' -f1 | cut -d'_' -f1") 112 | fi 113 | CURRENT_OS=$(echo ${DISTRO,,} | tr -d '"') 114 | } ;; 115 | *) 116 | { 117 | CURRENT_OS='unknown' 118 | } ;; 119 | esac 120 | } 121 | 122 | 123 | #---- Other Variables -------------------------------------------------------------- 124 | #---- Other Files ------------------------------------------------------------------ 125 | #---- Body ------------------------------------------------------------------------- 126 | 127 | #---- Set Backup destination 128 | section "Set backup destination" 129 | 130 | # Create PVESM backup storage destination list 131 | pvesmbackup_LIST=( $(pvesm status --content backup | awk 'NR > 1 { $6=sprintf("%.0f",$6/1024); OFS = ":"; print $1, $2, $3, $6 }') ) 132 | 133 | # Set PVESM backup destination 134 | msg "Set VZDUMP backup storage destination..." 135 | if [ "$(printf '%s\n' "${pvesmbackup_LIST[@]}" | awk -F':' -v BACKUP_SIZE=$(printf '%s\n' "${ctid_LIST[@]}" | awk -F':' '{sum+=$4;} END{print sum;}') 'BEGIN{OFS=FS} {if ($3 == "active" && $4 > BACKUP_SIZE) print $0 }' | wc -l)" = 1 ] 136 | then 137 | # Set backup storage if only 1x option 138 | BACKUP_DEST=$(printf '%s\n' "${pvesmbackup_LIST[@]}" | awk -F':' -v BACKUP_SIZE=$(printf '%s\n' "${ctid_LIST[@]}" | awk -F':' '{sum+=$4;} END{print sum;}') 'BEGIN{OFS=FS} {if ($3 == "active" && $4 > BACKUP_SIZE) print $1 }') 139 | info "Backup storage destination: ${YELLOW}${BACKUP_DEST}${NC}\n ( only one option available )" 140 | echo 141 | elif [ "$(printf '%s\n' "${pvesmbackup_LIST[@]}" | awk -F':' -v BACKUP_SIZE=$(printf '%s\n' "${ctid_LIST[@]}" | awk -F':' '{sum+=$4;} END{print sum;}') 'BEGIN{OFS=FS} {if ($3 == "active" && $4 > BACKUP_SIZE) print $0 }' | wc -l)" = 0 ] 142 | then 143 | # Fail msg if 1x option has no free space 144 | FAIL_MSG="The Toolbox CT Updater failed. Before performing any CT upgrade a full backup of every CT is made (by default). The PVE host backup storage size is less than the required minimum of $(printf '%s\n' "${ctid_LIST[@]}" | awk -F':' '{sum+=$4;} END{print sum;}')M. Try again when the following constraints are satisfied:\n 145 | Required constraints 146 | -- More than $(printf '%s\n' "${ctid_LIST[@]}" | awk -F':' '{sum+=$4;} END{print sum;}')M of backup storage space is available.\n 147 | Try again..." 148 | warn "$FAIL_MSG" 149 | echo 150 | return 151 | elif [ "$(printf '%s\n' "${pvesmbackup_LIST[@]}" | awk -F':' -v BACKUP_SIZE=$(printf '%s\n' "${ctid_LIST[@]}" | awk -F':' '{sum+=$4;} END{print sum;}') 'BEGIN{OFS=FS} {if ($3 == "active" && $4 > BACKUP_SIZE) print $0 }' | wc -l)" -gt 1 ] 152 | then 153 | # Select a CT backup storage destination (multiple option) 154 | msg_box "#### PLEASE READ CAREFULLY - SET CT BACKUP DESTINATION ####\n\nBefore performing any CT upgrade a full CT backup is made (by default).\n\nThe User must select a backup location from the following ${#pvesmbackup_LIST[@]}x available PVESM storage destinations." 155 | echo 156 | mapfile -t OPTIONS_VALUES_INPUT <<< $(printf '%s\n' "${pvesmbackup_LIST[@]}" | awk -F':' -v BACKUP_SIZE=$(printf '%s\n' "${ctid_LIST[@]}" | awk -F':' '{sum+=$4;} END{print sum;}') 'BEGIN{OFS=FS} \ 157 | {if ($3 == "active" && ($2 == "nfs" || $2 == "cifs") && $4 > BACKUP_SIZE) print $1 } \ 158 | {if ($3 == "active" && $2 == "dir" && $4 > BACKUP_SIZE) print $1 }') 159 | mapfile -t OPTIONS_LABELS_INPUT <<< $(printf '%s\n' "${pvesmbackup_LIST[@]}" | awk -F':' -v BACKUP_SIZE=$(printf '%s\n' "${ctid_LIST[@]}" | awk -F':' '{sum+=$4;} END{print sum;}') 'BEGIN{OFS=FS} \ 160 | {if ($3 == "active" && ($2 == "nfs" || $2 == "cifs") && $4 > BACKUP_SIZE) print "Backup network storage - "$1" ( Recommended )" } \ 161 | {if ($3 == "active" && $2 == "dir" && $4 > BACKUP_SIZE) print "Backup storage folder - "$1 }') 162 | 163 | makeselect_input2 "$OPTIONS_VALUES_INPUT" "$OPTIONS_LABELS_INPUT" 164 | singleselect SELECTED "$OPTIONS_STRING" 165 | 166 | # Set backup storage 167 | BACKUP_DEST="${RESULTS[@]}" 168 | fi 169 | 170 | 171 | #---- Perform updates 172 | section "Performing CT Updates" 173 | 174 | while IFS=':' read CTID STATUS NAME SIZE 175 | do 176 | msg "Commencing to update PVE CT: ${YELLOW}$CTID${NC} (be patient, can take some time)" 177 | if [ "$STATUS" = 'stopped' ] 178 | then 179 | # CT start 180 | pct_start_waitloop $CTID 181 | # Find CT OS 182 | findCurrentOSType $CTID 183 | # Perform backup 184 | msg "Performing CT '$CTID' backup..." 185 | vzdump $CTID --storage $BACKUP_DEST --compress zstd --quiet 1 --mode snapshot 186 | # CT update 187 | update_container $CTID 188 | # Return CT to former state 189 | msg "Returning to former state..." 190 | pct shutdown $CTID 191 | elif [ "$STATUS" = 'running' ] 192 | then 193 | # Find CT OS 194 | findCurrentOSType $CTID 195 | # Perform backup 196 | msg "Performing CT '$CTID' backup..." 197 | vzdump $CTID --storage $BACKUP_DEST --compress zstd --quiet 1 --mode snapshot 198 | # CT update 199 | update_container $CTID 200 | fi 201 | echo 202 | done < <( printf '%s\n' "${ctid_LIST[@]}" ) 203 | 204 | #---- Finish Line ------------------------------------------------------------------ 205 | 206 | section "Completion Status." 207 | 208 | msg "Success. Task complete." 209 | echo 210 | #----------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /src/pve_host_setup_basic.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ---------------------------------------------------------------------------------- 3 | # Filename: pve_host_setup_basic.sh 4 | # Description: Basic mods for Proxmox (PVE) Host machines 5 | # ---------------------------------------------------------------------------------- 6 | 7 | #---- Bash command to run script --------------------------------------------------- 8 | #---- Source ----------------------------------------------------------------------- 9 | #---- Dependencies ----------------------------------------------------------------- 10 | #---- Static Variables ------------------------------------------------------------- 11 | 12 | # Easy Script Section Header Body Text 13 | SECTION_HEAD='PVE Host Basic Setup' 14 | 15 | #---- Other Variables -------------------------------------------------------------- 16 | #---- Other Files ------------------------------------------------------------------ 17 | #---- Body ------------------------------------------------------------------------- 18 | 19 | #---- Prerequisites 20 | 21 | # First update 22 | apt-get update -y > /dev/null 23 | 24 | # nbtscan SW 25 | if [[ ! $(dpkg -s nbtscan 2> /dev/null) ]] 26 | then 27 | msg "Installing nbtscan..." 28 | apt-get install -y nbtscan >/dev/null 29 | info "nbtscan status: ${GREEN}active${NC}" 30 | echo 31 | fi 32 | 33 | 34 | #---- Introduction 35 | section "Introduction" 36 | 37 | msg_box "#### PLEASE READ CAREFULLY - PVE HOST BASICS ####\n 38 | This setup script is for configuring 'new' PVE hosts only. Tasks to be performed include: 39 | 40 | PREREQUISITES BASICS 41 | -- Update Proxmox 42 | -- Check and set Proxmox subscription key (free or enterprise) 43 | -- Install nbtscan SW 44 | -- Adjust sysctl parameters 45 | -- Set /etc/vzdump.conf tmp dir to /tmp ( fixes nfs PVE backup errors ) 46 | -- Set PVE boot delay to 300 sec ( allows for NAS to start/online on power outage ) 47 | -- Perform PVE container (CT) mapping ( required for all our PVE VM or CT builds )" 48 | echo 49 | while true 50 | do 51 | read -p "Perform PVE host basic tuning ( Recommended ) [y/n]?: " -n 1 -r YN 52 | echo 53 | case $YN in 54 | [Yy]*) 55 | info "The User has chosen to proceed." 56 | echo 57 | break 58 | ;; 59 | [Nn]*) 60 | info "You have chosen to skip this step." 61 | echo 62 | return 63 | ;; 64 | *) 65 | warn "Error! Entry must be 'y' or 'n'. Try again..." 66 | echo 67 | ;; 68 | esac 69 | done 70 | 71 | #---- Performing PVE Host Prerequisites 72 | section "PVE Host Basics" 73 | 74 | # Verify subscription key 75 | msg "Verifying PVE host subscription status..." 76 | if [ $(pvesubscription get | grep "status:.*" | awk '{ print $2 }' | tr '[:upper:]' '[:lower:]') != 'active' ] && [[ ! $(cat /etc/apt/sources.list | grep '^deb.*pve-no-subscription$') ]]; then 77 | msg_box "#### PLEASE READ CAREFULLY - PROXMOX SUBSCRIPTION KEYS ####\n\nNo paid Proxmox 'pve-enterprise' or 'pve-no-subscription' key is installed. A paid PVE subscription key is needed to access the Proxmox pve-enterprise level update repository. This costs money. But its not required for personal or home use.\n\nThe Proxmox 'pve-no-subscription' key is free for personal or home use only (Recommended)." 78 | 79 | OPTIONS_VALUES_INPUT=( "TYPE01" "TYPE02" "TYPE00") 80 | OPTIONS_LABELS_INPUT=( "Free Version - Proxmox with no subscription key (Recommended)" "Paid Enterprise version - You have a valid license key" "None. Return to the Toolbox" ) 81 | makeselect_input2 82 | singleselect SELECTED "$OPTIONS_STRING" 83 | 84 | if [ "$RESULTS" = 'TYPE01' ] 85 | then 86 | # pve-no-subscription 87 | msg "Setting PVE host to PVE to 'pve-no-subscription'..." 88 | if [ -f "/etc/apt/sources.list.d/pve-enterprise.list" ] 89 | then 90 | rm /etc/apt/sources.list.d/pve-enterprise.list > /dev/null 91 | fi 92 | # Remove any old 'pve-no-subscription' 93 | sed -i '/^.*pve-no-subscription$/d' /etc/apt/sources.list 94 | # Add debian 'pve-no-subscription' deb 95 | PVE_CODENAME=$(cat /etc/os-release | awk -F'=' '/VERSION_CODENAME/ { print $2 }') 96 | echo "deb http://download.proxmox.com/debian/pve $PVE_CODENAME pve-no-subscription" >> /etc/apt/sources.list 97 | # Update new list 98 | apt-get update -yqq 99 | info "PVE subscription status is: ${YELLOW}pve-no-subscription${NC}" 100 | elif [ "$RESULTS" = 'TYPE02' ] 101 | then 102 | # pve-enterprise 103 | msg "Use the Proxmox enterprise key guide to install and activate your key. Once complete re-run this installer. This script will exit in 3 seconds. Bye..." 104 | sleep 3 105 | return 106 | elif [ "$RESULTS" = 'TYPE00' ] 107 | then 108 | return 109 | fi 110 | elif [ "$(pvesubscription get | grep "status:.*" | awk '{ print $2 }' | tr '[:upper:]' '[:lower:]')" = 'active' ] 111 | then 112 | info "PVE subscription status: ${YELLOW}pve-enterprise edition${NC}" 113 | elif [[ $(cat /etc/apt/sources.list | grep '^deb.*pve-no-subscription$') ]] 114 | then 115 | info "PVE subscription status: ${YELLOW}pve-no-subscription${NC}" 116 | else 117 | # Fail msg 118 | FAIL_MSG="Cannot determine the PVE hosts subscription key status:\n 119 | Possible causes 120 | -- PVE subscription key has have expired (enterprise edition/paid version). 121 | -- PVE host cannot connect to the Proxmox key validation server (enterprise edition/paid version). 122 | Resolution 123 | -- Reinstall subscription key. 124 | -- Perform CLI 'apt-get update' and 'apt-get upgrade' and check for errors. 125 | -- Try restarting the PVE host. 126 | -- Use the PVE WebGUI to set the update repository setting. 127 | This script will exit in 3 seconds. Complete the above tasks and try again..." 128 | warn "$FAIL_MSG" 129 | sleep 3 130 | return 131 | fi 132 | echo 133 | 134 | 135 | # Update PVE OS 136 | msg "Performing PVE update..." 137 | apt-get -y update > /dev/null 2>&1 138 | msg "Performing PVE upgrade..." 139 | apt-get -yqq upgrade > /dev/null 2>&1 140 | msg "Performing PVE full upgrade (Linux Kernel if required)..." 141 | apt-get -y full-upgrade > /dev/null 2>&1 142 | msg "Performing PVE clean..." 143 | apt-get -y clean > /dev/null 2>&1 144 | msg "Performing PVE autoremove..." 145 | apt-get -y autoremove > /dev/null 2>&1 146 | 147 | # Update turnkey appliance list 148 | msg "Performing turnkey appliance list updates..." 149 | pveam update >/dev/null 150 | 151 | # PVE sysctl tunes 152 | msg "Adjusting sysctl parameters..." 153 | # Increase the inotify limits 154 | # Max Queued Ecents 155 | if [[ $(cat /etc/sysctl.conf | grep "fs.inotify.max_queued_events =.*") ]]; 156 | then 157 | sed -i -r '/^#?fs.inotify.max_queued_events =.*/c\fs.inotify.max_queued_events = 16384' /etc/sysctl.conf 158 | else 159 | echo "fs.inotify.max_queued_events = 16384" >> /etc/sysctl.conf 160 | fi 161 | # Max User Instances 162 | if [[ $(cat /etc/sysctl.conf | grep "fs.inotify.max_user_instances =.*") ]] 163 | then 164 | sed -i -r '/^#?fs.inotify.max_user_instances =.*/c\fs.inotify.max_user_instances = 512' /etc/sysctl.conf 165 | else 166 | echo "fs.inotify.max_user_instances = 512" >> /etc/sysctl.conf 167 | fi 168 | # Max User Watches 169 | if [[ $(cat /etc/sysctl.conf | grep "fs.inotify.max_user_watches =.*") ]] 170 | then 171 | sed -i -r '/^#?fs.inotify.max_user_watches =.*/c\fs.inotify.max_user_watches = 8192' /etc/sysctl.conf 172 | else 173 | echo "fs.inotify.max_user_watches = 8192" >> /etc/sysctl.conf 174 | fi 175 | 176 | # Set /etc/vzdump.conf tmp dir 177 | msg "Setting vzdump temporary dir variable..." 178 | sed -i -r '/^#?tmpdir:.*/c\tmpdir: \/tmp' /etc/vzdump.conf 179 | echo 180 | 181 | # Edit /etc/default/grub boot delay 182 | if [ -e /etc/default/grub ]; then 183 | sed -i 's/GRUB_TIMEOUT=.*/GRUB_TIMEOUT=300/' /etc/default/grub 184 | update-grub 185 | fi 186 | 187 | 188 | #---- Additional folders 189 | 190 | # Create snippets folder 191 | mkdir -p /var/lib/vz/snippets 192 | 193 | 194 | #---- PVE Container Mapping 195 | if [[ ! $(grep -qxF 'root:65604:100' /etc/subgid) ]] && [[ ! $(grep -qxF 'root:100:1' /etc/subgid) ]] && [[ ! $(grep -qxF 'root:1605:1' /etc/subuid) ]] && [[ ! $(grep -qxF 'root:1606:1' /etc/subuid) ]] && [[ ! $(grep -qxF 'root:1607:1' /etc/subuid) ]] 196 | then 197 | section "PVE Container UID & GID Mapping" 198 | 199 | msg_box "#### PLEASE READ CAREFULLY - UID & GID HOST MAPPING #### 200 | 201 | Unprivileged LXC containers have a issue with UIDs (User ID) and GIDs (Group ID) permissions and bind mounted shared data. With PVE VM/CTs the UIDs and GIDs are mapped to a different number range than that used on the host machine, where root (uid 0) becomes uid 100000, 1 will be 100001 and so on. Our default Users and Groups used on our NAS, PVE VMs and CTs are: 202 | 203 | -- GROUP: medialab (gid 65605) > USER: media (uid 1605) 204 | APPS: JellyFin, NZBGet, Deluge, Sonarr, Radarr, LazyLibrarian, Flexget etc 205 | 206 | -- GROUP: homelab (gid 65606) > USER: home (uid 1606) 207 | APPS: Syncthing, NextCloud, UniFi, Home Assistant, CCTV 208 | 209 | -- GROUP: privatelab (gid 65607) > USER: private (uid 1607) 210 | APPS: All things private. 211 | 212 | Our high GID number (Group ID) is to cater for the Synology GID creation scheme. To maintain user permissions and rights to a NAS file system the fix is to create UID and GID mapping on all PVE hosts. We need to define two ranges: 213 | 214 | 1. One where the system IDs (i.e root uid 0) of the container can be mapped to an arbitrary range on the host for security reasons. 215 | 216 | 2. And where NAS and notably Synology UID/GIDs above 65536 inside a container can be mapped to the same UID/GIDs on the PVE host. 217 | 218 | The following lines are added: 219 | 220 | -- EDITS TO /etc/subuid 221 | root:65604:100 root:1605:1 root:1606:1 root:1607:1 222 | -- EDITS TO /etc/subgid 223 | root:65604:100 root:100:1 224 | 225 | This modification is mandatory when using our PVE VM or CT builds." 226 | echo 227 | # UID and GID maps 228 | msg "Performing UID & GID host mapping..." 229 | grep -qxF 'root:65604:100' /etc/subuid || echo 'root:65604:100' >> /etc/subuid 230 | grep -qxF 'root:65604:100' /etc/subgid || echo 'root:65604:100' >> /etc/subgid 231 | info "Group GID mapping status: ${YELLOW}set${NC}" 232 | grep -qxF 'root:100:1' /etc/subgid || echo 'root:100:1' >> /etc/subgid 233 | info "User root uid mapping status: ${YELLOW}set${NC}" 234 | grep -qxF 'root:1605:1' /etc/subuid || echo 'root:1605:1' >> /etc/subuid 235 | info "User media uid mapping status: ${YELLOW}set${NC}" 236 | grep -qxF 'root:1606:1' /etc/subuid || echo 'root:1606:1' >> /etc/subuid 237 | info "User home uid mapping status: ${YELLOW}set${NC}" 238 | grep -qxF 'root:1607:1' /etc/subuid || echo 'root:1607:1' >> /etc/subuid 239 | info "User private uid mapping status: ${YELLOW}set${NC}" 240 | echo 241 | fi 242 | 243 | 244 | #---- Finish Line ------------------------------------------------------------------ 245 | 246 | section "Completion Status" 247 | msg "Success. Task complete." 248 | echo 249 | #----------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /src/pve_host_setup_sshkey.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ---------------------------------------------------------------------------------- 3 | # Filename: pve_host_setup_sshkey.sh 4 | # Description: Source script for setting up PVE host SSH Keys 5 | # ---------------------------------------------------------------------------------- 6 | 7 | #---- Bash command to run script --------------------------------------------------- 8 | 9 | #bash -c "$(wget -qLO - https://raw.githubusercontent.com/ahuacate/pve-host/main/scripts/pve_host_setup_sshkey.sh)" 10 | 11 | #---- Source ----------------------------------------------------------------------- 12 | #---- Dependencies ----------------------------------------------------------------- 13 | #---- Static Variables ------------------------------------------------------------- 14 | 15 | # Easy Script Section Header Body Text 16 | SECTION_HEAD='PVE Host SSH Keys' 17 | 18 | # Check PVE SMTP status 19 | check_smtp_status 20 | 21 | # Check for PVE Hostname mod 22 | if [ -z "${HOSTNAME_FIX+x}" ] 23 | then 24 | PVE_HOSTNAME=$HOSTNAME 25 | fi 26 | 27 | #---- Other Variables -------------------------------------------------------------- 28 | #---- Other Files ------------------------------------------------------------------ 29 | #---- Body ------------------------------------------------------------------------- 30 | 31 | #---- Introduction 32 | section "Introduction" 33 | 34 | msg_box "#### PLEASE READ CAREFULLY - CONFIGURING SSH AUTHORIZED KEYS #### 35 | 36 | PVE System Administrators should use SSH keys to access PVE root accounts over SSH. PVE requires all SSH keys to be in the OpenSSH format. Your PVE host SSH key choices are: 37 | 38 | 1. Append or add an existing SSH Public Key to PVE hosts authorized keys file. 39 | 40 | 2. Generate a new set of SSH key pairs. If the User chooses to append a existing SSH Public Key to the PVE host you will be prompted to paste the SSH Public Key into this terminal console. Use your mouse right-click to paste." 41 | echo 42 | while true 43 | do 44 | read -p "Configure this PVE host for SSH key access [y/n]?: " -n 1 -r YN 45 | echo 46 | case $YN in 47 | [Yy]*) 48 | msg "Setting up SSH Authorized Keys..." 49 | echo 50 | break 51 | ;; 52 | [Nn]*) 53 | info "The User has chosen to skip this step." 54 | exit 0 55 | break 56 | ;; 57 | *) 58 | warn "Error! Entry must be 'y' or 'n'. Try again..." 59 | echo 60 | ;; 61 | esac 62 | done 63 | 64 | 65 | #---- Checking PVE Host Prerequisites 66 | section "Checking Prerequisites" 67 | 68 | # nohup for PVE (part of package coreutils) 69 | if [[ ! $(dpkg -s coreutils) ]] 70 | then 71 | msg "Installing coreutils (nohup)..." 72 | apt-get install -y coreutils >/dev/null 73 | info "coreutils (nohup) status: ${GREEN}installed${NC}" 74 | echo 75 | fi 76 | 77 | # Install Puttytools 78 | if [[ ! $(dpkg -s putty-tools) ]] 79 | then 80 | msg "Installing Putty Tools..." 81 | apt-get install -y putty-tools >/dev/null 82 | info "Putty-Tools status: ${GREEN}installed${NC}" 83 | echo 84 | fi 85 | 86 | #---- Configuring SSH keys 87 | section "Configuring SSH Authorized Keys." 88 | 89 | msg "Select which method the User wants to add PVE SSH keys - add existing or generate new SSH key pairs..." 90 | OPTIONS_VALUES_INPUT=( "TYPE01" "TYPE02" ) 91 | OPTIONS_LABELS_INPUT=( "Existing SSH Keys - Append or add existing SSH Public Key to the host" "Create New SSH Keys - Generate a new set of SSH key pairs" ) 92 | makeselect_input2 93 | singleselect SELECTED "$OPTIONS_STRING" 94 | if [ "$RESULTS" = TYPE01 ] 95 | then 96 | SSH_TYPE=TYPE01 97 | elif [ "$RESULTS" = TYPE02 ] 98 | then 99 | SSH_TYPE=TYPE02 100 | fi 101 | 102 | # Copy and Paste your existing key into the terminal window 103 | if [ "$SSH_TYPE" = 'TYPE01' ] 104 | then 105 | section "Append or Add a existing SSH Public Key." 106 | msg "The User has chosen add a existing SSH Public Key to the PVE host. This method requires the User to strictly follow the next sequence of steps. First the User must copy the contents their ${UNDERLINE}SSH Public Key${NC} file to be added into the Users computer clipboard. 107 | 108 | -- COPY A SSH PUBLIC KEY FILE 109 | 1. Open the SSH Public Key file in a text editor ( such as Notepad++ ). 110 | 2. Highlight the key contents ( Ctrl + A ). 111 | 3. Copy the highlighted contents to the Users computer clipboard ( Ctrl + C ). 112 | -- PASTE THE SSH PUBLIC KEY FILE 113 | 1. Mouse Right-Click when you are prompted ( > ).\n" 114 | while true 115 | do 116 | echo 117 | read -r -p "Paste the SSH Public Key at the prompt then press ENTER: `echo $'\n> '`" INPUTLINE_PUBLIC_KEY 118 | if [ "$(grep -q "$(echo $INPUTLINE_PUBLIC_KEY)" /root/.ssh/authorized_keys; echo "$?")" = "0" ]; then 119 | warn "A matching SSH Public Key already exists on ${PVE_HOSTNAME,,}.\nNot proceeding." 120 | while true 121 | do 122 | read -p "Try another SSH Public Key [y/n]?: " -n 1 -r YN 123 | echo 124 | case $YN in 125 | [Yy]*) 126 | msg "Try again..." 127 | echo 128 | break 129 | ;; 130 | [Nn]*) 131 | info "User has chosen to skip this step. Exiting script." 132 | echo 133 | exit 0 134 | ;; 135 | *) 136 | warn "Error! Entry must be 'y' or 'n'. Try again..." 137 | echo 138 | ;; 139 | esac 140 | done 141 | elif [ "$(grep -q "$(echo "$INPUTLINE_PUBLIC_KEY")" /root/.ssh/authorized_keys; echo $?)" = 1 ] 142 | then 143 | echo "$INPUTLINE_PUBLIC_KEY" >> /root/.ssh/authorized_keys 144 | service sshd restart >/dev/null 145 | echo 146 | msg "Adding SSH Public Key to PVE host..." 147 | info "Success. The SSH Public Key has been added to PVE host ${PVE_HOSTNAME,,}\nauthorized_keys file." 148 | msg "========== SSH KEYS FOR PVE HOST : ${PVE_HOSTNAME^^} ==========\n\nFor root access to PVE host ${PVE_HOSTNAME,,} use the SSH Private key pair.\n\nLogin credentials are:\n Username: ${YELLOW}root${NC}\n Password: Only the System Administrator knows (SSH Private Key only).\n SSH Private Key: The must already have it.\n PVE Server LAN IP Address: ${YELLOW}$(hostname -I)${NC}" 149 | echo 150 | break 151 | fi 152 | done 153 | fi 154 | 155 | # Generate a new set of SSH RSA Key pairs 156 | if [ "$SSH_TYPE" = 'TYPE02' ] 157 | then 158 | section "Generate SSH Key pair files." 159 | echo 160 | if [[ $(df -h | awk 'NR>1 { print $1, "mounted on", $NF }' | grep "/mnt/pve/.*backup") ]] 161 | then 162 | msg "-- BACKUP LOCATION OF SSH PUBLIC KEY FILES 163 | NAS file location: ${WHITE}"$(df -h | awk 'NR>1 { print $1, $NF }' | grep "/mnt/pve/.*backup" | awk '{ print $1}')/${PVE_HOSTNAME,,}"_ssh_keys.tar.gz${NC} 164 | PVE file location: ${WHITE}$(df -h | awk 'NR>1 { print $1, $NF }' | grep "/mnt/pve/.*backup" | awk '{ print $NF}')/"${PVE_HOSTNAME,,}"_ssh_keys.tar.gz${NC}" 165 | echo 166 | # Backup Location 167 | SSH_BACKUP_LOCATION=$(df -h | awk 'NR>1 { print $1, $NF }' | grep "/mnt/pve/.*backup" | awk '{ print $NF}')/pve/ssh_keys 168 | SSH_BACKUP_FILENAME="${PVE_HOSTNAME,,}"_ssh_keys.tar.gz 169 | elif [[ ! $(df -h | awk 'NR>1 { print $1, "mounted on", $NF }' | grep "/mnt/pve/.*backup") ]] 170 | then 171 | msg "-- BACKUP LOCATION OF SSH PUBLIC KEY FILES 172 | Cannot locate a NAS NFS/CIFS backup folder mount point on PVE host '${HOSTNAME}'. Using PVE host '${HOSTNAME}' /tmp folder instead. The User should immediately move the backup '${PVE_HOSTNAME,,}_ssh_keys.tar.gz' to a secure storage location off the PVE host. 173 | Temporary PVE File Location: ${WHITE}/tmp/"${PVE_HOSTNAME,,}"_ssh_keys.tar.gz${NC}" 174 | echo 175 | # Backup Location 176 | SSH_BACKUP_LOCATION=/tmp 177 | SSH_BACKUP_FILENAME="${PVE_HOSTNAME,,}_ssh_keys.tar.gz" 178 | fi 179 | echo 180 | 181 | # Check SMTP server status 182 | msg "Checking PVE host SMTP email server status..." 183 | EMAIL_RECIPIENT=$(pveum user list | awk -F " │ " '$1 ~ /root@pam/' | awk -F " │ " '{ print $3 }') 184 | if [ "$SMTP_STATUS" = 0 ] 185 | then 186 | info "SMTP email status: ${YELLOW}enabled${NC}.\nThe Users SSH key pairs will be sent to: ${YELLOW}$EMAIL_RECIPIENT${NC}" 187 | echo 188 | elif [ "$SMTP_STATUS" = 1 ] 189 | then 190 | SMTP_STATUS=1 191 | info "The PVE host SMTP is not configured or working.\nNo SSH key pairs will be sent by email." 192 | echo 193 | fi 194 | 195 | # uuencode for Postfix (part of package sharutils) 196 | if [ "$SMTP_STATUS" = 0 ] 197 | then 198 | msg "Checking SMTP Postfix email server prerequisites..." 199 | if [[ ! $(dpkg -s sharutils) ]] 200 | then 201 | msg "Installing sharutils (uuencode)..." 202 | apt-get install -y sharutils >/dev/null 203 | info "sharutils (uuencode) status: ${GREEN}installed.${NC}" 204 | echo 205 | fi 206 | fi 207 | 208 | # Generating SSH Key Pair 209 | msg "Generating ed25519 SSH key pair..." 210 | ssh-keygen -o -q -t ed25519 -a 100 -f id_${PVE_HOSTNAME,,}_ed25519 -N "" 211 | # Create ppk key for Putty or Filezilla or ProFTPd 212 | msg "Creating a private PPK key (for Putty)..." 213 | puttygen id_${PVE_HOSTNAME,,}_ed25519 -o id_${PVE_HOSTNAME,,}_ed25519.ppk 214 | msg "Adding SSH Public Key to PVE host..." 215 | cat id_${PVE_HOSTNAME,,}_ed25519.pub >> /root/.ssh/authorized_keys 216 | msg "Creating backup ${WHITE}$SSH_BACKUP_FILENAME${NC} file of SSH key pairs{..." 217 | tar czf $SSH_BACKUP_FILENAME id_${PVE_HOSTNAME,,}_ed25519 id_${PVE_HOSTNAME,,}_ed25519.pub id_${PVE_HOSTNAME,,}_ed25519.ppk 218 | mkdir -p $SSH_BACKUP_LOCATION >/dev/null 219 | cp $SSH_BACKUP_FILENAME $SSH_BACKUP_LOCATION 220 | 221 | # Email SSH key pairs 222 | if [ "$SMTP_STATUS" = 0 ] 223 | then 224 | msg "Emailing SSH key pairs..." 225 | echo -e "\n========== SSH KEYS FOR PVE HOST : ${PVE_HOSTNAME^^} ==========\n\nFor root access to PVE host ${PVE_HOSTNAME,,} use the attached SSH Private Key file named id_${PVE_HOSTNAME,,}_ed25519.\n\nYour login credentials details are:\n Username: root\n Password: Not Required (SSH Private Key only).\n SSH Private Key: id_${PVE_HOSTNAME,,}_ed25519\n Putty SSH Private Key: id_${PVE_HOSTNAME,,}_ed25519.ppk\n PVE Server LAN IP Address: $(hostname -I)\n\nA backup linux tar.gz file containing your SSH Key pairs is also attached.\n Backup filename of SSH Key Pairs: $SSH_BACKUP_FILENAME\n" | (cat - && uuencode id_${PVE_HOSTNAME,,}_ed25519 id_${PVE_HOSTNAME,,}_ed25519 ; uuencode id_${PVE_HOSTNAME,,}_ed25519.pub id_${PVE_HOSTNAME,,}_ed25519.pub ; uuencode ${SSH_BACKUP_FILENAME} $SSH_BACKUP_FILENAME) | mail -s "SHH key pairs for PVE host $(echo ${SSH_BACKUP_FILENAME} | awk -F'_' '{ print $1}')." -- $EMAIL_RECIPIENT 226 | info "SSH key pairs to emailed to: ${YELLOW}$EMAIL_RECIPIENT${NC}" 227 | echo 228 | fi 229 | 230 | # Closing Message 231 | if [ "$SMTP_STATUS" = 0 ] 232 | then 233 | info "Success. Your new SSH Public Key has been added to PVE host ${PVE_HOSTNAME,,}\nauthorized_keys file.\n\n========== SSH KEYS FOR PVE HOST : ${PVE_HOSTNAME^^} ==========\n\nFor root access to PVE host ${PVE_HOSTNAME,,} use SSH Private Key\nfile named id_${PVE_HOSTNAME,,}_ed25519.\n\nYour login credentials details are:\n Username: ${YELLOW}root${NC}\n Password: Not Required (SSH Private Key only).\n SSH Private Key: ${YELLOW}id_${PVE_HOSTNAME,,}_ed25519${NC}\n Putty SSH Private Key: ${YELLOW}id_${PVE_HOSTNAME,,}_ed25519.ppk${NC}\n PVE Server LAN IP Address: ${YELLOW}$(hostname -I)${NC}\n\nA backup linux tar.gz file containing your SSH Key {pairs has also been} created.\n Backup filename of SSH Key Pairs: ${YELLOW}$SSH_BACKUP_FILENAME${NC}\n Backup of SSH Key Pairs emailed to: ${YELLOW}$EMAIL_RECIPIENT${NC}\n Backup location for SSH Key Pairs: ${YELLOW}${SSH_BACKUP_LOCATION}/$SSH_BACKUP_FILENAME${NC}" 234 | echo 235 | elif [ "$SMTP_STATUS" = 1 ] 236 | then 237 | info "Success. Your new SSH Public Key has been added to PVE host ${PVE_HOSTNAME,,}\nauthorized_keys file.\n\n========== SSH KEYS FOR PVE HOST : ${PVE_HOSTNAME^^} ==========\n\nFor root access to PVE host ${PVE_HOSTNAME,,} use SSH Private Key\nfile named id_${PVE_HOSTNAME,,}_ed25519.\n\nYour login credentials details are:\n Username: ${YELLOW}root${NC}\n Password: Not Required (SSH Private Key only).\n SSH Private Key: ${YELLOW}id_${PVE_HOSTNAME,,}_ed25519${NC}\n Putty SSH Private Key: ${YELLOW}id_${PVE_HOSTNAME,,}_ed25519.ppk${NC}\n PVE Server LAN IP Address: ${YELLOW}$(hostname -I)${NC}\n\nA backup linux tar.gz file containing your SSH Key pairs has also been created.\n Backup filename of SSH Key Pairs: ${YELLOW}$SSH_BACKUP_FILENAME${NC}\n Backup location for SSH Key Pairs: ${YELLOW}${SSH_BACKUP_LOCATION}/$SSH_BACKUP_FILENAME${NC}" 238 | echo 239 | fi 240 | fi 241 | 242 | 243 | #---- Configuring SSH Security 244 | section "Proxmox SSHD security modifications" 245 | 246 | msg "Minimizing vulnerabilities in the Secure Shell (SSH) protocol is key to ensuring the security of the PVE OS environment. The System Administrator can select from two preset measures to make PVE host '${HOSTNAME^}' more secure." 247 | echo 248 | 249 | # Select SSHD Security modifications 250 | OPTIONS_VALUES_INPUT=( "TYPE01" "TYPE02" ) 251 | OPTIONS_LABELS_INPUT=( "SSH Keys Only - Authentication by SSH key-pairs only" "SSH Keys & Passwords - Authentication by passwords & SSH key-pairs (Recommended)" ) 252 | makeselect_input2 253 | singleselect SELECTED "$OPTIONS_STRING" 254 | if [ "$RESULTS" = TYPE01 ] 255 | then 256 | SSH_SEC=TYPE01 257 | elif [ "$RESULTS" = TYPE02 ] 258 | then 259 | SSH_SEC=TYPE02 260 | fi 261 | 262 | if [ "$SSH_SEC" = TYPE01 ] 263 | then 264 | # SSH key only, permitted root login & prohibit password authentication 265 | sed -i -r '/^#?PermitRootLogin.*/c\PermitRootLogin prohibit-password' /etc/ssh/sshd_config 266 | sed -i -r '/^#?PasswordAuthentication.*/c\PasswordAuthentication no' /etc/ssh/sshd_config 267 | sed -i -r '/^#?PubkeyAuthentication.*/c\PubkeyAuthentication yes' /etc/ssh/sshd_config 268 | sed -i -r '/^#?PermitEmptyPasswords.*/c\PermitEmptyPasswords no' /etc/ssh/sshd_config 269 | info "SSH security modifications are:\n PermitRootLogin = ${YELLOW}prohibit-password${NC}\n PasswordAuthentication = ${YELLOW}no${NC}\n PubkeyAuthentication = ${YELLOW}yes${NC}\n PermitEmptyPasswords = ${YELLOW}no${NC}" 270 | elif [ "$SSH_SEC" = TYPE02 ] 271 | then 272 | # SSH key, permitted root login & allow password authentication 273 | sed -i -r '/^#?PermitRootLogin.*/c\PermitRootLogin yes' /etc/ssh/sshd_config 274 | sed -i -r '/^#?PasswordAuthentication.*/c\PasswordAuthentication yes' /etc/ssh/sshd_config 275 | sed -i -r '/^#?PubkeyAuthentication.*/c\PubkeyAuthentication yes' /etc/ssh/sshd_config 276 | sed -i -r '/^#?PermitEmptyPasswords.*/c\PermitEmptyPasswords no' /etc/ssh/sshd_config 277 | info "SSH security modifications are:\n PermitRootLogin = ${YELLOW}yes${NC}\n PasswordAuthentication = ${YELLOW}yes${NC}\n PubkeyAuthentication = ${YELLOW}yes${NC}\n PermitEmptyPasswords = ${YELLOW}no${NC}" 278 | fi 279 | 280 | #---- Finish Line ------------------------------------------------------------------ 281 | 282 | section "Completion Status" 283 | msg "Success. Task complete." 284 | echo 285 | #----------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /src/pve_host_add_nfs_mounts.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ---------------------------------------------------------------------------------- 3 | # Filename: pve_host_add_nfs_mounts.sh 4 | # Description: Source script for creating PVE Host NFS Mounts 5 | # ---------------------------------------------------------------------------------- 6 | 7 | #---- Bash command to run script --------------------------------------------------- 8 | #---- Source ----------------------------------------------------------------------- 9 | #---- Dependencies ----------------------------------------------------------------- 10 | #---- Static Variables ------------------------------------------------------------- 11 | 12 | # Easy Script Section Header Body Text 13 | SECTION_HEAD='PVESM NFS Storage Mounts' 14 | 15 | # Check for PVE Hostname mod 16 | if [ -z "${HOSTNAME_FIX+x}" ]; then 17 | PVE_HOSTNAME=$HOSTNAME 18 | fi 19 | 20 | #---- Other Variables -------------------------------------------------------------- 21 | #---- Other Files ------------------------------------------------------------------ 22 | #---- Body ------------------------------------------------------------------------- 23 | 24 | #---- Introduction 25 | section "Introduction" 26 | 27 | msg_box "#### PLEASE READ CAREFULLY - NAS NFS SERVER EXPORTS ####\n 28 | Proxmox can add storage by creating NFS and/or CIFS backend storage pools. Your NAS server NFS properties must be configured so your PVE NFS backend (client) can mount the NAS shares automatically. Your NAS server must support: 29 | 30 | NFS VERSION 31 | -- NFS v3/v4 32 | 33 | -- NAS NFS exports to all PVE nodes (i.e default PVE nodes are 192.168.1.101-192.168.1.109) 34 | 35 | We need to set some variables. The next steps requires your input. You can accept our default values by pressing ENTER on your keyboard. Or overwrite our default value by typing in your own value and then pressing ENTER to accept and to continue to the next step." 36 | echo 37 | while true 38 | do 39 | read -p "Create PVE NFS storage mounts [y/n]?: " -n 1 -r YN 40 | echo 41 | case $YN in 42 | [Yy]*) 43 | info "The User has chosen to proceed." 44 | echo 45 | break 46 | ;; 47 | [Nn]*) 48 | info "The User has chosen to skip this step." 49 | return 50 | ;; 51 | *) 52 | warn "Error! Entry must be 'y' or 'n'. Try again..." 53 | echo 54 | ;; 55 | esac 56 | done 57 | 58 | 59 | #---- Checking PVE Host Prerequisites 60 | section "Check Prerequisites" 61 | 62 | # nbtscan SW 63 | if [[ ! $(dpkg -s nbtscan) ]]; then 64 | msg "Installing nbtscan..." 65 | apt-get install -y nbtscan >/dev/null 66 | info "nbtscan status: ${GREEN}installed${NC}" 67 | echo 68 | fi 69 | 70 | 71 | #---- Checking NFS Server exports 72 | section "Select NFS server" 73 | 74 | # Look for NFS server using hostname or IP address 75 | while true 76 | do 77 | read -p "Enter your NFS Server (NAS) IPv4/6 address OR hostname: " -e -i nas-01 NAS_ID 78 | msg "Checking for a working NFS server..." 79 | if [ "$(valid_ip "$NAS_ID" > /dev/null 2>&1; echo $?)" = 0 ]; then 80 | # Perform IP ping check 81 | if [ "$(ping -s 1 -c 2 "$(echo "$NAS_ID")" > /dev/null; echo $?)" = 0 ]; then 82 | NAS_IP="$NAS_ID" 83 | info "Ping '$NAS_ID' status: ${YELLOW}pass${NC}" 84 | info "NAS IP status: ${YELLOW}pass${NC} ( $NAS_IP )" 85 | else 86 | NAS_IP="" 87 | info "Ping '$NAS_ID' status: ${RED}fail${NC}" 88 | info "NAS IP status: ${RED}fail${NC}" 89 | fi 90 | 91 | # Perform hostname check 92 | if [[ $(nbtscan -q $NAS_ID | awk '{print $2}') ]]; then 93 | NAS_HOSTNAME="$(nbtscan -q $NAS_ID | awk '{print $2}')" 94 | info "NAS hostname status: ${YELLOW}pass${NC} ( $NAS_HOSTNAME )" 95 | else 96 | NAS_HOSTNAME="" 97 | info "NAS hostname status: ${RED}fail${NC} ( cannot map hostname )" 98 | fi 99 | elif [[ "$NAS_ID" =~ ${hostname_regex} ]]; then 100 | # Perform hostname ping check 101 | if [ "$(ping -s 1 -c 2 "$(echo "$NAS_ID")" > /dev/null; echo $?)" = 0 ]; then 102 | NAS_HOSTNAME="$NAS_ID" 103 | info "Ping '$NAS_ID' status: ${YELLOW}pass${NC}" 104 | info "NAS hostname status: ${YELLOW}pass${NC} ( $NAS_HOSTNAME )" 105 | else 106 | NAS_HOSTNAME="" 107 | info "Ping '$NAS_ID' status: ${RED}fail${NC}" 108 | info "NAS hostname status: ${RED}fail${NC}" 109 | fi 110 | 111 | # Perform IP lookup using hostname 112 | if [[ $(nslookup "${NAS_ID}" | awk '/^Address: / { print $2 }') ]]; then 113 | NAS_IP="$(nslookup "$NAS_ID" | awk '/^Address: / { print $2 }')" 114 | info "NAS IP lookup status: ${YELLOW}pass${NC} ( $NAS_IP )" 115 | else 116 | NAS_IP="" 117 | info "NAS IP lookup status: ${RED}fail${NC} ( cannot map IP address )" 118 | fi 119 | fi 120 | 121 | # NFS IP server status ('0' enabled, '1' disabled) 122 | if [[ $(pvesm nfsscan "$NAS_IP" 2> /dev/null) ]] && [ -n ${NAS_IP} ]; then 123 | NAS_IP_STATUS=0 # '0' enabled, '1' disabled 124 | else 125 | NAS_IP_STATUS=1 # '0' enabled, '1' disabled 126 | fi 127 | 128 | # NFS hostname server status ('0' enabled, '1' disabled) 129 | if [[ $(pvesm nfsscan ${NAS_HOSTNAME} 2> /dev/null) ]] && [ -n ${NAS_HOSTNAME} ]; then 130 | NAS_HOSTNAME_STATUS=0 # '0' enabled, '1' disabled 131 | else 132 | NAS_HOSTNAME_STATUS=1 # '0' enabled, '1' disabled 133 | fi 134 | 135 | # Check status 136 | if [ "$NAS_HOSTNAME_STATUS" -eq 0 ] || [ "$NAS_IP_STATUS" -eq 0 ]; then 137 | break 138 | fi 139 | echo 140 | done 141 | 142 | 143 | #---- Select NFS mount protocol (IP or hostname) 144 | if [ "$NAS_HOSTNAME_STATUS" -eq 0 ] && [ "$NAS_IP_STATUS" -eq 0 ]; then 145 | # Select NFS protocol - NAS Hostname or Static IP 146 | print_DISPLAYIP=( "$(pvesm nfsscan "$NAS_IP" | awk '{print $1}' | uniq | sed "/.*\/backup$/d" | sed 's/proxmox$/proxmox\/backup/g')" ) 147 | print_DISPLAYHOSTNAME=( "$(pvesm nfsscan "$NAS_HOSTNAME" | awk '{print $1}' | uniq | sed "/.*\/backup$/d" | sed 's/proxmox$/proxmox\/backup/g')" ) 148 | msg_box "#### PLEASE READ CAREFULLY - NAS NFS SERVER EXPORTS BY PROTOCOL ####\n\nNAS NFS exports can be mounted using either the NAS IP address or NAS hostname protocol. NFS export shares may vary between the two protocols (but they can also be the same).\n\n$(paste <(printf "%s\n" "${print_DISPLAYIP[@]}") <(printf "%s\n" "${print_DISPLAYHOSTNAME[@]}") | column -t -N "NFS EXPORTS by HOSTNAME,NFS EXPORTS by IP" | indent2)\n\nSelect your preferred NAS NFS export protocol. Hostname protocol is recommended if the shares meet your requirements." 149 | echo 150 | 151 | OPTIONS_VALUES_INPUT=( "TYPE01" "TYPE02" "TYPE00") 152 | OPTIONS_LABELS_INPUT=( "Hostname - NFS by hostname '$NAS_HOSTNAME' (Recommended)" "IP address - NFS by static IP '$NAS_IP'" "None. Return to the Toolbox" ) 153 | makeselect_input2 154 | singleselect SELECTED "$OPTIONS_STRING" 155 | 156 | # Set the NFS protocol from menu 157 | if [ "$RESULTS" = 'TYPE01' ]; then 158 | # Set NFS by hostname 159 | NAS_ID="$NAS_HOSTNAME" 160 | info "NAS NFS export mount protocol set: ${YELLOW}$NAS_ID${NC} (by hostname)" 161 | elif [ "$RESULTS" = 'TYPE02' ]; then 162 | # Set NFS by IP 163 | NAS_ID="$NAS_IP" 164 | info "NAS NFS export mount protocol set: ${YELLOW}$NAS_ID${NC} (by IP)" 165 | elif [ "$RESULTS" = 'TYPE00' ]; then 166 | return 167 | fi 168 | elif [ "$NAS_HOSTNAME_STATUS" = 0 ] && [ "$NAS_IP_STATUS" = 1 ]; then 169 | # Set NFS protocol - by hostname 170 | NAS_ID="$NAS_HOSTNAME" 171 | info "NAS NFS export mount protocol set: ${YELLOW}$NAS_ID${NC} (by hostname)" 172 | elif [ "$NAS_HOSTNAME_STATUS" = 1 ] && [ "$NAS_IP_STATUS" = 0 ]; then 173 | # Set NFS protocol - by IP 174 | NAS_ID="$NAS_IP" 175 | info "NAS NFS export mount protocol set: ${YELLOW}$NAS_ID${NC} (by IP)" 176 | else 177 | # Fail msg 178 | FAIL_MSG="The entry '${NAS_ID}' not valid. A valid NAS NFS server address is when the following constraints are satisfied:\n 179 | Required constraints 180 | -- NAS IP or hostname is reachable. 181 | -- NAS NFS server is reachable. 182 | -- NAS NFS server supports NFSv3 or higher. 183 | -- the NAS NFS server name entry (IP or hostname) doesn't contain any white space. 184 | Other constraints 185 | -- a IP address entry is incorrectly formatted. It must be in the IPv4 or IPv6 format. 186 | -- a hostname entry is correctly formatted.\n 187 | Try again..." 188 | warn "$FAIL_MSG" 189 | break 190 | fi 191 | echo 192 | 193 | 194 | # Manually set NAS hostname 195 | # This runs when no hostname is found using nbtscan failed to get the NAS hostname using the NAS IP. 196 | if [ -z ${NAS_HOSTNAME} ]; then 197 | msg "For unknown reasons, we could not determine the hostname for the NAS server with IP '${NAS_IP}'. Please manually enter the NAS hostname at the prompt." 198 | while true 199 | do 200 | read -p "Enter your NAS NFS Server '${NAS_IP}' hostname: " -e -i $(nslookup $NAS_IP | awk 'sub(/.*name =/,""){print $1}' | sed 's/\..*//') NAS_HOSTNAME_VAR 201 | if [[ "$NAS_HOSTNAME_VAR" =~ ${hostname_regex} ]]; then 202 | NAS_HOSTNAME="$NAS_HOSTNAME_VAR" 203 | info "NAS hostname set: ${YELLOW}$NAS_HOSTNAME${NC}" 204 | echo 205 | break 206 | else 207 | # Fail msg 208 | FAIL_MSG="The hostname is not valid. A valid hostname is when all of the following constraints are satisfied:\n 209 | -- it contains only lowercase characters. 210 | -- it may include numerics, hyphens (-) and periods (.) but not start or end with them. 211 | -- it doesn't contain any other special characters [!#$&%*+_]. 212 | -- it doesn't contain any white space.\n 213 | Try again..." 214 | warn "${FAIL_MSG}" 215 | echo 216 | fi 217 | done 218 | fi 219 | 220 | 221 | # Check NFS version 222 | msg " Checking PVE NFS support" 223 | # Check PVE host NFS supported version no. 224 | # Match to highest NFS4 when possible for 'backup' mounts 225 | nfs_ver_pve_LIST=( "4.2" "4.1" "4" "3" "default" ) 226 | nfs_ver_pve_max=$(rpcinfo -p | awk '{print $2}' | sort -rn | head -1) 227 | 228 | # NAS NFS supported version no. 229 | # nfs_ver_nas_max=$(nfsstat -m "$NAS_ID" | grep -oP 'vers=\K\d+\.\d+' | sort -k2 -nr | head -1) 230 | nfs_ver_nas_max=$(rpcinfo -p "$NAS_ID" | grep nfs | awk '{print $2}' | sort -k2 -nr | head -1) 231 | 232 | 233 | # Set $nfs_ver_max 234 | # Set to highest nfs version match for client and server 235 | if (( $(echo "$nfs_ver_pve_max <= $nfs_ver_nas_max" | bc -l) )); then 236 | nfs_ver_max=$(printf '%s\n' "${nfs_ver_pve_LIST[@]}" | grep -E "^$nfs_ver_pve_max\.[0-9]+$" | sort -rn | head -1) 237 | if [ -z "$nfs_ver_max" ]; then 238 | nfs_ver_max=$(printf '%s\n' "${nfs_ver_pve_LIST[@]}" | grep -E "^$nfs_ver_pve_max$" | sort -rn | head -1) 239 | fi 240 | else 241 | nfs_ver_max=$(printf '%s\n' "${nfs_ver_pve_LIST[@]}" | grep -E "^$nfs_ver_nas_max\.[0-9]+$" | sort -rn | head -1) 242 | if [ -z "$nfs_ver_max" ]; then 243 | nfs_ver_max=$(printf '%s\n' "${nfs_ver_pve_LIST[@]}" | grep -E "^$nfs_ver_nas_max$" | sort -rn | head -1) 244 | fi 245 | fi 246 | 247 | # Check if NAS NFS version meets minimum requirement 248 | if (( $(echo "$nfs_ver_nas_max >= 4" | bc -l) )); then 249 | info "NFS version check: ${YELLOW}pass${NC}" 250 | elif (( $(echo "$nfs_ver_nas_max < 4 && $nfs_ver_nas_max >= 3" | bc -l) )); then 251 | info "NFS version check: ${YELLOW}pass${NC} (NFSv3 limit - potential connectivity issues)" 252 | else 253 | warn "Your NFS Server '${NAS_ID}' is running NFSv2 or older. You must upgrade your NFS server to support NFSv4 or higher. User intervention required. Exiting installation script." 254 | sleep 1 255 | return 256 | fi 257 | echo 258 | 259 | #---- Create NFS mount pairs 260 | section "Create PVE Storage Mounts" 261 | 262 | # Get NFS NAS Server export list 263 | mapfile -t nfs_server_LIST <<< $(pvesm nfsscan $NAS_ID | awk '{print $1}' | uniq | sed "/.*\/backup$/d" | sed 's/proxmox$/proxmox\/backup/g' | sed 's/[[:blank:]]*$//' | sed '/^$/d') # Removing backup dir, editing /src/proxmox/'backup' 264 | # Create required pvesm list 265 | mapfile -t pvesm_req_LIST <<< $(cat $SHARED_DIR/src/pve_host_mount_list | sed '/^#/d' | awk -F':' '$3 == "0" { print $1 }' | awk '{ print tolower ($1) }' | sed '/^$/d' | sed 's/[[:blank:]]*$//' | sed '/^$/d') 266 | 267 | 268 | # Match nfs exports vs required match list 269 | # Here we match our default list pf PVESM mounts "${pvesm_req_LIST[@]}" against your NFS Server exports "${nfs_server_LIST[@]}", removing any existing matching PVE NFS/CIF mounts to avoid conflicts. 270 | # 1=src:2=pvesm name:3=media type:4=status (0 existing, 1 required,):5=format(nfs,cifs) 271 | msg "Matching NFS Server '${NAS_ID}' exports with Ahuacate default shares (be patient, might take a while)..." 272 | unset match_LIST 273 | while IFS= read -r line 274 | do 275 | if [ "$(printf '%s\n' "${nfs_server_LIST[@]}" | grep -s "\.*${line}$" > /dev/null; echo $?)" = 0 ]; then 276 | match_LIST+=( "$(printf '%s\n' "${nfs_server_LIST[@]}" | grep -s "\.*${line}$"):$(echo "${NAS_HOSTNAME,,}-${line}":${line}:$(if [[ $(pvesm status | grep -E 'nfs|cifs' | tr '[:upper:]' '[:lower:]' | grep "^${NAS_HOSTNAME,,}-${line}") ]]; then pvesm status | grep -E 'nfs|cifs' | tr '[:upper:]' '[:lower:]' | grep "^${NAS_HOSTNAME,,}-${line}" | awk '{ print "0:"$2 }'; else echo "1:"; fi))" ) 277 | fi 278 | done < <( printf '%s\n' "${pvesm_req_LIST[@]}" ) 279 | 280 | while IFS= read -r line 281 | do 282 | if [ ! "$(printf '%s\n' "${match_LIST[@]}" | grep -s "^${line}" > /dev/null; echo $?)" = 0 ]; then 283 | match_LIST+=( "${line}::::" ) 284 | fi 285 | done < <( printf '%s\n' "${nfs_server_LIST[@]}" ) 286 | 287 | # Auto select and label exports 288 | if [ "$(printf '%s\n' "${match_LIST[@]}" | awk -F':' '{OFS=FS} { if (($4 == 0 || $4 == 1)) print $0 }' | wc -l)" = ${#pvesm_req_LIST[@]} ]; then 289 | # Auto selection and labelling of exports 290 | msg_box "#### AUTOMATIC PVE STORAGE MOUNT MATCHING ####\n\nWe have discovered and matched all the required PVE storage mounts. Any conflicting or existing mount points are excluded. Only mounts labeled 'required' will be created. This should work 'out-of-the-box'.\n\n$(printf '%s\n' "${match_LIST[@]}" | awk -F':' '{OFS=FS} { if ($4 == 0) print $1,"<<",$2,$5} { if ($4 == 1) print $1,"<<",$2,"required"}' | column -s ":" -t -N "SOURCE INPUT, ,PVESM LABEL,MOUNT STATUS" | indent2)\n\nAccept the auto match list by typing 'y' at the next prompt. Or manually select and match each PVE mount point(s) you want by entering 'n' at the next prompt." 291 | echo 292 | while true 293 | do 294 | read -p "Accept the auto matched pairing ( Recommended for our custom NAS builds ) [y/n]?: " -n 1 -r YN 295 | echo 296 | case $YN in 297 | [Yy]*) 298 | ES_LIST=0 299 | input_LIST=( $(printf '%s\n' "${match_LIST[@]}" | awk -F':' '{OFS=FS} { if ($4 == 1) print $1, $3}') ) 300 | info "The User has accepted the matched pairing." 301 | echo 302 | break 303 | ;; 304 | [Nn]*) 305 | ES_LIST=1 306 | info "The User has chosen to skip this option." 307 | break 308 | ;; 309 | *) 310 | warn "Error! Entry must be 'y' or 'n'. Try again..." 311 | echo 312 | ;; 313 | esac 314 | done 315 | else 316 | ES_LIST='1' 317 | fi 318 | 319 | # Manual selection and labelling of exports 320 | if [ "$ES_LIST" -eq 1 ]; then 321 | # Create required manual lists 322 | unset options_values_input_LIST 323 | unset options_labels_input_LIST 324 | while IFS=: read -r type desc; do 325 | if [ "$(printf '%s\n' "${match_LIST[@]}" | awk -F':' -v pvesm_id="${NAS_HOSTNAME,,}-${type}" '{OFS=FS} { if ($2=pvesm_id && $4 == 0) print $3 }' | sed '/^$/d' | grep "${type,,}" > /dev/null; echo $?)" != 0 ]; then 326 | options_values_input_LIST+=( "${type,,}" ) 327 | options_labels_input_LIST+=( "${type} - ${desc}" ) 328 | fi 329 | done < <( cat $SHARED_DIR/src/pve_host_mount_list | sed '/^#/d' | awk -F':' '{OFS=FS} $3 == "0" { print $1,$2 }' | sed 's/[[:blank:]]*$//' | sed '/^$/d' ) 330 | 331 | # Prepare required input arrays for func matchselect 332 | mapfile -t OPTIONS_VALUES_INPUT <<< $(printf '%s\n' "${options_values_input_LIST[@]}") 333 | mapfile -t OPTIONS_LABELS_INPUT <<< $(printf '%s\n' "${options_labels_input_LIST[@]}") 334 | SRC_VALUES_INPUT=( $(printf '%s\n' "${match_LIST[@]}" | awk -F':' '{OFS=FS} { if (($4 == "" || $4 == 1)) print $1 }') ) 335 | 336 | while true 337 | do 338 | msg_box "#### MANUAL PVE STORAGE MOUNT MATCHING ####\n\nWe have discovered ${#SRC_VALUES_INPUT[@]}x NAS exports available for PVE storage mounts. All conflicting or existing mount points are excluded.\n\nExisting PVE '${NAS_HOSTNAME^^}' storage mounts are:\n\n$(printf '%s\n' "${match_LIST[@]}" | awk -F':' '{OFS=FS} { if ($4 == 0) print $1,"<<",$2,$5}' | column -s ":" -t -N "SOURCE INPUT, ,PVESM NAME,MOUNT STATUS" | indent2)\n\nManual matching is required for the following:\n\n$(printf '%s\n' "${match_LIST[@]}" | awk -F':' '{OFS=FS} { if ($4 == 1 ) print $1,"<<",$3} { if ($4 == "") print $1,"","-"}' | column -s ":" -t -N "SOURCE INPUT, ,SUGGESTED MATCH TYPE" | indent2)\n\nTo ignore a NAS share export select:\n\n -- Ignore this match\n\nTo finish the task select (after matching all the required NAS exports):\n\n -- Exit/Finished - Nothing more to match" 339 | echo 340 | 341 | # Run func matchselect 342 | matchselect SELECTED 343 | 344 | # Print results 345 | printf '%s\n' "${PRINT_RESULTS[@]}" | awk -F':' '{OFS=FS} { print $1,">>",$2}' | column -s ":" -t -N "SOURCE INPUT, ,SELECTED PAIR DESCRIPTION" | indent2 346 | echo 347 | 348 | # Confirm selection 349 | read -p "Accept the matched pairing [y/n]?: " -n 1 -r YN 350 | echo 351 | case $YN in 352 | [Yy]*) 353 | info "The User has accepted the matched pairing." 354 | echo 355 | # Create match list 356 | input_LIST=( $(printf '%s\n' "${RESULTS[@]}") ) 357 | break 358 | ;; 359 | [Nn]*) 360 | msg "No problem. Try again..." 361 | echo 362 | ;; 363 | *) 364 | warn "Error! Entry must be 'y' or 'n'. Try again..." 365 | echo 366 | ;; 367 | esac 368 | done 369 | fi 370 | 371 | 372 | #---- Create PVE Storage Mounts 373 | if [ ${#input_LIST[@]} -ge 1 ]; then 374 | while IFS=':' read -r SHARE TYPE 375 | do 376 | PVESM_LABEL="${NAS_HOSTNAME,,}-${TYPE}" 377 | if [ "${PVESM_LABEL}" == "$(echo ${NAS_HOSTNAME,,}-backup)" ]; then 378 | # Round down $nfs_ver_max 379 | nfs_ver_max_int=$(printf "%.0f" "$nfs_ver_max") 380 | msg "Creating PVE storage mount..." 381 | pvesm add nfs $PVESM_LABEL --path /mnt/pve/$PVESM_LABEL --server $NAS_ID --export $SHARE --content backup,images --maxfiles 3 --preallocation metadata --options vers=$nfs_ver_max_int 382 | info "PVE storage mount created: ${YELLOW}$PVESM_LABEL${NC}\n (${NAS_ID}:${SHARE})" 383 | echo 384 | else 385 | msg "Creating PVE storage mount..." 386 | pvesm add nfs $PVESM_LABEL --path /mnt/pve/$PVESM_LABEL --server $NAS_ID --export $SHARE --content images 387 | info "PVE storage mount created: ${YELLOW}$PVESM_LABEL${NC}\n (${NAS_ID}:${SHARE})" 388 | echo 389 | fi 390 | done < <( printf '%s\n' "${input_LIST[@]}" ) 391 | else 392 | msg "It seems you already have all the required NFS PVE storage mounts. No additional PVE storage mounts will ne created." 393 | echo 394 | fi 395 | 396 | #---- Finish Line ------------------------------------------------------------------ 397 | 398 | section "Completion Status." 399 | msg "Success. Task complete." 400 | echo 401 | #----------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /src/pve_host_setup_postfix_server.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ---------------------------------------------------------------------------------- 3 | # Filename: pve_host_setup_postfix_server.sh 4 | # Description: Source script for PVE Host Postfix setup 5 | # ---------------------------------------------------------------------------------- 6 | 7 | #---- Bash command to run script --------------------------------------------------- 8 | 9 | # bash -c "$(wget -qLO - https://raw.githubusercontent.com/ahuacate/pve-host/main/scripts/pve_host_setup_postfix_server.sh)" 10 | 11 | #---- Source ----------------------------------------------------------------------- 12 | #---- Dependencies ----------------------------------------------------------------- 13 | 14 | # Check IP 15 | ipvalid () { 16 | # Set up local variables 17 | local ip=${1:-1.2.3.4} 18 | local IFS=.; local -a a=($ip) 19 | 20 | # Start with a regex format test 21 | [[ $ip =~ ^[0-9]+(\.[0-9]+){3}$ ]] || return 1 22 | # Test values of quads 23 | local quad 24 | for quad in {0..3}; do 25 | [[ "${a[$quad]}" -gt 255 ]] && return 1 26 | done 27 | return 0 28 | } 29 | 30 | #---- Static Variables ------------------------------------------------------------- 31 | 32 | # Easy Script Section Header Body Text 33 | SECTION_HEAD='Postfix Server' 34 | 35 | # # Check for PVE Hostname mod 36 | # if [ -z "${HOSTNAME_FIX+x}" ]; then 37 | # PVE_HOSTNAME=$HOSTNAME 38 | # fi 39 | 40 | # Local network 41 | LOCAL_NET=$(hostname -I | awk -F'.' -v OFS="." '{ print $1,$2,"0.0/16" }') 42 | 43 | # Postfix vars 44 | POSTFIX_CONFIG=/etc/postfix/main.cf 45 | POSTFIX_SASL_PWD=/etc/postfix/sasl_passwd 46 | POSTFIX_SASL_DB=/etc/postfix/sasl_passwd.db 47 | 48 | #---- Other Variables -------------------------------------------------------------- 49 | #---- Other Files ------------------------------------------------------------------ 50 | #---- Body ------------------------------------------------------------------------- 51 | 52 | #---- Install and Configure SSMTP Email 53 | 54 | section "Introduction" 55 | 56 | # Set display msg 57 | display_conditions_msg1=( "-- SMTP SERVER 58 | You require a SMTP server that can receive the emails from your machine and send them to the designated administrator. If you use Gmail SMTP server its best to enable 'App Passwords'. An 'App Password' is a 16-digit passcode that gives an app or device permission to access your Google Account. Or you can use a mailgun.com flex account relay server (Recommended). 59 | 60 | -- REQUIRED SMTP SERVER CREDENTIALS 61 | 1. Designated administrator email address (i.e your working admin email address) 62 | 63 | 2. SMTP server address (i.e smtp.gmail.com or smtp.mailgun.org) 64 | 65 | 3. SMTP server port (i.e gmail port is 587 and mailgun port is 587) 66 | 67 | 4. SMTP server username (i.e MyEmailAddress@gmail.com or postmaster@sandboxa6ac6.mailgun.org) 68 | 69 | 5. SMTP server default password (i.e your Gmail App Password or MailGun SMTP password) 70 | 71 | 6. Only SMTP SSL/TLS ports numbers are accepted" ) 72 | 73 | msg_box "#### PLEASE READ CAREFULLY - POSTFIX & EMAIL CREDENTIALS ####\n 74 | Send email alerts about your PVE host and VM/CTs to the systems designated administrator. Be alerted about unwarranted login attempts and other system critical alerts. 75 | 76 | Use email to send important VM/CT install details such as new user login credentials and SSH keys. 77 | 78 | Proxmox is preinstalled with Postfix SMTP server. SMTP is a simple Mail Transfer Agent (MTA) while easy to setup it requires the following prerequisites and credentials: 79 | 80 | $(printf '%s\n' "${display_conditions_msg1[@]}" | indent2) 81 | 82 | If you choose to proceed have your SMTP server credentials available." 83 | echo 84 | while true 85 | do 86 | read -p "Install and configure Postfix and email ( Recommended ) [y/n]?: " -n 1 -r YN 87 | echo 88 | case $YN in 89 | [Yy]*) 90 | while true 91 | do 92 | read -p "Do you have your GMail, MailGun or Custom SMTP Server credentials ready [y/n]?: " -n 1 -r YN 93 | echo 94 | case $YN in 95 | [Yy]*) 96 | info "The User has chosen to proceed." 97 | echo 98 | break 2 99 | ;; 100 | [Nn]*) 101 | warn "In the next steps you must have your 16 digit GMail App Password OR MailGun\n OR custom SMTP server credentials ready for input to continue.\nTry again..." 102 | echo 103 | break 104 | ;; 105 | *) 106 | warn "Error! Entry must be 'y' or 'n'. Try again..." 107 | echo 108 | ;; 109 | esac 110 | done 111 | ;; 112 | [Nn]*) 113 | info "You have chosen to skip this step. Bye..." 114 | echo 115 | return 116 | ;; 117 | *) 118 | warn "Error! Entry must be 'y' or 'n'. Try again..." 119 | echo 120 | ;; 121 | esac 122 | done 123 | 124 | 125 | #---- Checking PVE Host Prerequisites 126 | section "Checking Prerequisites" 127 | 128 | # libsasl2-modules for Postfix 129 | if [[ ! $(dpkg -s libsasl2-modules 2> /dev/null) ]] 130 | then 131 | msg "Installing libsasl2-modules..." 132 | apt-get install libsasl2-modules -y 2> /dev/null 133 | info "libsasl2-modules status: ${GREEN}installed${NC}" 134 | fi 135 | 136 | # postfix-pcre for Postfix 137 | if [[ ! $(dpkg -s postfix-pcre 2> /dev/null) ]] 138 | then 139 | msg "Installing postfix-pcre..." 140 | apt-get install postfix-pcre -y 2> /dev/null 141 | info "postfix-pcre status: ${GREEN}installed${NC}" 142 | fi 143 | 144 | # uuencode for Postfix (part of package sharutils) 145 | if [[ ! $(dpkg -s sharutils 2> /dev/null) ]] 146 | then 147 | msg "Installing sharutils (uuencode)..." 148 | apt-get install sharutils -y 2> /dev/null 149 | info "sharutils (uuencode) status: ${GREEN}installed${NC}" 150 | fi 151 | 152 | 153 | #--- Set PVE root administrator email address 154 | section "PVE root email address" 155 | 156 | # Set current root email address 157 | PVE_ROOT_EMAIL_OLD=$(pveum user list | awk -F " │ " '$1 ~ /root@pam/' | awk -F " │ " '{ print $3 }') 158 | 159 | msg_box "#### PLEASE READ CAREFULLY - ROOT EMAIL ADDRESS ####\n 160 | Your PVE root email address is '${PVE_ROOT_EMAIL_OLD}'. This email address is set to send all system notifications and alerts. In the next steps you have the option to accept or update your default PVE host root email address." 161 | while true; do 162 | msg "Validate your PVE root email address..." 163 | OPTIONS_VALUES_INPUT=( "TYPE01" "TYPE02" "TYPE00" ) 164 | OPTIONS_LABELS_INPUT=( "Accept - '${PVE_ROOT_EMAIL_OLD}' is valid and current" \ 165 | "Update/Edit - I want to update my PVE root email address" \ 166 | "None. Exit this installer") 167 | makeselect_input2 168 | singleselect SELECTED "$OPTIONS_STRING" 169 | 170 | if [ "$RESULTS" = 'TYPE01' ] 171 | then 172 | PVE_ROOT_EMAIL="$PVE_ROOT_EMAIL_OLD" 173 | break 174 | elif [ "$RESULTS" = 'TYPE02' ] 175 | then 176 | # Update PVE root email address 177 | while true 178 | do 179 | read -p "Enter a new email address: " -e -i $PVE_ROOT_EMAIL_OLD PVE_ROOT_EMAIL 180 | echo 181 | read -p "Accept email address '$PVE_ROOT_EMAIL' [y/n]?: " -n 1 -r 182 | case $YN in 183 | [Yy]*) 184 | # Validate email address 185 | if [[ ! "$PVE_ROOT_EMAIL" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$ ]] 186 | then 187 | FAIL_MSG="There are problems with your input:\n-- '${PVE_ROOT_EMAIL}' does not pass our email validity check\n-- whitespace and/or special characters are not allowed\nTry again..." 188 | warn "$FAIL_MSG" 189 | echo 190 | else 191 | echo 192 | break 193 | fi 194 | ;; 195 | [Nn]*) 196 | msg "No problem. Try again..." 197 | echo 198 | ;; 199 | *) 200 | warn "Error! Entry must be 'y' or 'n'. Try again..." 201 | echo 202 | ;; 203 | esac 204 | done 205 | elif [ "$RESULTS" = 'TYPE00' ] 206 | then 207 | # Exit installation 208 | msg "You have chosen not to proceed. Aborting. Bye..." 209 | echo 210 | return 211 | fi 212 | done 213 | 214 | 215 | #---- Set Postfix SMTP server address 216 | while true 217 | do 218 | section "Set Postfix SMTP server address" 219 | 220 | msg "Select your email SMTP provider..." 221 | OPTIONS_VALUES_INPUT=( "TYPE01" "TYPE02" "TYPE03" "TYPE00" ) 222 | OPTIONS_LABELS_INPUT=( "MailGun - Configure for a MailGun SMTP server (Recommended)" \ 223 | "GMail - Configure for a GMail SMTP server" \ 224 | "Custom - Custom SMTP server configuration" \ 225 | "None. Exit this installer") 226 | makeselect_input2 227 | singleselect SELECTED "$OPTIONS_STRING" 228 | 229 | if [ "$RESULTS" = 'TYPE01' ] 230 | then 231 | SMTP_HOST_ID=MailGun 232 | SMTP_SERVER_ADDRESS="smtp.mailgun.org" 233 | SMTP_SERVER_PORT=587 234 | SMTP_USE_TLS='yes' 235 | TLS='enabled' 236 | elif [ "$RESULTS" = 'TYPE02' ] 237 | then 238 | SMTP_HOST_ID=GMail 239 | SMTP_SERVER_ADDRESS="smtp.gmail.com" 240 | SMTP_SERVER_PORT=587 241 | SMTP_USE_TLS='yes' 242 | TLS='enabled' 243 | elif [ "$RESULTS" = 'TYPE03' ] 244 | then 245 | SMTP_HOST_ID=custom 246 | # Input custom smtp server credentials 247 | while true 248 | do 249 | # Input address 250 | read -p "Enter SMTP server address (i.e smtp.hello.com): " -e SMTP_SERVER_ADDRESS 251 | # Input port 252 | read -p "Enter SMTP server port number (i.e 465, 587): " -e -i 587 SMTP_SERVER_PORT 253 | # Input TLS 254 | read -p "Does your SMTP server support TLS encryption (Recommended) [y/n]?: " -n 1 -r YN 255 | echo 256 | case $YN in 257 | [Yy]*) 258 | SMTP_USE_TLS='yes' 259 | TLS='enabled' 260 | ;; 261 | [Nn]*) 262 | SMTP_USE_TLS='' 263 | TLS='disabled' 264 | ;; 265 | *) 266 | warn "Error! Entry must be 'y' or 'n'. Try again..." 267 | echo 268 | ;; 269 | esac 270 | # Confirm settings 271 | read -p "Confirm your SMTP server settings: ${WHITE}${SMTP_SERVER_ADDRESS}${NC}:${WHITE}${SMTP_SERVER_PORT}${NC} (TLS ${WHITE}${TLS}${NC}) [y/n]?: " -n 1 -r YN 272 | echo 273 | case $YN in 274 | [Yy]*) 275 | echo 276 | break 277 | ;; 278 | [Nn]*) 279 | msg "No problem. Try again..." 280 | echo 281 | ;; 282 | *) 283 | warn "Error! Entry must be 'y' or 'n'. Try again..." 284 | echo 285 | ;; 286 | esac 287 | done 288 | elif [ "$RESULTS" = 'TYPE00' ] 289 | then 290 | # Exit installation 291 | msg "You have chosen not to proceed. Aborting. Bye..." 292 | echo 293 | return 294 | fi 295 | 296 | # Check SMTP server address 297 | FAIL_MSG="The SMTP address is not valid. A SMTP server check failed. A valid SMTP server address is when all of the following constraints are satisfied:\n 298 | -- passes openssl s_client diagnostics for SSL/TLS 299 | -- the server responds\n 300 | Check your SMTP server address and port number. Try again..." 301 | if [ ! "$(timeout 10 openssl s_client -crlf -verify_quiet -starttls smtp -connect ${SMTP_SERVER_ADDRESS}:${SMTP_SERVER_PORT} &>/dev/null <<< QUIT; echo $?)" = 0 ] 302 | then 303 | warn "$FAIL_MSG" 304 | else 305 | break 306 | fi 307 | done 308 | 309 | 310 | #---- Set SMTP server account credentials 311 | while true 312 | do 313 | read -p "Enter your $SMTP_HOST_ID SMTP server account username: " -e SMTP_ACC_USERNAME 314 | read -p "Enter your $SMTP_HOST_ID SMTP server account password: " -e SMTP_ACC_PWD 315 | echo 316 | info "Your SMTP server credentials are:\nUsername: ${YELLOW}$SMTP_ACC_USERNAME${NC}\nPassword: ${YELLOW}$SMTP_ACC_PWD${NC}" 317 | read -p "Accept SMTP server credentials: [y/n]? " -n 1 -r 318 | case $YN in 319 | [Yy]*) 320 | info "SMTP server account credentials status: ${YELLOW}set${NC}" 321 | echo 322 | break 323 | ;; 324 | [Nn]*) 325 | msg "No problem. Try again..." 326 | echo 327 | ;; 328 | *) 329 | warn "Error! Entry must be 'y' or 'n'. Try again..." 330 | echo 331 | ;; 332 | esac 333 | done 334 | 335 | 336 | #---- Test email credentials 337 | section "Sending Test email" 338 | 339 | msg "Sending test email to '${PVE_ROOT_EMAIL}'..." 340 | # DL Swaks 341 | curl http://www.jetmore.org/john/code/swaks/files/swaks-20130209.0/swaks -o swaks 342 | # Set script permissions 343 | chmod +x swaks 344 | # Install perl 345 | apt-get install perl -y 346 | # Run test email 347 | ./swaks --auth --silent 3 \ 348 | --server ${SMTP_SERVER_ADDRESS}:${SMTP_SERVER_PORT} \ 349 | --au ${SMTP_ACC_USERNAME} \ 350 | --ap ${SMTP_ACC_PWD} \ 351 | --to ${PVE_ROOT_EMAIL} \ 352 | --from $(hostname)@$(hostname).$(hostname -d) \ 353 | --h-Subject: "SMTP credential test." \ 354 | --body 'Success! Proxmox awesomness.' 355 | 356 | # Send status 357 | SWAKS_EXIT_CODE=$? 358 | if [ ! "$SWAKS_EXIT_CODE" = 0 ] 359 | then 360 | # Swaks fail 361 | info "Email send status: ${RED}fail${NC} (Swaks error code $SWAKS_EXIT_CODE)" 362 | echo 363 | display_msg1=() 364 | display_msg1=( "The test email could not be sent for various reasons (Swaks error code ${SWAKS_EXIT_CODE}).\n\nAnyway, check your '${PVE_ROOT_EMAIL}' mailbox for our test email in case it was delivered. If the test email doesn't appear in your inbox:\n\n -- check your mailbox spam folder\n -- check your junk folder\n -- whitelist any test email\n -- check your input credentials" ) 365 | else 366 | # Swaks pass 367 | info "Email send status: ${GREEN}pass${NC}" 368 | echo 369 | display_msg1=() 370 | display_msg1=( "The test email has been successfully sent. Delivery speed is determined by your email service provider so be patient (normal delivery is within 1-2 minutes or less).\n\nCheck your '${PVE_ROOT_EMAIL}' mailbox for our test email. If the test email doesn't appear in your inbox:\n\n -- check your mailbox spam folder\n -- check your junk folder\n -- whitelist any test email" ) 371 | fi 372 | display_msg2=() 373 | display_msg2=( "From:$(hostname)@$(hostname).$(hostname -d)" \ 374 | "Subject:SMTP credential test." ) 375 | 376 | msg_box "#### PLEASE READ CAREFULLY - TEST EMAIL #### 377 | 378 | $(printf '%s\n' "${display_msg1[@]}") 379 | 380 | The test email details are: 381 | 382 | $(printf '%s\n' "${display_msg2[@]}" | column -s ":" -t | indent2)" 383 | 384 | # Confirm test email delivery 385 | msg "Confirm test email delivery..." 386 | OPTIONS_VALUES_INPUT=( "TYPE01" "TYPE00" ) 387 | OPTIONS_LABELS_INPUT=( "Yes - I received the test email" \ 388 | "No, Nothing, Zilch - No test email was delivered") 389 | makeselect_input2 390 | singleselect SELECTED "$OPTIONS_STRING" 391 | 392 | if [ "$RESULTS" = 'TYPE01' ] 393 | then 394 | info "SMTP server status: ${GREEN}ok${NC}" 395 | elif [ "$RESULTS" = 'TYPE00' ] 396 | then 397 | # Exit installation 398 | msg "Oops. Something must be wrong with your SMTP account and/or user credentials. Check the following prerequisites and credentials:\n\n$(printf '%s\n' "${display_conditions_msg1[@]}" | indent2)\n\nFix the problem and run our PVE Toolbox SSMTP option. Aborting. Bye..." 399 | echo 400 | return 401 | fi 402 | 403 | #----------------------------------------------------------------------------------- 404 | # Do not edit below this point. 405 | 406 | #---- Configure Postfix SMTP service 407 | 408 | # Create /etc/postfix/sasl_passwd 409 | echo "[${SMTP_SERVER_ADDRESS,,}]:${SMTP_SERVER_PORT} ${SMTP_ACC_USERNAME}:${SMTP_ACC_PWD}" > $POSTFIX_SASL_PWD 410 | # Create HASH 411 | postmap hash:${POSTFIX_SASL_PWD} 412 | # Set file permissions 413 | chmod 600 ${POSTFIX_SASL_PWD} ${POSTFIX_SASL_DB} 414 | 415 | 416 | # Server specific configure Postfix configuration file /etc/postfix/main.cf 417 | if [ "${SMTP_HOST_ID,,}" = 'gmail' ] 418 | then 419 | # Gmail 420 | # Specify SMTP relay host 421 | postconf -e relayhost=[${SMTP_SERVER_ADDRESS,,}]:${SMTP_SERVER_PORT} 422 | # Enable STARTTLS encryption 423 | postconf -e smtp_use_tls=${SMTP_USE_TLS} 424 | # Enable SASL authentication 425 | postconf -e smtp_sasl_auth_enable=yes 426 | # Disallow methods that allow anonymous authentication 427 | postconf -e smtp_sasl_security_options=noanonymous 428 | # Required for authentication to prevent the FROMTO error 429 | postconf -e smtp_sasl_security_options= 430 | # Location of smtp credentials 431 | postconf -e smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd 432 | # Location of CA certificates 433 | postconf -e smtp_tls_CAfile=/etc/ssl/certs/ca-certificates.crt 434 | # Customize From instead of Root 435 | postconf -e smtp_header_checks=pcre:/etc/postfix/smtp_header_checks 436 | # Other 437 | postconf -e smtp_tls_session_cache_database=btree:/var/lib/postfix/smtp_tls_session_cache 438 | postconf -e smtp_tls_session_cache_timeout=3600s 439 | echo 440 | elif [ "${SMTP_HOST_ID,,}" = 'mailgun' ] 441 | then 442 | # Mailgun 443 | # Specify SMTP relay host 444 | postconf -e relayhost=[${SMTP_SERVER_ADDRESS,,}]:${SMTP_SERVER_PORT} 445 | # Enable STARTTLS encryption 446 | postconf -e smtp_use_tls=${SMTP_USE_TLS} 447 | # Enable SASL authentication 448 | postconf -e smtp_sasl_auth_enable=yes 449 | # Disallow methods that allow anonymous authentication 450 | postconf -e smtp_sasl_tls_security_options=noanonymous 451 | # Required for authentication to prevent the FROMTO error 452 | postconf -e smtp_sasl_security_options=noanonymous 453 | # Location of smtp credentials 454 | postconf -e smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd 455 | # Location of CA certificates 456 | postconf -e smtp_tls_CAfile=/etc/ssl/certs/ca-certificates.crt 457 | # Other 458 | postconf -e smtp_tls_session_cache_database=btree:/var/lib/postfix/smtp_tls_session_cache 459 | postconf -e smtp_tls_session_cache_timeout=3600s 460 | echo 461 | elif [ "${SMTP_HOST_ID,,}" = 'custom' ] 462 | then 463 | # Custom 464 | # Specify SMTP relay host 465 | postconf -e relayhost=[${SMTP_SERVER_ADDRESS,,}]:${SMTP_SERVER_PORT} 466 | # Enable STARTTLS encryption 467 | postconf -e smtp_use_tls=${SMTP_USE_TLS} 468 | # Enable SASL authentication 469 | postconf -e smtp_sasl_auth_enable=yes 470 | # Disallow methods that allow anonymous authentication 471 | postconf -e smtp_sasl_tls_security_options=noanonymous 472 | # Required for authentication to prevent the FROMTO error 473 | postconf -e smtp_sasl_security_options= 474 | # Location of smtp credentials 475 | postconf -e smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd 476 | # Location of CA certificates 477 | postconf -e smtp_tls_CAfile=/etc/ssl/certs/ca-certificates.crt 478 | # Other 479 | postconf -e smtp_tls_session_cache_database=btree:/var/lib/postfix/smtp_tls_session_cache 480 | postconf -e smtp_tls_session_cache_timeout=3600s 481 | echo 482 | fi 483 | 484 | # Global (Main) configure Postfix configuration file /etc/postfix/main.cf 485 | postconf -e mynetworks="127.0.0.0/8, ${LOCAL_NET}" 486 | postconf -e inet_interfaces=all 487 | postconf -e smtpd_recipient_restrictions='permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination' 488 | postconf -e smtpd_client_restrictions='permit_mynetworks, reject' 489 | # Stop Spambots - restrict the use of the mail relay to your local network and the SASL-authorized users. 490 | postconf -e smtpd_relay_restrictions='permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination' 491 | 492 | # Enable Postfix Virtual Domain Aliases for PVE CT programs to send email to root/postmaster 493 | # Alias 'vmclient.alias@virtual-alias.domain' is used to send a CC copy of App mail 494 | # to the system administrator. 495 | touch /etc/postfix/virtual || exit 496 | # Check if the line exists in the file 497 | if ! grep -q 'vmclient.alias@virtual-alias.domain postmaster' /etc/postfix/virtual; then 498 | # If the line does not exist, add it to the file 499 | echo 'vmclient.alias@virtual-alias.domain postmaster' >> /etc/postfix/virtual 500 | fi 501 | # Enable 'Virtual Domain Aliases' in Postfix /etc/postfix/main.cf 502 | postconf -e 'virtual_alias_domains = virtual-alias.domain' 503 | postconf -e 'virtual_alias_maps = hash:/etc/postfix/virtual' 504 | # Update Postfix Aliases 505 | postmap /etc/postfix/virtual 506 | 507 | # Customized Email header 508 | echo /^From:.*/ REPLACE From: "$(hostname)-alert" '<'$(echo ${PVE_ROOT_EMAIL} | sed 's/@.*//')@$(hostname).$(hostname -d)'>' > /etc/postfix/smtp_header_checks 509 | postmap /etc/postfix/smtp_header_checks 510 | 511 | # Create check line in /etc/postfix/main.cf 512 | sed -i \ 513 | -e '/^#\?\(\s*ahuacate_smtp\s*=\s*\).*/{s//\11/;:a;n;ba;q}' \ 514 | -e '1i ahuacate_smtp=1' /etc/postfix/main.cf 515 | 516 | # Reload Postfix configuration file /etc/postfix/main.cf 517 | systemctl restart postfix.service 518 | 519 | #---- Finish Line ------------------------------------------------------------------ 520 | 521 | section "Completion Status" 522 | msg "Success. Task complete." 523 | echo 524 | #----------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /src/pve_host_setup_postfix.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ---------------------------------------------------------------------------------- 3 | # Filename: pve_host_setup_postfix.sh 4 | # Description: Source script for PVE Host Postfix setup 5 | # ---------------------------------------------------------------------------------- 6 | 7 | #---- Bash command to run script --------------------------------------------------- 8 | 9 | # bash -c "$(wget -qLO - https://raw.githubusercontent.com/ahuacate/pve-host/main/scripts/pve_host_setup_postfix.sh)" 10 | 11 | #---- Source ----------------------------------------------------------------------- 12 | #---- Dependencies ----------------------------------------------------------------- 13 | 14 | # Check IP 15 | ipvalid () { 16 | # Set up local variables 17 | local ip=${1:-1.2.3.4} 18 | local IFS=.; local -a a=($ip) 19 | 20 | # Start with a regex format test 21 | [[ $ip =~ ^[0-9]+(\.[0-9]+){3}$ ]] || return 1 22 | # Test values of quads 23 | local quad 24 | for quad in {0..3}; do 25 | [[ "${a[$quad]}" -gt 255 ]] && return 1 26 | done 27 | return 0 28 | } 29 | 30 | #---- Static Variables ------------------------------------------------------------- 31 | 32 | # Easy Script Section Header Body Text 33 | SECTION_HEAD='PVE Host Postfix Setup' 34 | 35 | # Check for PVE Hostname mod 36 | if [ -z "${HOSTNAME_FIX+x}" ] 37 | then 38 | PVE_HOSTNAME=$HOSTNAME 39 | fi 40 | 41 | #---- Other Variables -------------------------------------------------------------- 42 | #---- Other Files ------------------------------------------------------------------ 43 | #---- Body ------------------------------------------------------------------------- 44 | 45 | #---- Install and Configure SSMTP Email Alerts 46 | 47 | section "Introduction" 48 | 49 | msg_box "#### PLEASE READ CAREFULLY - POSTFIX & EMAIL ALERTS ####\n 50 | Send email alerts about your PVE host to the systems designated administrator. Be alerted about unwarranted login attempts and other system critical alerts. Proxmox is preinstalled with Postfix SMTP server which we use for sending your PVE nodes critical alerts. 51 | 52 | SMTP is a simple Mail Transfer Agent (MTA) while easy to setup it requires the following prerequisites and credentials: 53 | 54 | -- SMTP SERVER 55 | You require a SMTP server that can receive the emails from your machine and send them to the designated administrator. If you use Gmail SMTP server its best to enable 'App Passwords'. An 'App Password' is a 16-digit passcode that gives an app or device permission to access your Google Account. Or you can use a mailgun.com flex account relay server (Recommended). 56 | 57 | -- REQUIRED SMTP SERVER CREDENTIALS 58 | 1. Designated administrator email address (i.e your working admin email address) 59 | 60 | 2. SMTP server address (i.e smtp.gmail.com or smtp.mailgun.org) 61 | 62 | 3. SMTP server port (i.e gmail port is 587 and mailgun port is 587) 63 | 64 | 4. SMTP server username (i.e MyEmailAddress@gmail.com or postmaster@sandboxa6ac6.mailgun.org) 65 | 66 | 5. SMTP server default password (i.e your Gmail App Password or mailgun SMTP password) 67 | 68 | If you choose to proceed have your SMTP server credentials available. This script will configure your PVE nodes Postfix SMTP server." 69 | echo 70 | while true 71 | do 72 | read -p "Install and configure Postfix and email alerts( Recommended ) [y/n]?: " -n 1 -r YN 73 | echo 74 | case $YN in 75 | [Yy]*) 76 | while true 77 | do 78 | read -p "Do you have your GMail, MailGun or Custom SMTP Server credentials ready [y/n]?: " -n 1 -r YN 79 | echo 80 | case $YN in 81 | [Yy]*) 82 | info "The User has chosen to proceed." 83 | echo 84 | break 2 85 | ;; 86 | [Nn]*) 87 | warn "In the next steps you must have your 16 digit GMail App Password OR MailGun\n OR custom SMTP server credentials ready for input to continue.\nTry again..." 88 | echo 89 | break 90 | ;; 91 | *) 92 | warn "Error! Entry must be 'y' or 'n'. Try again..." 93 | echo 94 | ;; 95 | esac 96 | done 97 | ;; 98 | [Nn]*) 99 | info "You have chosen to skip this step." 100 | echo 101 | exit 0 102 | break 103 | ;; 104 | *) 105 | warn "Error! Entry must be 'y' or 'n'. Try again..." 106 | echo 107 | ;; 108 | esac 109 | done 110 | 111 | 112 | #---- Checking PVE Host Prerequisites 113 | section "Checking Prerequisites" 114 | 115 | # libsasl2-modules for Postfix 116 | if [[ ! $(dpkg -s libsasl2-modules 2> /dev/null) ]] 117 | then 118 | msg "Installing libsasl2-modules..." 119 | apt-get install libsasl2-modules -y 2> /dev/null 120 | info "libsasl2-modules status: ${GREEN}installed${NC}" 121 | fi 122 | 123 | # postfix-pcre for Postfix 124 | if [[ ! $(dpkg -s postfix-pcre 2> /dev/null) ]] 125 | then 126 | msg "Installing postfix-pcre..." 127 | apt-get install postfix-pcre -y 2> /dev/null 128 | info "postfix-pcre status: ${GREEN}installed${NC}" 129 | fi 130 | 131 | # uuencode for Postfix (part of package sharutils) 132 | if [[ ! $(dpkg -s sharutils 2> /dev/null) ]] 133 | then 134 | msg "Installing sharutils (uuencode)..." 135 | apt-get install sharutils -y 2> /dev/null 136 | info "sharutils (uuencode) status: ${GREEN}installed${NC}" 137 | fi 138 | 139 | #---- Setting PVE Postfix SMTP server vars 140 | 141 | while true; do 142 | section "Setting Postfix SMTP variables" 143 | 144 | # VAR for the script 145 | POSTFIX_CONFIG=/etc/postfix/main.cf 146 | POSTFIX_SASL_PWD=/etc/postfix/sasl_passwd 147 | POSTFIX_SASL_DB=/etc/postfix/sasl_passwd.db 148 | 149 | # Set PVE SMTP Server Type 150 | while true 151 | do 152 | TYPE01="${YELLOW}Mailgun${NC} - Configure for a Mailgun SMTP server." 153 | TYPE02="${YELLOW}GMail${NC} - Configure for a GMail SMTP server." 154 | TYPE03="${YELLOW}Other${NC} - Custom SMTP server configuration." 155 | PS3="Select the SMTP server type you use (entering numeric) : " 156 | msg "Available options:" 157 | options=("$TYPE01" "$TYPE02" "$TYPE03") 158 | select menu in "${options[@]}"; do 159 | case $menu in 160 | "$TYPE01") 161 | info "SMTP server is set as: $(echo $menu | awk '{print $1}')" 162 | SMTP_TYPE=mailgun 163 | SMTP_SERVER_ADDRESS="smtp.mailgun.org" 164 | SMTP_SERVER_PORT=587 165 | echo 166 | break 167 | ;; 168 | "$TYPE02") 169 | info "SMTP server is set as: $(echo $menu | awk '{print $1}')" 170 | SMTP_TYPE=gmail 171 | SMTP_SERVER_ADDRESS="smtp.gmail.com" 172 | SMTP_SERVER_PORT=587 173 | echo 174 | break 175 | ;; 176 | "$TYPE03") 177 | SMTP_TYPE=custom 178 | # while true; do 179 | read -p "Enter SMTP Server address (i.e smtp.hello.com): " -e SMTP_SERVER_ADDRESS 180 | read -p "Enter SMTP Server port number: " -e -i 587 SMTP_SERVER_PORT 181 | read -p "Accept SMTP server address: ${WHITE}${SMTP_SERVER_ADDRESS}${NC}:${WHITE}${SMTP_SERVER_PORT}${NC} [y/n]?: " -n 1 -r 182 | echo 183 | if [[ $REPLY =~ ^[Yy]$ ]]; then 184 | msg "Accepted. Now validating address." 185 | echo 186 | break 187 | else 188 | echo 189 | msg "Try again..." 190 | continue 191 | fi 192 | # done 193 | ;; 194 | *) warn "Invalid entry. Try again.." >&2 195 | esac 196 | done 197 | 198 | 199 | # Validating SMTP Server Address 200 | ip="$SMTP_SERVER_ADDRESS" 201 | if ipvalid "$ip"; then 202 | msg "Validating SMTP IPv4 address..." 203 | if [ "$(ping -s 1 -c 2 "$(echo "$SMTP_SERVER_ADDRESS")" >/dev/null; echo $?)" = 0 ] || [ $(nc -z -w 5 ${SMTP_SERVER_ADDRESS} ${SMTP_SERVER_PORT} 2>/dev/null; echo $?) = 0 ]; then 204 | info "SMTP server address is set as: ${YELLOW}${SMTP_SERVER_ADDRESS}${NC}:${YELLOW}${SMTP_SERVER_PORT}${NC}" 205 | echo 206 | break 207 | elif [ $(ping -s 1 -c 2 "$(echo "${SMTP_SERVER_ADDRESS}")" >/dev/null; echo $?) != 0 ] || [ $(nc -z -w 5 ${SMTP_SERVER_ADDRESS} ${SMTP_SERVER_PORT} 2>/dev/null; echo $?) != 0 ]; then 208 | warn "There are problems with your input:\n1. Your IP address meets the IPv4 standard, BUT\n2. Your IP address $(echo "${SMTP_SERVER_ADDRESS}") is not reachable.\nCheck your SMTP server IP address, port number and firewall settings.\nTry again..." 209 | echo 210 | fi 211 | else 212 | msg "Validating SMTP url address..." 213 | if [ $(ping -s 1 -c 2 "$(echo "${SMTP_SERVER_ADDRESS}")" >/dev/null; echo $?) = 0 ] || [ $(nc -z -w 5 ${SMTP_SERVER_ADDRESS} ${SMTP_SERVER_PORT} 2>/dev/null; echo $?) = 0 ]; then 214 | info "SMTP server address is set as: ${YELLOW}${SMTP_SERVER_ADDRESS}${NC}:${YELLOW}${SMTP_SERVER_PORT}${NC}" 215 | echo 216 | break 217 | elif [ $(ping -s 1 -c 2 "$(echo "${SMTP_SERVER_ADDRESS}")" >/dev/null; echo $?) != 0 ] || [ $(nc -z -w 5 ${SMTP_SERVER_ADDRESS} ${SMTP_SERVER_PORT} 2>/dev/null; echo $?) != 0 ]; then 218 | warn "There are problems with your input:\n1. The URL $(echo "${SMTP_SERVER_ADDRESS}") is not reachable.\nCheck your SMTP server URL address, port number and firewall settings.\nTry again..." 219 | echo 220 | fi 221 | fi 222 | done 223 | 224 | # Set SMTP Credentials 225 | while true 226 | do 227 | read -p "Enter your ${SMTP_TYPE,,} SMTP server login username: " -e SMTP_USERNAME 228 | read -p "Enter your ${SMTP_TYPE,,} SMTP server password: " -e SMTP_PWD 229 | echo 230 | info "Your ${SMTP_TYPE,,} SMTP server credentials are:\nUsername: ${YELLOW}${SMTP_USERNAME}${NC}\nPassword: ${YELLOW}${SMTP_PWD}${NC}" 231 | read -p "Accept ${SMTP_TYPE,,} SMTP server credentials: [y/n]? " -n 1 -r 232 | echo 233 | if [[ $REPLY =~ ^[Yy]$ ]]; then 234 | info "SMTP server login credentials are set : ${GREEN}OK${NC}" 235 | echo 236 | break 237 | else 238 | msg "Try again..." 239 | echo 240 | fi 241 | done 242 | 243 | # Set PVE root administrator email address 244 | PVE_ROOT_EMAIL_OLD=$(pveum user list | awk -F " │ " '$1 ~ /root@pam/' | awk -F " │ " '{ print $3 }') 245 | msg "Validate your PVE root or system email address..." 246 | msg "Your PVE root user email address is ${WHITE}$PVE_ROOT_EMAIL_OLD${NC}. This email address is set to send all PVE system notifications and alerts. In the next steps you have the option to accept or change your default PVE root email address." 247 | read -p "Accept PVE root email address ${WHITE}$PVE_ROOT_EMAIL_OLD${NC} [y/n]?: " -n 1 -r 248 | echo 249 | if [[ $REPLY =~ ^[Yy]$ ]] 250 | then 251 | PVE_ROOT_EMAIL="$PVE_ROOT_EMAIL_OLD" 252 | info "PVE root email address remains unchanged: ${YELLOW}$PVE_ROOT_EMAIL${NC}" 253 | echo 254 | else 255 | while true 256 | do 257 | read -p "Enter a valid PVE root email address: " -e -i $PVE_ROOT_EMAIL_OLD PVE_ROOT_EMAIL 258 | echo 259 | if [[ "$PVE_ROOT_EMAIL" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$ ]] 260 | then 261 | pveum user modify root@pam -email ${PVE_ROOT_EMAIL} 262 | msg "Email address $PVE_ROOT_EMAIL is valid." 263 | info "PVE root email address is set: ${YELLOW}$PVE_ROOT_EMAIL${NC}" 264 | echo 265 | break 266 | else 267 | msg "Email address $PVE_ROOT_EMAIL is invalid." 268 | warn "There are problems with your input:\n1. Email address $(echo "$PVE_ROOT_EMAIL") does not pass the validity check.\nTry again..." 269 | echo 270 | fi 271 | done 272 | fi 273 | 274 | 275 | #---- Configuring PVE Postfix 276 | section "Configuring PVE Postfix" 277 | 278 | # Creating /etc/postfix/sasl_passwd 279 | msg "Creating /etc/postfix/sasl_passwd..." 280 | echo [${SMTP_SERVER_ADDRESS,,}]:${SMTP_SERVER_PORT} ${SMTP_USERNAME}:${SMTP_PWD} > ${POSTFIX_SASL_PWD} 281 | # Generate a .db file 282 | if [ -f "${POSTFIX_SASL_DB}" ] 283 | then 284 | rm ${POSTFIX_SASL_DB} >/dev/null 285 | fi 286 | postmap hash:${POSTFIX_SASL_PWD} 287 | chmod 600 ${POSTFIX_SASL_PWD} ${POSTFIX_SASL_DB} 288 | 289 | # Modify Postfix configuration file /etc/postfix/main.cf 290 | if [ "$SMTP_TYPE" = 'gmail' ] 291 | then 292 | msg "Configuring Postfix for a ${SMTP_TYPE^} server..." 293 | # Gmail 294 | # Specify SMTP relay host 295 | postconf -e relayhost=[${SMTP_SERVER_ADDRESS,,}]:${SMTP_SERVER_PORT} 296 | # Enable STARTTLS encryption 297 | postconf -e smtp_use_tls=yes 298 | # Enable SASL authentication 299 | postconf -e smtp_sasl_auth_enable=yes 300 | # Disallow methods that allow anonymous authentication 301 | postconf -e smtp_sasl_security_options=noanonymous 302 | # Required for authentication to prevent the FROMTO error 303 | postconf -e smtp_sasl_security_options= 304 | # Location of smtp credentials 305 | postconf -e smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd 306 | # Location of CA certificates 307 | postconf -e smtp_tls_CAfile=/etc/ssl/certs/ca-certificates.crt 308 | # Stop Spambots - restrict the use of the mail relay to your local network and the SASL-authorized users that you defined earlier. 309 | postconf -e smtpd_relay_restrictions='permit_mynetworks permit_sasl_authenticated defer_unauth_destination' 310 | # Customize From instead of Root 311 | postconf -e smtp_header_checks=pcre:/etc/postfix/smtp_header_checks 312 | # Other 313 | postconf -e smtp_tls_session_cache_database=btree:/var/lib/postfix/smtp_tls_session_cache 314 | postconf -e smtp_tls_session_cache_timeout=3600s 315 | echo 316 | elif [ "$SMTP_TYPE" = 'mailgun' ] 317 | then 318 | msg "Configuring Postfix for a ${SMTP_TYPE^} server..." 319 | # Mailgun 320 | # Specify SMTP relay host 321 | postconf -e relayhost=[${SMTP_SERVER_ADDRESS,,}]:${SMTP_SERVER_PORT} 322 | # Enable STARTTLS encryption 323 | postconf -e smtp_use_tls=yes 324 | # Enable SASL authentication 325 | postconf -e smtp_sasl_auth_enable=yes 326 | # Disallow methods that allow anonymous authentication 327 | postconf -e smtp_sasl_tls_security_options=noanonymous 328 | # Required for authentication to prevent the FROMTO error 329 | postconf -e smtp_sasl_security_options=noanonymous 330 | # Location of smtp credentials 331 | postconf -e smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd 332 | # Location of CA certificates 333 | postconf -e smtp_tls_CAfile=/etc/ssl/certs/ca-certificates.crt 334 | # Stop Spambots - restrict the use of the mail relay to your local network and the SASL-authorized users that you defined earlier. 335 | postconf -e smtpd_relay_restrictions='permit_mynetworks permit_sasl_authenticated defer_unauth_destination' 336 | # Other 337 | postconf -e smtp_tls_session_cache_database=btree:/var/lib/postfix/smtp_tls_session_cache 338 | postconf -e smtp_tls_session_cache_timeout=3600s 339 | echo 340 | elif [ "$SMTP_TYPE" = 'custom' ] 341 | then 342 | msg "Configuring Postfix for a ${SMTP_TYPE^} server..." 343 | # Custom 344 | # Specify SMTP relay host 345 | postconf -e relayhost=[${SMTP_SERVER_ADDRESS,,}]:${SMTP_SERVER_PORT} 346 | # Enable STARTTLS encryption 347 | read -p "Does your SMTP server support TLS encryption [y/n]?: " -n 1 -r 348 | echo 349 | if [[ "$REPLY" =~ ^[Yy]$ ]] 350 | then 351 | postconf -e smtp_use_tls=yes 352 | info "Postfix SMTP TLS support: ${YELLOW}Enabled${NC}" 353 | echo 354 | else 355 | postconf -e smtp_use_tls= 356 | info "Postfix SMTP TLS support: ${YELLOW}Disabled${NC}" 357 | echo 358 | fi 359 | # Enable SASL authentication 360 | postconf -e smtp_sasl_auth_enable=yes 361 | # Disallow methods that allow anonymous authentication 362 | postconf -e smtp_sasl_tls_security_options=noanonymous 363 | # Required for authentication to prevent the FROMTO error 364 | postconf -e smtp_sasl_security_options= 365 | # Location of smtp credentials 366 | postconf -e smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd 367 | # Location of CA certificates 368 | postconf -e smtp_tls_CAfile=/etc/ssl/certs/ca-certificates.crt 369 | # Stop Spambots - restrict the use of the mail relay to your local network and the SASL-authorized users that you defined earlier. 370 | postconf -e smtpd_relay_restrictions='permit_mynetworks permit_sasl_authenticated defer_unauth_destination' 371 | # Other 372 | postconf -e smtp_tls_session_cache_database=btree:/var/lib/postfix/smtp_tls_session_cache 373 | postconf -e smtp_tls_session_cache_timeout=3600s 374 | echo 375 | fi 376 | 377 | # Customised Email header 378 | echo /^From:.*/ REPLACE From: "${PVE_HOSTNAME,,}-alert" '<'$(echo "$PVE_ROOT_EMAIL" | sed 's/@.*//')@localdomain'>' > /etc/postfix/smtp_header_checks 379 | postmap /etc/postfix/smtp_header_checks 380 | 381 | # Reload Postfix configuration file /etc/postfix/main.cf 382 | service postfix reload 383 | 384 | # Testing Postfix SMTP Server 385 | echo 386 | msg_box "#### PLEASE READ CAREFULLY - SMTP & EMAIL TESTING ####\n 387 | In the next step you have the option to test your SMTP settings by sending a test email to your PVE root or system email address. If you choose to send a test email then: 388 | 389 | -- Check your mailbox to validate your SMTP settings work. 390 | 391 | -- Check the mailbox spam folder and whitelist any test email found there. 392 | 393 | -- If you do not receive a test email then something is wrong with your configuration inputs. You have the option to re-enter your credentials and try again. 394 | 395 | If you choose NOT to send a test email then: 396 | 397 | -- SMTP settings are configured but not tested. 398 | 399 | -- All changes must be made manually by the PVE system administrator. (i.e edit /etc/postfix/main.cf )" 400 | echo 401 | read -p "Do you want to send a test email to $PVE_ROOT_EMAIL [y/n]?: " -n 1 -r 402 | echo 403 | if [[ "$REPLY" =~ ^[Yy]$ ]] 404 | then 405 | echo 406 | msg "Sending test email to ${PVE_ROOT_EMAIL}..." 407 | echo -e "\n To: ${PVE_ROOT_EMAIL}\n From: "${PVE_HOSTNAME,,}-alert"\n Subject: Test Postfix\n\n Hello World.\n\n Your PVE host Postfix SMTP mail server works.\n Congratulations.\n" 408 | echo -e "Hello World.\n\nYour PVE host Postfix SMTP mail server works.\nCongratulations." | mail -s "Test Postfix" ${PVE_ROOT_EMAIL} 409 | echo 410 | info "Test email sent to: ${WHITE}${PVE_ROOT_EMAIL}${NC}" 411 | echo 412 | msg "Next check for the test email in your mailbox ( ${WHITE}${PVE_ROOT_EMAIL}${NC} ).\nIt will be recieved ${WHITE}From: ${PVE_HOSTNAME,,}-alert${NC}. If you cannot find it\ncheck your Spam, All Mail and whitelist the test email." 413 | echo 414 | read -p "Did you receive a PVE test email message in your mailbox [y/n]?: " -n 1 -r 415 | echo 416 | if [[ "$REPLY" =~ ^[Yy]$ ]] 417 | then 418 | info "Success. Your PVE Postfix SMTP server is working." 419 | # Remove old Ahuacate Check line 420 | if [[ $(cat /etc/postfix/main.cf | grep "### Ahuacate_Check=.*") ]] 421 | then 422 | sed -i '/### Ahuacate_Check=.*/d' /etc/postfix/main.cf 423 | fi 424 | # Add Ahuacate Check line=0 425 | echo -e "\n### Ahuacate_Check=0 #### This is a Github Ahuacate script check line only.\n" >> /etc/postfix/main.cf 426 | break 427 | else 428 | read -p "Do you want to re-input your Postfix SMTP credentials (again) [y/n]?: " -n 1 -r 429 | echo 430 | if [[ "$REPLY" =~ ^[Yy]$ ]] 431 | then 432 | info "You have chosen to re-input your credentials. Try again." 433 | sleep 2 434 | echo 435 | continue 436 | else 437 | info "You have chosen to accept your inputs despite them not working.\nSkipping the validation step." 438 | # Remove old Ahuacate Check line 439 | if [[ $(cat /etc/postfix/main.cf | grep "### Ahuacate_Check=.*") ]] 440 | then 441 | sed -i '/### Ahuacate_Check=.*/d' /etc/postfix/main.cf 442 | fi 443 | # Add Ahuacate Check line=1 444 | echo -e "\n### Ahuacate_Check=1 #### This is a Github Ahuacate script check line only.\n" >> /etc/postfix/main.cf 445 | break 446 | fi 447 | fi 448 | else 449 | info "You have chosen not to test your Postfix SMTP email server. Skipping the\nvalidation step. SMTP settings are configured but not tested. All changes must\nbe made manually by the PVE system administrator." 450 | break 451 | fi 452 | done 453 | echo 454 | 455 | # Activate E-Mail Notification & Email Alerts 456 | # zfs-zed SW 457 | if [[ ! $(dpkg -s zfs-zed) ]] 458 | then 459 | msg "Installing zfs-zed..." 460 | apt-get install -y zfs-zed >/dev/null 461 | info "zfs-zed status: ${GREEN}active${NC} (running)" 462 | fi 463 | sed -i 's|#ZED_EMAIL_ADDR.*|ZED_EMAIL_ADDR="root"|g' /etc/zfs/zed.d/zed.rc 464 | 465 | #---- Finish Line ------------------------------------------------------------------ 466 | 467 | section "Completion Status." 468 | msg "Success. Task complete." 469 | echo 470 | #----------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /src/pve_host_add_cifs_mounts.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ---------------------------------------------------------------------------------- 3 | # Filename: pve_host_add_cifs_mounts.sh 4 | # Description: Source script for creating PVE Host CIFS Mounts 5 | # ---------------------------------------------------------------------------------- 6 | 7 | #---- Bash command to run script --------------------------------------------------- 8 | #---- Source ----------------------------------------------------------------------- 9 | #---- Dependencies ----------------------------------------------------------------- 10 | 11 | # nbtscan 12 | if [ ! $(dpkg -s nbtscan >/dev/null 2>&1; echo $?) = 0 ]; then 13 | apt-get install nbtscan -yqq 14 | fi 15 | 16 | #---- Static Variables ------------------------------------------------------------- 17 | 18 | # Easy Script Section Header Body Text 19 | SECTION_HEAD='PVESM CIFS Storage Mounts' 20 | 21 | # Check for PVE Hostname mod 22 | if [ -z "${HOSTNAME_FIX+x}" ]; then 23 | PVE_HOSTNAME=$HOSTNAME 24 | fi 25 | 26 | #---- Other Variables -------------------------------------------------------------- 27 | #---- Other Files ------------------------------------------------------------------ 28 | #---- Body ------------------------------------------------------------------------- 29 | 30 | #---- Introduction 31 | section "Introduction" 32 | 33 | msg_box "#### PLEASE READ CAREFULLY - NAS CIFS SERVER EXPORTS ####\n 34 | NAS server's SMB/CIFS properties must be configured so your Proxmox VE (PVE) CIFS backend (client) can automatically mount the SMB/CIFS shares. The SMB/CIFS server should support the SMB3 protocol (PVE default). SMB1 is NOT supported. Your NAS server should support: 35 | 36 | SMB VERSION 37 | -- Minimum SMB v2.02 (PVE default is v3.00 and above) 38 | -- NAS SMB shares accessible to all PVE nodes (default PVE nodes are 'nas-01' to 'nas-05' or '192.168.1.101' to '192.168.1.105') 39 | 40 | The user must input valid NAS user SMB credentials (username and password). The login user must have appropriate permissions (e.g., privatelab) to access, read, write, and execute the SMB server shares you wish to mount. If you have multiple SMB/CIFS servers and/or SMB login username accounts, run this script again for each SMB/CIFS server IP and SMB login username. 41 | 42 | The next steps require user input. You can accept the default values by pressing ENTER, or you can overwrite the default values by typing in your own value and pressing ENTER to continue to the next step." 43 | echo 44 | while true 45 | do 46 | read -p "Create PVE CIFS storage mounts [y/n]?: " -n 1 -r YN 47 | echo 48 | case $YN in 49 | [Yy]*) 50 | info "The User has chosen to proceed." 51 | echo 52 | break 53 | ;; 54 | [Nn]*) 55 | info "The User has chosen to skip this step." 56 | return 57 | ;; 58 | *) 59 | warn "Error! Entry must be 'y' or 'n'. Try again..." 60 | echo 61 | ;; 62 | esac 63 | done 64 | 65 | 66 | #---- Checking PVE Host Prerequisites 67 | section "Check Prerequisites" 68 | 69 | # nbtscan SW 70 | if [[ ! $(dpkg -s nbtscan) ]]; then 71 | msg "Installing nbtscan..." 72 | apt-get install -y nbtscan > /dev/null 73 | info "nbtscan status: ${GREEN}installed${NC}" 74 | echo 75 | fi 76 | 77 | 78 | #---- Checking NFS Server exports 79 | section "Select CIFS server" 80 | 81 | while true 82 | do 83 | read -p "Enter your NAS Server IPv4/6 address OR hostname: " -e -i nas-01 NAS_ID 84 | msg "Checking for a working CIFS NAS server..." 85 | if [ "$(valid_ip "$NAS_ID" > /dev/null 2>&1; echo $?)" = 0 ]; then 86 | # Perform IP ping check 87 | if [ "$(ping -s 1 -c 2 "$(echo "$NAS_ID")" > /dev/null; echo $?)" = 0 ]; then 88 | NAS_IP="$NAS_ID" 89 | info "Ping '$NAS_ID' status: ${YELLOW}pass${NC}" 90 | info "NAS IP status: ${YELLOW}pass${NC} ( $NAS_IP )" 91 | else 92 | NAS_IP="" 93 | info "Ping '$NAS_ID' status: ${RED}fail${NC}" 94 | info "NAS IP status: ${RED}fail${NC}" 95 | fi 96 | 97 | # Perform hostname check 98 | if [[ $(nbtscan -q $NAS_ID | awk '{print $2}') ]]; then 99 | NAS_HOSTNAME="$(nbtscan -q $NAS_ID | awk '{print $2}')" 100 | info "NAS hostname status: ${YELLOW}pass${NC} ( $NAS_HOSTNAME )" 101 | else 102 | NAS_HOSTNAME="" 103 | info "NAS hostname status: ${RED}fail${NC} ( cannot map hostname )" 104 | fi 105 | elif [[ "$NAS_ID" =~ ${hostname_regex} ]]; then 106 | # Perform hostname ping check 107 | if [ "$(ping -s 1 -c 2 "$(echo "$NAS_ID")" > /dev/null; echo $?)" = 0 ]; then 108 | NAS_HOSTNAME="$NAS_ID" 109 | info "Ping '$NAS_ID' status: ${YELLOW}pass${NC}" 110 | info "NAS hostname status: ${YELLOW}pass${NC} ( $NAS_HOSTNAME )" 111 | else 112 | NAS_HOSTNAME="" 113 | info "Ping '$NAS_ID' status: ${RED}fail${NC}" 114 | info "NAS hostname status: ${RED}fail${NC}" 115 | fi 116 | 117 | # Perform IP lookup using hostname 118 | if [[ $(nslookup "${NAS_ID}" | awk '/^Address: / { print $2 }') ]]; then 119 | NAS_IP="$(nslookup "$NAS_ID" | awk '/^Address: / { print $2 }')" 120 | info "NAS IP lookup status: ${YELLOW}pass${NC} ( $NAS_IP )" 121 | else 122 | NAS_IP="" 123 | info "NAS IP lookup status: ${RED}fail${NC} ( cannot map IP address )" 124 | fi 125 | fi 126 | 127 | # CIFS IP server status ('0' enabled, '1' disabled) 128 | if [[ $(nc -z ${NAS_IP} 139 && echo up) ]] && [ -n "${NAS_IP}" ]; then 129 | CIFS_EXPORT_IP=0 # '0' enabled, '1' disabled 130 | else 131 | CIFS_EXPORT_IP=1 # '0' enabled, '1' disabled 132 | fi 133 | 134 | # CIFS DHCP server status ('0' enabled, '1' disabled) 135 | if [[ $(nc -z ${NAS_HOSTNAME} 139 && echo up) ]] && [ -n "${NAS_HOSTNAME}" ]; then 136 | CIFS_EXPORT_DHCP=0 # '0' enabled, '1' disabled 137 | else 138 | CIFS_EXPORT_DHCP=1 # '0' enabled, '1' disabled 139 | fi 140 | 141 | # Check 142 | if [ "$CIFS_EXPORT_DHCP" = 0 ] || [ "$CIFS_EXPORT_IP" = 0 ]; then 143 | break 144 | else 145 | warn "There are problems with your input: 146 | 1. The IP address meets the IPv4 standard, BUT 147 | 2. The IP address $(echo "$NAS_IP") is not reachable by ping. 148 | Try again..." 149 | fi 150 | echo 151 | done 152 | 153 | # Set SMB version 154 | msg "Confirming NAS SMB version..." 155 | 156 | # Define the minimum SMB version required 157 | SMB_VER_MIN='2.02' 158 | # Run the nmap command and extract the highest SMB protocol version 159 | SMB_VER_SERVER=$(nmap --script smb-protocols ${NAS_IP} | grep \| | sed 's/[^0-9]*//' | sed '/^$/d' | sort -n | tail -1) 160 | # Check if SMB_VER_SERVER is not empty 161 | if [ -n "$SMB_VER_SERVER" ]; then 162 | # Compare the obtained SMB version with the minimum required version 163 | if [[ ${SMB_VER_SERVER} > ${SMB_VER_MIN} ]]; then 164 | NAS_SMB_VER="$SMB_VER_SERVER" 165 | MAN_SET_SMB_VER=1 166 | info "NAS SMB Version is set: ${YELLOW}SMB${NAS_SMB_VER}${NC}" 167 | else 168 | MAN_SET_SMB_VER=0 169 | fi 170 | else 171 | MAN_SET_SMB_VER=0 172 | info "Failed to determine the SMB version from the NAS." 173 | fi 174 | 175 | if [ "$MAN_SET_SMB_VER" -eq 0 ]; then 176 | msg_box "#### PLEASE READ CAREFULLY - SMB VERSION ####\n 177 | There are issues with determining the NAS server SMB protocol dialect (version). Proxmox requires a minimum SMB 2.02v. Check your NAS server SMB version support. If a firewall is blocking the SMB version broadcast then manually select the NAS SMB version." 178 | OPTIONS_VALUES_INPUT=( "TYPE01" "TYPE02" "TYPE03" "TYPE04" "TYPE05" "TYPE00") 179 | OPTIONS_LABELS_INPUT=( "SMB 2.0" "SMB 2.1" "SMB 3.0" "SMB 3.02" "SMB 3.11 and above" "No idea. Need to upgrade NAS SMB. Exit this installer." ) 180 | makeselect_input2 181 | singleselect SELECTED "$OPTIONS_STRING" 182 | # Manually set 183 | if [ "$(echo "${RESULTS[@]}")" = TYPE01 ]; then 184 | NAS_SMB_VER='2.0' 185 | elif [ "$(echo "${RESULTS[@]}")" = TYPE02 ]; then 186 | NAS_SMB_VER='2.0' 187 | elif [ "$(echo "${RESULTS[@]}")" = TYPE03 ]; then 188 | NAS_SMB_VER='3.0' 189 | elif [ "$(echo "${RESULTS[@]}")" = TYPE04 ]; then 190 | NAS_SMB_VER='3.0' 191 | elif [ "$(echo "${RESULTS[@]}")" = TYPE05 ]; then 192 | NAS_SMB_VER='3.0' 193 | elif [ "$(echo "${RESULTS[@]}")" = TYPE00 ]; then 194 | msg "Fix, upgrade or find your NAS SMB protocol dialect and try again. Exiting this script..." 195 | echo 196 | return 197 | fi 198 | fi 199 | 200 | #---- Select CIFS mount protocol (IP or hostname) 201 | if [ "$CIFS_EXPORT_DHCP" -eq 0 ] && [ "$CIFS_EXPORT_IP" -eq 0 ]; then 202 | msg_box "#### PLEASE READ CAREFULLY - NAS CIFS SERVER EXPORTS BY PROTOCOL ####\n\nNAS CIFS exports can be mounted using either the NAS IP address or NAS hostname protocol.\n\nSelect your preferred NAS CIFS export protocol. Hostname protocol is recommended." 203 | echo 204 | OPTIONS_VALUES_INPUT=( "TYPE01" "TYPE02" "TYPE00") 205 | OPTIONS_LABELS_INPUT=( "Hostname - CIFS by hostname '${NAS_HOSTNAME}' (Recommended)" "IP address - CIFS by static IP '${NAS_IP}'" "None. Return to the Toolbox" ) 206 | makeselect_input2 207 | singleselect SELECTED "$OPTIONS_STRING" 208 | 209 | # Set the CIFS protocol from menu 210 | if [ "$RESULTS" = 'TYPE01' ]; then 211 | # Set CIFS by hostname 212 | NAS_ID="$NAS_HOSTNAME" 213 | info "NAS CIFS export mount protocol set: ${YELLOW}$NAS_ID${NC} (by hostname)" 214 | elif [ "$RESULTS" = 'TYPE02' ]; then 215 | # Set CIFS by IP 216 | NAS_ID="$NAS_IP" 217 | info "NAS CIFS export mount protocol set: ${YELLOW}$NAS_ID${NC} (by IP)" 218 | elif [ "$RESULTS" = 'TYPE00' ]; then 219 | return 220 | fi 221 | elif [ "$CIFS_EXPORT_DHCP" -eq 0 ] && [ "$CIFS_EXPORT_IP" -eq 1 ]; then 222 | # Set CIFS by hostname 223 | NAS_ID="$NAS_HOSTNAME" 224 | info "NAS CIFS export mount protocol set: ${YELLOW}$NAS_ID${NC} (by hostname)" 225 | elif [ "$CIFS_EXPORT_DHCP" -eq 1 ] && [ "$CIFS_EXPORT_IP" -eq 0 ]; then 226 | # Set CIFS by hostname 227 | NAS_ID="$NAS_IP" 228 | info "NAS CIFS export mount protocol set: ${YELLOW}$NAS_ID${NC} (by IP)" 229 | fi 230 | echo 231 | 232 | # SMB/CIFS Server Credentials 233 | msg_box "#### PLEASE READ CAREFULLY - SMB/CIFS SERVER CREDENTIALS ####\n 234 | Your NAS SMB/CIFS Server shares are likely to be password protected. To create PVE SMB/CIFS backend storage pools we require your NAS SMB login credentials. The login user must have suitable permissions (i.e privatelab:rwx) to access, read, write and execute to the SMB server shares you wish to mount. 235 | 236 | If you have more than one SMB/CIFS Server and/or SMB login user account then run this script again for each SMB/CIFS Server IP or SMB username. 237 | 238 | If your SMB/CIFS Server is password protected then you will need to input your NAS SMB login username and password in the next steps." 239 | echo 240 | while true 241 | do 242 | read -p "Do you require SMB login credentials for '${NAS_HOSTNAME^^}' [y/n]?: " -n 1 -r YN 243 | echo 244 | case $YN in 245 | [Yy]*) 246 | SMB_CREDENTIALS=0 247 | # Enter SMB Server password 248 | while true; do 249 | read -p "Enter SMB Server login username : " SMB_USERNAME 250 | echo 251 | read -p "Enter Password: " SMB_PASSWORD 252 | echo 253 | read -p "Enter Password (again): " SMB_PASSWORD2 254 | echo 255 | # Test SMB connection 256 | if [ "$SMB_PASSWORD" != "$SMB_PASSWORD2" ]; then 257 | warn "Passwords do not match. Please try again." 258 | echo 259 | elif [ ! "$(pvesm scan cifs $NAS_ID --username $SMB_USERNAME --password $SMB_PASSWORD &> /dev/null; echo $?)" -eq 0 ]; then 260 | # Fail msg 261 | FAIL_MSG="The user name credentials are not valid.\nTry again..." 262 | warn "$FAIL_MSG" 263 | echo 264 | elif [ "$(pvesm scan cifs $NAS_ID --username $SMB_USERNAME --password $SMB_PASSWORD &> /dev/null; echo $?)" -eq 0 ]; then 265 | info "SMB server login credentials are set: ${YELLOW}$SMB_USERNAME${NC} ( username )" 266 | echo 267 | break 2 268 | fi 269 | done 270 | ;; 271 | [Nn]*) 272 | SMB_CREDENTIALS=1 273 | SMB_USERNAME="" 274 | SMB_PASSWORD="" 275 | if [ ! "$(pvesm scan cifs $NAS_ID --username $SMB_USERNAME --password $SMB_PASSWORD &> /dev/null; echo $?)" -eq 0 ]; then 276 | # Fail msg 277 | FAIL_MSG="User name credentials appear to be required for the NAS SMB/CIFS Server.\nTry again..." 278 | warn "$FAIL_MSG" 279 | echo 280 | else 281 | info "SMB server login credentials are set: ${YELLOW}Not Required${NC}" 282 | echo 283 | break 2 284 | fi 285 | ;; 286 | *) 287 | warn "Error! Entry must be 'y' or 'n'. Try again..." 288 | echo 289 | ;; 290 | esac 291 | done 292 | 293 | 294 | # Manually set NAS hostname (required because nbtscan failed to get the NAS hostname using the NAS IP ) 295 | if [ -z ${NAS_HOSTNAME} ]; then 296 | msg "For unknown reasons we could not determine the hostname the NAS server '${NAS_IP}'. The user must manually enter the NAS hostname at the prompt." 297 | while true; do 298 | read -p "Enter your NAS CIFS Server '${NAS_IP}' hostname: " -e -i $(nslookup ${NAS_IP} | awk 'sub(/.*name =/,""){print $1}' | sed 's/\..*//') NAS_HOSTNAME_VAR 299 | if [[ "$NAS_HOSTNAME_VAR" =~ ${hostname_regex} ]]; then 300 | NAS_HOSTNAME="$NAS_HOSTNAME_VAR" 301 | info "NAS hostname set: ${YELLOW}$NAS_HOSTNAME${NC}" 302 | echo 303 | break 304 | else 305 | # Fail msg 306 | FAIL_MSG="The hostname is not valid. A valid hostname is when all of the following constraints are satisfied:\n 307 | -- it contains only lowercase characters. 308 | -- it may include numerics, hyphens (-) and periods (.) but not start or end with them. 309 | -- it doesn't contain any other special characters [!#$&%*+_]. 310 | -- it doesn't contain any white space.\n 311 | Try again..." 312 | warn "${FAIL_MSG}" 313 | echo 314 | fi 315 | done 316 | fi 317 | 318 | 319 | #---- Create CIFS mount pairs 320 | section "Create PVE Storage Mounts" 321 | 322 | # Get CIFS NAS Server export list 323 | mapfile -t cifs_server_LIST <<< $(pvesm scan cifs $NAS_ID --username $SMB_USERNAME --password $SMB_PASSWORD | awk '{ print $1 }' | sort | uniq | sed "/.*\/backup$/d" | sed '/^backup/d' | sed 's/proxmox$/proxmox\/backup/g' | sed 's/[[:blank:]]*$//' | sed '/^$/d') # Removing backup dir, editing /src/proxmox/'backup' 324 | # Create required pvesm list 325 | mapfile -t pvesm_req_LIST <<< $(cat $SHARED_DIR/src/pve_host_mount_list | sed '/^#/d' | awk -F':' '$3 == "0" { print $1 }' | awk '{ print tolower ($1) }' | sed '/^$/d' | sed 's/[[:blank:]]*$//' | sed '/^$/d') 326 | 327 | 328 | # Match cifs exports vs required match list 329 | # Here we match our default list pf PVESM mounts "${pvesm_req_LIST[@]}" against your SMB/CIFS Server exports "${cifs_server_LIST[@]}", removing any existing matching PVE NFS/CIF mounts to avoid conflicts. 330 | # 1=src:2=pvesm name:3=media type:4=status (0 existing, 1 required,):5=format(nfs,cifs) 331 | msg "Creating a list of CIFS Server '${NAS_ID}' exports and performing match (be patient, might take a while)..." 332 | unset match_LIST 333 | while IFS= read -r line 334 | do 335 | if [ "$(printf '%s\n' "${cifs_server_LIST[@]}" | grep -s "\.*${line}$" > /dev/null; echo $?)" -eq 0 ]; then 336 | match_LIST+=( "$(printf '%s\n' "${cifs_server_LIST[@]}" | grep -s "\.*${line}$"):$(echo "${NAS_HOSTNAME,,}-${line}":${line}:$(if [[ $(pvesm status | grep -E 'nfs|cifs' | tr '[:upper:]' '[:lower:]' | grep "^${NAS_HOSTNAME,,}-${line}") ]]; then pvesm status | grep -E 'nfs|cifs' | tr '[:upper:]' '[:lower:]' | grep "^${NAS_HOSTNAME,,}-${line}" | awk '{ print "0:"$2 }'; else echo "1:"; fi))" ) 337 | fi 338 | done < <( printf '%s\n' "${pvesm_req_LIST[@]}" ) 339 | 340 | while IFS= read -r line 341 | do 342 | if [ ! "$(printf '%s\n' "${match_LIST[@]}" | grep -s "^${line}" > /dev/null; echo $?)" -eq 0 ]; then 343 | match_LIST+=( "${line}::::" ) 344 | fi 345 | done < <( printf '%s\n' "${cifs_server_LIST[@]}" ) 346 | 347 | # Auto select and label exports 348 | if [ "$(printf '%s\n' "${match_LIST[@]}" | awk -F':' '{OFS=FS} { if (($4 == 0 || $4 == 1)) print $0 }' | wc -l)" = ${#pvesm_req_LIST[@]} ]; then 349 | # Auto selection and labelling of exports 350 | msg_box "#### AUTOMATIC PVE STORAGE MOUNT MATCHING ####\n\nWe have discovered and matched all the required PVE storage mounts. Any conflicting or existing mount points are excluded. Only mounts labeled 'required' will be created. This should work 'out-of-the-box'.\n\n$(printf '%s\n' "${match_LIST[@]}" | awk -F':' '{OFS=FS} { if ($4 == 0) print $1,"<<",$2,$5} { if ($4 == 1) print $1,"<<",$2,"required"}' | column -s ":" -t -N "SOURCE INPUT, ,PVESM LABEL,MOUNT STATUS" | indent2)\n\nAccept the auto match list by typing 'y' at the next prompt. Or manually select and match each PVE mount point(s) you want by entering 'n' at the next prompt." 351 | echo 352 | while true 353 | do 354 | read -p "Accept the auto matched pairing ( Recommended for our custom NAS builds ) [y/n]?: " -n 1 -r YN 355 | echo 356 | case $YN in 357 | [Yy]*) 358 | ES_LIST=0 359 | input_LIST=( $(printf '%s\n' "${match_LIST[@]}" | awk -F':' '{OFS=FS} { if ($4 == 1) print $1, $3}') ) 360 | info "The User has accepted the matched pairing." 361 | echo 362 | break 363 | ;; 364 | [Nn]*) 365 | ES_LIST=1 366 | info "The User has chosen to skip this option." 367 | break 368 | ;; 369 | *) 370 | warn "Error! Entry must be 'y' or 'n'. Try again..." 371 | echo 372 | ;; 373 | esac 374 | done 375 | else 376 | ES_LIST=1 377 | fi 378 | 379 | # Manual selection and labelling of exports 380 | if [ "$ES_LIST" -eq 1 ]; then 381 | # Create required manual lists 382 | unset options_values_input_LIST 383 | unset options_labels_input_LIST 384 | while IFS=: read -r type desc 385 | do 386 | if [ "$(printf '%s\n' "${match_LIST[@]}" | awk -F':' -v pvesm_id="${NAS_HOSTNAME,,}-${type}" '{OFS=FS} { if ($2=pvesm_id && $4 == 0) print $3 }' | sed '/^$/d' | grep "${type,,}" > /dev/null; echo $?)" != 0 ]; then 387 | options_values_input_LIST+=( "${type,,}" ) 388 | options_labels_input_LIST+=( "${type} - ${desc}" ) 389 | fi 390 | done < <( cat ${SHARED_DIR}/src/pve_host_mount_list | sed '/^#/d' | awk -F':' '{OFS=FS} $3 == "0" { print $1,$2 }' | sed 's/[[:blank:]]*$//' | sed '/^$/d' ) 391 | 392 | # Prepare required input arrays for func matchselect 393 | mapfile -t OPTIONS_VALUES_INPUT <<< $(printf '%s\n' "${options_values_input_LIST[@]}") 394 | mapfile -t OPTIONS_LABELS_INPUT <<< $(printf '%s\n' "${options_labels_input_LIST[@]}") 395 | SRC_VALUES_INPUT=( $(printf '%s\n' "${match_LIST[@]}" | awk -F':' '{OFS=FS} { if (($4 == "" || $4 == 1)) print $1 }') ) 396 | 397 | while true 398 | do 399 | msg_box "#### MANUAL PVE STORAGE MOUNT MATCHING ####\n\nWe have discovered ${#SRC_VALUES_INPUT[@]}x NAS exports available for PVE storage mounts. All conflicting or existing mount points are excluded.\n\nExisting PVE '${NAS_HOSTNAME^^}' storage mounts are:\n\n$(printf '%s\n' "${match_LIST[@]}" | awk -F':' '{OFS=FS} { if ($4 == 0) print $1,"<<",$2,$5}' | column -s ":" -t -N "SOURCE INPUT, ,PVESM NAME,MOUNT STATUS" | indent2)\n\nManual matching is required for the following:\n\n$(printf '%s\n' "${match_LIST[@]}" | awk -F':' '{OFS=FS} { if ($4 == 1 ) print $1,"<<",$3} { if ($4 == "") print $1,"","-"}' | column -s ":" -t -N "SOURCE INPUT, ,SUGGESTED MATCH TYPE" | indent2)\n\nTo ignore a NAS share export select:\n\n -- Ignore this match\n\nTo finish the task select (after matching all the required NAS exports):\n\n -- Exit/Finished - Nothing more to match" 400 | echo 401 | 402 | # Run func matchselect 403 | matchselect SELECTED 404 | 405 | # Print results 406 | printf '%s\n' "${PRINT_RESULTS[@]}" | awk -F':' '{OFS=FS} { print $1,">>",$2}' | column -s ":" -t -N "SOURCE INPUT, ,SELECTED PAIR DESCRIPTION" | indent2 407 | echo 408 | 409 | # Confirm selection 410 | read -p "Accept the matched pairing [y/n]?: " -n 1 -r YN 411 | echo 412 | case $YN in 413 | [Yy]*) 414 | info "The User has accepted the matched pairing." 415 | echo 416 | # Create match list 417 | input_LIST=( $(printf '%s\n' "${RESULTS[@]}") ) 418 | break 419 | ;; 420 | [Nn]*) 421 | msg "No problem. Try again..." 422 | echo 423 | ;; 424 | *) 425 | warn "Error! Entry must be 'y' or 'n'. Try again..." 426 | echo 427 | ;; 428 | esac 429 | done 430 | fi 431 | 432 | 433 | #---- Create PVE Storage Mounts 434 | if [ ${#input_LIST[@]} -ge 1 ]; then 435 | while IFS=':' read -r SHARE TYPE 436 | do 437 | PVESM_LABEL="${NAS_HOSTNAME,,}-${TYPE}" # Set PVESM share label name 438 | if [ "${PVESM_LABEL}" = "$(echo ${NAS_HOSTNAME,,}-backup)" ]; then 439 | msg "Creating PVE storage mount..." 440 | pvesm add cifs $PVESM_LABEL --server $NAS_ID --path /mnt/pve/$PVESM_LABEL --share $SHARE --content backup --maxfiles 3 --smbversion $NAS_SMB_VER $(if [ "$SMB_CREDENTIALS" = 0 ]; then echo "--username $SMB_USERNAME --password $SMB_PASSWORD";fi) 441 | info "PVE storage mount created: ${YELLOW}$PVESM_LABEL${NC}\n (${NAS_ID}:${SHARE})" 442 | echo 443 | else 444 | msg "Creating PVE storage mount..." 445 | pvesm add cifs $PVESM_LABEL --server $NAS_ID --path /mnt/pve/$PVESM_LABEL --share $SHARE --content images --smbversion $NAS_SMB_VER $(if [ "$SMB_CREDENTIALS" = 0 ]; then echo "--username $SMB_USERNAME --password $SMB_PASSWORD";fi) 446 | info "PVE storage mount created: ${YELLOW}$PVESM_LABEL${NC}\n (${NAS_ID}:${SHARE})" 447 | echo 448 | fi 449 | done < <( printf '%s\n' "${input_LIST[@]}" ) 450 | else 451 | msg "It seems you already have all the required CIFS PVE storage mounts. No additional PVE storage mounts will ne created." 452 | echo 453 | fi 454 | #---- Finish Line ------------------------------------------------------------------ 455 | 456 | section "Completion Status." 457 | msg "Success. Task complete." 458 | echo 459 | #----------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

PVE Host Setup

2 | 3 | This guide aims to help you configure your Proxmox hosts to support our suite of LXC and VM applications, allowing for the creation of a dependable Proxmox host. 4 | 5 | It includes step-by-step instructions and an Easy Script Toolbox that can automate much of the work. Moreover, the "PVE Basic" add-on in the Easy Script Toolbox should be executed on all PVE hosts (both primary and secondary). This add-on contains essential PVE Container UID & GID mapping required by all Ahuacate CTs and VMs, ensuring permission rights for bind-mounted shared data are resolved. 6 | 7 |

Features

8 | 9 | * Step-by-step Proxmox installation instructions 10 | * Configure PVE host networking, hostnames and DNS 11 | * Configure network switches and VLANs 12 | 13 | Easy Script Toolbox menu includes the following tasks. 14 | 15 | * PVE Basic - required by all PVE hosts (mandatory/required) 16 | - Update Proxmox 17 | - Check and set Proxmox subscription key (free or enterprise) 18 | - Install nbtscan SW 19 | - Adjust sysctl parameters 20 | - Perform PVE container (CT) mapping 21 | * PVESM NFS Storage - add additional NFS PVE storage mounts 22 | * PVESM SMB/CIFS Storage - add additional SMB/CIFS storage mounts 23 | * PVE Hostname Updater - change the hostname of a node 24 | * Fail2Ban Installer 25 | * SSMTP Email Installer 26 | * PVE Host Grub boot delay - set the grub boot delay 27 | * PVE Intel Amd iGPU LXC support - allow LXC access to CPU iGPU 28 | * PVE CT updater - mass update all CT OS 29 | 30 |

Prerequisites

31 | 32 | Read about our system-wide requirements before proceeding any further. 33 | 34 | **Network Prerequisites** 35 | Network prerequisites are: 36 | - [x] Layer 2/3 Network Switches 37 | - [x] Network Gateway is `XXX.XXX.XXX.5` ( *default is 192.168.1.5* ) 38 | - [x] Network DHCP server is `XXX.XXX.XXX.5` ( *default is 192.168.1.5* ) 39 | - [x] Internet access for the PVE host 40 | - [x] File server or NAS (i.e NAS-01) . Our default NAS IPv4 address is `XXX.XXX.XXX.10` ( *default is 192.168.1.10* ) 41 | - [x] File server or NAS configured with network shares, either CIFS or NFS, as per these guides: 42 | - OEM (Synology) or Linux NAS [build guide](https://github.com/ahuacate/nas-hardmetal) 43 | - PVE hosted NAS [build guide](https://github.com/ahuacate/pve-nas) 44 | 45 | **Other Prerequisites** 46 | Optional information required running specific Easy Script Toolbox add-ons. 47 | 48 | - [ ] SMB/NAS CIFS user account credentials as per these (Only if your adding PVE storage using NAS SMB/CIFS storage mounts) 49 | - [ ] Optional PVE Postfix 50 | - Email account credentials 51 | - MailGun account credentials 52 | 53 |

Local DNS Records

54 | 55 | Before proceeding, we strongly advise that you familiarize yourself with network Local DNS and the importance of having a PiHole server. To learn more, click here. 56 | 57 | It is essential to set your network's Local Domain or Search domain. For residential and small networks, we recommend using only top-level domain (spTLD) names because they cannot be resolved across the internet. Routers and DNS servers understand that ARPA requests they do not recognize should not be forwarded onto the public internet. It is best to select one of the following names: local, home.arpa, localdomain, or lan only. We strongly advise against using made-up names. 58 | 59 |

Easy Scripts

60 | 61 | Easy Scripts simplify the process of installing and configuring preset configurations. To use them, all you have to do is copy and paste the Easy Script command into your terminal window, hit Enter, and follow the prompts and terminal instructions. 62 | 63 | Please note that all Easy Scripts assume that your network is VLAN and DHCP IPv4 ready. If this is not the case, you can decline the Easy Script prompt to accept our default settings. Simply enter 'n' to proceed without the default settings. After declining the default settings, you can configure all your PVE container variables. 64 | 65 | However, before proceeding, we highly recommend that you read our guide to fully understand the input requirements. 66 | 67 |

Easy Script Toolbox

68 | 69 | Before running the Easy Script Toolbox first configure your Proxmox hosts networking (Read-on). 70 | 71 | SSH login to your PVE host `ssh root@IP_address`. Then run the following command. 72 | 73 | ```bash 74 | bash -c "$(wget -qLO - https://raw.githubusercontent.com/ahuacate/pve-host/main/pve_host_toolbox.sh)" 75 | ``` 76 | 77 |
78 | 79 |

Table of Contents

80 | 81 | 82 | 83 | - [1. Prepare your Hardware](#1-prepare-your-hardware) 84 | - [1.1. PVE OS Installation](#11-pve-os-installation) 85 | - [1.1.1. PVE OS Install](#111-pve-os-install) 86 | - [1.1.2. Proxmox VE OS Install - Final Steps](#112-proxmox-ve-os-install---final-steps) 87 | - [2. Prepare Proxmox network interfaces](#2-prepare-proxmox-network-interfaces) 88 | - [2.1. PVE Host - single NIC](#21-pve-host---single-nic) 89 | - [2.2. PVE Host - Dual NIC (PfSense support)](#22-pve-host---dual-nic-pfsense-support) 90 | - [3. Prepare network switch](#3-prepare-network-switch) 91 | - [3.1. Configure UniFi LAN networks](#31-configure-unifi-lan-networks) 92 | - [3.1.1. Configure UniFi default network](#311-configure-unifi-default-network) 93 | - [3.1.2. Configure UniFi WAN network (VLAN2)](#312-configure-unifi-wan-network-vlan2) 94 | - [3.2. Assign UniFi switch ports](#32-assign-unifi-switch-ports) 95 | - [3.2.1. Assign switch port to PVE-LAN](#321-assign-switch-port-to-pve-lan) 96 | - [3.2.2. Assign switch port to WAN VLAN2](#322-assign-switch-port-to-wan-vlan2) 97 | - [4. File Server (NAS)](#4-file-server-nas) 98 | - [4.1. NAS Appliance](#41-nas-appliance) 99 | - [4.2. PVE NAS](#42-pve-nas) 100 | - [5. PVE Easy Script Toolbox](#5-pve-easy-script-toolbox) 101 | - [5.1. Run our PVE Host Toolbox Easy Script](#51-run-our-pve-host-toolbox-easy-script) 102 | - [5.2. PVE Basic](#52-pve-basic) 103 | - [5.3. PVESM NFS Storage](#53-pvesm-nfs-storage) 104 | - [5.4. PVESM SMB/CIFS Storage](#54-pvesm-smbcifs-storage) 105 | - [5.5. PVE Hostname Updater](#55-pve-hostname-updater) 106 | - [5.6. Fail2Ban Installer](#56-fail2ban-installer) 107 | - [5.7. SMTP Server Credentials (Recommended)](#57-smtp-server-credentials-recommended) 108 | - [5.8. PVE CT updater](#58-pve-ct-updater) 109 | - [5.9. PVE Host Grub boot delay (recommended)](#59-pve-host-grub-boot-delay-recommended) 110 | - [5.10. PVE Intel Amd iGPU LXC support - allow LXC access to CPU iGPU](#510-pve-intel-amd-igpu-lxc-support---allow-lxc-access-to-cpu-igpu) 111 | - [6. GitHub "ttneck" helper scripts](#6-github-ttneck-helper-scripts) 112 | - [7. Create a PVE Cluster](#7-create-a-pve-cluster) 113 | - [7.1. Create a Cluster](#71-create-a-cluster) 114 | - [7.2. Join the other Nodes to the New Cluster](#72-join-the-other-nodes-to-the-new-cluster) 115 | - [7.3. How to delete an existing cluster on a node](#73-how-to-delete-an-existing-cluster-on-a-node) 116 | - [8. Fixes, patches & Troubleshooting](#8-fixes-patches--troubleshooting) 117 | - [8.1. Proxmox VZdump backup write errors to NAS](#81-proxmox-vzdump-backup-write-errors-to-nas) 118 | 119 | 120 |
121 | 122 | # 1. Prepare your Hardware 123 | 124 | Proxmox installs on any x86 hardware with a few conditions. The hardware should have Intel NIC devices and commercial grade SSD or NVMe drives. 125 | 126 | Your installation options are determined by your hardware specifications and requirements. 127 | 128 | PVE hosts require 1x or 2x ethernet NIC adapters and single boot disk device. A standard PVE host can be installed as your primary or secondary PVE host for creating a PVE cluster. A minimum of two secondary PVE hosts is required to form a cluster quorum in the event a PVE host fails. 129 | * 1x ethernet NIC - This is a standard generic build. Not suitable for hosting a pfSense VM. 130 | * 2x or more ethernet NIC - Suitable for hosting a pfSense VM. 131 | 132 | ## 1.1. PVE OS Installation 133 | Go to the Proxmox website and [download](https://www.proxmox.com/en/downloads) the latest ISO and burn it to a USB stick. Instructions are [here](https://pve.proxmox.com/wiki/Prepare_Installation_Media). 134 | 135 | In this guide, we refer to SCSi and SATA (Serial ATA) controller devices designated disk names such as `sda`, `sdb`, `sdc` and so on, a generic Linux naming convention, as `sdx` only. Ideally `sda` (and `sdb`) should be allocated as the Proxmox OS SSD device. 136 | 137 | Some main boards may not show disk devices as `sda/sdb/sdc` because the SSD is not installed on a SCSi or SATA controller. For example, NVMe drives show as /dev/nvme0(n1..). It's most important to check your hardware device schematics and note which device type is designated to which type of hard drive (SSD) you have installed. 138 | 139 | ### 1.1.1. PVE OS Install 140 | Boot from the Proxmox installation USB stick and configure Proxmox VE as follows: 141 | 142 | **Proxmox Virtualization Environment (PVE)** - At this stage you must select your PVE OS installation drives, Raid type and partition sizes. Click 'options' and complete as follows: 143 | 144 | | Option | Value | Notes | 145 | |-------------------------------|-----------------------|----------------------------------------| 146 | | Filesystem - 1x SSD | `ext4 or zfs (RAID0)` | Ext4 is fine. | 147 | | Filesystem - 2x SSD | `ext4 or zfs (RAID1)` | Ext4 is fine. | 148 | | **Disk Setup - SATA** | | | 149 | | Harddisk 0 | /dev/sdx | | 150 | | Harddisk 1 | /dev/sdx | | 151 | | **Disk Setup - PCIe NVMe** | | | 152 | | Harddisk 0 | /dev/nvmeXn1 | | 153 | | Harddisk 1 | /dev/nvmeXn1 | | 154 | | **Advanced Options** | | | 155 | | ashift | `12` | 4K sector size. For 8K sectors use 13. | 156 | | compress | `lz4` | | 157 | | checksum | `on` | | 158 | | copies | `1` | | 159 | | SSD size - 240GB (or smaller) | `220` | Over-provisioning is recommended. | 160 | 161 | 162 | ### 1.1.2. Proxmox VE OS Install - Final Steps 163 | 164 | The final step is to configure a network device. If you have multiple onboard ethernet LAN NIC devices, 10GbE ethernet or a multi-port Intel PCIe LAN Card installed, you must choose *one single device only* to configure at this stage. 165 | 166 | The selected device will be your LAN. If you have 10GbE ethernet, on a primary or secondary PVE host, then always select and configure the 10GbE device. 167 | 168 | If your PVE host has only 1GbE LAN NICs then you must choose the first ethernet device ID of either an onboard mainboard Intel NIC or if available the first device of your installed Intel PCIe LAN Card. Your decision is based on how many valid (Intel brand) ethernet devices are available ignoring all other brands if you can. For example, if you have an Intel I350-T4 PCIe x4 LAN Card 4x Port installed and 2x onboard **Realtek** NICs, always ignore the 2x **Realtek** devices from all selection criteria. Try to use only Intel NICs whenever possible. 169 | 170 | Here's a table to help you understand your options: 171 | 172 | || Port 1 | Port 2 | Port 3 | Port 4 173 | | :--- | :--- | :--- | :--- | :--- 174 | | **Example 1** 175 | | 10GbE SFP+ | ✅ 176 | | Onboard x2 (Realtek) | ❌ | ❌ 177 | | Intel PCIe LAN Card 4x Ports | ☑ | ☑ | ☑ | ☑ 178 | | **Example 2** 179 | | Onboard x1 (Intel) | ✅ 180 | | Intel PCIe LAN Card 2x Ports | ☑ | ☑ 181 | | **Example 3** 182 | | Onboard x2 (Intel) | ✅ | ☑ 183 | | Intel PCIe LAN Card 2x Ports | ☑ | ☑ 184 | | **Example 4** 185 | | Onboard x1 (Realtek) | ❌ 186 | | Intel PCIe LAN Card 4x Ports | ✅ | ☑ | ☑ | ☑ 187 | 188 | Primary PVE hosts must be assigned hostname `pve-01.local`, IPv4 address of `192.168.1.101` or at least denoted by xxx.xxx.xxx.`101`. 189 | 190 | If your want to create a pfSense OpenVPN Gateway for your network clients then you must have a minimum of 2x Intel Ethernet LAN NICs available in all PVE hosts. 191 | 192 | The remaining steps in configuring PVE are self-explanatory. Configure each PVE host as follows. 193 | 194 | | Option | Primary Host | Secondary Host | Secondary Host | Notes 195 | |:--- |:--- |:--- |:--- |:--- 196 | | Country | Input your Country | Input your Country | Input your Country 197 | | Timezone | Select | Select | Select 198 | | Keymap | `en-us` | `en-us` | `en-us` | 199 | | Password | Enter your new password | Enter your new password | Enter your new password | Same user credentials on all nodes. 200 | | E-mail | Enter your Email | Enter your Email | Enter a your Email | Use a valid email address. It needs to be valid for PVE Postfix alerts and other email services to work. If you don't want to enter a valid email type mail@example.com. 201 | | Management interface | Leave Default | Leave Default | Leave Default 202 | | Hostname | `pve-01.local` | `pve-02.local` | `pve-03.local` | Note the naming convention and use of 'local'. We recommend only top-level domain (spTLD) names for residential and small networks names because they cannot be resolved across the internet. Routers and DNS servers know, in theory, not to forward ARPA requests they do not understand onto the public internet. It is best to choose one of our listed names: local, home.arpa, localdomain or lan only. Do NOT use made-up names. 203 | | IP Address | `192.168.1.101` | `192.168.1.102` | `192.168.1.103` | Note the IP number assignments - XXX.XXX.XXX.101 > .102 > .103 > | 204 | | Netmask | `255.255.255.0` | `255.255.255.0` | `255.255.255.0` 205 | | Gateway | `192.168.1.5` | `192.168.1.5` | `192.168.1.5` | UniFi UGS/UDM or router. 206 | | DNS Server 1 | `192.168.1.6` | `192.168.1.6` | `192.168.1.6` | Set to use PiHole. 207 | | DNS Server 2 | `192.168.1.5` | `192.168.1.5` | `192.168.1.5`| Set to use your router static IP. 208 | 209 |
210 | 211 | # 2. Prepare Proxmox network interfaces 212 | 213 | Your LAN network switches must be L2/L3 compatible to support VLANs. 214 | 215 | If you have extra NICs available you may consider using 802.3ad Dynamic link aggregation on these hosts too to increase bandwidth. The internet is your information source about LAGs. When considering LAGs the network switch appliance side will use 802.3ad Dynamic link aggregation (802.3ad)(LACP) so your switch must be 802.3ad compliant. 216 | 217 | It's important the PVE Linux Bridge, Bond and VLAN naming convention is adhered to. This naming convention is used in all our Proxmox builds and Easy Scripts. 218 | 219 | Linux Network Device names vary because they are determined by the host's mainboard (here we use *enp1s0-enp01s1*). 220 | 221 | In the example below we use standard 1GBe NICs. This example is made for hosting a pfSense VM (vmbr2). 222 | 223 | ![alt text](./images/Proxmox-network2.png) 224 | 225 | In the example below we use LAGs for illustration purposes only. This example is also made for hosting a pfSense VM. 226 | 227 | ![alt text](./images/Proxmox-network.png) 228 | 229 | ## 2.1. PVE Host - single NIC 230 | 231 | Configure a PVE Linux Bridge `vmbr0` using a single 1GbE, 10GbE, or a PVE Linux Bond. 232 | 233 | The input name `vmbr0` is critical. 234 | 235 | | Linux Bridge || 236 | | :--- | :--- 237 | | Name | vmbr0 238 | | IPv4/CIDR | `192.168.1.101/24` 239 | | Gateway (IPv4) | `192.168.1.5` 240 | | IPv6/CIDR | Leave blank 241 | | Gateway (IPv6) | Leave blank 242 | | Autostart | `☑` 243 | | VLAN aware | `☑` 244 | | Bridge ports | Input your NIC name (i.e enp1s0) 245 | | Comment | `Default LAN` 246 | | MTU | 1500 247 | 248 | ## 2.2. PVE Host - Dual NIC (PfSense support) 249 | 250 | PVE pfSense VM requires 2x ethernet NICs. A LAN and a WAN (VPN-egress). 251 | 252 | Configure a PVE Linux Bridge `vmbr0` and `vmbr2` using a single 1GbE, 10GbE, or a PVE Linux Bond. The fastest NIC should be assigned to `vmbr0`. 253 | 254 | The input names `vmbr0` abd `vmbr2` are critical. 255 | 256 | | Linux Bridge ||| 257 | | :--- | :--- | :--- 258 | | Name | `vmbr0` | `vmbr2` 259 | | IPv4/CIDR | `192.168.1.101/24` | Leave blank 260 | | Gateway (IPv4) | `192.168.1.5` | Leave blank 261 | | IPv6/CIDR | Leave blank | Leave blank 262 | | Gateway (IPv6) | Leave blank | Leave blank 263 | | Autostart | `☑` | `☑` 264 | | VLAN aware | `☑` | `☑` 265 | | Bridge ports | Input your NIC name (i.e enp1s0) | Input your NIC name (i.e enp1s1) 266 | | Comment | `Default LAN` | `VPN-egress` 267 | | MTU | 1500 | 1500 268 | 269 |
270 | 271 | # 3. Prepare network switch 272 | 273 | These instructions are based on an UniFi US-24 port switch. Just transpose the settings to whatever brand of Layer 2/3 Switch you use. 274 | 275 | ## 3.1. Configure UniFi LAN networks 276 | We use VLANs to separate networks for easier management and to apply security policies. 277 | 278 | ![alt text](./images/UniFi-Networks.png) 279 | 280 | ### 3.1.1. Configure UniFi default network 281 | The first step is to edit your default LAN network configuration. 282 | 283 | Navigate using the UniFi controller web interface to `Settings` > `Networks` > `Create New Network` and complete as follows. 284 | 285 | | Description | Default 286 | | :--- | :--- 287 | | Network Name |`Default` 288 | | GatewayIP/Subnet | `☐` Auto Scale Network 289 | || `192.168.1.5/24` 290 | | **Advanced Configuration** | `manual` 291 | | Network Type | `☑` Standard `☐` Guest 292 | | IGMP Snooping | `☑` Enable 293 | | Multicast DNS | `☐` Enable 294 | | Network Group | `LAN` 295 | | **DHCP** 296 | | DHCP Mode | `DHCP Server` 297 | | DHCP Range | `192.168.1.150`-`192.168.1.250` 298 | | DHCP Service Management 299 | | DHCP DNS Server | `☑` Enabled 300 | || `192.168.1.6` (Pi-Hole) 301 | || `1.1.1.1` 302 | | DHCP Default Gateway | `☑` Auto 303 | | DHCP Lease Time | `86400` 304 | | Domain Name | `local` 305 | | **IPv6** 306 | | IPv6 Interface Type | `☑` None `☐` Static `☐` Prefix 307 | 308 | 309 | ### 3.1.2. Configure UniFi WAN network (VLAN2) 310 | Create a dedicated VLAN2 network for pfSense WAN only (labeled VPN-egress). All pfSense VPN traffic will exit pfSense on WAN VLAN2. For added security, we assign VLAN2 Guest status. 311 | 312 | Navigate using the UniFi controller web interface to `Settings` > `Networks` > `Create New Network` and complete as follows. 313 | 314 | | Description | VPN-egress 315 | | :--- | :--- 316 | | Network Name |`VPN-egress` 317 | | GatewayIP/Subnet | `☐` Auto Scale Network 318 | || `192.168.2.5/28` 319 | | **Advanced Configuration** | `manual` 320 | | VLAN ID | `2` 321 | | Network Type | `☐` Standard `☑` Guest 322 | | IGMP Snooping | `☑` Enable 323 | | Multicast DNS | `☐` Enable 324 | | Network Group | `LAN` 325 | | **DHCP** 326 | | DHCP Mode | `DHCP Server` 327 | | DHCP Range | `192.168.2.1`-`192.168.2.14` 328 | | **IPv6** 329 | | IPv6 Interface Type | `☑` None `☐` Static `☐` Prefix 330 | 331 | ![alt text](./images/UniFi-Network-VPN.egress.png) 332 | 333 | ## 3.2. Assign UniFi switch ports 334 | In UniFi you must assign the 2x physical LAN cables connecting your UniFi switch to your Proxmox host or pfSense device with a UniFi Port Profile. Both LAN and WAN connections must be identified. For cable management I dedicate switch ports 1-6 to my Proxmox cluster. 335 | 336 | ### 3.2.1. Assign switch port to PVE-LAN 337 | Navigate using the UniFi controller web interface to `Devices` > `Select switch device` > `Port Management` and then select the switch port which is physically connected and assigned to Proxmox host or pfSense as LAN. 338 | 339 | My Proxmox and pfSense "LAN" is a port aggregate of UniFi NIC ports 1 & 2 which is not a requirement. 340 | 341 | What important is the UniFi `Port Profile` of your selected NIC port must be assigned as `All`. 342 | 343 | ![alt text](./images/UniFi-Devices-Port_Management-pvelan.png) 344 | 345 | ### 3.2.2. Assign switch port to WAN VLAN2 346 | Navigate using the UniFi controller web interface to `Devices` > `Select switch device` > `Port Management` and then select the switch port which is physically connected and assigned to pfSense as WAN (VPN-egress). 347 | 348 | My pfSense "WAN" is a port aggregate of UniFi NIC ports 3 & 4 which is not a requirement. 349 | 350 | What important is the UniFi `Port Profile` of your selected NIC port must be assigned as `VPN-egress`. 351 | 352 | ![alt text](./images/UniFi-Devices-Port_Management-vpnegress.png) 353 | 354 |
355 | 356 | # 4. File Server (NAS) 357 | 358 | A network-accessible file server (NAS) that supports NFS and/or CIFS sharing protocol is required. Proxmox provides storage to VMs by creating a CIFS or NFS backend storage pool by mounting your NAS export shares points. 359 | 360 | Your PVE host must be allowed to mount all CIFS or NFS shares automatically. 361 | 362 | ## 4.1. NAS Appliance 363 | A NAS of any brand or type (Synology, OMV, QNap, FreeNAS, Windows or Linux server). The NAS must support SMB3, NFSv4 and ACL services. Our NAS default IPv4 address is 192.168.1.10. 364 | 365 | ## 4.2. PVE NAS 366 | A PVE based NAS uses a ZFS or LVM Raid backend storage pool hosted on a Proxmox host (preferred pve-01). 367 | 368 | Frontend management and NAS services are by a our own PVE Ubuntu CT (hostname label NAS-01). NAS-01 fully supports SMB3, NFSv4.1 and ACL services. A detailed guide with build options is available [here](https://github.com/ahuacate/pve-nas). 369 | 370 |
371 | 372 | # 5. PVE Easy Script Toolbox 373 | 374 | Our Easy Script Toolbox will configure your PVE hosts to support Ahuacate CTs and VMs. Each Toolbox script will create, modify and change system settings including: 375 | 376 | 1. PVE Basic - required by all PVE hosts (mandatory / required) 377 | - Update Proxmox 378 | - Check and set Proxmox subscription key (free or enterprise) 379 | - Install nbtscan SW 380 | - Adjust sysctl parameters 381 | - Set PVE container (CT) mapping 382 | - Set '/etc/vzdump.conf' variable to `tmpdir: /tmp` 383 | 3. PVESM NFS Storage - add additional NFS PVE storage mounts 384 | 4. PVESM SMB/CIFS Storage - add additional SMB/CIFS storage mounts 385 | 5. PVE Hostname Updater - change the hostname of a node 386 | 6. Fail2Ban Installer 387 | 7. SMTP Email Setup 388 | 8. PVE CT updater 389 | 390 | 391 | The available options vary between PVE primary and secondary hosts. 392 | 393 | ## 5.1. Run our PVE Host Toolbox Easy Script 394 | 395 | To execute SSH into your PVE host ( i.e. `ssh root@192.168.1.101` ) or use the Proxmox web interface CLI shell `pve-0x` > `>_ Shell` and cut & paste the following into the CLI terminal window and press ENTER: 396 | 397 | ```bash 398 | bash -c "$(wget -qLO - https://raw.githubusercontent.com/ahuacate/pve-host/main/pve_host_setup_toolbox.sh)" 399 | ``` 400 | ## 5.2. PVE Basic 401 | 402 | You must run this script on all primary and secondary hosts before deployment. 403 | 404 | ## 5.3. PVESM NFS Storage 405 | 406 | Add NFS storage mounts which are required by our suite of CT and VM applications. You must have the following NAS exports including linux share permissions as shown [here](https://github.com/ahuacate/common/blob/main/nas/src/nas_basefolderlist). 407 | 408 | Read about your [HARDMETAL NAS](https://github.com/ahuacate/nas-hardmetal) and [PVE-NAS](https://github.com/ahuacate/pve-nas) build and configure options. 409 | 410 | You may combine NFS and CIFS storage mounts on your PVE primary host. I use NFS only. 411 | 412 | ## 5.4. PVESM SMB/CIFS Storage 413 | 414 | Add SMB/CIFS storage mounts which are required by our suite of CT and VM applications. You must have the following NAS exports including linux share permissions as shown [here](https://github.com/ahuacate/common/blob/main/nas/src/nas_basefolderlist). 415 | 416 | Read about your [HARDMETAL NAS](https://github.com/ahuacate/nas-hardmetal) and [PVE-NAS](https://github.com/ahuacate/pve-nas) build and configure options. 417 | 418 | You may combine NFS and CIFS storage mounts on your PVE primary host. I use NFS only. 419 | 420 | ## 5.5. PVE Hostname Updater 421 | 422 | Change or edit your PVE node hostname. 423 | 424 | ## 5.6. Fail2Ban Installer 425 | 426 | Fail2Ban is an intrusion prevention software framework that protects computer servers from brute-force attacks. 427 | 428 | Most commonly this is used to block selected IP addresses that may belong to hosts that are trying to breach the systems security. It can ban any host IP address that makes too many login attempts or performs any other unwanted action within a time frame defined by the PVE administrator. 429 | 430 | Our default Fail2ban configuration sets the following rule sets: 431 | 432 | * **PVE WEBGUI HTTP(S) ACCESS** 433 | Maximum HTTP retry 3 attempts. 434 | PVE HTTP(S) ban time is 1 hour. 435 | If your PVE Postfix SMTP server is configured then Fail2ban will send send email alerts. 436 | 437 | * **PVE EMAIL ALERTS** 438 | Send email alerts of banned login attempts. (requires working PVE Postfix SMTP server) 439 | 440 | ## 5.7. SMTP Server Credentials (Recommended) 441 | You have the option to configure a Postfix SMTP Email server. SMTP is Mail Transfer Agent (MTA) used to send email alerts about your machines like details about new user accounts, unwarranted login attempts, and system critical alerts to the system's designated administrator. The SMTP server is required for any PVE CT or VM which requires a email service. 442 | 443 | You will be asked for the credentials of your SMTP Server. You can use Gmail, GoDaddy, AWS, Microsoft or any SMTP server credentials (i.e address, port, username and password, encryption type etc. 444 | 445 | But we recommend you create an account at mailgun.com to relay your NAS system emails to your designated administrator. With MailGun you are not potentially exposing your private email server credentials held within a text file on your PVE host. This is an added layer of security. 446 | 447 | ## 5.8. PVE CT updater 448 | 449 | The script performs an OS update on all PVE CTs. All CTs are returned to their former run state in the background before moving on to CT. 450 | 451 | ## 5.9. PVE Host Grub boot delay (recommended) 452 | 453 | All your PVE hosts depend on your NAS and other network devices such as routers, DNS, DHCP servers and LAN switches. In the event of a power outage, we need your PVE hosts to be the last online. 454 | 455 | Our solution is to edit the 'grub timeout' parameter and apply a delay of 300 seconds. 456 | 457 | Your Proxmox server now waits 5 minutes before starting the OS, by which time your NAS and network devices (i.e switches, DNS servers) should be operational. There will be no more manual restarting of virtual machines following a power outage. 458 | 459 | ## 5.10. PVE Intel Amd iGPU LXC support - allow LXC access to CPU iGPU 460 | Setup Intel or AMD iGPU video render to support your LXC. Required by Jellyfin and Tdarr or any LXC performing video rendering. 461 | 462 |
463 | 464 | # 6. GitHub "ttneck" helper scripts 465 | tneck has a lot of helpful scripts to help you with your Homelab and Proxmox. More information [here](https://tteck.github.io/Proxmox/). 466 | 467 | For tuning your Proxmox hosts I use these: 468 | * Proxmox VE Tools 469 | 1. Proxmox VE Processor Microcode 470 | 2. Proxmox VE CPU Scaling Governor 471 | 472 | 473 |
474 | 475 | # 7. Create a PVE Cluster 476 | 477 | Proxmox requires a minimum of three PVE hosts on the same network to form a cluster - PVE-01, PVE-02 and PVE-03. 478 | 479 | 480 | ## 7.1. Create a Cluster 481 | 482 | Using the PVE web interface on host PVE-01, go to `Datacenter` > `Cluster` > `Create Cluster` and fill out the fields as follows: 483 | 484 | | Create Cluster | Value | Notes | 485 | |----------------|---------------|-------| 486 | | Cluster Name | `pve-cluster` | | 487 | | Ring 0 Address | Leave Blank | | 488 | 489 | And Click `Create`. 490 | 491 | ## 7.2. Join the other Nodes to the New Cluster 492 | 493 | The first step in joining other nodes to your cluster, `pve-cluster`, is to copy PVE-01 cluster manager fingerprint/join information into your clipboard. 494 | 495 | **Step One:** 496 | 497 | Using PVE web interface on host PVE-01, go to `Datacenter` > `Cluster` > `Join Information` and a new window will appear showing `Cluster Join Information` with the option to `Copy Information` into your clipboard. Click `Copy Information`. 498 | 499 | **Step Two:** 500 | 501 | Using the PVE web interface on the OTHER hosts, PVE-02/03/04, go to `Datacenter` > `Cluster` > `Join Cluster` and a new window will appear showing `Cluster Join` with the option to paste the `Cluster Join Information` into an `Information` field. Paste the information, enter your root password into the `Password` field and the other fields will automatically be filled. 502 | 503 | And Click `Join`. Repeat for on all nodes. 504 | 505 | All PVE host management can be performed from the PVE-01 node. Using the PVE web management WebGUI (https://192.168.1.101:8006) all added cluster hosts should be listed below `Datacenter (pve-cluster)`. Or type `pvecm status` into any host `pve-01` > `>_Shell`: 506 | 507 | ``` 508 | pvecm status 509 | 510 | # Results ... 511 | Quorum information 512 | ------------------ 513 | Date: Mon Jul 22 13:44:10 2019 514 | Quorum provider: corosync_votequorum 515 | Nodes: 3 516 | Node ID: 0x00000001 517 | Ring ID: 1/348 518 | Quorate: Yes 519 | 520 | Votequorum information 521 | ---------------------- 522 | Expected votes: 3 523 | Highest expected: 3 524 | Total votes: 3 525 | Quorum: 2 526 | Flags: Quorate 527 | 528 | Membership information 529 | ---------------------- 530 | Nodeid Votes Name 531 | 0x00000001 1 192.168.1.101 (local) 532 | 0x00000002 1 192.168.1.102 533 | 0x00000003 1 192.168.1.103 534 | ``` 535 | 536 | ## 7.3. How to delete an existing cluster on a node 537 | 538 | If you make a mistake when setting up your cluster the following should reset your cluster settings to the PVE default. 539 | 540 | ```bash 541 | systemctl stop pve-cluster 542 | pmxcfs -l 543 | rm -f /etc/pve/cluster.conf /etc/pve/corosync.conf 544 | rm -f /etc/cluster/cluster.conf /etc/corosync/corosync.conf 545 | systemctl stop pve-cluster 546 | rm /var/lib/pve-cluster/.pmxcfs.lockfile 547 | rm -f /etc/corosync/authkey 548 | systemctl start pve-cluster 549 | systemctl restart pvedaemon 550 | systemctl restart pveproxy 551 | systemctl restart pvestatd 552 | reboot 553 | ``` 554 |
555 | 556 | # 8. Fixes, patches & Troubleshooting 557 | ## 8.1. Proxmox VZdump backup write errors to NAS 558 | If you experience permission errors or encounter failures when PVE (Proxmox Virtual Environment) attempts to write temporary files during the creation of a container backup, the issue may be attributed to permission problems when PVE generates temporary files. To resolve this, execute the following command on all PVE hosts: 559 | 560 | ``` 561 | # Set /etc/vzdump.conf tmp dir 562 | sed -i -r '/^#?tmpdir:.*/c\tmpdir: \/tmp' /etc/vzdump.conf 563 | ``` 564 | 565 | Or you could edit the `/etc/vzdump.conf` using nano: 566 | ``` 567 | tmpdir: /tmp 568 | #dumpdir: DIR 569 | #storage: STORAGE_ID 570 | #mode: snapshot|suspend|stop 571 | #bwlimit: KBPS 572 | #performance: [max-workers=N][,pbs-entries-max=N] 573 | #ionice: PRI 574 | #lockwait: MINUTES 575 | #stopwait: MINUTES 576 | #stdexcludes: BOOLEAN 577 | #mailto: ADDRESSLIST 578 | #prune-backups: keep-INTERVAL=N[,...] 579 | #script: FILENAME 580 | #exclude-path: PATHLIST 581 | #pigz: N 582 | #notes-template: {{guestname}} 583 | ``` 584 | 585 | This patch may be overwritten when performing a Proxmox release upgrade requiring you to patch the file. 586 | 587 |
-------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . --------------------------------------------------------------------------------