upgrade.sh 33 KB

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