post-pve-install.sh 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. exit_script() {
  39. clear
  40. echo -e "⚠ User exited script \n"
  41. exit
  42. }
  43. start_routines() {
  44. header_info
  45. CHOICE=$(
  46. 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 \
  47. "yes" " " \
  48. "no" " " 3>&2 2>&1 1>&3
  49. )
  50. exit_status=$?
  51. if [ $exit_status == 1 ]; then
  52. exit_script
  53. fi
  54. case $CHOICE in
  55. yes)
  56. msg_info "Disabling 'pve-enterprise' repository"
  57. sed -i 's/^deb/#deb/g' /etc/apt/sources.list.d/pve-enterprise.list
  58. msg_ok "Disabled 'pve-enterprise' repository"
  59. ;;
  60. no)
  61. msg_error "Selected no to Disabling 'pve-enterprise' repository"
  62. ;;
  63. esac
  64. CHOICE=$(
  65. 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 \
  66. "yes" " " \
  67. "no" " " 3>&2 2>&1 1>&3
  68. )
  69. exit_status=$?
  70. if [ $exit_status == 1 ]; then
  71. exit_script
  72. fi
  73. case $CHOICE in
  74. yes)
  75. msg_info "Correcting Proxmox VE 7 Sources"
  76. cat <<EOF >/etc/apt/sources.list
  77. deb http://ftp.debian.org/debian bullseye main contrib
  78. deb http://ftp.debian.org/debian bullseye-updates main contrib
  79. deb http://security.debian.org/debian-security bullseye-security main contrib
  80. EOF
  81. msg_ok "Corrected Proxmox VE 7 Sources"
  82. ;;
  83. no)
  84. msg_error "Selected no to Correcting Proxmox VE 7 Sources"
  85. ;;
  86. esac
  87. CHOICE=$(
  88. 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 \
  89. "yes" " " \
  90. "no" " " 3>&2 2>&1 1>&3
  91. )
  92. exit_status=$?
  93. if [ $exit_status == 1 ]; then
  94. exit_script
  95. fi
  96. case $CHOICE in
  97. yes)
  98. msg_info "Enabling 'pve-no-subscription' repository"
  99. cat <<EOF >>/etc/apt/sources.list
  100. deb http://download.proxmox.com/debian/pve bullseye pve-no-subscription
  101. EOF
  102. msg_ok "Enabled 'pve-no-subscription' repository"
  103. ;;
  104. no)
  105. msg_error "Selected no to Enabling 'pve-no-subscription' repository"
  106. ;;
  107. esac
  108. CHOICE=$(
  109. 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 \
  110. "yes" " " \
  111. "no" " " 3>&2 2>&1 1>&3
  112. )
  113. exit_status=$?
  114. if [ $exit_status == 1 ]; then
  115. exit_script
  116. fi
  117. case $CHOICE in
  118. yes)
  119. msg_info "Adding 'pvetest' repository and set disabled"
  120. cat <<EOF >>/etc/apt/sources.list
  121. # deb http://download.proxmox.com/debian/pve bullseye pvetest
  122. EOF
  123. msg_ok "Added 'pvetest' repository"
  124. ;;
  125. no)
  126. msg_error "Selected no to Adding 'pvetest' repository"
  127. ;;
  128. esac
  129. CHOICE=$(
  130. 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 \
  131. "yes" " " \
  132. "no" " " 3>&2 2>&1 1>&3
  133. )
  134. exit_status=$?
  135. if [ $exit_status == 1 ]; then
  136. exit_script
  137. fi
  138. case $CHOICE in
  139. yes)
  140. msg_info "Disabling subscription nag"
  141. 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
  142. apt --reinstall install proxmox-widget-toolkit &>/dev/null
  143. msg_ok "Disabled subscription nag (Delete browser cache)"
  144. ;;
  145. no)
  146. msg_error "Selected no to Disabling subscription nag"
  147. ;;
  148. esac
  149. CHOICE=$(
  150. whiptail --title "Proxmox VE 7 Post Install" --menu "\nUpdate Proxmox VE 7 now?" 11 58 2 \
  151. "yes" " " \
  152. "no" " " 3>&2 2>&1 1>&3
  153. )
  154. exit_status=$?
  155. if [ $exit_status == 1 ]; then
  156. exit_script
  157. fi
  158. case $CHOICE in
  159. yes)
  160. msg_info "Updating Proxmox VE 7 (Patience)"
  161. apt-get update &>/dev/null
  162. apt-get -y dist-upgrade &>/dev/null
  163. msg_ok "Updated Proxmox VE 7 (Reboot recommended)"
  164. ;;
  165. no)
  166. msg_error "Selected no to Updating Proxmox VE 7"
  167. ;;
  168. esac
  169. CHOICE=$(
  170. whiptail --title "Proxmox VE 7 Post Install" --menu "\nReboot Proxmox VE 7 now?" 11 58 2 \
  171. "yes" " " \
  172. "no" " " 3>&2 2>&1 1>&3
  173. )
  174. exit_status=$?
  175. if [ $exit_status == 1 ]; then
  176. exit_script
  177. fi
  178. case $CHOICE in
  179. yes)
  180. msg_info "Rebooting Proxmox VE 7"
  181. sleep 2
  182. msg_ok "Completed Post Install Routines"
  183. reboot
  184. ;;
  185. no)
  186. msg_error "Selected no to Rebooting Proxmox VE 7"
  187. msg_ok "Completed Post Install Routines"
  188. ;;
  189. esac
  190. }
  191. header_info
  192. echo -e "\nThis script will Perform Post Install Routines.\n"
  193. while true; do
  194. read -p "Start the Proxmox VE 7 Post Install Script (y/n)?" yn
  195. case $yn in
  196. [Yy]*) break ;;
  197. [Nn]*) exit_script ;;
  198. *) echo "Please answer yes or no." ;;
  199. esac
  200. done
  201. if ! command -v pveversion >/dev/null 2>&1; then
  202. header_info
  203. msg_error "\n No PVE Detected!\n"
  204. exit
  205. fi
  206. if [ $(pveversion | grep "pve-manager/7" | wc -l) -ne 1 ]; then
  207. header_info
  208. msg_error "This version of Proxmox Virtual Environment is not supported"
  209. echo -e " Requires PVE Version: 7.XX"
  210. echo -e "\nExiting..."
  211. sleep 3
  212. exit
  213. fi
  214. start_routines