upgrade.sh 34 KB

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