upgrade.sh 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. #!/bin/bash
  2. # Hestia Control Panel - Upgrade Control Script
  3. # Import system health check and repair library
  4. source $HESTIA/func/syshealth.sh
  5. #####################################################################
  6. ####### Functions & Initialization #######
  7. #####################################################################
  8. is_debug_build() {
  9. if [[ "$new_version" =~ "alpha" ]] || [[ "$new_version" =~ "beta" ]]; then
  10. DEBUG_MODE="true"
  11. fi
  12. # Remove pre-release designation tags from display version
  13. DISPLAY_VER=$(echo $new_version | sed "s|~alpha||g" | sed "s|~beta||g")
  14. }
  15. upgrade_health_check() {
  16. echo "============================================================================="
  17. echo "[ ! ] Performing system health check before proceeding with installation... "
  18. # Perform basic health check against hestia.conf to ensure that
  19. # system variables exist and are set to expected defaults.
  20. if [ -z "$VERSION" ]; then
  21. export VERSION="1.1.0"
  22. $BIN/v-change-sys-config-value 'VERSION' "$VERSION"
  23. echo
  24. echo "[ ! ] Unable to detect installed version of Hestia Control Panel."
  25. echo " Setting default version to $VERSION and processing upgrade steps."
  26. echo
  27. fi
  28. syshealth_repair_system_config
  29. echo "[ * ] Health check complete. Starting upgrade from $VERSION to $new_version..."
  30. echo "============================================================================="
  31. }
  32. upgrade_welcome_message() {
  33. echo
  34. echo ' _ _ _ _ ____ ____ '
  35. echo ' | | | | ___ ___| |_(_) __ _ / ___| _ \ '
  36. echo ' | |_| |/ _ \/ __| __| |/ _` | | | |_) | '
  37. echo ' | _ | __/\__ \ |_| | (_| | |___| __/ '
  38. echo ' |_| |_|\___||___/\__|_|\__,_|\____|_| '
  39. echo " "
  40. echo " Hestia Control Panel Software Update "
  41. echo " Version: ${DISPLAY_VER} "
  42. if [[ "$new_version" =~ "beta" ]]; then
  43. echo " BETA RELEASE "
  44. fi
  45. if [[ "$new_version" =~ "alpha" ]]; then
  46. echo " DEVELOPMENT SNAPSHOT "
  47. echo " NOT INTENDED FOR PRODUCTION USE "
  48. echo " USE AT YOUR OWN RISK "
  49. fi
  50. echo
  51. echo "=============================================================================="
  52. echo
  53. echo "[ ! ] IMPORTANT INFORMATION: "
  54. echo
  55. echo "Default configuration files and templates may be modified or replaced "
  56. echo "during the upgrade process. You may restore these files from: "
  57. echo ""
  58. echo "Backup directory: $HESTIA_BACKUP/ "
  59. echo "Installation log: $LOG "
  60. }
  61. upgrade_welcome_message_log() {
  62. echo "=============================================================================="
  63. echo "Hestia Control Panel Software Update Log"
  64. echo "=============================================================================="
  65. echo
  66. echo "OPERATING SYSTEM: $OS_TYPE ($OS_VERSION)"
  67. echo "CURRENT VERSION: $VERSION"
  68. echo "NEW VERSION: $new_version"
  69. echo "RELEASE BRANCH: $RELEASE_BRANCH"
  70. if [[ "$new_version" =~ "alpha" ]]; then
  71. echo "BUILD TYPE: Development snapshot"
  72. elif [[ "$new_version" =~ "beta" ]]; then
  73. echo "BUILD TYPE: Beta release"
  74. else
  75. echo "BUILD TYPE: Production release"
  76. fi
  77. echo
  78. echo "INSTALLER OPTIONS:"
  79. echo "============================================================================="
  80. echo "Send email notification on upgrade complete: $UPGRADE_SEND_EMAIL"
  81. echo "Send installed log output to admin email: $UPGRADE_SEND_EMAIL_LOG"
  82. echo
  83. }
  84. upgrade_step_message() {
  85. echo
  86. echo "[ - ] Now applying any necessary patches from version v$version_step..."
  87. }
  88. upgrade_complete_message() {
  89. # Echo message to console output
  90. echo "============================================================================="
  91. echo
  92. echo "Upgrade complete! If you encounter any issues or find a bug, "
  93. echo "please take a moment to report it to us on GitHub at the URL below: "
  94. echo "https://github.com/hestiacp/hestiacp/issues "
  95. echo
  96. echo "We hope that you enjoy using this version of Hestia Control Panel, "
  97. echo "have a wonderful day! "
  98. echo
  99. echo "Sincerely, "
  100. echo "The Hestia Control Panel development team "
  101. echo
  102. echo "Web: https://www.hestiacp.com/ "
  103. echo "Forum: https://forum.hestiacp.com/ "
  104. echo "Discord: https://discord.gg/nXRUZch "
  105. echo "GitHub: https://github.com/hestiacp/hestiacp/ "
  106. echo
  107. echo "Help support the Hestia Control Panel project by donating via PayPal: "
  108. echo "https://www.hestiacp.com/donate "
  109. echo
  110. echo "Made with love & pride by the open-source community around the world. "
  111. echo
  112. echo "============================================================================="
  113. echo
  114. }
  115. upgrade_complete_message_log() {
  116. echo
  117. echo "============================================================================="
  118. echo "UPGRADE COMPLETE. "
  119. echo "Please report any issues on GitHub: "
  120. echo "https://github.com/hestiacp/hestiacp/issues "
  121. echo "============================================================================="
  122. echo
  123. $BIN/v-log-action "system" "Info" "Updates" "Update installed (Version: $new_version)."
  124. }
  125. upgrade_cleanup_message() {
  126. echo "============================================================================="
  127. echo "Installation tasks complete, performing clean-up... "
  128. echo "============================================================================="
  129. }
  130. upgrade_get_version() {
  131. # Retrieve new version number for Hestia Control Panel from .deb package
  132. new_version=$(dpkg -l | awk '$2=="hestia" { print $3 }')
  133. }
  134. upgrade_set_version() {
  135. # Set new version number in hestia.conf
  136. $BIN/v-change-sys-config-value "VERSION" "$@"
  137. }
  138. upgrade_set_branch() {
  139. # Set branch in hestia.conf
  140. DISPLAY_VER=$(echo $@ | sed "s|~alpha||g" | sed "s|~beta||g");
  141. if [ "$DISPLAY_VER" = "$@" ]; then
  142. $BIN/v-change-sys-config-value "RELEASE_BRANCH" "release"
  143. fi
  144. }
  145. upgrade_send_notification_to_panel () {
  146. # Add notification to panel if variable is set to true or is not set
  147. if [[ "$new_version" =~ "alpha" ]]; then
  148. # Send notifications for development releases
  149. $HESTIA/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'
  150. elif [[ "$new_version" =~ "beta" ]]; then
  151. # Send feedback notification for beta releases
  152. $HESTIA/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'
  153. else
  154. # Send normal upgrade complete notification for stable releases
  155. $HESTIA/bin/v-add-user-notification admin 'Upgrade complete' 'Your server has been updated to Hestia Control Panel <b>v'$new_version'</b>.<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>.<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'
  156. fi
  157. }
  158. upgrade_send_notification_to_email () {
  159. if [ "$UPGRADE_SEND_EMAIL" = "true" ]; then
  160. # Retrieve admin email address, sendmail path, and message temp file path
  161. admin_email=$($HESTIA/bin/v-list-user admin json | grep "CONTACT" | cut -d'"' -f4)
  162. send_mail="$HESTIA/web/inc/mail-wrapper.php"
  163. message_tmp_file="/tmp/hestia-upgrade-complete.txt"
  164. # Create temporary file
  165. touch $message_tmp_file
  166. # Write message to file
  167. echo "$HOSTNAME has been upgraded from Hestia Control Panel v$VERSION to v${new_version}." >> $message_tmp_file
  168. echo "Installation log: $LOG" >> $message_tmp_file
  169. echo "" >> $message_tmp_file
  170. echo "What's new: https://github.com/hestiacp/hestiacp/blob/$RELEASE_BRANCH/CHANGELOG.md" >> $message_tmp_file
  171. echo >> $message_tmp_file
  172. echo "What to do if you run into issues:" >> $message_tmp_file
  173. echo "- Check our forums for possible solutions: https://forum.hestiacp.com" >> $message_tmp_file
  174. echo "- File an issue report on GitHub: https://github.com/hestiacp/hestiacp/issues" >> $message_tmp_file
  175. echo "" >> $message_tmp_file
  176. echo "===================================================" >> $message_tmp_file
  177. echo "Have a wonderful day," >> $message_tmp_file
  178. echo "The Hestia Control Panel development team" >> $message_tmp_file
  179. # Read back message from file and pass through to sendmail
  180. cat $message_tmp_file | $send_mail -s "Update Installed - v${new_version}" $admin_email
  181. rm -f $message_tmp_file
  182. fi
  183. }
  184. upgrade_send_log_to_email() {
  185. if [ "$UPGRADE_SEND_EMAIL_LOG" = "true" ]; then
  186. admin_email=$($BIN/v-list-user admin json | grep "CONTACT" | cut -d'"' -f4)
  187. send_mail="$HESTIA/web/inc/mail-wrapper.php"
  188. cat $LOG | $send_mail -s "Update Installation Log - v${new_version}" $admin_email
  189. fi
  190. }
  191. upgrade_init_backup() {
  192. # Ensure that backup directories are created
  193. # Hestia Control Panel configuration files
  194. mkdir -p $HESTIA_BACKUP/conf/hestia/
  195. # System services (apache2, nginx, bind9, vsftpd, etc).
  196. if [ ! -z "$WEB_SYSTEM" ]; then
  197. mkdir -p $HESTIA_BACKUP/conf/$WEB_SYSTEM/
  198. fi
  199. if [ ! -z "$IMAP_SYSTEM" ]; then
  200. mkdir -p $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
  201. fi
  202. if [ ! -z "$MAIL_SYSTEM" ]; then
  203. mkdir -p $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
  204. fi
  205. if [ ! -z "$DNS_SYSTEM" ]; then
  206. mkdir -p $HESTIA_BACKUP/conf/$DNS_SYSTEM/
  207. fi
  208. if [ ! -z "$PROXY_SYSTEM" ]; then
  209. mkdir -p $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  210. fi
  211. if [ ! -z "$DB_SYSTEM" ]; then
  212. mkdir -p $HESTIA_BACKUP/conf/$DB_SYSTEM/
  213. fi
  214. if [ ! -z "$FTP_SYSTEM" ]; then
  215. mkdir -p $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  216. fi
  217. if [ ! -z "$FIREWALL_SYSTEM" ]; then
  218. mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_SYSTEM/
  219. fi
  220. if [ ! -z "$FIREWALL_EXTENSION" ]; then
  221. mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  222. fi
  223. if [ -e "/etc/ssh/sshd_config" ]; then
  224. mkdir -p $HESTIA_BACKUP/conf/ssh/
  225. fi
  226. # Hosting Packages
  227. mkdir -p $HESTIA_BACKUP/packages/
  228. # Domain template files
  229. mkdir -p $HESTIA_BACKUP/templates/
  230. # System services (apache2, nginx, bind9, vsftpd, etc).
  231. if [ ! -z "$WEB_SYSTEM" ]; then
  232. mkdir -p $HESTIA_BACKUP/conf/$WEB_SYSTEM/
  233. fi
  234. if [ ! -z "$IMAP_SYSTEM" ]; then
  235. mkdir -p $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
  236. fi
  237. if [ ! -z "$MAIL_SYSTEM" ]; then
  238. mkdir -p $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
  239. fi
  240. if [ ! -z "$DNS_SYSTEM" ]; then
  241. mkdir -p $HESTIA_BACKUP/conf/$DNS_SYSTEM/
  242. fi
  243. if [ ! -z "$PROXY_SYSTEM" ]; then
  244. mkdir -p $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  245. fi
  246. if [ ! -z "$DB_SYSTEM" ]; then
  247. if [[ "$DB_SYSTEM" =~ "mysql" ]]; then
  248. mkdir -p $HESTIA_BACKUP/conf/mysql/
  249. fi
  250. if [[ "$DB_SYSTEM" =~ "pgsql" ]]; then
  251. mkdir -p $HESTIA_BACKUP/conf/pgsql/
  252. fi
  253. fi
  254. if [ ! -z "$FTP_SYSTEM" ]; then
  255. mkdir -p $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  256. fi
  257. if [ ! -z "$FIREWALL_SYSTEM" ]; then
  258. mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_SYSTEM/
  259. fi
  260. if [ ! -z "$FIREWALL_EXTENSION" ]; then
  261. mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  262. fi
  263. if [ -e "/etc/ssh/sshd_config" ]; then
  264. mkdir -p $HESTIA_BACKUP/conf/ssh/
  265. fi
  266. }
  267. upgrade_init_logging() {
  268. # Set log file path
  269. LOG="$HESTIA_BACKUP/hst-upgrade-$(date +%d%m%Y%H%M).log"
  270. # Create log file
  271. touch $LOG
  272. # Add message to system log
  273. $BIN/v-log-action "system" "Info" "Updates" "Started update installation (Latest: $new_version, Previous: $VERSION)."
  274. # Add warnings for pre-release builds
  275. if [[ "$new_version" =~ "alpha" ]]; then
  276. $BIN/v-log-action "system" "Warning" "Updates" "Development build for testing purposes only. Report bugs at https://github.com/hestiacp/hestiacp/issues/."
  277. fi
  278. if [[ "$new_version" =~ "beta" ]]; then
  279. $BIN/v-log-action "system" "Warning" "Updates" "Beta release. Please report bugs at https://github.com/hestiacp/hestiacp/issues/."
  280. fi
  281. }
  282. upgrade_start_backup() {
  283. echo "[ * ] Backing up existing templates and configuration files..."
  284. if [ "$DEBUG_MODE" = "true" ]; then
  285. echo " - Packages"
  286. fi
  287. cp -rf $HESTIA/data/packages/* $HESTIA_BACKUP/packages/
  288. if [ "$DEBUG_MODE" = "true" ]; then
  289. echo " - Templates"
  290. fi
  291. cp -rf $HESTIA/data/templates/* $HESTIA_BACKUP/templates/
  292. if [ "$DEBUG_MODE" = "true" ]; then
  293. echo " - Configuration files:"
  294. fi
  295. # Hestia Control Panel configuration files
  296. if [ "$DEBUG_MODE" = "true" ]; then
  297. echo " ---- hestia"
  298. fi
  299. cp -rf $HESTIA/conf/* $HESTIA_BACKUP/conf/hestia/
  300. # System service configuration files (apache2, nginx, bind9, vsftpd, etc).
  301. if [ ! -z "$WEB_SYSTEM" ]; then
  302. if [ "$DEBUG_MODE" = "true" ]; then
  303. echo " ---- $WEB_SYSTEM"
  304. fi
  305. cp -f /etc/$WEB_SYSTEM/*.conf $HESTIA_BACKUP/conf/$WEB_SYSTEM/
  306. cp -f /etc/$WEB_SYSTEM/conf.d/*.conf $HESTIA_BACKUP/conf/$WEB_SYSTEM/
  307. fi
  308. if [ ! -z "$PROXY_SYSTEM" ]; then
  309. if [ "$DEBUG_MODE" = "true" ]; then
  310. echo " ---- $PROXY_SYSTEM"
  311. fi
  312. cp -f /etc/$PROXY_SYSTEM/*.conf $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  313. cp -f /etc/$PROXY_SYSTEM/conf.d/*.conf $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  314. cp -f /etc/$PROXY_SYSTEM/conf.d/*.inc $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  315. fi
  316. if [ ! -z "$IMAP_SYSTEM" ]; then
  317. if [ "$DEBUG_MODE" = "true" ]; then
  318. echo " ---- $IMAP_SYSTEM"
  319. fi
  320. cp -f /etc/$IMAP_SYSTEM/*.conf $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
  321. cp -f /etc/$IMAP_SYSTEM/conf.d/*.conf $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
  322. fi
  323. if [ ! -z "$MAIL_SYSTEM" ]; then
  324. if [ "$DEBUG_MODE" = "true" ]; then
  325. echo " ---- $MAIL_SYSTEM"
  326. fi
  327. cp -f /etc/$MAIL_SYSTEM/*.conf $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
  328. fi
  329. if [ ! -z "$DNS_SYSTEM" ]; then
  330. if [ "$DNS_SYSTEM" = "bind9" ]; then
  331. if [ "$DEBUG_MODE" = "true" ]; then
  332. echo " ---- $DNS_SYSTEM"
  333. fi
  334. cp -f /etc/bind/*.conf $HESTIA_BACKUP/conf/$DNS_SYSTEM/
  335. fi
  336. fi
  337. if [ ! -z "$DB_SYSTEM" ]; then
  338. if [[ "$DB_SYSTEM" =~ "mysql" ]]; then
  339. if [ "$DEBUG_MODE" = "true" ]; then
  340. echo " ---- mysql"
  341. fi
  342. cp -f /etc/mysql/*.cnf $HESTIA_BACKUP/conf/mysql/
  343. cp -f /etc/mysql/conf.d/*.cnf $HESTIA_BACKUP/conf/mysql/ > /dev/null 2>&1
  344. cp -f /etc/mysql/mariadb.conf.d/*.cnf $HESTIA_BACKUP/conf/mysql/ > /dev/null 2>&1
  345. fi
  346. if [[ "$DB_SYSTEM" =~ "pgsql" ]]; then
  347. if [ "$DEBUG_MODE" = "true" ]; then
  348. echo " ---- pgsql"
  349. fi
  350. cp -f /etc/mysql/*.cnf $HESTIA_BACKUP/conf/pgsql/
  351. cp -f /etc/mysql/conf.d/*.cnf $HESTIA_BACKUP/conf/pgsql/
  352. fi
  353. fi
  354. if [ ! -z "$FTP_SYSTEM" ]; then
  355. if [ "$DEBUG_MODE" = "true" ]; then
  356. echo " ---- $FTP_SYSTEM"
  357. fi
  358. if [ "$FTP_SYSTEM" = "vsftpd" ]; then
  359. cp -f /etc/$FTP_SYSTEM.conf $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  360. fi
  361. if [ "$FTP_SYSTEM" = "proftpd" ]; then
  362. cp -f /etc/proftpd/proftpd.conf $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  363. fi
  364. fi
  365. if [ ! -z "$FIREWALL_EXTENSION" ]; then
  366. if [ "$DEBUG_MODE" = "true" ]; then
  367. echo " ---- $FIREWALL_EXTENSION"
  368. fi
  369. cp -f /etc/$FIREWALL_EXTENSION/*.conf $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  370. cp -f /etc/$FIREWALL_EXTENSION/*.local $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  371. fi
  372. if [ -e "/etc/ssh/sshd_config" ]; then
  373. if [ "$DEBUG_MODE" = "true" ]; then
  374. echo " ---- sshd"
  375. fi
  376. cp -f /etc/ssh/sshd_config $HESTIA_BACKUP/conf/ssh/sshd_config
  377. fi
  378. }
  379. upgrade_refresh_config() {
  380. source /usr/local/hestia/conf/hestia.conf
  381. source /usr/local/hestia/func/main.sh
  382. }
  383. upgrade_start_routine() {
  384. # Parse version numbers for comparison
  385. function check_version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
  386. # Remove pre-release designation from version number for upgrade scripts
  387. VERSION=$(echo $VERSION | sed "s|~alpha||g" | sed "s|~beta||g")
  388. # Get list of all available version steps and create array
  389. upgrade_steps=$(ls $HESTIA/install/upgrade/versions/*.sh)
  390. for script in $upgrade_steps; do
  391. declare -a available_versions
  392. available_versions+=($(echo $script | sed "s|/usr/local/hestia/install/upgrade/versions/||g" | sed "s|.sh||g"))
  393. done
  394. # Define variables for accessing supported versions
  395. # Sort version by -V due to issues with version numbers 1.4.10 and higher
  396. all_versions=$(printf "%s\n" ${available_versions[@]} | sort -V)
  397. oldest_version=$(printf "%s\n" ${available_versions[@]} | sort -V | head -n1)
  398. latest_version=$(printf "%s\n" ${available_versions[@]} | sort -V | tail -n1)
  399. # Check for supported versions and process necessary upgrade steps
  400. if [ $(check_version $latest_version) -gt $(check_version $VERSION) ]; then
  401. for version_step in "${available_versions[@]}"
  402. do
  403. if [ $(check_version $VERSION) -lt $(check_version "$version_step") ]; then
  404. upgrade_step_message
  405. source $HESTIA/install/upgrade/versions/$version_step.sh
  406. fi
  407. done
  408. upgrade_set_version $VERSION
  409. upgrade_refresh_config
  410. else
  411. echo ""
  412. echo "[ ! ] The latest version of Hestia Control Panel is already installed."
  413. echo " Verifying configuration..."
  414. echo ""
  415. if [ -e "$HESTIA/install/upgrade/versions/$VERSION.sh" ]; then
  416. source $HESTIA/install/upgrade/versions/$VERSION.sh
  417. fi
  418. VERSION="$new_version"
  419. upgrade_set_version $VERSION
  420. upgrade_refresh_config
  421. fi
  422. #####################################################################
  423. ####### End version-specific upgrade instruction sets #######
  424. #####################################################################
  425. }
  426. upgrade_phpmyadmin() {
  427. if [ "$UPGRADE_UPDATE_PHPMYADMIN" = "true" ]; then
  428. # Check if MariaDB/MySQL is installed on the server before attempting to install or upgrade phpMyAdmin
  429. if [ ! -z "$(echo $DB_SYSTEM | grep -w 'mysql')" ]; then
  430. # Define version check function
  431. function version_ge(){ test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" -o ! -z "$1" -a "$1" = "$2"; }
  432. pma_release_file=$(ls /usr/share/phpmyadmin/RELEASE-DATE-* 2>/dev/null |tail -n 1)
  433. if version_ge "${pma_release_file##*-}" "$pma_v"; then
  434. echo "[ ! ] Verifying phpMyAdmin v${pma_release_file##*-} installation..."
  435. # Update permissions
  436. if [ -e /var/lib/phpmyadmin/blowfish_secret.inc.php ]; then
  437. chown root:www-data /var/lib/phpmyadmin/blowfish_secret.inc.php
  438. chmod 0640 /var/lib/phpmyadmin/blowfish_secret.inc.php
  439. fi
  440. else
  441. # Display upgrade information
  442. echo "[ * ] Upgrading phpMyAdmin to version v$pma_v..."
  443. [ -d /usr/share/phpmyadmin ] || mkdir -p /usr/share/phpmyadmin
  444. # Download latest phpMyAdmin release
  445. wget --quiet https://files.phpmyadmin.net/phpMyAdmin/$pma_v/phpMyAdmin-$pma_v-all-languages.tar.gz
  446. # Unpack files
  447. tar xzf phpMyAdmin-$pma_v-all-languages.tar.gz
  448. # Delete file to prevent error
  449. rm -rf /usr/share/phpmyadmin/doc/html
  450. # Overwrite old files
  451. cp -rf phpMyAdmin-$pma_v-all-languages/* /usr/share/phpmyadmin
  452. # Set config and log directory
  453. sed -i "s|define('CONFIG_DIR', ROOT_PATH);|define('CONFIG_DIR', '/etc/phpmyadmin/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
  454. sed -i "s|define('TEMP_DIR', ROOT_PATH . 'tmp/');|define('TEMP_DIR', '/var/lib/phpmyadmin/tmp/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
  455. # Create temporary folder and change permissions
  456. if [ ! -d /usr/share/phpmyadmin/tmp ]; then
  457. mkdir /usr/share/phpmyadmin/tmp
  458. chown root:www-data /usr/share/phpmyadmin/tmp
  459. chmod 770 /usr/share/phpmyadmin/tmp
  460. fi
  461. if [ -e /var/lib/phpmyadmin/blowfish_secret.inc.php ]; then
  462. chown root:www-data /var/lib/phpmyadmin/blowfish_secret.inc.php
  463. chmod 0640 /var/lib/phpmyadmin/blowfish_secret.inc.php
  464. fi
  465. # Clean up source files
  466. rm -fr phpMyAdmin-$pma_v-all-languages
  467. rm -f phpMyAdmin-$pma_v-all-languages.tar.gz
  468. fi
  469. fi
  470. fi
  471. }
  472. upgrade_filemanager() {
  473. if [ "$UPGRADE_UPDATE_FILEMANAGER" = "true" ]; then
  474. FILE_MANAGER_CHECK=$(cat $HESTIA/conf/hestia.conf | grep "FILE_MANAGER='false'")
  475. if [ -z "$FILE_MANAGER_CHECK" ]; then
  476. echo "[ * ] Updating File Manager..."
  477. # Reinstall the File Manager
  478. $HESTIA/bin/v-delete-sys-filemanager quiet
  479. $HESTIA/bin/v-add-sys-filemanager quiet
  480. fi
  481. fi
  482. }
  483. upgrade_filemanager_update_config() {
  484. if [ "$UPGRADE_UPDATE_FILEMANAGER_CONFIG" = "true" ]; then
  485. FILE_MANAGER_CHECK=$(cat $HESTIA/conf/hestia.conf | grep "FILE_MANAGER='false'")
  486. if [ -z "$FILE_MANAGER_CHECK" ]; then
  487. if [ -e "$HESTIA/web/fm/configuration.php" ]; then
  488. echo "[ * ] Updating File Manager configuration..."
  489. # Update configuration.php
  490. cp -f $HESTIA_INSTALL_DIR/filemanager/filegator/configuration.php $HESTIA/web/fm/configuration.php
  491. # Set environment variable for interface
  492. $HESTIA/bin/v-change-sys-config-value 'FILE_MANAGER' 'true'
  493. fi
  494. fi
  495. fi
  496. }
  497. upgrade_roundcube(){
  498. if [ "UPGRADE_UPDATE_ROUNDCUBE" = "true" ]; then
  499. if [ ! -z "$(echo "$WEBMAIL_SYSTEM" | grep -w 'roundcube')" ]; then
  500. rc_version=$(cat /var/lib/roundcube/index.php | grep -o -E '[0-9].[0-9].[0-9]+' | head -1);
  501. if [ "$rc_version" == "$rc_v" ]; then
  502. echo "[ * ] Upgrading Roundcube to version v$rc_v..."
  503. $HESTIA/bin/v-add-sys-roundcube
  504. fi
  505. fi
  506. fi
  507. }
  508. upgrade_rainloop(){
  509. if [ "UPGRADE_UPDATE_RAINLOOP" = "true" ]; then
  510. if [ ! -z "$(echo "$WEBMAIL_SYSTEM" | grep -w 'rainloop')" ]; then
  511. rc_version=$(cat /var/lib/rainloop/data/VERSION);
  512. if [ "$rc_version" == "$rc_v" ]; then
  513. echo "[ * ] Upgrading Rainloop to version v$rl_v..."
  514. $HESTIA/bin/v-add-sys-rainloop
  515. fi
  516. fi
  517. fi
  518. }
  519. upgrade_rebuild_web_templates() {
  520. if [ "$UPGRADE_UPDATE_WEB_TEMPLATES" = "true" ]; then
  521. echo "[ ! ] Updating default web domain templates..."
  522. $BIN/v-update-web-templates "no" "skip"
  523. fi
  524. }
  525. upgrade_rebuild_mail_templates() {
  526. if [ "$UPGRADE_UPDATE_MAIL_TEMPLATES" = "true" ]; then
  527. echo "[ ! ] Updating default mail domain templates..."
  528. $BIN/v-update-mail-templates "no" "skip"
  529. fi
  530. }
  531. upgrade_rebuild_dns_templates() {
  532. if [ "$UPGRADE_UPDATE_DNS_TEMPLATES" = "true" ]; then
  533. echo "[ ! ] Updating default DNS zone templates..."
  534. $BIN/v-update-dns-templates
  535. fi
  536. }
  537. upgrade_rebuild_users() {
  538. if [ "$UPGRADE_REBUILD_USERS" = "true" ]; then
  539. if [ "$DEBUG_MODE" = "true" ]; then
  540. echo "[ * ] Rebuilding user accounts and domains:"
  541. else
  542. echo "[ * ] Rebuilding user accounts and domains, this may take a few minutes..."
  543. fi
  544. for user in $($HESTIA/bin/v-list-sys-users plain); do
  545. export restart="no"
  546. if [ "$DEBUG_MODE" = "true" ]; then
  547. echo " - $user:"
  548. else
  549. echo " - $user..."
  550. fi
  551. if [ ! -z "$WEB_SYSTEM" ]; then
  552. if [ "$DEBUG_MODE" = "true" ]; then
  553. echo " ---- Web domains..."
  554. $BIN/v-rebuild-web-domains $user 'no'
  555. else
  556. $BIN/v-rebuild-web-domains $user 'no' >/dev/null 2>&1
  557. fi
  558. fi
  559. if [ ! -z "$DNS_SYSTEM" ]; then
  560. if [ "$DEBUG_MODE" = "true" ]; then
  561. echo " ---- DNS zones..."
  562. $BIN/v-rebuild-dns-domains $user 'no'
  563. else
  564. $BIN/v-rebuild-dns-domains $user 'no' >/dev/null 2>&1
  565. fi
  566. fi
  567. if [ ! -z "$MAIL_SYSTEM" ]; then
  568. if [ "$DEBUG_MODE" = "true" ]; then
  569. echo " ---- Mail domains..."
  570. $BIN/v-rebuild-mail-domains $user 'no'
  571. else
  572. $BIN/v-rebuild-mail-domains $user 'no' >/dev/null 2>&1
  573. fi
  574. fi
  575. if [ "$DEBUG_MODE" = "true" ]; then
  576. echo " ---- User configuration..."
  577. $BIN/v-rebuild-user $user 'no'
  578. else
  579. $BIN/v-rebuild-user $user 'no' >/dev/null 2>&1
  580. fi
  581. done
  582. fi
  583. }
  584. upgrade_replace_default_config() {
  585. if [ "$UPGRADE_REPLACE_KNOWN_KEYS" ]; then
  586. syshealth_update_web_config_format
  587. syshealth_update_mail_config_format
  588. syshealth_update_dns_config_format
  589. syshealth_update_db_config_format
  590. syshealth_update_user_config_format
  591. fi
  592. }
  593. upgrade_restart_services() {
  594. if [ "$UPGRADE_RESTART_SERVICES" = "true" ]; then
  595. echo "[ * ] Restarting services..."
  596. export restart="yes"
  597. sleep 2
  598. if [ ! -z "$MAIL_SYSTEM" ]; then
  599. if [ "$DEBUG_MODE" = "true" ]; then
  600. echo " - $MAIL_SYSTEM"
  601. fi
  602. $BIN/v-restart-mail $restart
  603. fi
  604. if [ ! -z "$WEB_SYSTEM" ]; then
  605. if [ "$DEBUG_MODE" = "true" ]; then
  606. echo " - $WEB_SYSTEM"
  607. fi
  608. $BIN/v-restart-web $restart
  609. fi
  610. if [ ! -z "$PROXY_SYSTEM" ]; then
  611. if [ "$DEBUG_MODE" = "true" ]; then
  612. echo " - $PROXY_SYSTEM"
  613. fi
  614. $BIN/v-restart-proxy $restart
  615. fi
  616. if [ ! -z "$DNS_SYSTEM" ]; then
  617. if [ "$DEBUG_MODE" = "true" ]; then
  618. echo " - $DNS_SYSTEM"
  619. fi
  620. $BIN/v-restart-dns $restart
  621. fi
  622. for v in `ls /etc/php/`; do
  623. if [ -e /etc/php/$v/fpm ]; then
  624. if [ "$DEBUG_MODE" = "true" ]; then
  625. echo " - php$v-fpm"
  626. fi
  627. $BIN/v-restart-service php$v-fpm
  628. fi
  629. done
  630. if [ ! -z "$FTP_SYSTEM" ]; then
  631. if [ "$DEBUG_MODE" = "true" ]; then
  632. echo " - $FTP_SYSTEM"
  633. fi
  634. $BIN/v-restart-ftp $restart
  635. fi
  636. if [ ! -z "$FIREWALL_EXTENSION" ]; then
  637. if [ "$DEBUG_MODE" = "true" ]; then
  638. echo " - $FIREWALL_EXTENSION"
  639. fi
  640. $BIN/v-restart-service $FIREWALL_EXTENSION
  641. fi
  642. # Restart SSH daemon service
  643. if [ "$DEBUG_MODE" = "true" ]; then
  644. echo " - sshd"
  645. fi
  646. $BIN/v-restart-service ssh
  647. fi
  648. # Always restart the Hestia Control Panel service
  649. if [ "$DEBUG_MODE" = "true" ]; then
  650. echo " - hestia"
  651. fi
  652. $BIN/v-restart-service hestia
  653. }