upgrade.sh 30 KB

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