post-pve-install.sh 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. #!/usr/bin/env bash
  2. # Copyright (c) 2021-2023 tteck
  3. # Author: tteck (tteckster)
  4. # License: MIT
  5. # https://github.com/tteck/Proxmox/raw/main/LICENSE
  6. header_info() {
  7. clear
  8. cat <<"EOF"
  9. ____ _ _____________ ____ __ ____ __ ____
  10. / __ \ | / / ____/__ / / __ \____ _____/ /_ / _/___ _____/ /_____ _/ / /
  11. / /_/ / | / / __/ / / / /_/ / __ \/ ___/ __/ / // __ \/ ___/ __/ __ / / /
  12. / ____/| |/ / /___ / / / ____/ /_/ (__ ) /_ _/ // / / (__ ) /_/ /_/ / / /
  13. /_/ |___/_____/ /_/ /_/ \____/____/\__/ /___/_/ /_/____/\__/\__,_/_/_/
  14. EOF
  15. }
  16. RD=$(echo "\033[01;31m")
  17. YW=$(echo "\033[33m")
  18. GN=$(echo "\033[1;92m")
  19. CL=$(echo "\033[m")
  20. BFR="\\r\\033[K"
  21. HOLD="-"
  22. CM="${GN}✓${CL}"
  23. CROSS="${RD}✗${CL}"
  24. set -euo pipefail
  25. shopt -s inherit_errexit nullglob
  26. msg_info() {
  27. local msg="$1"
  28. echo -ne " ${HOLD} ${YW}${msg}..."
  29. }
  30. msg_ok() {
  31. local msg="$1"
  32. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  33. }
  34. msg_error() {
  35. local msg="$1"
  36. echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
  37. }
  38. start_routines() {
  39. header_info
  40. CHOICE=$(whiptail --title "Proxmox VE 7 Post Install" --menu "The 'pve-enterprise' repository is only available to users who have purchased a Proxmox VE subscription.\n \nDisable 'pve-enterprise' repository?" 14 58 2 \
  41. "yes" " " \
  42. "no" " " 3>&2 2>&1 1>&3)
  43. case $CHOICE in
  44. yes)
  45. msg_info "Disabling 'pve-enterprise' repository"
  46. sed -i 's/^deb/#deb/g' /etc/apt/sources.list.d/pve-enterprise.list
  47. msg_ok "Disabled 'pve-enterprise' repository"
  48. ;;
  49. no)
  50. msg_error "Selected no to Disabling 'pve-enterprise' repository"
  51. ;;
  52. esac
  53. CHOICE=$(whiptail --title "Proxmox VE 7 Post Install" --menu "The package manager will use the correct sources to update and install packages on your Proxmox VE 7 server.\n \nCorrect Proxmox VE 7 sources?" 14 58 2 \
  54. "yes" " " \
  55. "no" " " 3>&2 2>&1 1>&3)
  56. case $CHOICE in
  57. yes)
  58. msg_info "Correcting Proxmox VE 7 Sources"
  59. cat <<EOF >/etc/apt/sources.list
  60. deb http://ftp.debian.org/debian bullseye main contrib
  61. deb http://ftp.debian.org/debian bullseye-updates main contrib
  62. deb http://security.debian.org/debian-security bullseye-security main contrib
  63. EOF
  64. msg_ok "Corrected Proxmox VE 7 Sources"
  65. ;;
  66. no)
  67. msg_error "Selected no to Correcting Proxmox VE 7 Sources"
  68. ;;
  69. esac
  70. CHOICE=$(whiptail --title "Proxmox VE 7 Post Install" --menu "The 'pve-no-subscription' repository provides access to all of the open-source components of Proxmox VE.\n \nEnable 'pve-no-subscription' repository?" 14 58 2 \
  71. "yes" " " \
  72. "no" " " 3>&2 2>&1 1>&3)
  73. case $CHOICE in
  74. yes)
  75. msg_info "Enabling 'pve-no-subscription' repository"
  76. cat <<EOF >>/etc/apt/sources.list
  77. deb http://download.proxmox.com/debian/pve bullseye pve-no-subscription
  78. EOF
  79. msg_ok "Enabled 'pve-no-subscription' repository"
  80. ;;
  81. no)
  82. msg_error "Selected no to Enabling 'pve-no-subscription' repository"
  83. ;;
  84. esac
  85. CHOICE=$(whiptail --title "Proxmox VE 7 Post Install" --menu "The 'pvetest' repository can give advanced users access to new features and updates before they are officially released.\n \nAdd (Disabled) 'pvetest' repository?" 14 58 2 \
  86. "yes" " " \
  87. "no" " " 3>&2 2>&1 1>&3)
  88. case $CHOICE in
  89. yes)
  90. msg_info "Adding 'pvetest' repository and set disabled"
  91. cat <<EOF >>/etc/apt/sources.list
  92. # deb http://download.proxmox.com/debian/pve bullseye pvetest
  93. EOF
  94. msg_ok "Added 'pvetest' repository"
  95. ;;
  96. no)
  97. msg_error "Selected no to Adding 'pvetest' repository"
  98. ;;
  99. esac
  100. CHOICE=$(whiptail --title "Proxmox VE 7 Post Install" --menu "This will disable the nag message reminding you to purchase a subscription every time you log in to the web interface.\n \nDisable subscription nag?" 14 58 2 \
  101. "yes" " " \
  102. "no" " " 3>&2 2>&1 1>&3)
  103. case $CHOICE in
  104. yes)
  105. msg_info "Disabling subscription nag"
  106. echo "DPkg::Post-Invoke { \"dpkg -V proxmox-widget-toolkit | grep -q '/proxmoxlib\.js$'; if [ \$? -eq 1 ]; then { echo 'Removing subscription nag from UI...'; sed -i '/data\.status.*{/{s/\!//;s/active/NoMoreNagging/}' /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js; }; fi\"; };" >/etc/apt/apt.conf.d/no-nag-script
  107. apt --reinstall install proxmox-widget-toolkit &>/dev/null
  108. msg_ok "Disabled subscription nag (Delete browser cache)"
  109. ;;
  110. no)
  111. msg_error "Selected no to Disabling subscription nag"
  112. ;;
  113. esac
  114. CHOICE=$(whiptail --title "Proxmox VE 7 Post Install" --menu "\nUpdate Proxmox VE 7 now?" 11 58 2 \
  115. "yes" " " \
  116. "no" " " 3>&2 2>&1 1>&3)
  117. case $CHOICE in
  118. yes)
  119. msg_info "Updating Proxmox VE 7 (Patience)"
  120. apt-get update &>/dev/null
  121. apt-get -y dist-upgrade &>/dev/null
  122. msg_ok "Updated Proxmox VE 7"
  123. ;;
  124. no)
  125. msg_error "Selected no to Updating Proxmox VE 7"
  126. ;;
  127. esac
  128. microcode=""
  129. cpu=$(lscpu | grep -oP 'Vendor ID:\s*\K\S+')
  130. if [ "$cpu" == "GenuineIntel" ]; then
  131. if lscpu | grep -qP 'Model name:.*N'; then
  132. CHOICE=$(whiptail --title "N-SERIES PROCESSOR DETECTED" --menu "\nTo ensure compatibility with Proxmox VE on systems equipped with N-series processors, it is recommended to install the Proxmox 6.2 kernel.\n\nInstall the Proxmox 6.2 kernel now?" 16 58 2 \
  133. "yes" " " \
  134. "no" " " 3>&1 1>&2 2>&3)
  135. case $CHOICE in
  136. yes)
  137. msg_info "Installing Proxmox 6.2 kernel"
  138. apt-get install -y pve-kernel-6.2 &>/dev/null
  139. microcode="need"
  140. msg_ok "Installed Proxmox 6.2 kernel"
  141. ;;
  142. no)
  143. msg_error "Selected no to Installing the Proxmox 6.2 kernel"
  144. ;;
  145. esac
  146. fi
  147. fi
  148. if [ "$microcode" == "need" ]; then
  149. CHOICE=$(whiptail --title "INTEL MICROCODE" --menu "\nMicrocode updates can fix hardware bugs, improve performance, and enhance security features of the processor.\n\nInstall the Intel Microcode now?" 16 58 2 \
  150. "yes" " " \
  151. "no" " " 3>&2 2>&1 1>&3)
  152. case $CHOICE in
  153. yes)
  154. msg_info "Installing Intel Microcode"
  155. apt-get install -y iucode-tool &>/dev/null
  156. wget -q http://ftp.debian.org/debian/pool/non-free-firmware/i/intel-microcode/intel-microcode_3.20230512.1_amd64.deb
  157. dpkg -i intel-microcode_3.20230512.1_amd64.deb &>/dev/null
  158. rm intel-microcode_3.20230512.1_amd64.deb
  159. msg_ok "Installed Intel Microcode"
  160. ;;
  161. no)
  162. msg_error "Selected no to Installing the Intel Microcode"
  163. ;;
  164. esac
  165. fi
  166. CHOICE=$(whiptail --title "Proxmox VE 7 Post Install" --menu "\nReboot Proxmox VE 7 now? (recommended)" 11 58 2 \
  167. "yes" " " \
  168. "no" " " 3>&2 2>&1 1>&3)
  169. case $CHOICE in
  170. yes)
  171. msg_info "Rebooting Proxmox VE 7"
  172. sleep 2
  173. msg_ok "Completed Post Install Routines"
  174. reboot
  175. ;;
  176. no)
  177. msg_error "Selected no to Rebooting Proxmox VE 7 (Reboot recommended)"
  178. msg_ok "Completed Post Install Routines"
  179. ;;
  180. esac
  181. }
  182. header_info
  183. echo -e "\nThis script will Perform Post Install Routines.\n"
  184. while true; do
  185. read -p "Start the Proxmox VE 7 Post Install Script (y/n)?" yn
  186. case $yn in
  187. [Yy]*) break ;;
  188. [Nn]*) clear; exit ;;
  189. *) echo "Please answer yes or no." ;;
  190. esac
  191. done
  192. if ! command -v pveversion >/dev/null 2>&1; then
  193. header_info
  194. msg_error "\n No PVE Detected!\n"
  195. exit
  196. fi
  197. if [ $(pveversion | grep "pve-manager/7" | wc -l) -ne 1 ]; then
  198. header_info
  199. msg_error "This version of Proxmox Virtual Environment is not supported"
  200. echo -e " Requires PVE Version: 7.XX"
  201. echo -e "\nExiting..."
  202. sleep 3
  203. exit
  204. fi
  205. start_routines