upgrade.sh 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  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 tell us about any bugs or issues by opening an issue report on <a href="https://github.com/hestiacp/hestiacp/issues" target="_new"><i class="fab fa-github"></i> GitHub</a> and feel free to share your feedback on our <a href="https://forum.hestiacp.com" target="_new">discussion forum</a>.<br><br><i class="fas fa-heart status-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="_new">discussion forum</a>.<br><br>Found a bug? Report it on <a href="https://github.com/hestiacp/hestiacp/issues" target="_new"><i class="fab fa-github"></i> GitHub</a>!</b><br><br><i class="fas fa-heart status-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="_new">View release notes</a><br><br>Please tell us about any bugs or issues by opening a new issue report on <a href="https://github.com/hestiacp/hestiacp/issues" target="_new"><i class="fab fa-github"></i> GitHub</a>.<br><br><b>Have a wonderful day!</b><br><br><i class="fas fa-heart status-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=$($HESTIA/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
  229. do
  230. if [[ ! $lhs =~ ^\ *# && -n $lhs ]]; then
  231. rhs="${rhs%%\#*}" # Del in line right comments
  232. rhs="${rhs%%*( )}" # Del trailing spaces
  233. rhs="${rhs%\'*}" # Del opening string quotes
  234. rhs="${rhs#\'*}" # Del closing string quotes
  235. echo "$lhs='$rhs'" >> $HESTIA_BACKUP/upgrade.conf
  236. fi
  237. done < "$HESTIA/install/upgrade/upgrade.conf"
  238. }
  239. upgrade_init_backup() {
  240. # Ensure that backup directories are created
  241. # Hestia Control Panel configuration files
  242. mkdir -p $HESTIA_BACKUP/conf/hestia/
  243. # System services (apache2, nginx, bind9, vsftpd, etc).
  244. if [ -n "$WEB_SYSTEM" ]; then
  245. mkdir -p $HESTIA_BACKUP/conf/$WEB_SYSTEM/
  246. fi
  247. if [ -n "$IMAP_SYSTEM" ]; then
  248. mkdir -p $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
  249. fi
  250. if [ -n "$MAIL_SYSTEM" ]; then
  251. mkdir -p $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
  252. fi
  253. if [ -n "$DNS_SYSTEM" ]; then
  254. mkdir -p $HESTIA_BACKUP/conf/$DNS_SYSTEM/
  255. fi
  256. if [ -n "$PROXY_SYSTEM" ]; then
  257. mkdir -p $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  258. fi
  259. if [ -n "$DB_SYSTEM" ]; then
  260. mkdir -p $HESTIA_BACKUP/conf/$DB_SYSTEM/
  261. fi
  262. if [ -n "$FTP_SYSTEM" ]; then
  263. mkdir -p $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  264. fi
  265. if [ -n "$FIREWALL_SYSTEM" ]; then
  266. mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_SYSTEM/
  267. fi
  268. if [ -n "$FIREWALL_EXTENSION" ]; then
  269. mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  270. fi
  271. if [ -e "/etc/ssh/sshd_config" ]; then
  272. mkdir -p $HESTIA_BACKUP/conf/ssh/
  273. fi
  274. # Hosting Packages
  275. mkdir -p $HESTIA_BACKUP/packages/
  276. # Domain template files
  277. mkdir -p $HESTIA_BACKUP/templates/
  278. # System services (apache2, nginx, bind9, vsftpd, etc).
  279. if [ -n "$WEB_SYSTEM" ]; then
  280. mkdir -p $HESTIA_BACKUP/conf/$WEB_SYSTEM/
  281. fi
  282. if [ -n "$IMAP_SYSTEM" ]; then
  283. mkdir -p $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
  284. fi
  285. if [ -n "$MAIL_SYSTEM" ]; then
  286. mkdir -p $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
  287. fi
  288. if [ -n "$DNS_SYSTEM" ]; then
  289. mkdir -p $HESTIA_BACKUP/conf/$DNS_SYSTEM/
  290. fi
  291. if [ -n "$PROXY_SYSTEM" ]; then
  292. mkdir -p $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  293. fi
  294. if [ -n "$DB_SYSTEM" ]; then
  295. if [[ "$DB_SYSTEM" =~ "mysql" ]]; then
  296. mkdir -p $HESTIA_BACKUP/conf/mysql/
  297. fi
  298. if [[ "$DB_SYSTEM" =~ "pgsql" ]]; then
  299. mkdir -p $HESTIA_BACKUP/conf/pgsql/
  300. fi
  301. fi
  302. if [ -n "$FTP_SYSTEM" ]; then
  303. mkdir -p $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  304. fi
  305. if [ -n "$FIREWALL_SYSTEM" ]; then
  306. mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_SYSTEM/
  307. fi
  308. if [ -n "$FIREWALL_EXTENSION" ]; then
  309. mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  310. fi
  311. if [ -e "/etc/ssh/sshd_config" ]; then
  312. mkdir -p $HESTIA_BACKUP/conf/ssh/
  313. fi
  314. if [ -d "/etc/roundcube/" ]; then
  315. mkdir -p $HESTIA_BACKUP/conf/roundcube/
  316. fi
  317. if [ -d "/etc/rainloop/" ]; then
  318. mkdir -p $HESTIA_BACKUP/conf/rainloop/
  319. fi
  320. if [ -d "/etc/phpmyadmin/" ]; then
  321. mkdir -p $HESTIA_BACKUP/conf/phpmyadmin/
  322. fi
  323. }
  324. upgrade_init_logging() {
  325. # Set log file path
  326. LOG="$HESTIA_BACKUP/hst-upgrade-$(date +%d%m%Y%H%M).log"
  327. # Create log file
  328. touch $LOG
  329. # Add message to system log
  330. $BIN/v-log-action "system" "Info" "Updates" "Started update installation (Latest: $new_version, Previous: $VERSION)."
  331. # Add warnings for pre-release builds
  332. if [[ "$new_version" =~ "alpha" ]]; then
  333. $BIN/v-log-action "system" "Warning" "Updates" "Development build for testing purposes only. Report bugs at https://github.com/hestiacp/hestiacp/issues/."
  334. fi
  335. if [[ "$new_version" =~ "beta" ]]; then
  336. $BIN/v-log-action "system" "Warning" "Updates" "Beta release. Please report bugs at https://github.com/hestiacp/hestiacp/issues/."
  337. fi
  338. }
  339. upgrade_start_backup() {
  340. echo "[ * ] Backing up existing templates and configuration files..."
  341. if [ "$DEBUG_MODE" = "true" ]; then
  342. echo " - Packages"
  343. fi
  344. cp -rf $HESTIA/data/packages/* $HESTIA_BACKUP/packages/
  345. if [ "$DEBUG_MODE" = "true" ]; then
  346. echo " - Templates"
  347. fi
  348. cp -rf $HESTIA/data/templates/* $HESTIA_BACKUP/templates/
  349. if [ "$DEBUG_MODE" = "true" ]; then
  350. echo " - Configuration files:"
  351. fi
  352. # Hestia Control Panel configuration files
  353. if [ "$DEBUG_MODE" = "true" ]; then
  354. echo " ---- hestia"
  355. fi
  356. cp -rf $HESTIA/conf/* $HESTIA_BACKUP/conf/hestia/
  357. # System service configuration files (apache2, nginx, bind9, vsftpd, etc).
  358. if [ -n "$WEB_SYSTEM" ]; then
  359. if [ "$DEBUG_MODE" = "true" ]; then
  360. echo " ---- $WEB_SYSTEM"
  361. fi
  362. cp -fr /etc/$WEB_SYSTEM/* $HESTIA_BACKUP/conf/$WEB_SYSTEM/
  363. fi
  364. if [ -n "$PROXY_SYSTEM" ]; then
  365. if [ "$DEBUG_MODE" = "true" ]; then
  366. echo " ---- $PROXY_SYSTEM"
  367. fi
  368. cp -fr /etc/$PROXY_SYSTEM/* $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  369. fi
  370. if [ -n "$IMAP_SYSTEM" ]; then
  371. if [ "$DEBUG_MODE" = "true" ]; then
  372. echo " ---- $IMAP_SYSTEM"
  373. fi
  374. cp -fr /etc/$IMAP_SYSTEM/* $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
  375. fi
  376. if [ -n "$MAIL_SYSTEM" ]; then
  377. if [ "$DEBUG_MODE" = "true" ]; then
  378. echo " ---- $MAIL_SYSTEM"
  379. fi
  380. cp -fr /etc/$MAIL_SYSTEM/* $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
  381. fi
  382. if [ -n "$DNS_SYSTEM" ]; then
  383. if [ "$DNS_SYSTEM" = "bind9" ]; then
  384. if [ "$DEBUG_MODE" = "true" ]; then
  385. echo " ---- $DNS_SYSTEM"
  386. fi
  387. cp -fr /etc/bind/* $HESTIA_BACKUP/conf/$DNS_SYSTEM/
  388. fi
  389. fi
  390. if [ -n "$DB_SYSTEM" ]; then
  391. if [[ "$DB_SYSTEM" =~ "mysql" ]]; then
  392. if [ "$DEBUG_MODE" = "true" ]; then
  393. echo " ---- mysql"
  394. fi
  395. cp -fr /etc/mysql/* $HESTIA_BACKUP/conf/mysql/
  396. fi
  397. if [[ "$DB_SYSTEM" =~ "pgsql" ]]; then
  398. if [ "$DEBUG_MODE" = "true" ]; then
  399. echo " ---- pgsql"
  400. fi
  401. # config for postgresql is stored in /etc/postgresql/version/main/
  402. cp -fr /etc/postgresql/* $HESTIA_BACKUP/conf/pgsql/
  403. fi
  404. fi
  405. if [ -n "$FTP_SYSTEM" ]; then
  406. if [ "$DEBUG_MODE" = "true" ]; then
  407. echo " ---- $FTP_SYSTEM"
  408. fi
  409. if [ "$FTP_SYSTEM" = "vsftpd" ]; then
  410. cp -f /etc/$FTP_SYSTEM.conf $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  411. fi
  412. if [ "$FTP_SYSTEM" = "proftpd" ]; then
  413. cp -f /etc/proftpd/proftpd.conf $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  414. fi
  415. fi
  416. if [ -n "$FIREWALL_EXTENSION" ]; then
  417. if [ "$DEBUG_MODE" = "true" ]; then
  418. echo " ---- $FIREWALL_EXTENSION"
  419. fi
  420. cp -f /etc/$FIREWALL_EXTENSION/*.conf $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  421. cp -f /etc/$FIREWALL_EXTENSION/*.local $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  422. fi
  423. if [ -e "/etc/ssh/sshd_config" ]; then
  424. if [ "$DEBUG_MODE" = "true" ]; then
  425. echo " ---- sshd"
  426. fi
  427. cp -fr /etc/ssh/* $HESTIA_BACKUP/conf/ssh/
  428. fi
  429. if [ -d "/etc/roundcube" ]; then
  430. if [ "$DEBUG_MODE" = "true" ]; then
  431. echo " ---- Roundcube"
  432. fi
  433. cp -fr /etc/roundcube/* $HESTIA_BACKUP/conf/roundcube
  434. fi
  435. if [ -d "/etc/rainloop" ]; then
  436. if [ "$DEBUG_MODE" = "true" ]; then
  437. echo " ---- Rainloop"
  438. fi
  439. cp -fr /etc/rainloop/* $HESTIA_BACKUP/conf/rainloop
  440. fi
  441. if [ -d "/etc/phpmyadmin" ]; then
  442. if [ "$DEBUG_MODE" = "true" ]; then
  443. echo " ---- phpMyAdmin"
  444. fi
  445. cp -fr /etc/phpmyadmin/* $HESTIA_BACKUP/conf/phpmyadmin
  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 $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[@]}"
  470. do
  471. if [ $(check_version $VERSION) -lt $(check_version "$version_step") ]; then
  472. upgrade_step_message
  473. source $HESTIA/install/upgrade/versions/$version_step.sh
  474. fi
  475. done
  476. upgrade_set_version "$VERSION"
  477. upgrade_refresh_config
  478. else
  479. echo ""
  480. echo "[ ! ] The latest version of Hestia Control Panel is already installed."
  481. echo " Verifying configuration..."
  482. echo ""
  483. if [ -e "$HESTIA/install/upgrade/versions/$VERSION.sh" ]; then
  484. source $HESTIA/install/upgrade/versions/$VERSION.sh
  485. fi
  486. VERSION="$new_version"
  487. upgrade_set_version "$VERSION"
  488. upgrade_refresh_config
  489. fi
  490. #####################################################################
  491. ####### End version-specific upgrade instruction sets #######
  492. #####################################################################
  493. }
  494. upgrade_phpmyadmin() {
  495. # Check if MariaDB/MySQL is installed on the server before attempting to install or upgrade phpMyAdmin
  496. if [ -n "$(echo $DB_SYSTEM | grep -w 'mysql')" ]; then
  497. # Define version check function
  498. function version_ge(){ test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" -o -n "$1" -a "$1" = "$2"; }
  499. pma_release_file=$(ls /usr/share/phpmyadmin/RELEASE-DATE-* 2>/dev/null |tail -n 1)
  500. if version_ge "${pma_release_file##*-}" "$pma_v"; then
  501. echo "[ * ] phpMyAdmin is up to date (${pma_release_file##*-})..."
  502. # Update permissions
  503. if [ -e /var/lib/phpmyadmin/blowfish_secret.inc.php ]; then
  504. chown root:www-data /var/lib/phpmyadmin/blowfish_secret.inc.php
  505. chmod 0640 /var/lib/phpmyadmin/blowfish_secret.inc.php
  506. fi
  507. else
  508. # Display upgrade information
  509. echo "[ * ] Upgrading phpMyAdmin to version v$pma_v..."
  510. [ -d /usr/share/phpmyadmin ] || mkdir -p /usr/share/phpmyadmin
  511. # Download latest phpMyAdmin release
  512. wget --quiet https://files.phpmyadmin.net/phpMyAdmin/$pma_v/phpMyAdmin-$pma_v-all-languages.tar.gz
  513. # Unpack files
  514. tar xzf phpMyAdmin-$pma_v-all-languages.tar.gz
  515. # Delete file to prevent error
  516. rm -rf /usr/share/phpmyadmin/doc/html
  517. # Overwrite old files
  518. cp -rf phpMyAdmin-$pma_v-all-languages/* /usr/share/phpmyadmin
  519. # Set config and log directory
  520. sed -i "s|define('CONFIG_DIR', ROOT_PATH);|define('CONFIG_DIR', '/etc/phpmyadmin/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
  521. sed -i "s|define('TEMP_DIR', ROOT_PATH . 'tmp/');|define('TEMP_DIR', '/var/lib/phpmyadmin/tmp/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
  522. # Create temporary folder and change permissions
  523. if [ ! -d /usr/share/phpmyadmin/tmp ]; then
  524. mkdir /usr/share/phpmyadmin/tmp
  525. chown root:www-data /usr/share/phpmyadmin/tmp
  526. chmod 770 /usr/share/phpmyadmin/tmp
  527. fi
  528. if [ -e /var/lib/phpmyadmin/blowfish_secret.inc.php ]; then
  529. chown root:www-data /var/lib/phpmyadmin/blowfish_secret.inc.php
  530. chmod 0640 /var/lib/phpmyadmin/blowfish_secret.inc.php
  531. fi
  532. # Clean up source files
  533. rm -fr phpMyAdmin-$pma_v-all-languages
  534. rm -f phpMyAdmin-$pma_v-all-languages.tar.gz
  535. fi
  536. fi
  537. }
  538. upgrade_filemanager() {
  539. FILE_MANAGER_CHECK=$(cat $HESTIA/conf/hestia.conf | grep "FILE_MANAGER='false'")
  540. if [ -z "$FILE_MANAGER_CHECK" ]; then
  541. if [ -f "$HESTIA/web/fm/version" ]; then
  542. fm_version=$(cat $HESTIA/web/fm/version);
  543. else
  544. fm_version="1.0.0"
  545. fi
  546. if [ "$fm_version" != "$fm_v" ]; then
  547. echo "[ ! ] Updating File Manager..."
  548. # Reinstall the File Manager
  549. $HESTIA/bin/v-delete-sys-filemanager quiet yes
  550. $HESTIA/bin/v-add-sys-filemanager quiet
  551. else
  552. echo "[ * ] File Manager is up to date ($fm_v)..."
  553. if [ "$UPGRADE_UPDATE_FILEMANAGER_CONFIG" = "true" ]; then
  554. if [ -e "$HESTIA/web/fm/configuration.php" ]; then
  555. echo "[ ! ] Updating File Manager configuration..."
  556. # Update configuration.php
  557. cp -f $HESTIA_INSTALL_DIR/filemanager/filegator/configuration.php $HESTIA/web/fm/configuration.php
  558. # Set environment variable for interface
  559. $HESTIA/bin/v-change-sys-config-value 'FILE_MANAGER' 'true'
  560. fi
  561. fi
  562. fi
  563. fi
  564. }
  565. upgrade_roundcube(){
  566. if [ -n "$(echo "$WEBMAIL_SYSTEM" | grep -w 'roundcube')" ]; then
  567. if [ -d "/usr/share/roundcube" ]; then
  568. echo "[ ! ] Roundcube: Updates are currently managed using the apt package manager";
  569. 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/"
  570. else
  571. rc_version=$(cat /var/lib/roundcube/index.php | grep -o -E '[0-9].[0-9].[0-9]+' | head -1);
  572. if [ "$rc_version" != "$rc_v" ]; then
  573. echo "[ ! ] Upgrading Roundcube to version v$rc_v..."
  574. $HESTIA/bin/v-add-sys-roundcube
  575. else
  576. echo "[ * ] Roundcube is up to date ($rc_v)..."
  577. fi
  578. fi
  579. fi
  580. }
  581. upgrade_rainloop(){
  582. if [ -n "$(echo "$WEBMAIL_SYSTEM" | grep -w 'rainloop')" ]; then
  583. rl_version=$(cat /var/lib/rainloop/data/VERSION);
  584. if [ "$rl_version" != "$rl_v" ]; then
  585. echo "[ ! ] Upgrading Rainloop to version v$rl_v..."
  586. $HESTIA/bin/v-add-sys-rainloop
  587. else
  588. echo "[ * ] Rainloop is up to date ($rl_v)..."
  589. fi
  590. fi
  591. }
  592. upgrade_phpmailer(){
  593. if [ ! -d "$HESTIA/web/inc/vendor/" ]; then
  594. echo "[ ! ] Install PHPmailer";
  595. $HESTIA/bin/v-add-sys-phpmailer
  596. fi
  597. phpm_version=$(cat $HESTIA/web/inc/vendor/phpmailer/phpmailer/VERSION);
  598. if [ "$phpm_version" != "$pm_v" ]; then
  599. echo "[ ! ] Upgrading PHPmailer..."
  600. $HESTIA/bin/v-add-sys-phpmailer
  601. else
  602. echo "[ * ] PHPmailer is up to date ($pm_v)..."
  603. fi
  604. }
  605. upgrade_rebuild_web_templates() {
  606. if [ "$UPGRADE_UPDATE_WEB_TEMPLATES" = "true" ]; then
  607. echo "[ ! ] Updating default web domain templates..."
  608. $BIN/v-update-web-templates "no" "skip"
  609. fi
  610. }
  611. upgrade_rebuild_mail_templates() {
  612. if [ "$UPGRADE_UPDATE_MAIL_TEMPLATES" = "true" ]; then
  613. echo "[ ! ] Updating default mail domain templates..."
  614. $BIN/v-update-mail-templates "no" "skip"
  615. fi
  616. }
  617. upgrade_rebuild_dns_templates() {
  618. if [ "$UPGRADE_UPDATE_DNS_TEMPLATES" = "true" ]; then
  619. echo "[ ! ] Updating default DNS zone templates..."
  620. $BIN/v-update-dns-templates
  621. fi
  622. }
  623. upgrade_rebuild_users() {
  624. if [ "$UPGRADE_REBUILD_USERS" = "true" ]; then
  625. if [ "$DEBUG_MODE" = "true" ]; then
  626. echo "[ * ] Rebuilding user accounts and domains:"
  627. else
  628. echo "[ * ] Rebuilding user accounts and domains, this may take a few minutes..."
  629. fi
  630. for user in $($HESTIA/bin/v-list-sys-users plain); do
  631. export restart="no"
  632. if [ "$DEBUG_MODE" = "true" ]; then
  633. echo " - $user:"
  634. else
  635. echo " - $user..."
  636. fi
  637. if [ -n "$WEB_SYSTEM" ]; then
  638. if [ "$DEBUG_MODE" = "true" ]; then
  639. echo " ---- Web domains..."
  640. $BIN/v-rebuild-web-domains "$user" 'no'
  641. else
  642. $BIN/v-rebuild-web-domains "$user" 'no' >/dev/null 2>&1
  643. fi
  644. fi
  645. if [ -n "$DNS_SYSTEM" ]; then
  646. if [ "$DEBUG_MODE" = "true" ]; then
  647. echo " ---- DNS zones..."
  648. $BIN/v-rebuild-dns-domains "$user" 'no'
  649. else
  650. $BIN/v-rebuild-dns-domains "$user" 'no' >/dev/null 2>&1
  651. fi
  652. fi
  653. if [ -n "$MAIL_SYSTEM" ]; then
  654. if [ "$DEBUG_MODE" = "true" ]; then
  655. echo " ---- Mail domains..."
  656. $BIN/v-rebuild-mail-domains "$user" 'no'
  657. else
  658. $BIN/v-rebuild-mail-domains "$user" 'no' >/dev/null 2>&1
  659. fi
  660. fi
  661. if [ "$DEBUG_MODE" = "true" ]; then
  662. echo " ---- User configuration..."
  663. $BIN/v-rebuild-user "$user" 'no'
  664. else
  665. $BIN/v-rebuild-user "$user" 'no' >/dev/null 2>&1
  666. fi
  667. done
  668. fi
  669. }
  670. upgrade_replace_default_config() {
  671. if [ "$UPGRADE_REPLACE_KNOWN_KEYS" ]; then
  672. syshealth_update_web_config_format
  673. syshealth_update_mail_config_format
  674. syshealth_update_dns_config_format
  675. syshealth_update_db_config_format
  676. syshealth_update_user_config_format
  677. fi
  678. }
  679. upgrade_restart_services() {
  680. if [ "$UPGRADE_RESTART_SERVICES" = "true" ]; then
  681. echo "[ * ] Restarting services..."
  682. sleep 2
  683. if [ -n "$MAIL_SYSTEM" ]; then
  684. if [ "$DEBUG_MODE" = "true" ]; then
  685. echo " - $MAIL_SYSTEM"
  686. fi
  687. $BIN/v-restart-mail 'yes'
  688. fi
  689. if [ -n "$IMAP_SYSTEM" ]; then
  690. if [ "$DEBUG_MODE" = "true" ]; then
  691. echo " - $IMAP_SYSTEM"
  692. fi
  693. $BIN/v-restart-service "$IMAP_SYSTEM"
  694. fi
  695. if [ -n "$WEB_SYSTEM" ]; then
  696. if [ "$DEBUG_MODE" = "true" ]; then
  697. echo " - $WEB_SYSTEM"
  698. fi
  699. $BIN/v-restart-web 'yes'
  700. fi
  701. if [ -n "$PROXY_SYSTEM" ]; then
  702. if [ "$DEBUG_MODE" = "true" ]; then
  703. echo " - $PROXY_SYSTEM"
  704. fi
  705. $BIN/v-restart-proxy 'yes'
  706. fi
  707. if [ -n "$DNS_SYSTEM" ]; then
  708. if [ "$DEBUG_MODE" = "true" ]; then
  709. echo " - $DNS_SYSTEM"
  710. fi
  711. $BIN/v-restart-dns 'yes'
  712. fi
  713. if [ -n "$WEB_BACKEND" ]; then
  714. versions_list=$($BIN/v-list-sys-php plain)
  715. for v in $versions_list; do
  716. if [ "$DEBUG_MODE" = "true" ]; then
  717. echo " - php$v-fpm"
  718. fi
  719. $BIN/v-restart-service "php$v-fpm" 'yes'
  720. done
  721. fi
  722. if [ -n "$FTP_SYSTEM" ]; then
  723. if [ "$DEBUG_MODE" = "true" ]; then
  724. echo " - $FTP_SYSTEM"
  725. fi
  726. $BIN/v-restart-ftp 'yes'
  727. fi
  728. if [ -n "$FIREWALL_EXTENSION" ]; then
  729. if [ "$DEBUG_MODE" = "true" ]; then
  730. echo " - $FIREWALL_EXTENSION"
  731. fi
  732. $BIN/v-restart-service "$FIREWALL_EXTENSION"
  733. fi
  734. # Restart SSH daemon service
  735. if [ "$DEBUG_MODE" = "true" ]; then
  736. echo " - sshd"
  737. fi
  738. $BIN/v-restart-service ssh
  739. fi
  740. # Always restart the Hestia Control Panel service
  741. if [ "$DEBUG_MODE" = "true" ]; then
  742. echo " - hestia"
  743. fi
  744. $BIN/v-restart-service hestia
  745. }