upgrade.sh 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  1. #!/bin/bash
  2. #===========================================================================#
  3. # #
  4. # Hestia Control Panel - Upgrade Function Library #
  5. # #
  6. #===========================================================================#
  7. # Import system health check and repair library
  8. # shellcheck source=/usr/local/hestia/func/syshealth.sh
  9. source $HESTIA/func/syshealth.sh
  10. #####################################################################
  11. ####### Functions & Initialization #######
  12. #####################################################################
  13. add_upgrade_message() {
  14. if [ -f "$HESTIA_BACKUP/message.log" ]; then
  15. echo -e $1 >> $HESTIA_BACKUP/message.log
  16. echo -e "\n\n" >> $HESTIA_BACKUP/message.log
  17. else
  18. echo -e $1 > $HESTIA_BACKUP/message.log
  19. fi
  20. }
  21. is_debug_build() {
  22. if [[ "$new_version" =~ "alpha" ]] || [[ "$new_version" =~ "beta" ]]; then
  23. DEBUG_MODE="true"
  24. fi
  25. # Remove pre-release designation tags from display version
  26. DISPLAY_VER=$(echo $new_version | sed "s|~alpha||g" | sed "s|~beta||g")
  27. }
  28. upgrade_health_check() {
  29. echo "============================================================================="
  30. echo "[ ! ] Performing system health check before proceeding with installation... "
  31. # Perform basic health check against hestia.conf to ensure that
  32. # system variables exist and are set to expected defaults.
  33. if [ -z "$VERSION" ]; then
  34. export VERSION="1.1.0"
  35. $BIN/v-change-sys-config-value 'VERSION' "$VERSION"
  36. echo
  37. echo "[ ! ] Unable to detect installed version of Hestia Control Panel."
  38. echo " Setting default version to $VERSION and processing upgrade steps."
  39. echo
  40. fi
  41. syshealth_repair_system_config
  42. echo "[ * ] Health check complete. Starting upgrade from $VERSION to $new_version..."
  43. echo "============================================================================="
  44. }
  45. upgrade_welcome_message() {
  46. echo
  47. echo ' _ _ _ _ ____ ____ '
  48. echo ' | | | | ___ ___| |_(_) __ _ / ___| _ \ '
  49. echo ' | |_| |/ _ \/ __| __| |/ _` | | | |_) | '
  50. echo ' | _ | __/\__ \ |_| | (_| | |___| __/ '
  51. echo ' |_| |_|\___||___/\__|_|\__,_|\____|_| '
  52. echo " "
  53. echo " Hestia Control Panel Software Update "
  54. echo " Version: ${DISPLAY_VER}"
  55. if [[ "$new_version" =~ "beta" ]]; then
  56. echo " BETA RELEASE "
  57. fi
  58. if [[ "$new_version" =~ "alpha" ]]; then
  59. echo " DEVELOPMENT SNAPSHOT "
  60. echo " NOT INTENDED FOR PRODUCTION USE "
  61. echo " USE AT YOUR OWN RISK "
  62. fi
  63. echo
  64. echo "============================================================================="
  65. echo
  66. echo "[ ! ] IMPORTANT INFORMATION: "
  67. echo
  68. echo "Default configuration files and templates may be modified or replaced "
  69. echo "during the upgrade process. You may restore these files from: "
  70. echo ""
  71. echo "Backup directory: $HESTIA_BACKUP/"
  72. echo "Installation log: $LOG"
  73. }
  74. upgrade_welcome_message_log() {
  75. echo "============================================================================="
  76. echo "Hestia Control Panel Software Update Log"
  77. echo "============================================================================="
  78. echo
  79. echo "OPERATING SYSTEM: $OS_TYPE ($OS_VERSION)"
  80. echo "CURRENT VERSION: $VERSION"
  81. echo "NEW VERSION: $new_version"
  82. echo "RELEASE BRANCH: $RELEASE_BRANCH"
  83. if [[ "$new_version" =~ "alpha" ]]; then
  84. echo "BUILD TYPE: Development snapshot"
  85. elif [[ "$new_version" =~ "beta" ]]; then
  86. echo "BUILD TYPE: Beta release"
  87. else
  88. echo "BUILD TYPE: Production release"
  89. fi
  90. echo
  91. echo "INSTALLER OPTIONS:"
  92. echo "============================================================================="
  93. echo "Send email notification on upgrade complete: $UPGRADE_SEND_EMAIL"
  94. echo "Send installed log output to admin email: $UPGRADE_SEND_EMAIL_LOG"
  95. echo
  96. }
  97. upgrade_step_message() {
  98. echo
  99. echo "[ - ] Now applying patches and updates for version v$version_step..."
  100. }
  101. upgrade_complete_message() {
  102. # Echo message to console output
  103. echo "============================================================================="
  104. echo
  105. echo "Upgrade complete! If you encounter any issues or find a bug, "
  106. echo "please take a moment to report it to us on GitHub at the URL below: "
  107. echo "https://github.com/hestiacp/hestiacp/issues "
  108. echo
  109. echo "Read the release notes to learn about new fixes and features: "
  110. echo "https://github.com/hestiacp/hestiacp/blob/release/CHANGELOG.md "
  111. echo
  112. echo "We hope that you enjoy using this version of Hestia Control Panel, "
  113. echo "have a wonderful day! "
  114. echo
  115. echo "Sincerely, "
  116. echo "The Hestia Control Panel development team "
  117. echo
  118. echo "Web: https://www.hestiacp.com/ "
  119. echo "Forum: https://forum.hestiacp.com/ "
  120. echo "Discord: https://discord.gg/nXRUZch "
  121. echo "GitHub: https://github.com/hestiacp/hestiacp/ "
  122. echo
  123. echo "Help support the Hestia Control Panel project by donating via PayPal: "
  124. echo "https://www.hestiacp.com/donate "
  125. echo
  126. echo "Made with love & pride by the open-source community around the world. "
  127. echo
  128. echo "============================================================================="
  129. echo
  130. }
  131. upgrade_complete_message_log() {
  132. echo
  133. echo "============================================================================="
  134. echo "UPGRADE COMPLETE. "
  135. echo "Please report any issues on GitHub: "
  136. echo "https://github.com/hestiacp/hestiacp/issues "
  137. echo "============================================================================="
  138. echo
  139. $BIN/v-log-action "system" "Info" "Updates" "Update installed (Version: $new_version)."
  140. }
  141. upgrade_cleanup_message() {
  142. echo "============================================================================="
  143. echo "Installation tasks complete, performing clean-up... "
  144. echo "============================================================================="
  145. }
  146. upgrade_get_version() {
  147. # Retrieve new version number for Hestia Control Panel from .deb package
  148. new_version=$(dpkg -l | awk '$2=="hestia" { print $3 }')
  149. }
  150. upgrade_set_version() {
  151. # Set new version number in hestia.conf
  152. $BIN/v-change-sys-config-value "VERSION" "$@"
  153. }
  154. upgrade_set_branch() {
  155. # Set branch in hestia.conf
  156. DISPLAY_VER=$(echo "$1" | sed "s|~alpha||g" | sed "s|~beta||g")
  157. if [ "$DISPLAY_VER" = "$1" ]; then
  158. $BIN/v-change-sys-config-value "RELEASE_BRANCH" "release"
  159. fi
  160. }
  161. upgrade_send_notification_to_panel() {
  162. # Add notification to panel if variable is set to true or is not set
  163. if [[ "$new_version" =~ "alpha" ]]; then
  164. # Send notifications for development releases
  165. $BIN/v-add-user-notification admin 'Development snapshot installed' '<p><span class="u-text-bold">Version:</span> '$new_version'<br><span class="u-text-bold">Code Branch:</span> '$RELEASE_BRANCH'</p><p>Please report any bugs by <a href="https://github.com/hestiacp/hestiacp/issues" target="_blank">opening an issue on GitHub</a>, and feel free to share your feedback on our <a href="https://forum.hestiacp.com" target="_blank">discussion forum</a>.</p><p><i class="fas fa-heart icon-red"></i> The Hestia Control Panel development team</p>'
  166. elif [[ "$new_version" =~ "beta" ]]; then
  167. # Send feedback notification for beta releases
  168. $BIN/v-add-user-notification admin 'Thank you for testing Hestia Control Panel '$new_version'.' '<p>Please share your feedback with our development team through our <a href="https://forum.hestiacp.com" target="_blank">discussion forum</a>.</p><p>Found a bug? <a href="https://github.com/hestiacp/hestiacp/issues" target="_blank">Open an issue on GitHub</a>!</p><p><i class="fas fa-heart icon-red"></i> The Hestia Control Panel development team</p>'
  169. else
  170. # Send normal upgrade complete notification for stable releases
  171. $BIN/v-add-user-notification admin 'Upgrade complete' '<p>Hestia Control Panel has been updated to <span class="u-text-bold">v'$new_version'</span>.</p><p><a href="https://github.com/hestiacp/hestiacp/blob/release/CHANGELOG.md" target="_blank">View release notes</a></p><p>Please report any bugs by <a href="https://github.com/hestiacp/hestiacp/issues" target="_blank">opening an issue on GitHub</a>.</p><p class="u-text-bold">Have a wonderful day!</p><p><i class="fas fa-heart icon-red"></i> The Hestia Control Panel development team</p>'
  172. fi
  173. }
  174. upgrade_send_notification_to_email() {
  175. if [ "$UPGRADE_SEND_EMAIL" = "true" ]; then
  176. # Retrieve admin email address, sendmail path, and message temp file path
  177. admin_email=$($BIN/v-list-user admin json | grep "CONTACT" | cut -d'"' -f4)
  178. send_mail="$HESTIA/web/inc/mail-wrapper.php"
  179. message_tmp_file="/tmp/hestia-upgrade-complete.txt"
  180. # Create temporary file
  181. touch $message_tmp_file
  182. # Write message to file
  183. echo "$HOSTNAME has been upgraded from Hestia Control Panel v$VERSION to v${new_version}." >> $message_tmp_file
  184. echo "Installation log: $LOG" >> $message_tmp_file
  185. echo "" >> $message_tmp_file
  186. # Check for additional upgrade notes from update scripts.
  187. if [[ -f "$HESTIA_BACKUP/message.log" ]]; then
  188. echo "===================================================" >> $message_tmp_file
  189. echo "The upgrade script has generated additional notifications, which must be heeded urgently:" >> $message_tmp_file
  190. echo "" >> $message_tmp_file
  191. cat $HESTIA_BACKUP/message.log >> $message_tmp_file
  192. echo "" >> $message_tmp_file
  193. echo "===================================================" >> $message_tmp_file
  194. echo "" >> $message_tmp_file
  195. fi
  196. echo "What's new: https://github.com/hestiacp/hestiacp/blob/$RELEASE_BRANCH/CHANGELOG.md" >> $message_tmp_file
  197. echo >> $message_tmp_file
  198. echo "What to do if you run into issues:" >> $message_tmp_file
  199. echo "- Check our forums for possible solutions: https://forum.hestiacp.com" >> $message_tmp_file
  200. echo "- File an issue report on GitHub: https://github.com/hestiacp/hestiacp/issues" >> $message_tmp_file
  201. echo "" >> $message_tmp_file
  202. echo "Help support the Hestia Control Panel project by donating via PayPal: https://www.hestiacp.com/donate" >> $message_tmp_file
  203. echo "===================================================" >> $message_tmp_file
  204. echo "Have a wonderful day," >> $message_tmp_file
  205. echo "The Hestia Control Panel development team" >> $message_tmp_file
  206. # Read back message from file and pass through to sendmail
  207. cat $message_tmp_file | $send_mail -s "Update Installed - v${new_version}" $admin_email
  208. rm -f $message_tmp_file
  209. fi
  210. }
  211. upgrade_send_log_to_email() {
  212. if [ "$UPGRADE_SEND_EMAIL_LOG" = "true" ]; then
  213. admin_email=$($BIN/v-list-user admin json | grep "CONTACT" | cut -d'"' -f4)
  214. send_mail="$HESTIA/web/inc/mail-wrapper.php"
  215. cat $LOG | $send_mail -s "Update Installation Log - v${new_version}" $admin_email
  216. fi
  217. }
  218. upgrade_config_set_value() {
  219. if [ -f "$HESTIA_BACKUP/upgrade.conf" ]; then
  220. if [ "$2" = "true" ]; then
  221. sed -i "s/$1='false'/$1='true'/g" $HESTIA_BACKUP/upgrade.conf
  222. fi
  223. fi
  224. }
  225. prepare_upgrade_config() {
  226. mkdir -p $HESTIA_BACKUP
  227. touch $HESTIA_BACKUP/upgrade.conf
  228. while IFS='= ' read -r lhs rhs; do
  229. if [[ ! $lhs =~ ^\ *# && -n $lhs ]]; then
  230. rhs="${rhs%%\#*}" # Del in line right comments
  231. rhs="${rhs%%*( )}" # Del trailing spaces
  232. rhs="${rhs%\'*}" # Del opening string quotes
  233. rhs="${rhs#\'*}" # Del closing string quotes
  234. echo "$lhs='$rhs'" >> $HESTIA_BACKUP/upgrade.conf
  235. fi
  236. done < "$HESTIA/install/upgrade/upgrade.conf"
  237. }
  238. upgrade_init_backup() {
  239. # Ensure that backup directories are created
  240. # Hestia Control Panel configuration files
  241. mkdir -p $HESTIA_BACKUP/conf/hestia/
  242. # OpenSSL configuration files
  243. mkdir -p $HESTIA_BACKUP/conf/openssl/
  244. # Hosting Packages
  245. mkdir -p $HESTIA_BACKUP/packages/
  246. # Domain template files
  247. mkdir -p $HESTIA_BACKUP/templates/
  248. # System services (apache2, nginx, bind9, vsftpd, etc).
  249. if [ -n "$WEB_SYSTEM" ]; then
  250. mkdir -p $HESTIA_BACKUP/conf/$WEB_SYSTEM/
  251. fi
  252. if [ -n "$IMAP_SYSTEM" ]; then
  253. mkdir -p $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
  254. fi
  255. if [ -n "$MAIL_SYSTEM" ]; then
  256. mkdir -p $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
  257. fi
  258. if [ -n "$DNS_SYSTEM" ]; then
  259. mkdir -p $HESTIA_BACKUP/conf/$DNS_SYSTEM/
  260. fi
  261. if [ -n "$PROXY_SYSTEM" ]; then
  262. mkdir -p $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  263. fi
  264. if [ -n "$DB_SYSTEM" ]; then
  265. if [[ "$DB_SYSTEM" =~ "mysql" ]]; then
  266. mkdir -p $HESTIA_BACKUP/conf/mysql/
  267. fi
  268. if [[ "$DB_SYSTEM" =~ "pgsql" ]]; then
  269. mkdir -p $HESTIA_BACKUP/conf/pgsql/
  270. fi
  271. fi
  272. if [ -n "$FTP_SYSTEM" ]; then
  273. mkdir -p $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  274. fi
  275. if [ -n "$FIREWALL_SYSTEM" ]; then
  276. mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_SYSTEM/
  277. fi
  278. if [ -n "$FIREWALL_EXTENSION" ]; then
  279. mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  280. fi
  281. if [ -e "/etc/ssh/sshd_config" ]; then
  282. mkdir -p $HESTIA_BACKUP/conf/ssh/
  283. fi
  284. if [ -d "/etc/roundcube/" ]; then
  285. mkdir -p $HESTIA_BACKUP/conf/roundcube/
  286. fi
  287. if [ -d "/etc/snappymail/" ]; then
  288. mkdir -p $HESTIA_BACKUP/conf/snappymail/
  289. fi
  290. if [ -d "/etc/phpmyadmin/" ]; then
  291. mkdir -p $HESTIA_BACKUP/conf/phpmyadmin/
  292. fi
  293. if [ -d "/etc/phppgadmin/" ]; then
  294. mkdir -p $HESTIA_BACKUP/conf/phppgadmin/
  295. fi
  296. }
  297. upgrade_init_logging() {
  298. # Set log file path
  299. LOG="$HESTIA_BACKUP/hst-upgrade-$(date +%d%m%Y%H%M).log"
  300. # Create log file
  301. touch $LOG
  302. # Add message to system log
  303. $BIN/v-log-action "system" "Info" "Updates" "Started update installation (Latest: $new_version, Previous: $VERSION)."
  304. # Add warnings for pre-release builds
  305. if [[ "$new_version" =~ "alpha" ]]; then
  306. $BIN/v-log-action "system" "Warning" "Updates" "Development build for testing purposes only. Report bugs at https://github.com/hestiacp/hestiacp/issues/."
  307. fi
  308. if [[ "$new_version" =~ "beta" ]]; then
  309. $BIN/v-log-action "system" "Warning" "Updates" "Beta release. Please report bugs at https://github.com/hestiacp/hestiacp/issues/."
  310. fi
  311. }
  312. upgrade_start_backup() {
  313. echo "============================================================================="
  314. echo "[ * ] Backing up existing templates and configuration files..."
  315. if [ "$DEBUG_MODE" = "true" ]; then
  316. echo " - Packages"
  317. fi
  318. cp -fr $HESTIA/data/packages/* $HESTIA_BACKUP/packages/
  319. if [ "$DEBUG_MODE" = "true" ]; then
  320. echo " - Templates"
  321. fi
  322. cp -fr $HESTIA/data/templates/* $HESTIA_BACKUP/templates/
  323. if [ "$DEBUG_MODE" = "true" ]; then
  324. echo " - Configuration files:"
  325. fi
  326. # Hestia Control Panel configuration files
  327. if [ "$DEBUG_MODE" = "true" ]; then
  328. echo " ---- hestia"
  329. fi
  330. cp -fr $HESTIA/conf/* $HESTIA_BACKUP/conf/hestia/
  331. # OpenSSL configuration files
  332. if [ "$DEBUG_MODE" = "true" ]; then
  333. echo " ---- openssl"
  334. fi
  335. cp -f /etc/ssl/*.cnf $HESTIA_BACKUP/conf/openssl/
  336. # System service configuration files (apache2, nginx, bind9, vsftpd, etc).
  337. if [ -n "$WEB_SYSTEM" ]; then
  338. if [ "$DEBUG_MODE" = "true" ]; then
  339. echo " ---- $WEB_SYSTEM"
  340. fi
  341. cp -fr /etc/$WEB_SYSTEM/* $HESTIA_BACKUP/conf/$WEB_SYSTEM/
  342. fi
  343. if [ -n "$PROXY_SYSTEM" ]; then
  344. if [ "$DEBUG_MODE" = "true" ]; then
  345. echo " ---- $PROXY_SYSTEM"
  346. fi
  347. cp -fr /etc/$PROXY_SYSTEM/* $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  348. fi
  349. if [ -n "$IMAP_SYSTEM" ]; then
  350. if [ "$DEBUG_MODE" = "true" ]; then
  351. echo " ---- $IMAP_SYSTEM"
  352. fi
  353. cp -fr /etc/$IMAP_SYSTEM/* $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
  354. fi
  355. if [ -n "$MAIL_SYSTEM" ]; then
  356. if [ "$DEBUG_MODE" = "true" ]; then
  357. echo " ---- $MAIL_SYSTEM"
  358. fi
  359. cp -fr /etc/$MAIL_SYSTEM/* $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
  360. fi
  361. if [ -n "$DNS_SYSTEM" ]; then
  362. if [ "$DNS_SYSTEM" = "bind9" ]; then
  363. if [ "$DEBUG_MODE" = "true" ]; then
  364. echo " ---- $DNS_SYSTEM"
  365. fi
  366. cp -fr /etc/bind/* $HESTIA_BACKUP/conf/$DNS_SYSTEM/
  367. fi
  368. fi
  369. if [ -n "$DB_SYSTEM" ]; then
  370. if [[ "$DB_SYSTEM" =~ "mysql" ]]; then
  371. if [ "$DEBUG_MODE" = "true" ]; then
  372. echo " ---- mysql"
  373. fi
  374. cp -fr /etc/mysql/* $HESTIA_BACKUP/conf/mysql/
  375. fi
  376. if [[ "$DB_SYSTEM" =~ "pgsql" ]]; then
  377. if [ "$DEBUG_MODE" = "true" ]; then
  378. echo " ---- pgsql"
  379. fi
  380. # config for postgresql is stored in /etc/postgresql/version/main/
  381. cp -fr /etc/postgresql/* $HESTIA_BACKUP/conf/pgsql/
  382. fi
  383. fi
  384. if [ -n "$FTP_SYSTEM" ]; then
  385. if [ "$DEBUG_MODE" = "true" ]; then
  386. echo " ---- $FTP_SYSTEM"
  387. fi
  388. if [ "$FTP_SYSTEM" = "vsftpd" ]; then
  389. cp -f /etc/$FTP_SYSTEM.conf $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  390. fi
  391. if [ "$FTP_SYSTEM" = "proftpd" ]; then
  392. cp -f /etc/proftpd/proftpd.conf $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  393. fi
  394. fi
  395. if [ -n "$FIREWALL_SYSTEM" ]; then
  396. if [ "$DEBUG_MODE" = "true" ]; then
  397. echo " ---- $FIREWALL_SYSTEM"
  398. fi
  399. [ -e "/etc/sysconfig/iptables" ] && cp -f /etc/sysconfig/iptables $HESTIA_BACKUP/conf/$FIREWALL_SYSTEM/
  400. [ -e "/etc/iptables.rules" ] && cp -f /etc/iptables.rules $HESTIA_BACKUP/conf/$FIREWALL_SYSTEM/
  401. fi
  402. if [ -n "$FIREWALL_EXTENSION" ]; then
  403. if [ "$DEBUG_MODE" = "true" ]; then
  404. echo " ---- $FIREWALL_EXTENSION"
  405. fi
  406. cp -f /etc/$FIREWALL_EXTENSION/*.conf $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  407. cp -f /etc/$FIREWALL_EXTENSION/*.local $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  408. fi
  409. if [ -e "/etc/ssh/sshd_config" ]; then
  410. if [ "$DEBUG_MODE" = "true" ]; then
  411. echo " ---- sshd"
  412. fi
  413. cp -fr /etc/ssh/* $HESTIA_BACKUP/conf/ssh/
  414. fi
  415. if [ -d "/etc/roundcube" ]; then
  416. if [ "$DEBUG_MODE" = "true" ]; then
  417. echo " ---- Roundcube"
  418. fi
  419. cp -fr /etc/roundcube/* $HESTIA_BACKUP/conf/roundcube
  420. fi
  421. if [ -d "/etc/snappymail" ]; then
  422. if [ "$DEBUG_MODE" = "true" ]; then
  423. echo " ---- SnappyMail"
  424. fi
  425. cp -fr /etc/snappymail/* $HESTIA_BACKUP/conf/snappymail
  426. fi
  427. if [ -d "/etc/phpmyadmin" ]; then
  428. if [ "$DEBUG_MODE" = "true" ]; then
  429. echo " ---- phpMyAdmin"
  430. fi
  431. cp -fr /etc/phpmyadmin/* $HESTIA_BACKUP/conf/phpmyadmin
  432. fi
  433. if [ -d "/etc/phppgadmin" ]; then
  434. if [ "$DEBUG_MODE" = "true" ]; then
  435. echo " ---- phppgadmin"
  436. fi
  437. cp -fr /etc/phppgadmin/* $HESTIA_BACKUP/conf/phppgadmin
  438. fi
  439. }
  440. upgrade_refresh_config() {
  441. source_conf "/usr/local/hestia/conf/hestia.conf"
  442. }
  443. upgrade_start_routine() {
  444. # Parse version numbers for comparison
  445. function check_version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
  446. # Remove pre-release designation from version number for upgrade scripts
  447. VERSION=$(echo "$VERSION" | sed "s/~\([a-zA-Z0-9].*\)//g")
  448. # Get list of all available version steps and create array
  449. upgrade_steps=$(ls -v $HESTIA/install/upgrade/versions/*.sh)
  450. for script in $upgrade_steps; do
  451. declare -a available_versions
  452. available_versions+=($(echo $script | sed "s|/usr/local/hestia/install/upgrade/versions/||g" | sed "s|.sh||g"))
  453. done
  454. # Define variables for accessing supported versions
  455. # Sort version by -V due to issues with version numbers 1.4.10 and higher
  456. all_versions=$(printf "%s\n" "${available_versions[@]}" | sort -V)
  457. oldest_version=$(printf "%s\n" "$all_versions" | head -n1)
  458. latest_version=$(printf "%s\n" "$all_versions" | sort -V | tail -n1)
  459. # Check for supported versions and process necessary upgrade steps
  460. if [ $(check_version $latest_version) -gt $(check_version $VERSION) ]; then
  461. for version_step in "${available_versions[@]}"; do
  462. if [ $(check_version $VERSION) -lt $(check_version "$version_step") ]; then
  463. upgrade_step_message
  464. source $HESTIA/install/upgrade/versions/$version_step.sh
  465. fi
  466. done
  467. upgrade_set_version "$VERSION"
  468. upgrade_refresh_config
  469. else
  470. echo ""
  471. echo "[ ! ] The latest version of Hestia Control Panel is already installed."
  472. echo " Verifying configuration..."
  473. echo ""
  474. if [ -e "$HESTIA/install/upgrade/versions/$VERSION.sh" ]; then
  475. source $HESTIA/install/upgrade/versions/$VERSION.sh
  476. fi
  477. VERSION="$new_version"
  478. upgrade_set_version "$VERSION"
  479. upgrade_refresh_config
  480. fi
  481. #####################################################################
  482. ####### End version-specific upgrade instruction sets #######
  483. #####################################################################
  484. }
  485. upgrade_b2_tool() {
  486. b2cli="/usr/local/bin/b2"
  487. b2lnk="https://github.com/Backblaze/B2_Command_Line_Tool/releases/download/v$b2_v/b2-linux"
  488. if [ -f "$b2cli" ]; then
  489. b2_version=$($b2cli version | grep -o -E '[0-9].[0-9].[0-9]+' | head -1)
  490. if version_ge "$b2_version" "$b2_v"; then
  491. echo "[ * ] Backblaze CLI tool is up to date ($b2_v)..."
  492. else
  493. echo "[ * ] Upgrading Backblaze CLI tool to version $b2_v..."
  494. rm $b2cli
  495. wget -O $b2cli $b2lnk > /dev/null 2>&1
  496. chmod +x $b2cli > /dev/null 2>&1
  497. if [ ! -f "$b2cli" ]; then
  498. echo "Error: Binary download failed, b2 doesn't work as expected."
  499. exit 3
  500. fi
  501. fi
  502. fi
  503. }
  504. upgrade_cloudflare_ip() {
  505. if [ "$WEB_SYSTEM" = "nginx" ] || [ "$PROXY_SYSTEM" = "nginx" ]; then
  506. cf_ips="$(curl -fsLm5 --retry 2 https://api.cloudflare.com/client/v4/ips)"
  507. if [ -n "$cf_ips" ] && [ "$(echo "$cf_ips" | jq -r '.success//""')" = "true" ]; then
  508. cf_inc="/etc/nginx/conf.d/cloudflare.inc"
  509. echo "[ * ] Updating Cloudflare IP Ranges for NGINX..."
  510. echo "# Cloudflare IP Ranges" > $cf_inc
  511. echo "" >> $cf_inc
  512. echo "# IPv4" >> $cf_inc
  513. for ipv4 in $(echo "$cf_ips" | jq -r '.result.ipv4_cidrs[]//""' | sort); do
  514. echo "set_real_ip_from $ipv4;" >> $cf_inc
  515. done
  516. echo "" >> $cf_inc
  517. echo "# IPv6" >> $cf_inc
  518. for ipv6 in $(echo "$cf_ips" | jq -r '.result.ipv6_cidrs[]//""' | sort); do
  519. echo "set_real_ip_from $ipv6;" >> $cf_inc
  520. done
  521. echo "" >> $cf_inc
  522. echo "real_ip_header CF-Connecting-IP;" >> $cf_inc
  523. fi
  524. fi
  525. }
  526. upgrade_phppgadmin() {
  527. if [ -n "$(echo $DB_SYSTEM | grep -w 'pgsql')" ]; then
  528. pga_release=$(cat /usr/share/phppgadmin/libraries/lib.inc.php | grep appVersion | head -n1 | cut -f2 -d\' | cut -f1 -d-)
  529. if version_ge "$pga_release" "pga_v"; then
  530. echo "[ * ] phppgadmin is up to date ($pga_release)..."
  531. else
  532. # Display upgrade information
  533. echo "[ * ] Upgrading phppgadmin to version $pga_v..."
  534. [ -d /usr/share/phppgadmin ] || mkdir -p /usr/share/phppgadmin
  535. # Download latest phpMyAdmin release
  536. wget --retry-connrefused --quiet https://github.com/hestiacp/phppgadmin/releases/download/v$pga_v/phppgadmin-v$pga_v.tar.gz
  537. tar xzf phppgadmin-v$pga_v.tar.gz -C /usr/share/phppgadmin/
  538. if ! version_ge "$pga_release" "7.14.0"; then
  539. cp -f $HESTIA_INSTALL_DIR/pga/config.inc.php /etc/phppgadmin/
  540. fi
  541. if [ ! -f /usr/share/phppgadmin/conf/config.inc.php ]; then
  542. ln -s /etc/phppgadmin/config.inc.php /usr/share/phppgadmin/conf
  543. fi
  544. rm -f phppgadmin-v$pga_v.tar.gz
  545. fi
  546. fi
  547. }
  548. upgrade_phpmyadmin() {
  549. # Check if MariaDB/MySQL is installed on the server before attempting to install or upgrade phpMyAdmin
  550. if [ -n "$(echo $DB_SYSTEM | grep -w 'mysql')" ]; then
  551. pma_version=$(jq -r .version /usr/share/phpmyadmin/package.json)
  552. if version_ge "$pma_version" "$pma_v"; then
  553. echo "[ * ] phpMyAdmin is up to date (${pma_version})..."
  554. # Update permissions
  555. if [ -e /var/lib/phpmyadmin/blowfish_secret.inc.php ]; then
  556. chown root:www-data /var/lib/phpmyadmin/blowfish_secret.inc.php
  557. chmod 0640 /var/lib/phpmyadmin/blowfish_secret.inc.php
  558. fi
  559. else
  560. # Display upgrade information
  561. echo "[ * ] Upgrading phpMyAdmin to version $pma_v..."
  562. [ -d /usr/share/phpmyadmin ] || mkdir -p /usr/share/phpmyadmin
  563. # Download latest phpMyAdmin release
  564. wget --quiet https://files.phpmyadmin.net/phpMyAdmin/$pma_v/phpMyAdmin-$pma_v-all-languages.tar.gz
  565. # Unpack files
  566. tar xzf phpMyAdmin-$pma_v-all-languages.tar.gz
  567. # Delete file to prevent error
  568. rm -rf /usr/share/phpmyadmin/doc/html
  569. # Overwrite old files
  570. cp -rf phpMyAdmin-$pma_v-all-languages/* /usr/share/phpmyadmin
  571. # Set config and log directory
  572. sed -i "s|'configFile' => ROOT_PATH . 'config.inc.php',|'configFile' => '/etc/phpmyadmin/config.inc.php',|g" /usr/share/phpmyadmin/libraries/vendor_config.php
  573. # Create temporary folder and change permissions
  574. if [ ! -d /usr/share/phpmyadmin/tmp ]; then
  575. mkdir /usr/share/phpmyadmin/tmp
  576. chown root:www-data /usr/share/phpmyadmin/tmp
  577. chmod 0770 /usr/share/phpmyadmin/tmp
  578. fi
  579. if [ -e /var/lib/phpmyadmin/blowfish_secret.inc.php ]; then
  580. chown root:www-data /var/lib/phpmyadmin/blowfish_secret.inc.php
  581. chmod 0640 /var/lib/phpmyadmin/blowfish_secret.inc.php
  582. fi
  583. # Clean up source files
  584. rm -fr phpMyAdmin-$pma_v-all-languages
  585. rm -f phpMyAdmin-$pma_v-all-languages.tar.gz
  586. fi
  587. fi
  588. }
  589. upgrade_filemanager() {
  590. FILE_MANAGER_CHECK=$(cat $HESTIA/conf/hestia.conf | grep "FILE_MANAGER='false'")
  591. if [ -z "$FILE_MANAGER_CHECK" ]; then
  592. if [ -f "$HESTIA/web/fm/version" ]; then
  593. fm_version=$(cat $HESTIA/web/fm/version)
  594. else
  595. fm_version="1.0.0"
  596. fi
  597. if ! version_ge "$fm_version" "$fm_v"; then
  598. echo "[ ! ] Upgrading File Manager to version $fm_v..."
  599. # Reinstall the File Manager
  600. $BIN/v-delete-sys-filemanager quiet yes
  601. $BIN/v-add-sys-filemanager quiet
  602. else
  603. echo "[ * ] File Manager is up to date ($fm_v)..."
  604. if [ "$UPGRADE_UPDATE_FILEMANAGER_CONFIG" = "true" ]; then
  605. if [ -e "$HESTIA/web/fm/configuration.php" ]; then
  606. echo "[ ! ] Updating File Manager configuration..."
  607. # Update configuration.php
  608. cp -f $HESTIA_INSTALL_DIR/filemanager/filegator/configuration.php $HESTIA/web/fm/configuration.php
  609. # Set environment variable for interface
  610. $BIN/v-change-sys-config-value 'FILE_MANAGER' 'true'
  611. fi
  612. fi
  613. fi
  614. fi
  615. }
  616. upgrade_roundcube() {
  617. if [ -n "$(echo "$WEBMAIL_SYSTEM" | grep -w 'roundcube')" ]; then
  618. if [ -d "/usr/share/roundcube" ]; then
  619. echo "[ ! ] Roundcube: Updates are currently managed using the apt package manager"
  620. echo " To upgrade to the latest version of Roundcube directly from upstream, from please run the command migrate_roundcube.sh located in: /usr/local/hestia/install/upgrade/manual/"
  621. else
  622. rc_version=$(cat /var/lib/roundcube/index.php | grep -o -E '[0-9].[0-9].[0-9]+' | head -1)
  623. if ! version_ge "$rc_version" "$rc_v"; then
  624. echo "[ ! ] Upgrading Roundcube to version $rc_v..."
  625. $BIN/v-add-sys-roundcube
  626. else
  627. echo "[ * ] Roundcube is up to date ($rc_v)..."
  628. fi
  629. fi
  630. fi
  631. }
  632. upgrade_snappymail() {
  633. if [ -n "$(echo "$WEBMAIL_SYSTEM" | grep -w 'snappymail')" ]; then
  634. sm_version=$(cat /var/lib/snappymail/data/VERSION)
  635. if ! version_ge "$sm_version" "$sm_v"; then
  636. echo "[ ! ] Upgrading SnappyMail to version $sm_v..."
  637. $BIN/v-add-sys-snappymail
  638. else
  639. echo "[ * ] SnappyMail is up to date ($sm_v)..."
  640. fi
  641. fi
  642. }
  643. upgrade_dependencies() {
  644. echo "[ ! ] Update Hestia PHP dependencies..."
  645. $BIN/v-add-sys-dependencies
  646. }
  647. upgrade_rebuild_web_templates() {
  648. if [ "$UPGRADE_UPDATE_WEB_TEMPLATES" = "true" ]; then
  649. echo "[ ! ] Updating default web domain templates..."
  650. $BIN/v-update-web-templates "no" "skip"
  651. fi
  652. }
  653. upgrade_rebuild_mail_templates() {
  654. if [ "$UPGRADE_UPDATE_MAIL_TEMPLATES" = "true" ]; then
  655. echo "[ ! ] Updating default mail domain templates..."
  656. $BIN/v-update-mail-templates "no" "skip"
  657. fi
  658. }
  659. upgrade_rebuild_dns_templates() {
  660. if [ "$UPGRADE_UPDATE_DNS_TEMPLATES" = "true" ]; then
  661. echo "[ ! ] Updating default DNS zone templates..."
  662. $BIN/v-update-dns-templates
  663. fi
  664. }
  665. upgrade_rebuild_users() {
  666. if [ "$UPGRADE_REBUILD_USERS" = "true" ]; then
  667. if [ "$DEBUG_MODE" = "true" ]; then
  668. echo "[ * ] Rebuilding user accounts and domains:..."
  669. else
  670. echo "[ * ] Rebuilding user accounts and domains, this may take a few minutes..."
  671. fi
  672. for user in $($BIN/v-list-sys-users plain); do
  673. export restart="no"
  674. if [ "$DEBUG_MODE" = "true" ]; then
  675. echo " - $user:"
  676. else
  677. echo " - $user..."
  678. fi
  679. if [ -n "$WEB_SYSTEM" ]; then
  680. if [ "$DEBUG_MODE" = "true" ]; then
  681. echo " ---- Web domains..."
  682. $BIN/v-rebuild-web-domains "$user" 'no'
  683. else
  684. $BIN/v-rebuild-web-domains "$user" 'no' > /dev/null 2>&1
  685. fi
  686. fi
  687. if [ -n "$DNS_SYSTEM" ]; then
  688. if [ "$DEBUG_MODE" = "true" ]; then
  689. echo " ---- DNS zones..."
  690. $BIN/v-rebuild-dns-domains "$user" 'no'
  691. else
  692. $BIN/v-rebuild-dns-domains "$user" 'no' > /dev/null 2>&1
  693. fi
  694. fi
  695. if [ -n "$MAIL_SYSTEM" ]; then
  696. if [ "$DEBUG_MODE" = "true" ]; then
  697. echo " ---- Mail domains..."
  698. $BIN/v-rebuild-mail-domains "$user" 'no'
  699. else
  700. $BIN/v-rebuild-mail-domains "$user" 'no' > /dev/null 2>&1
  701. fi
  702. fi
  703. if [ "$DEBUG_MODE" = "true" ]; then
  704. echo " ---- User configuration..."
  705. $BIN/v-rebuild-user "$user" 'no'
  706. else
  707. $BIN/v-rebuild-user "$user" 'no' > /dev/null 2>&1
  708. fi
  709. done
  710. fi
  711. }
  712. update_whitelabel_logo() {
  713. $BIN/v-update-white-label-logo
  714. }
  715. upgrade_replace_default_config() {
  716. syshealth_update_web_config_format
  717. syshealth_update_mail_config_format
  718. syshealth_update_mail_account_config_format
  719. syshealth_update_dns_config_format
  720. syshealth_update_db_config_format
  721. syshealth_update_user_config_format
  722. }
  723. upgrade_restart_services() {
  724. if [ "$UPGRADE_RESTART_SERVICES" = "true" ]; then
  725. echo "[ * ] Restarting services..."
  726. sleep 2
  727. if [ -n "$MAIL_SYSTEM" ]; then
  728. if [ "$DEBUG_MODE" = "true" ]; then
  729. echo " - $MAIL_SYSTEM"
  730. fi
  731. $BIN/v-restart-mail 'yes'
  732. fi
  733. if [ -n "$IMAP_SYSTEM" ]; then
  734. if [ "$DEBUG_MODE" = "true" ]; then
  735. echo " - $IMAP_SYSTEM"
  736. fi
  737. $BIN/v-restart-service "$IMAP_SYSTEM"
  738. fi
  739. if [ -n "$WEB_SYSTEM" ]; then
  740. if [ "$DEBUG_MODE" = "true" ]; then
  741. echo " - $WEB_SYSTEM"
  742. fi
  743. $BIN/v-restart-web 'yes'
  744. fi
  745. if [ -n "$PROXY_SYSTEM" ]; then
  746. if [ "$DEBUG_MODE" = "true" ]; then
  747. echo " - $PROXY_SYSTEM"
  748. fi
  749. $BIN/v-restart-proxy 'yes'
  750. fi
  751. if [ -n "$DNS_SYSTEM" ]; then
  752. if [ "$DEBUG_MODE" = "true" ]; then
  753. echo " - $DNS_SYSTEM"
  754. fi
  755. $BIN/v-restart-dns 'yes'
  756. fi
  757. if [ -n "$WEB_BACKEND" ]; then
  758. versions_list=$($BIN/v-list-sys-php plain)
  759. for v in $versions_list; do
  760. if [ "$DEBUG_MODE" = "true" ]; then
  761. echo " - php$v-fpm"
  762. fi
  763. $BIN/v-restart-service "php$v-fpm" 'yes'
  764. done
  765. fi
  766. if [ -n "$FTP_SYSTEM" ]; then
  767. if [ "$DEBUG_MODE" = "true" ]; then
  768. echo " - $FTP_SYSTEM"
  769. fi
  770. $BIN/v-restart-ftp 'yes'
  771. fi
  772. if [ -n "$FIREWALL_EXTENSION" ]; then
  773. if [ "$DEBUG_MODE" = "true" ]; then
  774. echo " - $FIREWALL_EXTENSION"
  775. fi
  776. $BIN/v-restart-service "$FIREWALL_EXTENSION"
  777. fi
  778. # Restart SSH daemon service
  779. if [ "$DEBUG_MODE" = "true" ]; then
  780. echo " - sshd"
  781. fi
  782. $BIN/v-restart-service ssh
  783. fi
  784. # Always restart the Hestia Control Panel service
  785. if [ "$DEBUG_MODE" = "true" ]; then
  786. echo " - hestia"
  787. fi
  788. $BIN/v-restart-service hestia
  789. }