upgrade.sh 31 KB

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