upgrade.sh 32 KB

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