upgrade.sh 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  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. sed -i "/VERSION/d" $HESTIA/conf/hestia.conf
  137. echo "VERSION='$@'" >> $HESTIA/conf/hestia.conf
  138. }
  139. upgrade_send_notification_to_panel () {
  140. # Add notification to panel if variable is set to true or is not set
  141. if [[ "$new_version" =~ "alpha" ]]; then
  142. # Send notifications for development releases
  143. $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'
  144. elif [[ "$new_version" =~ "beta" ]]; then
  145. # Send feedback notification for beta releases
  146. $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'
  147. else
  148. # Send normal upgrade complete notification for stable releases
  149. $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'
  150. fi
  151. }
  152. upgrade_send_notification_to_email () {
  153. if [ "$UPGRADE_SEND_EMAIL" = "true" ]; then
  154. # Retrieve admin email address, sendmail path, and message temp file path
  155. admin_email=$($HESTIA/bin/v-list-user admin json | grep "CONTACT" | cut -d'"' -f4)
  156. send_mail="$HESTIA/web/inc/mail-wrapper.php"
  157. message_tmp_file="/tmp/hestia-upgrade-complete.txt"
  158. # Create temporary file
  159. touch $message_tmp_file
  160. # Write message to file
  161. echo "$HOSTNAME has been upgraded from Hestia Control Panel v$VERSION to v${new_version}." >> $message_tmp_file
  162. echo "Installation log: $LOG" >> $message_tmp_file
  163. echo "" >> $message_tmp_file
  164. echo "What's new: https://github.com/hestiacp/hestiacp/blob/$RELEASE_BRANCH/CHANGELOG.md" >> $message_tmp_file
  165. echo >> $message_tmp_file
  166. echo "What to do if you run into issues:" >> $message_tmp_file
  167. echo "- Check our forums for possible solutions: https://forum.hestiacp.com" >> $message_tmp_file
  168. echo "- File an issue report on GitHub: https://github.com/hestiacp/hestiacp/issues" >> $message_tmp_file
  169. echo "" >> $message_tmp_file
  170. echo "===================================================" >> $message_tmp_file
  171. echo "Have a wonderful day," >> $message_tmp_file
  172. echo "The Hestia Control Panel development team" >> $message_tmp_file
  173. # Read back message from file and pass through to sendmail
  174. cat $message_tmp_file | $send_mail -s "Update Installed - v${new_version}" $admin_email
  175. rm -f $message_tmp_file
  176. fi
  177. }
  178. upgrade_send_log_to_email() {
  179. if [ "$UPGRADE_SEND_EMAIL_LOG" = "true" ]; then
  180. admin_email=$($BIN/v-list-user admin json | grep "CONTACT" | cut -d'"' -f4)
  181. send_mail="$HESTIA/web/inc/mail-wrapper.php"
  182. cat $LOG | $send_mail -s "Update Installation Log - v${new_version}" $admin_email
  183. fi
  184. }
  185. upgrade_init_backup() {
  186. # Ensure that backup directories are created
  187. # Hestia Control Panel configuration files
  188. mkdir -p $HESTIA_BACKUP/conf/hestia/
  189. # System services (apache2, nginx, bind9, vsftpd, etc).
  190. if [ ! -z "$WEB_SYSTEM" ]; then
  191. mkdir -p $HESTIA_BACKUP/conf/$WEB_SYSTEM/
  192. fi
  193. if [ ! -z "$IMAP_SYSTEM" ]; then
  194. mkdir -p $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
  195. fi
  196. if [ ! -z "$MAIL_SYSTEM" ]; then
  197. mkdir -p $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
  198. fi
  199. if [ ! -z "$DNS_SYSTEM" ]; then
  200. mkdir -p $HESTIA_BACKUP/conf/$DNS_SYSTEM/
  201. fi
  202. if [ ! -z "$PROXY_SYSTEM" ]; then
  203. mkdir -p $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  204. fi
  205. if [ ! -z "$DB_SYSTEM" ]; then
  206. mkdir -p $HESTIA_BACKUP/conf/$DB_SYSTEM/
  207. fi
  208. if [ ! -z "$FTP_SYSTEM" ]; then
  209. mkdir -p $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  210. fi
  211. if [ ! -z "$FIREWALL_SYSTEM" ]; then
  212. mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_SYSTEM/
  213. fi
  214. if [ ! -z "$FIREWALL_EXTENSION" ]; then
  215. mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  216. fi
  217. if [ -e "/etc/ssh/sshd_config" ]; then
  218. mkdir -p $HESTIA_BACKUP/conf/ssh/
  219. fi
  220. # Hosting Packages
  221. mkdir -p $HESTIA_BACKUP/packages/
  222. # Domain template files
  223. mkdir -p $HESTIA_BACKUP/templates/
  224. # System services (apache2, nginx, bind9, vsftpd, etc).
  225. if [ ! -z "$WEB_SYSTEM" ]; then
  226. mkdir -p $HESTIA_BACKUP/conf/$WEB_SYSTEM/
  227. fi
  228. if [ ! -z "$IMAP_SYSTEM" ]; then
  229. mkdir -p $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
  230. fi
  231. if [ ! -z "$MAIL_SYSTEM" ]; then
  232. mkdir -p $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
  233. fi
  234. if [ ! -z "$DNS_SYSTEM" ]; then
  235. mkdir -p $HESTIA_BACKUP/conf/$DNS_SYSTEM/
  236. fi
  237. if [ ! -z "$PROXY_SYSTEM" ]; then
  238. mkdir -p $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  239. fi
  240. if [ ! -z "$DB_SYSTEM" ]; then
  241. if [[ "$DB_SYSTEM" =~ "mysql" ]]; then
  242. mkdir -p $HESTIA_BACKUP/conf/mysql/
  243. fi
  244. if [[ "$DB_SYSTEM" =~ "pgsql" ]]; then
  245. mkdir -p $HESTIA_BACKUP/conf/pgsql/
  246. fi
  247. fi
  248. if [ ! -z "$FTP_SYSTEM" ]; then
  249. mkdir -p $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  250. fi
  251. if [ ! -z "$FIREWALL_SYSTEM" ]; then
  252. mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_SYSTEM/
  253. fi
  254. if [ ! -z "$FIREWALL_EXTENSION" ]; then
  255. mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  256. fi
  257. if [ -e "/etc/ssh/sshd_config" ]; then
  258. mkdir -p $HESTIA_BACKUP/conf/ssh/
  259. fi
  260. }
  261. upgrade_init_logging() {
  262. # Set log file path
  263. LOG="$HESTIA_BACKUP/hst-upgrade-$(date +%d%m%Y%H%M).log"
  264. # Create log file
  265. touch $LOG
  266. # Add message to system log
  267. $BIN/v-log-action "system" "Info" "Updates" "Started update installation (Latest: $new_version, Previous: $VERSION)."
  268. # Add warnings for pre-release builds
  269. if [[ "$new_version" =~ "alpha" ]]; then
  270. $BIN/v-log-action "system" "Warning" "Updates" "Development build for testing purposes only. Report bugs at https://github.com/hestiacp/hestiacp/issues/."
  271. fi
  272. if [[ "$new_version" =~ "beta" ]]; then
  273. $BIN/v-log-action "system" "Warning" "Updates" "Beta release. Please report bugs at https://github.com/hestiacp/hestiacp/issues/."
  274. fi
  275. }
  276. upgrade_start_backup() {
  277. echo "[ * ] Backing up existing templates and configuration files..."
  278. if [ "$DEBUG_MODE" = "true" ]; then
  279. echo " - Packages"
  280. fi
  281. cp -rf $HESTIA/data/packages/* $HESTIA_BACKUP/packages/
  282. if [ "$DEBUG_MODE" = "true" ]; then
  283. echo " - Templates"
  284. fi
  285. cp -rf $HESTIA/data/templates/* $HESTIA_BACKUP/templates/
  286. if [ "$DEBUG_MODE" = "true" ]; then
  287. echo " - Configuration files:"
  288. fi
  289. # Hestia Control Panel configuration files
  290. if [ "$DEBUG_MODE" = "true" ]; then
  291. echo " ---- hestia"
  292. fi
  293. cp -rf $HESTIA/conf/* $HESTIA_BACKUP/conf/hestia/
  294. # System service configuration files (apache2, nginx, bind9, vsftpd, etc).
  295. if [ ! -z "$WEB_SYSTEM" ]; then
  296. if [ "$DEBUG_MODE" = "true" ]; then
  297. echo " ---- $WEB_SYSTEM"
  298. fi
  299. cp -f /etc/$WEB_SYSTEM/*.conf $HESTIA_BACKUP/conf/$WEB_SYSTEM/
  300. cp -f /etc/$WEB_SYSTEM/conf.d/*.conf $HESTIA_BACKUP/conf/$WEB_SYSTEM/
  301. fi
  302. if [ ! -z "$PROXY_SYSTEM" ]; then
  303. if [ "$DEBUG_MODE" = "true" ]; then
  304. echo " ---- $PROXY_SYSTEM"
  305. fi
  306. cp -f /etc/$PROXY_SYSTEM/*.conf $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  307. cp -f /etc/$PROXY_SYSTEM/conf.d/*.conf $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  308. cp -f /etc/$PROXY_SYSTEM/conf.d/*.inc $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  309. fi
  310. if [ ! -z "$IMAP_SYSTEM" ]; then
  311. if [ "$DEBUG_MODE" = "true" ]; then
  312. echo " ---- $IMAP_SYSTEM"
  313. fi
  314. cp -f /etc/$IMAP_SYSTEM/*.conf $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
  315. cp -f /etc/$IMAP_SYSTEM/conf.d/*.conf $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
  316. fi
  317. if [ ! -z "$MAIL_SYSTEM" ]; then
  318. if [ "$DEBUG_MODE" = "true" ]; then
  319. echo " ---- $MAIL_SYSTEM"
  320. fi
  321. cp -f /etc/$MAIL_SYSTEM/*.conf $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
  322. fi
  323. if [ ! -z "$DNS_SYSTEM" ]; then
  324. if [ "$DNS_SYSTEM" = "bind9" ]; then
  325. if [ "$DEBUG_MODE" = "true" ]; then
  326. echo " ---- $DNS_SYSTEM"
  327. fi
  328. cp -f /etc/bind/*.conf $HESTIA_BACKUP/conf/$DNS_SYSTEM/
  329. fi
  330. fi
  331. if [ ! -z "$DB_SYSTEM" ]; then
  332. if [[ "$DB_SYSTEM" =~ "mysql" ]]; then
  333. if [ "$DEBUG_MODE" = "true" ]; then
  334. echo " ---- mysql"
  335. fi
  336. cp -f /etc/mysql/*.cnf $HESTIA_BACKUP/conf/mysql/
  337. cp -f /etc/mysql/conf.d/*.cnf $HESTIA_BACKUP/conf/mysql/ > /dev/null 2>&1
  338. cp -f /etc/mysql/mariadb.conf.d/*.cnf $HESTIA_BACKUP/conf/mysql/ > /dev/null 2>&1
  339. fi
  340. if [[ "$DB_SYSTEM" =~ "pgsql" ]]; then
  341. if [ "$DEBUG_MODE" = "true" ]; then
  342. echo " ---- pgsql"
  343. fi
  344. cp -f /etc/mysql/*.cnf $HESTIA_BACKUP/conf/pgsql/
  345. cp -f /etc/mysql/conf.d/*.cnf $HESTIA_BACKUP/conf/pgsql/
  346. fi
  347. fi
  348. if [ ! -z "$FTP_SYSTEM" ]; then
  349. if [ "$DEBUG_MODE" = "true" ]; then
  350. echo " ---- $FTP_SYSTEM"
  351. fi
  352. if [ "$FTP_SYSTEM" = "vsftpd" ]; then
  353. cp -f /etc/$FTP_SYSTEM.conf $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  354. fi
  355. if [ "$FTP_SYSTEM" = "proftpd" ]; then
  356. cp -f /etc/proftpd/proftpd.conf $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  357. fi
  358. fi
  359. if [ ! -z "$FIREWALL_EXTENSION" ]; then
  360. if [ "$DEBUG_MODE" = "true" ]; then
  361. echo " ---- $FIREWALL_EXTENSION"
  362. fi
  363. cp -f /etc/$FIREWALL_EXTENSION/*.conf $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  364. cp -f /etc/$FIREWALL_EXTENSION/*.local $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  365. fi
  366. if [ -e "/etc/ssh/sshd_config" ]; then
  367. if [ "$DEBUG_MODE" = "true" ]; then
  368. echo " ---- sshd"
  369. fi
  370. cp -f /etc/ssh/sshd_config $HESTIA_BACKUP/conf/ssh/sshd_config
  371. fi
  372. }
  373. upgrade_refresh_config() {
  374. source /usr/local/hestia/conf/hestia.conf
  375. source /usr/local/hestia/func/main.sh
  376. }
  377. upgrade_start_routine() {
  378. # Parse version numbers for comparison
  379. function check_version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
  380. # Remove pre-release designation from version number for upgrade scripts
  381. VERSION=$(echo $VERSION | sed "s|~alpha||g" | sed "s|~beta||g")
  382. # Get list of all available version steps and create array
  383. upgrade_steps=$(ls $HESTIA/install/upgrade/versions/*.sh)
  384. for script in $upgrade_steps; do
  385. declare -a available_versions
  386. available_versions+=($(echo $script | sed "s|/usr/local/hestia/install/upgrade/versions/||g" | sed "s|.sh||g"))
  387. done
  388. # Define variables for accessing supported versions
  389. all_versions=$(printf "%s\n" ${available_versions[@]})
  390. oldest_version=$(printf "%s\n" ${available_versions[@]} | sort -r | tail -n1)
  391. latest_version=$(printf "%s\n" ${available_versions[@]} | tail -n1)
  392. # Check for supported versions and process necessary upgrade steps
  393. if [ $(check_version $latest_version) -gt $(check_version $VERSION) ]; then
  394. for version_step in "${available_versions[@]}"
  395. do
  396. if [ $(check_version $VERSION) -lt $(check_version "$version_step") ]; then
  397. upgrade_step_message
  398. source $HESTIA/install/upgrade/versions/$version_step.sh
  399. fi
  400. done
  401. upgrade_set_version $VERSION
  402. upgrade_refresh_config
  403. else
  404. echo ""
  405. echo "[ ! ] The latest version of Hestia Control Panel is already installed."
  406. echo " Verifying configuration..."
  407. echo ""
  408. if [ -e "$HESTIA/install/upgrade/versions/$VERSION.sh" ]; then
  409. source $HESTIA/install/upgrade/versions/$VERSION.sh
  410. fi
  411. VERSION="$new_version"
  412. upgrade_set_version $VERSION
  413. upgrade_refresh_config
  414. fi
  415. #####################################################################
  416. ####### End version-specific upgrade instruction sets #######
  417. #####################################################################
  418. }
  419. upgrade_phpmyadmin() {
  420. if [ "$UPGRADE_UPDATE_PHPMYADMIN" = "true" ]; then
  421. # Check if MariaDB/MySQL is installed on the server before attempting to install or upgrade phpMyAdmin
  422. if [ "$DB_SYSTEM" = "mysql" ]; then
  423. # Define version check function
  424. function version_ge(){ test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" -o ! -z "$1" -a "$1" = "$2"; }
  425. pma_release_file=$(ls /usr/share/phpmyadmin/RELEASE-DATE-* 2>/dev/null |tail -n 1)
  426. if version_ge "${pma_release_file##*-}" "$pma_v"; then
  427. echo "[ ! ] Verifying phpMyAdmin v${pma_release_file##*-} installation..."
  428. # Update permissions
  429. if [ -e /var/lib/phpmyadmin/blowfish_secret.inc.php ]; then
  430. chmod 0644 /var/lib/phpmyadmin/blowfish_secret.inc.php
  431. fi
  432. else
  433. # Display upgrade information
  434. echo "[ * ] Upgrading phpMyAdmin to version v$pma_v..."
  435. [ -d /usr/share/phpmyadmin ] || mkdir -p /usr/share/phpmyadmin
  436. # Download latest phpMyAdmin release
  437. wget --quiet https://files.phpmyadmin.net/phpMyAdmin/$pma_v/phpMyAdmin-$pma_v-all-languages.tar.gz
  438. # Unpack files
  439. tar xzf phpMyAdmin-$pma_v-all-languages.tar.gz
  440. # Delete file to prevent error
  441. rm -fr /usr/share/phpmyadmin/doc/html
  442. # Overwrite old files
  443. cp -rf phpMyAdmin-$pma_v-all-languages/* /usr/share/phpmyadmin
  444. # Set config and log directory
  445. sed -i "s|define('CONFIG_DIR', ROOT_PATH);|define('CONFIG_DIR', '/etc/phpmyadmin/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
  446. sed -i "s|define('TEMP_DIR', ROOT_PATH . 'tmp/');|define('TEMP_DIR', '/var/lib/phpmyadmin/tmp/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
  447. # Create temporary folder and change permissions
  448. if [ ! -d /usr/share/phpmyadmin/tmp ]; then
  449. mkdir /usr/share/phpmyadmin/tmp
  450. chmod 777 /usr/share/phpmyadmin/tmp
  451. fi
  452. if [ -e /var/lib/phpmyadmin/blowfish_secret.inc.php ]; then
  453. chmod 0644 /var/lib/phpmyadmin/blowfish_secret.inc.php
  454. fi
  455. # Clean up source files
  456. rm -fr phpMyAdmin-$pma_v-all-languages
  457. rm -f phpMyAdmin-$pma_v-all-languages.tar.gz
  458. fi
  459. fi
  460. fi
  461. }
  462. upgrade_filemanager() {
  463. if [ "$UPGRADE_UPDATE_FILEMANAGER" = "true" ]; then
  464. FILE_MANAGER_CHECK=$(cat $HESTIA/conf/hestia.conf | grep "FILE_MANAGER='false'")
  465. if [ -z "$FILE_MANAGER_CHECK" ]; then
  466. echo "[ * ] Updating File Manager..."
  467. # Reinstall the File Manager
  468. $HESTIA/bin/v-delete-sys-filemanager quiet
  469. $HESTIA/bin/v-add-sys-filemanager quiet
  470. fi
  471. fi
  472. }
  473. upgrade_filemanager_update_config() {
  474. if [ "$UPGRADE_UPDATE_FILEMANAGER_CONFIG" = "true" ]; then
  475. FILE_MANAGER_CHECK=$(cat $HESTIA/conf/hestia.conf | grep "FILE_MANAGER='false'")
  476. if [ -z "$FILE_MANAGER_CHECK" ]; then
  477. if [ -e "$HESTIA/web/fm/configuration.php" ]; then
  478. echo "[ * ] Updating File Manager configuration..."
  479. # Update configuration.php
  480. cp -f $HESTIA_INSTALL_DIR/filemanager/filegator/configuration.php $HESTIA/web/fm/configuration.php
  481. # Set environment variable for interface
  482. $HESTIA/bin/v-change-sys-config-value 'FILE_MANAGER' 'true'
  483. fi
  484. fi
  485. fi
  486. }
  487. upgrade_roundcube(){
  488. if [ "UPGRADE_UPDATE_ROUNDCUBE" = "true" ]; then
  489. if [ ! -z "$(echo "$WEBMAIL_SYSTEM" | grep -w 'roundcube')" ]; then
  490. rc_version=$(cat /var/lib/roundcube/index.php | grep -o -E '[0-9].[0-9].[0-9]+' | head -1);
  491. if [ "$rc_version" == "$rc_v" ]; then
  492. echo "[ * ] Upgrading Roundcube to version v$rc_v..."
  493. $HESTIA/bin/v-add-sys-roundcube
  494. fi
  495. fi
  496. fi
  497. }
  498. upgrade_rainloop(){
  499. if [ "UPGRADE_UPDATE_RAINLOOP" = "true" ]; then
  500. if [ ! -z "$(echo "$WEBMAIL_SYSTEM" | grep -w 'rainloop')" ]; then
  501. rc_version=$(cat /var/lib/rainloop/data/VERSION);
  502. if [ "$rc_version" == "$rc_v" ]; then
  503. echo "[ * ] Upgrading Rainloop to version v$rl_v..."
  504. $HESTIA/bin/v-add-sys-rainloop
  505. fi
  506. fi
  507. fi
  508. }
  509. upgrade_rebuild_web_templates() {
  510. if [ "$UPGRADE_UPDATE_WEB_TEMPLATES" = "true" ]; then
  511. echo "[ ! ] Updating default web domain templates..."
  512. $BIN/v-update-web-templates "no" "skip"
  513. fi
  514. }
  515. upgrade_rebuild_mail_templates() {
  516. if [ "$UPGRADE_UPDATE_MAIL_TEMPLATES" = "true" ]; then
  517. echo "[ ! ] Updating default mail domain templates..."
  518. $BIN/v-update-mail-templates "no" "skip"
  519. fi
  520. }
  521. upgrade_rebuild_dns_templates() {
  522. if [ "$UPGRADE_UPDATE_DNS_TEMPLATES" = "true" ]; then
  523. echo "[ ! ] Updating default DNS zone templates..."
  524. $BIN/v-update-dns-templates
  525. fi
  526. }
  527. upgrade_rebuild_users() {
  528. if [ "$UPGRADE_REBUILD_USERS" = "true" ]; then
  529. if [ "$DEBUG_MODE" = "true" ]; then
  530. echo "[ * ] Rebuilding user accounts and domains:"
  531. else
  532. echo "[ * ] Rebuilding user accounts and domains, this may take a few minutes..."
  533. fi
  534. for user in $($HESTIA/bin/v-list-sys-users plain); do
  535. export restart="no"
  536. if [ "$DEBUG_MODE" = "true" ]; then
  537. echo " - $user:"
  538. else
  539. echo " - $user..."
  540. fi
  541. if [ ! -z "$WEB_SYSTEM" ]; then
  542. if [ "$DEBUG_MODE" = "true" ]; then
  543. echo " ---- Web domains..."
  544. $BIN/v-rebuild-web-domains $user 'no'
  545. else
  546. $BIN/v-rebuild-web-domains $user 'no' >/dev/null 2>&1
  547. fi
  548. fi
  549. if [ ! -z "$DNS_SYSTEM" ]; then
  550. if [ "$DEBUG_MODE" = "true" ]; then
  551. echo " ---- DNS zones..."
  552. $BIN/v-rebuild-dns-domains $user 'no'
  553. else
  554. $BIN/v-rebuild-dns-domains $user 'no' >/dev/null 2>&1
  555. fi
  556. fi
  557. if [ ! -z "$MAIL_SYSTEM" ]; then
  558. if [ "$DEBUG_MODE" = "true" ]; then
  559. echo " ---- Mail domains..."
  560. $BIN/v-rebuild-mail-domains $user 'no'
  561. else
  562. $BIN/v-rebuild-mail-domains $user 'no' >/dev/null 2>&1
  563. fi
  564. fi
  565. if [ "$DEBUG_MODE" = "true" ]; then
  566. echo " ---- User configuration..."
  567. $BIN/v-rebuild-user $user 'no'
  568. else
  569. $BIN/v-rebuild-user $user 'no' >/dev/null 2>&1
  570. fi
  571. done
  572. fi
  573. }
  574. upgrade_replace_default_config() {
  575. if [ "$UPGRADE_REPLACE_KNOWN_KEYS" ]; then
  576. syshealth_update_web_config_format
  577. syshealth_update_mail_config_format
  578. syshealth_update_dns_config_format
  579. syshealth_update_db_config_format
  580. syshealth_update_user_config_format
  581. fi
  582. }
  583. upgrade_restart_services() {
  584. if [ "$UPGRADE_RESTART_SERVICES" = "true" ]; then
  585. echo "[ * ] Restarting services..."
  586. export restart="yes"
  587. sleep 2
  588. if [ ! -z "$MAIL_SYSTEM" ]; then
  589. if [ "$DEBUG_MODE" = "true" ]; then
  590. echo " - $MAIL_SYSTEM"
  591. fi
  592. $BIN/v-restart-mail $restart
  593. fi
  594. if [ ! -z "$WEB_SYSTEM" ]; then
  595. if [ "$DEBUG_MODE" = "true" ]; then
  596. echo " - $WEB_SYSTEM"
  597. fi
  598. $BIN/v-restart-web $restart
  599. fi
  600. if [ ! -z "$PROXY_SYSTEM" ]; then
  601. if [ "$DEBUG_MODE" = "true" ]; then
  602. echo " - $PROXY_SYSTEM"
  603. fi
  604. $BIN/v-restart-proxy $restart
  605. fi
  606. if [ ! -z "$DNS_SYSTEM" ]; then
  607. if [ "$DEBUG_MODE" = "true" ]; then
  608. echo " - $DNS_SYSTEM"
  609. fi
  610. $BIN/v-restart-dns $restart
  611. fi
  612. for v in `ls /etc/php/`; do
  613. if [ -e /etc/php/$v/fpm ]; then
  614. if [ "$DEBUG_MODE" = "true" ]; then
  615. echo " - php$v-fpm"
  616. fi
  617. $BIN/v-restart-service php$v-fpm
  618. fi
  619. done
  620. if [ ! -z "$FTP_SYSTEM" ]; then
  621. if [ "$DEBUG_MODE" = "true" ]; then
  622. echo " - $FTP_SYSTEM"
  623. fi
  624. $BIN/v-restart-ftp $restart
  625. fi
  626. if [ ! -z "$FIREWALL_EXTENSION" ]; then
  627. if [ "$DEBUG_MODE" = "true" ]; then
  628. echo " - $FIREWALL_EXTENSION"
  629. fi
  630. $BIN/v-restart-service $FIREWALL_EXTENSION
  631. fi
  632. # Restart SSH daemon service
  633. if [ "$DEBUG_MODE" = "true" ]; then
  634. echo " - sshd"
  635. fi
  636. $BIN/v-restart-service ssh
  637. fi
  638. # Always restart the Hestia Control Panel service
  639. if [ "$DEBUG_MODE" = "true" ]; then
  640. echo " - hestia"
  641. fi
  642. $BIN/v-restart-service hestia
  643. }
  644. upgrade_perform_cleanup() {
  645. # Remove upgrade configuration file as it's not needed
  646. rm -f $HESTIA_INSTALL_DIR/upgrade/upgrade.conf
  647. }