upgrade.sh 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  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' '<b>Version:</b> '$new_version'<br><b>Code Branch:</b> '$RELEASE_BRANCH'<br><br>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>.<br><br><i class="fas fa-heart icon-red"></i> The Hestia Control Panel development team'
  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'.' '<b>Please share your feedback with our development team through our <a href="https://forum.hestiacp.com" target="_blank">discussion forum</a>.<br><br>Found a bug? <a href="https://github.com/hestiacp/hestiacp/issues" target="_blank">Open an issue on GitHub</a>!</b><br><br><i class="fas fa-heart icon-red"></i> The Hestia Control Panel development team'
  169. else
  170. # Send normal upgrade complete notification for stable releases
  171. $BIN/v-add-user-notification admin 'Upgrade complete' 'Hestia Control Panel has been updated to <b>v'$new_version'</b>.<br><a href="https://github.com/hestiacp/hestiacp/blob/release/CHANGELOG.md" target="_blank">View release notes</a><br><br>Please report any bugs by <a href="https://github.com/hestiacp/hestiacp/issues" target="_blank">opening an issue on GitHub</a>.<br><br><b>Have a wonderful day!</b><br><br><i class="fas fa-heart icon-red"></i> The Hestia Control Panel development team'
  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. # Hosting Packages
  243. mkdir -p $HESTIA_BACKUP/packages/
  244. # Domain template files
  245. mkdir -p $HESTIA_BACKUP/templates/
  246. # System services (apache2, nginx, bind9, vsftpd, etc).
  247. if [ -n "$WEB_SYSTEM" ]; then
  248. mkdir -p $HESTIA_BACKUP/conf/$WEB_SYSTEM/
  249. fi
  250. if [ -n "$IMAP_SYSTEM" ]; then
  251. mkdir -p $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
  252. fi
  253. if [ -n "$MAIL_SYSTEM" ]; then
  254. mkdir -p $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
  255. fi
  256. if [ -n "$DNS_SYSTEM" ]; then
  257. mkdir -p $HESTIA_BACKUP/conf/$DNS_SYSTEM/
  258. fi
  259. if [ -n "$PROXY_SYSTEM" ]; then
  260. mkdir -p $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  261. fi
  262. if [ -n "$DB_SYSTEM" ]; then
  263. if [[ "$DB_SYSTEM" =~ "mysql" ]]; then
  264. mkdir -p $HESTIA_BACKUP/conf/mysql/
  265. fi
  266. if [[ "$DB_SYSTEM" =~ "pgsql" ]]; then
  267. mkdir -p $HESTIA_BACKUP/conf/pgsql/
  268. fi
  269. fi
  270. if [ -n "$FTP_SYSTEM" ]; then
  271. mkdir -p $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  272. fi
  273. if [ -n "$FIREWALL_SYSTEM" ]; then
  274. mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_SYSTEM/
  275. fi
  276. if [ -n "$FIREWALL_EXTENSION" ]; then
  277. mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  278. fi
  279. if [ -e "/etc/ssh/sshd_config" ]; then
  280. mkdir -p $HESTIA_BACKUP/conf/ssh/
  281. fi
  282. if [ -d "/etc/roundcube/" ]; then
  283. mkdir -p $HESTIA_BACKUP/conf/roundcube/
  284. fi
  285. if [ -d "/etc/rainloop/" ]; then
  286. mkdir -p $HESTIA_BACKUP/conf/rainloop/
  287. fi
  288. if [ -d "/etc/phpmyadmin/" ]; then
  289. mkdir -p $HESTIA_BACKUP/conf/phpmyadmin/
  290. fi
  291. if [ -d "/etc/phppgadmin/" ]; then
  292. mkdir -p $HESTIA_BACKUP/conf/phppgadmin/
  293. fi
  294. }
  295. upgrade_init_logging() {
  296. # Set log file path
  297. LOG="$HESTIA_BACKUP/hst-upgrade-$(date +%d%m%Y%H%M).log"
  298. # Create log file
  299. touch $LOG
  300. # Add message to system log
  301. $BIN/v-log-action "system" "Info" "Updates" "Started update installation (Latest: $new_version, Previous: $VERSION)."
  302. # Add warnings for pre-release builds
  303. if [[ "$new_version" =~ "alpha" ]]; then
  304. $BIN/v-log-action "system" "Warning" "Updates" "Development build for testing purposes only. Report bugs at https://github.com/hestiacp/hestiacp/issues/."
  305. fi
  306. if [[ "$new_version" =~ "beta" ]]; then
  307. $BIN/v-log-action "system" "Warning" "Updates" "Beta release. Please report bugs at https://github.com/hestiacp/hestiacp/issues/."
  308. fi
  309. }
  310. upgrade_start_backup() {
  311. echo "============================================================================="
  312. echo "[ * ] Backing up existing templates and configuration files..."
  313. if [ "$DEBUG_MODE" = "true" ]; then
  314. echo " - Packages"
  315. fi
  316. cp -rf $HESTIA/data/packages/* $HESTIA_BACKUP/packages/
  317. if [ "$DEBUG_MODE" = "true" ]; then
  318. echo " - Templates"
  319. fi
  320. cp -rf $HESTIA/data/templates/* $HESTIA_BACKUP/templates/
  321. if [ "$DEBUG_MODE" = "true" ]; then
  322. echo " - Configuration files:"
  323. fi
  324. # Hestia Control Panel configuration files
  325. if [ "$DEBUG_MODE" = "true" ]; then
  326. echo " ---- hestia"
  327. fi
  328. cp -rf $HESTIA/conf/* $HESTIA_BACKUP/conf/hestia/
  329. # System service configuration files (apache2, nginx, bind9, vsftpd, etc).
  330. if [ -n "$WEB_SYSTEM" ]; then
  331. if [ "$DEBUG_MODE" = "true" ]; then
  332. echo " ---- $WEB_SYSTEM"
  333. fi
  334. cp -fr /etc/$WEB_SYSTEM/* $HESTIA_BACKUP/conf/$WEB_SYSTEM/
  335. fi
  336. if [ -n "$PROXY_SYSTEM" ]; then
  337. if [ "$DEBUG_MODE" = "true" ]; then
  338. echo " ---- $PROXY_SYSTEM"
  339. fi
  340. cp -fr /etc/$PROXY_SYSTEM/* $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  341. fi
  342. if [ -n "$IMAP_SYSTEM" ]; then
  343. if [ "$DEBUG_MODE" = "true" ]; then
  344. echo " ---- $IMAP_SYSTEM"
  345. fi
  346. cp -fr /etc/$IMAP_SYSTEM/* $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
  347. fi
  348. if [ -n "$MAIL_SYSTEM" ]; then
  349. if [ "$DEBUG_MODE" = "true" ]; then
  350. echo " ---- $MAIL_SYSTEM"
  351. fi
  352. cp -fr /etc/$MAIL_SYSTEM/* $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
  353. fi
  354. if [ -n "$DNS_SYSTEM" ]; then
  355. if [ "$DNS_SYSTEM" = "bind9" ]; then
  356. if [ "$DEBUG_MODE" = "true" ]; then
  357. echo " ---- $DNS_SYSTEM"
  358. fi
  359. cp -fr /etc/bind/* $HESTIA_BACKUP/conf/$DNS_SYSTEM/
  360. fi
  361. fi
  362. if [ -n "$DB_SYSTEM" ]; then
  363. if [[ "$DB_SYSTEM" =~ "mysql" ]]; then
  364. if [ "$DEBUG_MODE" = "true" ]; then
  365. echo " ---- mysql"
  366. fi
  367. cp -fr /etc/mysql/* $HESTIA_BACKUP/conf/mysql/
  368. fi
  369. if [[ "$DB_SYSTEM" =~ "pgsql" ]]; then
  370. if [ "$DEBUG_MODE" = "true" ]; then
  371. echo " ---- pgsql"
  372. fi
  373. # config for postgresql is stored in /etc/postgresql/version/main/
  374. cp -fr /etc/postgresql/* $HESTIA_BACKUP/conf/pgsql/
  375. fi
  376. fi
  377. if [ -n "$FTP_SYSTEM" ]; then
  378. if [ "$DEBUG_MODE" = "true" ]; then
  379. echo " ---- $FTP_SYSTEM"
  380. fi
  381. if [ "$FTP_SYSTEM" = "vsftpd" ]; then
  382. cp -f /etc/$FTP_SYSTEM.conf $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  383. fi
  384. if [ "$FTP_SYSTEM" = "proftpd" ]; then
  385. cp -f /etc/proftpd/proftpd.conf $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  386. fi
  387. fi
  388. if [ -n "$FIREWALL_SYSTEM" ]; then
  389. if [ "$DEBUG_MODE" = "true" ]; then
  390. echo " ---- $FIREWALL_SYSTEM"
  391. fi
  392. [ -e "/etc/sysconfig/iptables" ] && cp -f /etc/sysconfig/iptables $HESTIA_BACKUP/conf/$FIREWALL_SYSTEM/
  393. [ -e "/etc/iptables.rules" ] && cp -f /etc/iptables.rules $HESTIA_BACKUP/conf/$FIREWALL_SYSTEM/
  394. fi
  395. if [ -n "$FIREWALL_EXTENSION" ]; then
  396. if [ "$DEBUG_MODE" = "true" ]; then
  397. echo " ---- $FIREWALL_EXTENSION"
  398. fi
  399. cp -f /etc/$FIREWALL_EXTENSION/*.conf $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  400. cp -f /etc/$FIREWALL_EXTENSION/*.local $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  401. fi
  402. if [ -e "/etc/ssh/sshd_config" ]; then
  403. if [ "$DEBUG_MODE" = "true" ]; then
  404. echo " ---- sshd"
  405. fi
  406. cp -fr /etc/ssh/* $HESTIA_BACKUP/conf/ssh/
  407. fi
  408. if [ -d "/etc/roundcube" ]; then
  409. if [ "$DEBUG_MODE" = "true" ]; then
  410. echo " ---- Roundcube"
  411. fi
  412. cp -fr /etc/roundcube/* $HESTIA_BACKUP/conf/roundcube
  413. fi
  414. if [ -d "/etc/rainloop" ]; then
  415. if [ "$DEBUG_MODE" = "true" ]; then
  416. echo " ---- Rainloop"
  417. fi
  418. cp -fr /etc/rainloop/* $HESTIA_BACKUP/conf/rainloop
  419. fi
  420. if [ -d "/etc/phpmyadmin" ]; then
  421. if [ "$DEBUG_MODE" = "true" ]; then
  422. echo " ---- phpMyAdmin"
  423. fi
  424. cp -fr /etc/phpmyadmin/* $HESTIA_BACKUP/conf/phpmyadmin
  425. fi
  426. if [ -d "/etc/phppgadmin" ]; then
  427. if [ "$DEBUG_MODE" = "true" ]; then
  428. echo " ---- phppgadmin"
  429. fi
  430. cp -fr /etc/phppgadmin/* $HESTIA_BACKUP/conf/phppgadmin
  431. fi
  432. }
  433. upgrade_refresh_config() {
  434. source_conf "/usr/local/hestia/conf/hestia.conf"
  435. }
  436. upgrade_start_routine() {
  437. # Parse version numbers for comparison
  438. function check_version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
  439. # Remove pre-release designation from version number for upgrade scripts
  440. VERSION=$(echo "$VERSION" | sed "s/~\([a-zA-Z0-9].*\)//g")
  441. # Get list of all available version steps and create array
  442. upgrade_steps=$(ls -v $HESTIA/install/upgrade/versions/*.sh)
  443. for script in $upgrade_steps; do
  444. declare -a available_versions
  445. available_versions+=($(echo $script | sed "s|/usr/local/hestia/install/upgrade/versions/||g" | sed "s|.sh||g"))
  446. done
  447. # Define variables for accessing supported versions
  448. # Sort version by -V due to issues with version numbers 1.4.10 and higher
  449. all_versions=$(printf "%s\n" "${available_versions[@]}" | sort -V)
  450. oldest_version=$(printf "%s\n" "$all_versions" | head -n1)
  451. latest_version=$(printf "%s\n" "$all_versions" | sort -V | tail -n1)
  452. # Check for supported versions and process necessary upgrade steps
  453. if [ $(check_version $latest_version) -gt $(check_version $VERSION) ]; then
  454. for version_step in "${available_versions[@]}"; do
  455. if [ $(check_version $VERSION) -lt $(check_version "$version_step") ]; then
  456. upgrade_step_message
  457. source $HESTIA/install/upgrade/versions/$version_step.sh
  458. fi
  459. done
  460. upgrade_set_version "$VERSION"
  461. upgrade_refresh_config
  462. else
  463. echo ""
  464. echo "[ ! ] The latest version of Hestia Control Panel is already installed."
  465. echo " Verifying configuration..."
  466. echo ""
  467. if [ -e "$HESTIA/install/upgrade/versions/$VERSION.sh" ]; then
  468. source $HESTIA/install/upgrade/versions/$VERSION.sh
  469. fi
  470. VERSION="$new_version"
  471. upgrade_set_version "$VERSION"
  472. upgrade_refresh_config
  473. fi
  474. #####################################################################
  475. ####### End version-specific upgrade instruction sets #######
  476. #####################################################################
  477. }
  478. upgrade_b2_tool() {
  479. b2cli="/usr/local/bin/b2"
  480. b2lnk="https://github.com/Backblaze/B2_Command_Line_Tool/releases/download/v$b2_v/b2-linux"
  481. if [ -f "$b2cli" ]; then
  482. b2_version=$($b2cli version | grep -o -E '[0-9].[0-9].[0-9]+' | head -1)
  483. if version_ge "$b2_version" "$b2_v"; then
  484. echo "[ * ] Backblaze CLI tool is up to date ($b2_v)..."
  485. else
  486. echo "[ * ] Upgrading Backblaze CLI tool to version $b2_v..."
  487. rm $b2cli
  488. wget -O $b2cli $b2lnk > /dev/null 2>&1
  489. chmod +x $b2cli > /dev/null 2>&1
  490. if [ ! -f "$b2cli" ]; then
  491. echo "Error: Binary download failed, b2 doesn't work as expected."
  492. exit 3
  493. fi
  494. fi
  495. fi
  496. }
  497. upgrade_cloudflare_ip() {
  498. if [ "$WEB_SYSTEM" = "nginx" ] || [ "$PROXY_SYSTEM" = "nginx" ]; then
  499. cf_ips="$(curl -fsLm2 --retry 1 https://api.cloudflare.com/client/v4/ips)"
  500. if [ -n "$cf_ips" ] && [ "$(echo "$cf_ips" | jq -r '.success//""')" = "true" ]; then
  501. cf_inc="/etc/nginx/conf.d/cloudflare.inc"
  502. echo "[ * ] Updating Cloudflare IP Ranges for Nginx..."
  503. echo "# Cloudflare IP Ranges" > $cf_inc
  504. echo "" >> $cf_inc
  505. echo "# IPv4" >> $cf_inc
  506. for ipv4 in $(echo "$cf_ips" | jq -r '.result.ipv4_cidrs[]//""' | sort); do
  507. echo "set_real_ip_from $ipv4;" >> $cf_inc
  508. done
  509. echo "" >> $cf_inc
  510. echo "# IPv6" >> $cf_inc
  511. for ipv6 in $(echo "$cf_ips" | jq -r '.result.ipv6_cidrs[]//""' | sort); do
  512. echo "set_real_ip_from $ipv6;" >> $cf_inc
  513. done
  514. echo "" >> $cf_inc
  515. echo "real_ip_header CF-Connecting-IP;" >> $cf_inc
  516. fi
  517. fi
  518. }
  519. upgrade_phppgadmin() {
  520. if [ -n "$(echo $DB_SYSTEM | grep -w 'pgsql')" ]; then
  521. pga_release=$(cat /usr/share/phppgadmin/libraries/lib.inc.php | grep appVersion | head -n1 | cut -f2 -d\' | cut -f1 -d-)
  522. if version_ge "$pga_release" "pga_v"; then
  523. echo "[ * ] phppgadmin is up to date ($pga_release)..."
  524. else
  525. # Display upgrade information
  526. echo "[ * ] Upgrading phppgadmin to version $pga_v..."
  527. [ -d /usr/share/phppgadmin ] || mkdir -p /usr/share/phppgadmin
  528. # Download latest phpMyAdmin release
  529. wget --retry-connrefused --quiet https://github.com/hestiacp/phppgadmin/releases/download/v$pga_v/phppgadmin-v$pga_v.tar.gz
  530. tar xzf phppgadmin-v$pga_v.tar.gz -C /usr/share/phppgadmin/
  531. if ! version_ge "$pga_release" "7.14.0"; then
  532. cp -f $HESTIA_INSTALL_DIR/pga/config.inc.php /etc/phppgadmin/
  533. fi
  534. if [ ! -f /usr/share/phppgadmin/conf/config.inc.php ]; then
  535. ln -s /etc/phppgadmin/config.inc.php /usr/share/phppgadmin/conf
  536. fi
  537. rm -f phppgadmin-v$pga_v.tar.gz
  538. fi
  539. fi
  540. }
  541. upgrade_phpmyadmin() {
  542. # Check if MariaDB/MySQL is installed on the server before attempting to install or upgrade phpMyAdmin
  543. if [ -n "$(echo $DB_SYSTEM | grep -w 'mysql')" ]; then
  544. pma_version=$(jq -r .version /usr/share/phpmyadmin/package.json)
  545. if version_ge "$pma_version" "$pma_v"; then
  546. echo "[ * ] phpMyAdmin is up to date (${pma_version})..."
  547. # Update permissions
  548. if [ -e /var/lib/phpmyadmin/blowfish_secret.inc.php ]; then
  549. chown root:www-data /var/lib/phpmyadmin/blowfish_secret.inc.php
  550. chmod 0640 /var/lib/phpmyadmin/blowfish_secret.inc.php
  551. fi
  552. else
  553. # Display upgrade information
  554. echo "[ * ] Upgrading phpMyAdmin to version $pma_v..."
  555. [ -d /usr/share/phpmyadmin ] || mkdir -p /usr/share/phpmyadmin
  556. # Download latest phpMyAdmin release
  557. wget --quiet https://files.phpmyadmin.net/phpMyAdmin/$pma_v/phpMyAdmin-$pma_v-all-languages.tar.gz
  558. # Unpack files
  559. tar xzf phpMyAdmin-$pma_v-all-languages.tar.gz
  560. # Delete file to prevent error
  561. rm -rf /usr/share/phpmyadmin/doc/html
  562. # Overwrite old files
  563. cp -rf phpMyAdmin-$pma_v-all-languages/* /usr/share/phpmyadmin
  564. # Set config and log directory
  565. sed -i "s|'configFile' => ROOT_PATH . 'config.inc.php',|'configFile' => '/etc/phpmyadmin/config.inc.php',|g" /usr/share/phpmyadmin/libraries/vendor_config.php
  566. # Create temporary folder and change permissions
  567. if [ ! -d /usr/share/phpmyadmin/tmp ]; then
  568. mkdir /usr/share/phpmyadmin/tmp
  569. chown root:www-data /usr/share/phpmyadmin/tmp
  570. chmod 0770 /usr/share/phpmyadmin/tmp
  571. fi
  572. if [ -e /var/lib/phpmyadmin/blowfish_secret.inc.php ]; then
  573. chown root:www-data /var/lib/phpmyadmin/blowfish_secret.inc.php
  574. chmod 0640 /var/lib/phpmyadmin/blowfish_secret.inc.php
  575. fi
  576. # Clean up source files
  577. rm -fr phpMyAdmin-$pma_v-all-languages
  578. rm -f phpMyAdmin-$pma_v-all-languages.tar.gz
  579. fi
  580. fi
  581. }
  582. upgrade_filemanager() {
  583. FILE_MANAGER_CHECK=$(cat $HESTIA/conf/hestia.conf | grep "FILE_MANAGER='false'")
  584. if [ -z "$FILE_MANAGER_CHECK" ]; then
  585. if [ -f "$HESTIA/web/fm/version" ]; then
  586. fm_version=$(cat $HESTIA/web/fm/version)
  587. else
  588. fm_version="1.0.0"
  589. fi
  590. if ! version_ge "$fm_version" "$fm_v"; then
  591. echo "[ ! ] Upgrading File Manager to version $fm_v..."
  592. # Reinstall the File Manager
  593. $BIN/v-delete-sys-filemanager quiet yes
  594. $BIN/v-add-sys-filemanager quiet
  595. else
  596. echo "[ * ] File Manager is up to date ($fm_v)..."
  597. if [ "$UPGRADE_UPDATE_FILEMANAGER_CONFIG" = "true" ]; then
  598. if [ -e "$HESTIA/web/fm/configuration.php" ]; then
  599. echo "[ ! ] Updating File Manager configuration..."
  600. # Update configuration.php
  601. cp -f $HESTIA_INSTALL_DIR/filemanager/filegator/configuration.php $HESTIA/web/fm/configuration.php
  602. # Set environment variable for interface
  603. $BIN/v-change-sys-config-value 'FILE_MANAGER' 'true'
  604. fi
  605. fi
  606. fi
  607. fi
  608. }
  609. upgrade_roundcube() {
  610. if [ -n "$(echo "$WEBMAIL_SYSTEM" | grep -w 'roundcube')" ]; then
  611. if [ -d "/usr/share/roundcube" ]; then
  612. echo "[ ! ] Roundcube: Updates are currently managed using the apt package manager"
  613. 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/"
  614. else
  615. rc_version=$(cat /var/lib/roundcube/index.php | grep -o -E '[0-9].[0-9].[0-9]+' | head -1)
  616. if ! version_ge "$rc_version" "$rc_v"; then
  617. echo "[ ! ] Upgrading Roundcube to version $rc_v..."
  618. $BIN/v-add-sys-roundcube
  619. else
  620. echo "[ * ] Roundcube is up to date ($rc_v)..."
  621. fi
  622. fi
  623. fi
  624. }
  625. upgrade_rainloop() {
  626. if [ -n "$(echo "$WEBMAIL_SYSTEM" | grep -w 'rainloop')" ]; then
  627. rl_version=$(cat /var/lib/rainloop/data/VERSION)
  628. if ! version_ge "$rl_version" "$rl_v"; then
  629. echo "[ ! ] Upgrading Rainloop to version $rl_v..."
  630. $BIN/v-add-sys-rainloop
  631. else
  632. echo "[ * ] Rainloop is up to date ($rl_v)..."
  633. fi
  634. fi
  635. }
  636. upgrade_dependencies() {
  637. echo "[ ! ] Update Hestia PHP dependencies..."
  638. $BIN/v-add-sys-dependencies
  639. }
  640. upgrade_rebuild_web_templates() {
  641. if [ "$UPGRADE_UPDATE_WEB_TEMPLATES" = "true" ]; then
  642. echo "[ ! ] Updating default web domain templates..."
  643. $BIN/v-update-web-templates "no" "skip"
  644. fi
  645. }
  646. upgrade_rebuild_mail_templates() {
  647. if [ "$UPGRADE_UPDATE_MAIL_TEMPLATES" = "true" ]; then
  648. echo "[ ! ] Updating default mail domain templates..."
  649. $BIN/v-update-mail-templates "no" "skip"
  650. fi
  651. }
  652. upgrade_rebuild_dns_templates() {
  653. if [ "$UPGRADE_UPDATE_DNS_TEMPLATES" = "true" ]; then
  654. echo "[ ! ] Updating default DNS zone templates..."
  655. $BIN/v-update-dns-templates
  656. fi
  657. }
  658. upgrade_rebuild_users() {
  659. if [ "$UPGRADE_REBUILD_USERS" = "true" ]; then
  660. if [ "$DEBUG_MODE" = "true" ]; then
  661. echo "[ * ] Rebuilding user accounts and domains:..."
  662. else
  663. echo "[ * ] Rebuilding user accounts and domains, this may take a few minutes..."
  664. fi
  665. for user in $($BIN/v-list-sys-users plain); do
  666. export restart="no"
  667. if [ "$DEBUG_MODE" = "true" ]; then
  668. echo " - $user:"
  669. else
  670. echo " - $user..."
  671. fi
  672. if [ -n "$WEB_SYSTEM" ]; then
  673. if [ "$DEBUG_MODE" = "true" ]; then
  674. echo " ---- Web domains..."
  675. $BIN/v-rebuild-web-domains "$user" 'no'
  676. else
  677. $BIN/v-rebuild-web-domains "$user" 'no' > /dev/null 2>&1
  678. fi
  679. fi
  680. if [ -n "$DNS_SYSTEM" ]; then
  681. if [ "$DEBUG_MODE" = "true" ]; then
  682. echo " ---- DNS zones..."
  683. $BIN/v-rebuild-dns-domains "$user" 'no'
  684. else
  685. $BIN/v-rebuild-dns-domains "$user" 'no' > /dev/null 2>&1
  686. fi
  687. fi
  688. if [ -n "$MAIL_SYSTEM" ]; then
  689. if [ "$DEBUG_MODE" = "true" ]; then
  690. echo " ---- Mail domains..."
  691. $BIN/v-rebuild-mail-domains "$user" 'no'
  692. else
  693. $BIN/v-rebuild-mail-domains "$user" 'no' > /dev/null 2>&1
  694. fi
  695. fi
  696. if [ "$DEBUG_MODE" = "true" ]; then
  697. echo " ---- User configuration..."
  698. $BIN/v-rebuild-user "$user" 'no'
  699. else
  700. $BIN/v-rebuild-user "$user" 'no' > /dev/null 2>&1
  701. fi
  702. done
  703. fi
  704. }
  705. update_whitelabel_logo() {
  706. $BIN/v-update-white-label-logo
  707. }
  708. upgrade_replace_default_config() {
  709. syshealth_update_web_config_format
  710. syshealth_update_mail_config_format
  711. syshealth_update_mail_account_config_format
  712. syshealth_update_dns_config_format
  713. syshealth_update_db_config_format
  714. syshealth_update_user_config_format
  715. }
  716. upgrade_restart_services() {
  717. if [ "$UPGRADE_RESTART_SERVICES" = "true" ]; then
  718. echo "[ * ] Restarting services..."
  719. sleep 2
  720. if [ -n "$MAIL_SYSTEM" ]; then
  721. if [ "$DEBUG_MODE" = "true" ]; then
  722. echo " - $MAIL_SYSTEM"
  723. fi
  724. $BIN/v-restart-mail 'yes'
  725. fi
  726. if [ -n "$IMAP_SYSTEM" ]; then
  727. if [ "$DEBUG_MODE" = "true" ]; then
  728. echo " - $IMAP_SYSTEM"
  729. fi
  730. $BIN/v-restart-service "$IMAP_SYSTEM"
  731. fi
  732. if [ -n "$WEB_SYSTEM" ]; then
  733. if [ "$DEBUG_MODE" = "true" ]; then
  734. echo " - $WEB_SYSTEM"
  735. fi
  736. $BIN/v-restart-web 'yes'
  737. fi
  738. if [ -n "$PROXY_SYSTEM" ]; then
  739. if [ "$DEBUG_MODE" = "true" ]; then
  740. echo " - $PROXY_SYSTEM"
  741. fi
  742. $BIN/v-restart-proxy 'yes'
  743. fi
  744. if [ -n "$DNS_SYSTEM" ]; then
  745. if [ "$DEBUG_MODE" = "true" ]; then
  746. echo " - $DNS_SYSTEM"
  747. fi
  748. $BIN/v-restart-dns 'yes'
  749. fi
  750. if [ -n "$WEB_BACKEND" ]; then
  751. versions_list=$($BIN/v-list-sys-php plain)
  752. for v in $versions_list; do
  753. if [ "$DEBUG_MODE" = "true" ]; then
  754. echo " - php$v-fpm"
  755. fi
  756. $BIN/v-restart-service "php$v-fpm" 'yes'
  757. done
  758. fi
  759. if [ -n "$FTP_SYSTEM" ]; then
  760. if [ "$DEBUG_MODE" = "true" ]; then
  761. echo " - $FTP_SYSTEM"
  762. fi
  763. $BIN/v-restart-ftp 'yes'
  764. fi
  765. if [ -n "$FIREWALL_EXTENSION" ]; then
  766. if [ "$DEBUG_MODE" = "true" ]; then
  767. echo " - $FIREWALL_EXTENSION"
  768. fi
  769. $BIN/v-restart-service "$FIREWALL_EXTENSION"
  770. fi
  771. # Restart SSH daemon service
  772. if [ "$DEBUG_MODE" = "true" ]; then
  773. echo " - sshd"
  774. fi
  775. $BIN/v-restart-service ssh
  776. fi
  777. # Always restart the Hestia Control Panel service
  778. if [ "$DEBUG_MODE" = "true" ]; then
  779. echo " - hestia"
  780. fi
  781. $BIN/v-restart-service hestia
  782. }