upgrade.sh 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  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 "[ * ] Backing up existing templates and configuration files..."
  343. if [ "$DEBUG_MODE" = "true" ]; then
  344. echo " - Packages"
  345. fi
  346. cp -rf $HESTIA/data/packages/* $HESTIA_BACKUP/packages/
  347. if [ "$DEBUG_MODE" = "true" ]; then
  348. echo " - Templates"
  349. fi
  350. cp -rf $HESTIA/data/templates/* $HESTIA_BACKUP/templates/
  351. if [ "$DEBUG_MODE" = "true" ]; then
  352. echo " - Configuration files:"
  353. fi
  354. # Hestia Control Panel configuration files
  355. if [ "$DEBUG_MODE" = "true" ]; then
  356. echo " ---- hestia"
  357. fi
  358. cp -rf $HESTIA/conf/* $HESTIA_BACKUP/conf/hestia/
  359. # System service configuration files (apache2, nginx, bind9, vsftpd, etc).
  360. if [ -n "$WEB_SYSTEM" ]; then
  361. if [ "$DEBUG_MODE" = "true" ]; then
  362. echo " ---- $WEB_SYSTEM"
  363. fi
  364. cp -fr /etc/$WEB_SYSTEM/* $HESTIA_BACKUP/conf/$WEB_SYSTEM/
  365. fi
  366. if [ -n "$PROXY_SYSTEM" ]; then
  367. if [ "$DEBUG_MODE" = "true" ]; then
  368. echo " ---- $PROXY_SYSTEM"
  369. fi
  370. cp -fr /etc/$PROXY_SYSTEM/* $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  371. fi
  372. if [ -n "$IMAP_SYSTEM" ]; then
  373. if [ "$DEBUG_MODE" = "true" ]; then
  374. echo " ---- $IMAP_SYSTEM"
  375. fi
  376. cp -fr /etc/$IMAP_SYSTEM/* $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
  377. fi
  378. if [ -n "$MAIL_SYSTEM" ]; then
  379. if [ "$DEBUG_MODE" = "true" ]; then
  380. echo " ---- $MAIL_SYSTEM"
  381. fi
  382. cp -fr /etc/$MAIL_SYSTEM/* $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
  383. fi
  384. if [ -n "$DNS_SYSTEM" ]; then
  385. if [ "$DNS_SYSTEM" = "bind9" ]; then
  386. if [ "$DEBUG_MODE" = "true" ]; then
  387. echo " ---- $DNS_SYSTEM"
  388. fi
  389. cp -fr /etc/bind/* $HESTIA_BACKUP/conf/$DNS_SYSTEM/
  390. fi
  391. fi
  392. if [ -n "$DB_SYSTEM" ]; then
  393. if [[ "$DB_SYSTEM" =~ "mysql" ]]; then
  394. if [ "$DEBUG_MODE" = "true" ]; then
  395. echo " ---- mysql"
  396. fi
  397. cp -fr /etc/mysql/* $HESTIA_BACKUP/conf/mysql/
  398. fi
  399. if [[ "$DB_SYSTEM" =~ "pgsql" ]]; then
  400. if [ "$DEBUG_MODE" = "true" ]; then
  401. echo " ---- pgsql"
  402. fi
  403. # config for postgresql is stored in /etc/postgresql/version/main/
  404. cp -fr /etc/postgresql/* $HESTIA_BACKUP/conf/pgsql/
  405. fi
  406. fi
  407. if [ -n "$FTP_SYSTEM" ]; then
  408. if [ "$DEBUG_MODE" = "true" ]; then
  409. echo " ---- $FTP_SYSTEM"
  410. fi
  411. if [ "$FTP_SYSTEM" = "vsftpd" ]; then
  412. cp -f /etc/$FTP_SYSTEM.conf $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  413. fi
  414. if [ "$FTP_SYSTEM" = "proftpd" ]; then
  415. cp -f /etc/proftpd/proftpd.conf $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  416. fi
  417. fi
  418. if [ -n "$FIREWALL_EXTENSION" ]; then
  419. if [ "$DEBUG_MODE" = "true" ]; then
  420. echo " ---- $FIREWALL_EXTENSION"
  421. fi
  422. cp -f /etc/$FIREWALL_EXTENSION/*.conf $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  423. cp -f /etc/$FIREWALL_EXTENSION/*.local $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  424. fi
  425. if [ -e "/etc/ssh/sshd_config" ]; then
  426. if [ "$DEBUG_MODE" = "true" ]; then
  427. echo " ---- sshd"
  428. fi
  429. cp -fr /etc/ssh/* $HESTIA_BACKUP/conf/ssh/
  430. fi
  431. if [ -d "/etc/roundcube" ]; then
  432. if [ "$DEBUG_MODE" = "true" ]; then
  433. echo " ---- Roundcube"
  434. fi
  435. cp -fr /etc/roundcube/* $HESTIA_BACKUP/conf/roundcube
  436. fi
  437. if [ -d "/etc/rainloop" ]; then
  438. if [ "$DEBUG_MODE" = "true" ]; then
  439. echo " ---- Rainloop"
  440. fi
  441. cp -fr /etc/rainloop/* $HESTIA_BACKUP/conf/rainloop
  442. fi
  443. if [ -d "/etc/phpmyadmin" ]; then
  444. if [ "$DEBUG_MODE" = "true" ]; then
  445. echo " ---- phpMyAdmin"
  446. fi
  447. cp -fr /etc/phpmyadmin/* $HESTIA_BACKUP/conf/phpmyadmin
  448. fi
  449. }
  450. upgrade_refresh_config() {
  451. source_conf "/usr/local/hestia/conf/hestia.conf"
  452. }
  453. upgrade_start_routine() {
  454. # Parse version numbers for comparison
  455. function check_version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
  456. # Remove pre-release designation from version number for upgrade scripts
  457. VERSION=$(echo "$VERSION" | sed "s/~\([a-zA-Z0-9].*\)//g");
  458. # Get list of all available version steps and create array
  459. upgrade_steps=$(ls $HESTIA/install/upgrade/versions/*.sh)
  460. for script in $upgrade_steps; do
  461. declare -a available_versions
  462. available_versions+=($(echo $script | sed "s|/usr/local/hestia/install/upgrade/versions/||g" | sed "s|.sh||g"))
  463. done
  464. # Define variables for accessing supported versions
  465. # Sort version by -V due to issues with version numbers 1.4.10 and higher
  466. all_versions=$(printf "%s\n" "${available_versions[@]}" | sort -V)
  467. oldest_version=$(printf "%s\n" "$all_versions" | head -n1)
  468. latest_version=$(printf "%s\n" "$all_versions" | sort -V | tail -n1)
  469. # Check for supported versions and process necessary upgrade steps
  470. if [ $(check_version $latest_version) -gt $(check_version $VERSION) ]; then
  471. for version_step in "${available_versions[@]}"
  472. do
  473. if [ $(check_version $VERSION) -lt $(check_version "$version_step") ]; then
  474. upgrade_step_message
  475. source $HESTIA/install/upgrade/versions/$version_step.sh
  476. fi
  477. done
  478. upgrade_set_version "$VERSION"
  479. upgrade_refresh_config
  480. else
  481. echo ""
  482. echo "[ ! ] The latest version of Hestia Control Panel is already installed."
  483. echo " Verifying configuration..."
  484. echo ""
  485. if [ -e "$HESTIA/install/upgrade/versions/$VERSION.sh" ]; then
  486. source $HESTIA/install/upgrade/versions/$VERSION.sh
  487. fi
  488. VERSION="$new_version"
  489. upgrade_set_version "$VERSION"
  490. upgrade_refresh_config
  491. fi
  492. #####################################################################
  493. ####### End version-specific upgrade instruction sets #######
  494. #####################################################################
  495. }
  496. upgrade_b2_tool(){
  497. b2cli="/usr/local/bin/b2"
  498. b2lnk="https://github.com/Backblaze/B2_Command_Line_Tool/releases/download/v$b2_v/b2-linux"
  499. if [ -f "$b2cli" ]; then
  500. b2_version=$($b2cli version | grep -o -E '[0-9].[0-9].[0-9]+' | head -1);
  501. if version_ge "$b2_version" "$b2_v"; then
  502. echo "[ * ] Backblaze CLI tool is up to date ($b2_v)..."
  503. else
  504. echo "[ * ] Upgrading Backblaze CLI tool to version $b2_v..."
  505. rm $b2cli
  506. wget -O $b2cli $b2lnk > /dev/null 2>&1
  507. chmod +x $b2cli > /dev/null 2>&1
  508. if [ ! -f "$b2cli" ]; then
  509. echo "Error: Binary download failed, b2 doesnt work as expected."
  510. exit 3
  511. fi
  512. fi
  513. fi
  514. }
  515. upgrade_phpmyadmin() {
  516. # Check if MariaDB/MySQL is installed on the server before attempting to install or upgrade phpMyAdmin
  517. if [ -n "$(echo $DB_SYSTEM | grep -w 'mysql')" ]; then
  518. pma_release_file=$(ls /usr/share/phpmyadmin/RELEASE-DATE-* 2>/dev/null |tail -n 1)
  519. if version_ge "${pma_release_file##*-}" "$pma_v"; then
  520. echo "[ * ] phpMyAdmin is up to date (${pma_release_file##*-})..."
  521. # Update permissions
  522. if [ -e /var/lib/phpmyadmin/blowfish_secret.inc.php ]; then
  523. chown root:www-data /var/lib/phpmyadmin/blowfish_secret.inc.php
  524. chmod 0640 /var/lib/phpmyadmin/blowfish_secret.inc.php
  525. fi
  526. else
  527. # Display upgrade information
  528. echo "[ * ] Upgrading phpMyAdmin to version $pma_v..."
  529. [ -d /usr/share/phpmyadmin ] || mkdir -p /usr/share/phpmyadmin
  530. # Download latest phpMyAdmin release
  531. wget --quiet https://files.phpmyadmin.net/phpMyAdmin/$pma_v/phpMyAdmin-$pma_v-all-languages.tar.gz
  532. # Unpack files
  533. tar xzf phpMyAdmin-$pma_v-all-languages.tar.gz
  534. # Delete file to prevent error
  535. rm -rf /usr/share/phpmyadmin/doc/html
  536. # Overwrite old files
  537. cp -rf phpMyAdmin-$pma_v-all-languages/* /usr/share/phpmyadmin
  538. # Set config and log directory
  539. sed -i "s|define('CONFIG_DIR', ROOT_PATH);|define('CONFIG_DIR', '/etc/phpmyadmin/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
  540. sed -i "s|define('TEMP_DIR', ROOT_PATH . 'tmp/');|define('TEMP_DIR', '/var/lib/phpmyadmin/tmp/');|" /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_phpmailer(){
  612. if [ ! -d "$HESTIA/web/inc/vendor/" ]; then
  613. echo "[ ! ] Install PHPmailer";
  614. $HESTIA/bin/v-add-sys-phpmailer
  615. fi
  616. phpm_version=$(cat $HESTIA/web/inc/vendor/phpmailer/phpmailer/VERSION);
  617. if [ "$phpm_version" != "$pm_v" ]; then
  618. echo "[ ! ] Upgrading PHPmailer to version $pm_v..."
  619. $HESTIA/bin/v-add-sys-phpmailer
  620. else
  621. echo "[ * ] PHPmailer is up to date ($pm_v)..."
  622. fi
  623. }
  624. upgrade_rebuild_web_templates() {
  625. if [ "$UPGRADE_UPDATE_WEB_TEMPLATES" = "true" ]; then
  626. echo "[ ! ] Updating default web domain templates..."
  627. $BIN/v-update-web-templates "no" "skip"
  628. fi
  629. }
  630. upgrade_rebuild_mail_templates() {
  631. if [ "$UPGRADE_UPDATE_MAIL_TEMPLATES" = "true" ]; then
  632. echo "[ ! ] Updating default mail domain templates..."
  633. $BIN/v-update-mail-templates "no" "skip"
  634. fi
  635. }
  636. upgrade_rebuild_dns_templates() {
  637. if [ "$UPGRADE_UPDATE_DNS_TEMPLATES" = "true" ]; then
  638. echo "[ ! ] Updating default DNS zone templates..."
  639. $BIN/v-update-dns-templates
  640. fi
  641. }
  642. upgrade_rebuild_users() {
  643. if [ "$UPGRADE_REBUILD_USERS" = "true" ]; then
  644. if [ "$DEBUG_MODE" = "true" ]; then
  645. echo "[ * ] Rebuilding user accounts and domains:"
  646. else
  647. echo "[ * ] Rebuilding user accounts and domains, this may take a few minutes..."
  648. fi
  649. for user in $($HESTIA/bin/v-list-sys-users plain); do
  650. export restart="no"
  651. if [ "$DEBUG_MODE" = "true" ]; then
  652. echo " - $user:"
  653. else
  654. echo " - $user..."
  655. fi
  656. if [ -n "$WEB_SYSTEM" ]; then
  657. if [ "$DEBUG_MODE" = "true" ]; then
  658. echo " ---- Web domains..."
  659. $BIN/v-rebuild-web-domains "$user" 'no'
  660. else
  661. $BIN/v-rebuild-web-domains "$user" 'no' >/dev/null 2>&1
  662. fi
  663. fi
  664. if [ -n "$DNS_SYSTEM" ]; then
  665. if [ "$DEBUG_MODE" = "true" ]; then
  666. echo " ---- DNS zones..."
  667. $BIN/v-rebuild-dns-domains "$user" 'no'
  668. else
  669. $BIN/v-rebuild-dns-domains "$user" 'no' >/dev/null 2>&1
  670. fi
  671. fi
  672. if [ -n "$MAIL_SYSTEM" ]; then
  673. if [ "$DEBUG_MODE" = "true" ]; then
  674. echo " ---- Mail domains..."
  675. $BIN/v-rebuild-mail-domains "$user" 'no'
  676. else
  677. $BIN/v-rebuild-mail-domains "$user" 'no' >/dev/null 2>&1
  678. fi
  679. fi
  680. if [ "$DEBUG_MODE" = "true" ]; then
  681. echo " ---- User configuration..."
  682. $BIN/v-rebuild-user "$user" 'no'
  683. else
  684. $BIN/v-rebuild-user "$user" 'no' >/dev/null 2>&1
  685. fi
  686. done
  687. fi
  688. }
  689. upgrade_replace_default_config() {
  690. syshealth_update_web_config_format
  691. syshealth_update_mail_config_format
  692. syshealth_update_mail_account_config_format
  693. syshealth_update_dns_config_format
  694. syshealth_update_db_config_format
  695. syshealth_update_user_config_format
  696. }
  697. upgrade_restart_services() {
  698. if [ "$UPGRADE_RESTART_SERVICES" = "true" ]; then
  699. echo "[ * ] Restarting services..."
  700. sleep 2
  701. if [ -n "$MAIL_SYSTEM" ]; then
  702. if [ "$DEBUG_MODE" = "true" ]; then
  703. echo " - $MAIL_SYSTEM"
  704. fi
  705. $BIN/v-restart-mail 'yes'
  706. fi
  707. if [ -n "$IMAP_SYSTEM" ]; then
  708. if [ "$DEBUG_MODE" = "true" ]; then
  709. echo " - $IMAP_SYSTEM"
  710. fi
  711. $BIN/v-restart-service "$IMAP_SYSTEM"
  712. fi
  713. if [ -n "$WEB_SYSTEM" ]; then
  714. if [ "$DEBUG_MODE" = "true" ]; then
  715. echo " - $WEB_SYSTEM"
  716. fi
  717. $BIN/v-restart-web 'yes'
  718. fi
  719. if [ -n "$PROXY_SYSTEM" ]; then
  720. if [ "$DEBUG_MODE" = "true" ]; then
  721. echo " - $PROXY_SYSTEM"
  722. fi
  723. $BIN/v-restart-proxy 'yes'
  724. fi
  725. if [ -n "$DNS_SYSTEM" ]; then
  726. if [ "$DEBUG_MODE" = "true" ]; then
  727. echo " - $DNS_SYSTEM"
  728. fi
  729. $BIN/v-restart-dns 'yes'
  730. fi
  731. if [ -n "$WEB_BACKEND" ]; then
  732. versions_list=$($BIN/v-list-sys-php plain)
  733. for v in $versions_list; do
  734. if [ "$DEBUG_MODE" = "true" ]; then
  735. echo " - php$v-fpm"
  736. fi
  737. $BIN/v-restart-service "php$v-fpm" 'yes'
  738. done
  739. fi
  740. if [ -n "$FTP_SYSTEM" ]; then
  741. if [ "$DEBUG_MODE" = "true" ]; then
  742. echo " - $FTP_SYSTEM"
  743. fi
  744. $BIN/v-restart-ftp 'yes'
  745. fi
  746. if [ -n "$FIREWALL_EXTENSION" ]; then
  747. if [ "$DEBUG_MODE" = "true" ]; then
  748. echo " - $FIREWALL_EXTENSION"
  749. fi
  750. $BIN/v-restart-service "$FIREWALL_EXTENSION"
  751. fi
  752. # Restart SSH daemon service
  753. if [ "$DEBUG_MODE" = "true" ]; then
  754. echo " - sshd"
  755. fi
  756. $BIN/v-restart-service ssh
  757. fi
  758. # Always restart the Hestia Control Panel service
  759. if [ "$DEBUG_MODE" = "true" ]; then
  760. echo " - hestia"
  761. fi
  762. $BIN/v-restart-service hestia
  763. }