upgrade.sh 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  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 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 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 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=$($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; do
  231. if [[ ! $lhs =~ ^\ *# && -n $lhs ]]; then
  232. rhs="${rhs%%\#*}" # Del in line right comments
  233. rhs="${rhs%%*( )}" # Del trailing spaces
  234. rhs="${rhs%\'*}" # Del opening string quotes
  235. rhs="${rhs#\'*}" # Del closing string quotes
  236. echo "$lhs='$rhs'" >> $HESTIA_BACKUP/upgrade.conf
  237. fi
  238. done < "$HESTIA/install/upgrade/upgrade.conf"
  239. }
  240. upgrade_init_backup() {
  241. # Ensure that backup directories are created
  242. # Hestia Control Panel configuration files
  243. mkdir -p $HESTIA_BACKUP/conf/hestia/
  244. # Hosting Packages
  245. mkdir -p $HESTIA_BACKUP/packages/
  246. # Domain template files
  247. mkdir -p $HESTIA_BACKUP/templates/
  248. # System services (apache2, nginx, bind9, vsftpd, etc).
  249. if [ -n "$WEB_SYSTEM" ]; then
  250. mkdir -p $HESTIA_BACKUP/conf/$WEB_SYSTEM/
  251. fi
  252. if [ -n "$IMAP_SYSTEM" ]; then
  253. mkdir -p $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
  254. fi
  255. if [ -n "$MAIL_SYSTEM" ]; then
  256. mkdir -p $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
  257. fi
  258. if [ -n "$DNS_SYSTEM" ]; then
  259. mkdir -p $HESTIA_BACKUP/conf/$DNS_SYSTEM/
  260. fi
  261. if [ -n "$PROXY_SYSTEM" ]; then
  262. mkdir -p $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  263. fi
  264. if [ -n "$DB_SYSTEM" ]; then
  265. if [[ "$DB_SYSTEM" =~ "mysql" ]]; then
  266. mkdir -p $HESTIA_BACKUP/conf/mysql/
  267. fi
  268. if [[ "$DB_SYSTEM" =~ "pgsql" ]]; then
  269. mkdir -p $HESTIA_BACKUP/conf/pgsql/
  270. fi
  271. fi
  272. if [ -n "$FTP_SYSTEM" ]; then
  273. mkdir -p $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  274. fi
  275. if [ -n "$FIREWALL_SYSTEM" ]; then
  276. mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_SYSTEM/
  277. fi
  278. if [ -n "$FIREWALL_EXTENSION" ]; then
  279. mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  280. fi
  281. if [ -e "/etc/ssh/sshd_config" ]; then
  282. mkdir -p $HESTIA_BACKUP/conf/ssh/
  283. fi
  284. if [ -d "/etc/roundcube/" ]; then
  285. mkdir -p $HESTIA_BACKUP/conf/roundcube/
  286. fi
  287. if [ -d "/etc/rainloop/" ]; then
  288. mkdir -p $HESTIA_BACKUP/conf/rainloop/
  289. fi
  290. if [ -d "/etc/phpmyadmin/" ]; then
  291. mkdir -p $HESTIA_BACKUP/conf/phpmyadmin/
  292. fi
  293. if [ -d "/etc/phppgadmin/" ]; then
  294. mkdir -p $HESTIA_BACKUP/conf/phppgadmin/
  295. fi
  296. }
  297. upgrade_init_logging() {
  298. # Set log file path
  299. LOG="$HESTIA_BACKUP/hst-upgrade-$(date +%d%m%Y%H%M).log"
  300. # Create log file
  301. touch $LOG
  302. # Add message to system log
  303. $BIN/v-log-action "system" "Info" "Updates" "Started update installation (Latest: $new_version, Previous: $VERSION)."
  304. # Add warnings for pre-release builds
  305. if [[ "$new_version" =~ "alpha" ]]; then
  306. $BIN/v-log-action "system" "Warning" "Updates" "Development build for testing purposes only. Report bugs at https://github.com/hestiacp/hestiacp/issues/."
  307. fi
  308. if [[ "$new_version" =~ "beta" ]]; then
  309. $BIN/v-log-action "system" "Warning" "Updates" "Beta release. Please report bugs at https://github.com/hestiacp/hestiacp/issues/."
  310. fi
  311. }
  312. upgrade_start_backup() {
  313. echo "============================================================================="
  314. echo "[ * ] Backing up existing templates and configuration files..."
  315. if [ "$DEBUG_MODE" = "true" ]; then
  316. echo " - Packages"
  317. fi
  318. cp -rf $HESTIA/data/packages/* $HESTIA_BACKUP/packages/
  319. if [ "$DEBUG_MODE" = "true" ]; then
  320. echo " - Templates"
  321. fi
  322. cp -rf $HESTIA/data/templates/* $HESTIA_BACKUP/templates/
  323. if [ "$DEBUG_MODE" = "true" ]; then
  324. echo " - Configuration files:"
  325. fi
  326. # Hestia Control Panel configuration files
  327. if [ "$DEBUG_MODE" = "true" ]; then
  328. echo " ---- hestia"
  329. fi
  330. cp -rf $HESTIA/conf/* $HESTIA_BACKUP/conf/hestia/
  331. # System service configuration files (apache2, nginx, bind9, vsftpd, etc).
  332. if [ -n "$WEB_SYSTEM" ]; then
  333. if [ "$DEBUG_MODE" = "true" ]; then
  334. echo " ---- $WEB_SYSTEM"
  335. fi
  336. cp -fr /etc/$WEB_SYSTEM/* $HESTIA_BACKUP/conf/$WEB_SYSTEM/
  337. fi
  338. if [ -n "$PROXY_SYSTEM" ]; then
  339. if [ "$DEBUG_MODE" = "true" ]; then
  340. echo " ---- $PROXY_SYSTEM"
  341. fi
  342. cp -fr /etc/$PROXY_SYSTEM/* $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  343. fi
  344. if [ -n "$IMAP_SYSTEM" ]; then
  345. if [ "$DEBUG_MODE" = "true" ]; then
  346. echo " ---- $IMAP_SYSTEM"
  347. fi
  348. cp -fr /etc/$IMAP_SYSTEM/* $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
  349. fi
  350. if [ -n "$MAIL_SYSTEM" ]; then
  351. if [ "$DEBUG_MODE" = "true" ]; then
  352. echo " ---- $MAIL_SYSTEM"
  353. fi
  354. cp -fr /etc/$MAIL_SYSTEM/* $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
  355. fi
  356. if [ -n "$DNS_SYSTEM" ]; then
  357. if [ "$DNS_SYSTEM" = "bind9" ]; then
  358. if [ "$DEBUG_MODE" = "true" ]; then
  359. echo " ---- $DNS_SYSTEM"
  360. fi
  361. cp -fr /etc/bind/* $HESTIA_BACKUP/conf/$DNS_SYSTEM/
  362. fi
  363. fi
  364. if [ -n "$DB_SYSTEM" ]; then
  365. if [[ "$DB_SYSTEM" =~ "mysql" ]]; then
  366. if [ "$DEBUG_MODE" = "true" ]; then
  367. echo " ---- mysql"
  368. fi
  369. cp -fr /etc/mysql/* $HESTIA_BACKUP/conf/mysql/
  370. fi
  371. if [[ "$DB_SYSTEM" =~ "pgsql" ]]; then
  372. if [ "$DEBUG_MODE" = "true" ]; then
  373. echo " ---- pgsql"
  374. fi
  375. # config for postgresql is stored in /etc/postgresql/version/main/
  376. cp -fr /etc/postgresql/* $HESTIA_BACKUP/conf/pgsql/
  377. fi
  378. fi
  379. if [ -n "$FTP_SYSTEM" ]; then
  380. if [ "$DEBUG_MODE" = "true" ]; then
  381. echo " ---- $FTP_SYSTEM"
  382. fi
  383. if [ "$FTP_SYSTEM" = "vsftpd" ]; then
  384. cp -f /etc/$FTP_SYSTEM.conf $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  385. fi
  386. if [ "$FTP_SYSTEM" = "proftpd" ]; then
  387. cp -f /etc/proftpd/proftpd.conf $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  388. fi
  389. fi
  390. if [ -n "$FIREWALL_SYSTEM" ]; then
  391. if [ "$DEBUG_MODE" = "true" ]; then
  392. echo " ---- $FIREWALL_SYSTEM"
  393. fi
  394. [ -e "/etc/sysconfig/iptables" ] && cp -f /etc/sysconfig/iptables $HESTIA_BACKUP/conf/$FIREWALL_SYSTEM/
  395. [ -e "/etc/iptables.rules" ] && cp -f /etc/iptables.rules $HESTIA_BACKUP/conf/$FIREWALL_SYSTEM/
  396. fi
  397. if [ -n "$FIREWALL_EXTENSION" ]; then
  398. if [ "$DEBUG_MODE" = "true" ]; then
  399. echo " ---- $FIREWALL_EXTENSION"
  400. fi
  401. cp -f /etc/$FIREWALL_EXTENSION/*.conf $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  402. cp -f /etc/$FIREWALL_EXTENSION/*.local $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  403. fi
  404. if [ -e "/etc/ssh/sshd_config" ]; then
  405. if [ "$DEBUG_MODE" = "true" ]; then
  406. echo " ---- sshd"
  407. fi
  408. cp -fr /etc/ssh/* $HESTIA_BACKUP/conf/ssh/
  409. fi
  410. if [ -d "/etc/roundcube" ]; then
  411. if [ "$DEBUG_MODE" = "true" ]; then
  412. echo " ---- Roundcube"
  413. fi
  414. cp -fr /etc/roundcube/* $HESTIA_BACKUP/conf/roundcube
  415. fi
  416. if [ -d "/etc/rainloop" ]; then
  417. if [ "$DEBUG_MODE" = "true" ]; then
  418. echo " ---- Rainloop"
  419. fi
  420. cp -fr /etc/rainloop/* $HESTIA_BACKUP/conf/rainloop
  421. fi
  422. if [ -d "/etc/phpmyadmin" ]; then
  423. if [ "$DEBUG_MODE" = "true" ]; then
  424. echo " ---- phpMyAdmin"
  425. fi
  426. cp -fr /etc/phpmyadmin/* $HESTIA_BACKUP/conf/phpmyadmin
  427. fi
  428. if [ -d "/etc/phppgadmin" ]; then
  429. if [ "$DEBUG_MODE" = "true" ]; then
  430. echo " ---- phppgadmin"
  431. fi
  432. cp -fr /etc/phppgadmin/* $HESTIA_BACKUP/conf/phppgadmin
  433. fi
  434. }
  435. upgrade_refresh_config() {
  436. source_conf "/usr/local/hestia/conf/hestia.conf"
  437. }
  438. upgrade_start_routine() {
  439. # Parse version numbers for comparison
  440. function check_version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
  441. # Remove pre-release designation from version number for upgrade scripts
  442. VERSION=$(echo "$VERSION" | sed "s/~\([a-zA-Z0-9].*\)//g")
  443. # Get list of all available version steps and create array
  444. upgrade_steps=$(ls -v $HESTIA/install/upgrade/versions/*.sh)
  445. for script in $upgrade_steps; do
  446. declare -a available_versions
  447. available_versions+=($(echo $script | sed "s|/usr/local/hestia/install/upgrade/versions/||g" | sed "s|.sh||g"))
  448. done
  449. # Define variables for accessing supported versions
  450. # Sort version by -V due to issues with version numbers 1.4.10 and higher
  451. all_versions=$(printf "%s\n" "${available_versions[@]}" | sort -V)
  452. oldest_version=$(printf "%s\n" "$all_versions" | head -n1)
  453. latest_version=$(printf "%s\n" "$all_versions" | sort -V | tail -n1)
  454. # Check for supported versions and process necessary upgrade steps
  455. if [ $(check_version $latest_version) -gt $(check_version $VERSION) ]; then
  456. for version_step in "${available_versions[@]}"; do
  457. if [ $(check_version $VERSION) -lt $(check_version "$version_step") ]; then
  458. upgrade_step_message
  459. source $HESTIA/install/upgrade/versions/$version_step.sh
  460. fi
  461. done
  462. upgrade_set_version "$VERSION"
  463. upgrade_refresh_config
  464. else
  465. echo ""
  466. echo "[ ! ] The latest version of Hestia Control Panel is already installed."
  467. echo " Verifying configuration..."
  468. echo ""
  469. if [ -e "$HESTIA/install/upgrade/versions/$VERSION.sh" ]; then
  470. source $HESTIA/install/upgrade/versions/$VERSION.sh
  471. fi
  472. VERSION="$new_version"
  473. upgrade_set_version "$VERSION"
  474. upgrade_refresh_config
  475. fi
  476. #####################################################################
  477. ####### End version-specific upgrade instruction sets #######
  478. #####################################################################
  479. }
  480. upgrade_b2_tool() {
  481. b2cli="/usr/local/bin/b2"
  482. b2lnk="https://github.com/Backblaze/B2_Command_Line_Tool/releases/download/v$b2_v/b2-linux"
  483. if [ -f "$b2cli" ]; then
  484. b2_version=$($b2cli version | grep -o -E '[0-9].[0-9].[0-9]+' | head -1)
  485. if version_ge "$b2_version" "$b2_v"; then
  486. echo "[ * ] Backblaze CLI tool is up to date ($b2_v)..."
  487. else
  488. echo "[ * ] Upgrading Backblaze CLI tool to version $b2_v..."
  489. rm $b2cli
  490. wget -O $b2cli $b2lnk > /dev/null 2>&1
  491. chmod +x $b2cli > /dev/null 2>&1
  492. if [ ! -f "$b2cli" ]; then
  493. echo "Error: Binary download failed, b2 doesnt work as expected."
  494. exit 3
  495. fi
  496. fi
  497. fi
  498. }
  499. upgrade_cloudflare_ip() {
  500. echo "[ * ] Update Cloudflare IP"
  501. # https://github.com/ergin/nginx-cloudflare-real-ip/
  502. CLOUDFLARE_FILE_PATH='/etc/nginx/conf.d/cloudflare.inc'
  503. echo "#Cloudflare" > $CLOUDFLARE_FILE_PATH
  504. echo "" >> $CLOUDFLARE_FILE_PATH
  505. echo "# - IPv4" >> $CLOUDFLARE_FILE_PATH
  506. for i in $(curl -s -L https://www.cloudflare.com/ips-v4); do
  507. echo "set_real_ip_from $i;" >> $CLOUDFLARE_FILE_PATH
  508. done
  509. echo "" >> $CLOUDFLARE_FILE_PATH
  510. echo "# - IPv6" >> $CLOUDFLARE_FILE_PATH
  511. for i in $(curl -s -L https://www.cloudflare.com/ips-v6); do
  512. echo "set_real_ip_from $i;" >> $CLOUDFLARE_FILE_PATH
  513. done
  514. echo "" >> $CLOUDFLARE_FILE_PATH
  515. echo "real_ip_header CF-Connecting-IP;" >> $CLOUDFLARE_FILE_PATH
  516. }
  517. upgrade_phppgadmin() {
  518. if [ -n "$(echo $DB_SYSTEM | grep -w 'pgsql')" ]; then
  519. pga_release=$(cat /usr/share/phppgadmin/libraries/lib.inc.php | grep appVersion | head -n1 | cut -f2 -d\' | cut -f1 -d-)
  520. if version_ge "$pga_release" "pga_v"; then
  521. echo "[ * ] phppgadmin is up to date ($pga_release)..."
  522. else
  523. # Display upgrade information
  524. echo "[ * ] Upgrading phppgadmin to version $pga_v..."
  525. [ -d /usr/share/phpmyadmin ] || mkdir -p /usr/share/phpmyadmin
  526. # Download latest phpMyAdmin release
  527. wget --retry-connrefused --quiet https://github.com/hestiacp/phppgadmin/releases/download/v$pga_v/phppgadmin-v$pga_v.tar.gz
  528. tar xzf phppgadmin-v$pga_v.tar.gz -C /usr/share/phppgadmin/
  529. if ! version_ge "$pga_release" "7.14.0"; then
  530. cp -f $HESTIA_INSTALL_DIR/pga/config.inc.php /etc/phppgadmin/
  531. fi
  532. if [ ! -f /usr/share/phppgadmin/conf/config.inc.php ]; then
  533. ln -s /etc/phppgadmin/config.inc.php /usr/share/phppgadmin/conf
  534. fi
  535. rm -f phppgadmin-v$pga_v.tar.gz
  536. fi
  537. fi
  538. }
  539. upgrade_phpmyadmin() {
  540. # Check if MariaDB/MySQL is installed on the server before attempting to install or upgrade phpMyAdmin
  541. if [ -n "$(echo $DB_SYSTEM | grep -w 'mysql')" ]; then
  542. pma_version=$(jq -r .version /usr/share/phpmyadmin/package.json)
  543. if version_ge "$pma_version" "$pma_v"; then
  544. echo "[ * ] phpMyAdmin is up to date (${pma_release_file##*-})..."
  545. # Update permissions
  546. if [ -e /var/lib/phpmyadmin/blowfish_secret.inc.php ]; then
  547. chown root:www-data /var/lib/phpmyadmin/blowfish_secret.inc.php
  548. chmod 0640 /var/lib/phpmyadmin/blowfish_secret.inc.php
  549. fi
  550. else
  551. # Display upgrade information
  552. echo "[ * ] Upgrading phpMyAdmin to version $pma_v..."
  553. [ -d /usr/share/phpmyadmin ] || mkdir -p /usr/share/phpmyadmin
  554. # Download latest phpMyAdmin release
  555. wget --quiet https://files.phpmyadmin.net/phpMyAdmin/$pma_v/phpMyAdmin-$pma_v-all-languages.tar.gz
  556. # Unpack files
  557. tar xzf phpMyAdmin-$pma_v-all-languages.tar.gz
  558. # Delete file to prevent error
  559. rm -rf /usr/share/phpmyadmin/doc/html
  560. # Overwrite old files
  561. cp -rf phpMyAdmin-$pma_v-all-languages/* /usr/share/phpmyadmin
  562. # Set config and log directory
  563. sed -i "s|'configFile' => ROOT_PATH . 'config.inc.php',|'configFile' => '/etc/phpmyadmin/config.inc.php',|g" /usr/share/phpmyadmin/libraries/vendor_config.php
  564. # Create temporary folder and change permissions
  565. if [ ! -d /usr/share/phpmyadmin/tmp ]; then
  566. mkdir /usr/share/phpmyadmin/tmp
  567. chown root:www-data /usr/share/phpmyadmin/tmp
  568. chmod 0770 /usr/share/phpmyadmin/tmp
  569. fi
  570. if [ -e /var/lib/phpmyadmin/blowfish_secret.inc.php ]; then
  571. chown root:www-data /var/lib/phpmyadmin/blowfish_secret.inc.php
  572. chmod 0640 /var/lib/phpmyadmin/blowfish_secret.inc.php
  573. fi
  574. # Clean up source files
  575. rm -fr phpMyAdmin-$pma_v-all-languages
  576. rm -f phpMyAdmin-$pma_v-all-languages.tar.gz
  577. fi
  578. fi
  579. }
  580. upgrade_filemanager() {
  581. FILE_MANAGER_CHECK=$(cat $HESTIA/conf/hestia.conf | grep "FILE_MANAGER='false'")
  582. if [ -z "$FILE_MANAGER_CHECK" ]; then
  583. if [ -f "$HESTIA/web/fm/version" ]; then
  584. fm_version=$(cat $HESTIA/web/fm/version)
  585. else
  586. fm_version="1.0.0"
  587. fi
  588. if ! version_ge "$fm_version" "$fm_v"; then
  589. echo "[ ! ] Upgrading File Manager to version $fm_v..."
  590. # Reinstall the File Manager
  591. $BIN/v-delete-sys-filemanager quiet yes
  592. $BIN/v-add-sys-filemanager quiet
  593. else
  594. echo "[ * ] File Manager is up to date ($fm_v)..."
  595. if [ "$UPGRADE_UPDATE_FILEMANAGER_CONFIG" = "true" ]; then
  596. if [ -e "$HESTIA/web/fm/configuration.php" ]; then
  597. echo "[ ! ] Updating File Manager configuration..."
  598. # Update configuration.php
  599. cp -f $HESTIA_INSTALL_DIR/filemanager/filegator/configuration.php $HESTIA/web/fm/configuration.php
  600. # Set environment variable for interface
  601. $BIN/v-change-sys-config-value 'FILE_MANAGER' 'true'
  602. fi
  603. fi
  604. fi
  605. fi
  606. }
  607. upgrade_roundcube() {
  608. if [ -n "$(echo "$WEBMAIL_SYSTEM" | grep -w 'roundcube')" ]; then
  609. if [ -d "/usr/share/roundcube" ]; then
  610. echo "[ ! ] Roundcube: Updates are currently managed using the apt package manager"
  611. 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/"
  612. else
  613. rc_version=$(cat /var/lib/roundcube/index.php | grep -o -E '[0-9].[0-9].[0-9]+' | head -1)
  614. if ! version_ge "$rc_version" "$rc_v"; then
  615. echo "[ ! ] Upgrading Roundcube to version $rc_v..."
  616. $BIN/v-add-sys-roundcube
  617. else
  618. echo "[ * ] Roundcube is up to date ($rc_v)..."
  619. fi
  620. fi
  621. fi
  622. }
  623. upgrade_rainloop() {
  624. if [ -n "$(echo "$WEBMAIL_SYSTEM" | grep -w 'rainloop')" ]; then
  625. rl_version=$(cat /var/lib/rainloop/data/VERSION)
  626. if ! version_ge "$rl_version" "$rl_v"; then
  627. echo "[ ! ] Upgrading Rainloop to version $rl_v..."
  628. $BIN/v-add-sys-rainloop
  629. else
  630. echo "[ * ] Rainloop is up to date ($rl_v)..."
  631. fi
  632. fi
  633. }
  634. upgrade_dependencies() {
  635. echo "[ ! ] Update Hesita PHP dependencies"
  636. $BIN/v-add-sys-dependencies
  637. }
  638. upgrade_rebuild_web_templates() {
  639. if [ "$UPGRADE_UPDATE_WEB_TEMPLATES" = "true" ]; then
  640. echo "[ ! ] Updating default web domain templates..."
  641. $BIN/v-update-web-templates "no" "skip"
  642. fi
  643. }
  644. upgrade_rebuild_mail_templates() {
  645. if [ "$UPGRADE_UPDATE_MAIL_TEMPLATES" = "true" ]; then
  646. echo "[ ! ] Updating default mail domain templates..."
  647. $BIN/v-update-mail-templates "no" "skip"
  648. fi
  649. }
  650. upgrade_rebuild_dns_templates() {
  651. if [ "$UPGRADE_UPDATE_DNS_TEMPLATES" = "true" ]; then
  652. echo "[ ! ] Updating default DNS zone templates..."
  653. $BIN/v-update-dns-templates
  654. fi
  655. }
  656. upgrade_rebuild_users() {
  657. if [ "$UPGRADE_REBUILD_USERS" = "true" ]; then
  658. if [ "$DEBUG_MODE" = "true" ]; then
  659. echo "[ * ] Rebuilding user accounts and domains:"
  660. else
  661. echo "[ * ] Rebuilding user accounts and domains, this may take a few minutes..."
  662. fi
  663. for user in $($BIN/v-list-sys-users plain); do
  664. export restart="no"
  665. if [ "$DEBUG_MODE" = "true" ]; then
  666. echo " - $user:"
  667. else
  668. echo " - $user..."
  669. fi
  670. if [ -n "$WEB_SYSTEM" ]; then
  671. if [ "$DEBUG_MODE" = "true" ]; then
  672. echo " ---- Web domains..."
  673. $BIN/v-rebuild-web-domains "$user" 'no'
  674. else
  675. $BIN/v-rebuild-web-domains "$user" 'no' > /dev/null 2>&1
  676. fi
  677. fi
  678. if [ -n "$DNS_SYSTEM" ]; then
  679. if [ "$DEBUG_MODE" = "true" ]; then
  680. echo " ---- DNS zones..."
  681. $BIN/v-rebuild-dns-domains "$user" 'no'
  682. else
  683. $BIN/v-rebuild-dns-domains "$user" 'no' > /dev/null 2>&1
  684. fi
  685. fi
  686. if [ -n "$MAIL_SYSTEM" ]; then
  687. if [ "$DEBUG_MODE" = "true" ]; then
  688. echo " ---- Mail domains..."
  689. $BIN/v-rebuild-mail-domains "$user" 'no'
  690. else
  691. $BIN/v-rebuild-mail-domains "$user" 'no' > /dev/null 2>&1
  692. fi
  693. fi
  694. if [ "$DEBUG_MODE" = "true" ]; then
  695. echo " ---- User configuration..."
  696. $BIN/v-rebuild-user "$user" 'no'
  697. else
  698. $BIN/v-rebuild-user "$user" 'no' > /dev/null 2>&1
  699. fi
  700. done
  701. fi
  702. }
  703. upgrade_replace_default_config() {
  704. syshealth_update_web_config_format
  705. syshealth_update_mail_config_format
  706. syshealth_update_mail_account_config_format
  707. syshealth_update_dns_config_format
  708. syshealth_update_db_config_format
  709. syshealth_update_user_config_format
  710. }
  711. upgrade_restart_services() {
  712. if [ "$UPGRADE_RESTART_SERVICES" = "true" ]; then
  713. echo "[ * ] Restarting services..."
  714. sleep 2
  715. if [ -n "$MAIL_SYSTEM" ]; then
  716. if [ "$DEBUG_MODE" = "true" ]; then
  717. echo " - $MAIL_SYSTEM"
  718. fi
  719. $BIN/v-restart-mail 'yes'
  720. fi
  721. if [ -n "$IMAP_SYSTEM" ]; then
  722. if [ "$DEBUG_MODE" = "true" ]; then
  723. echo " - $IMAP_SYSTEM"
  724. fi
  725. $BIN/v-restart-service "$IMAP_SYSTEM"
  726. fi
  727. if [ -n "$WEB_SYSTEM" ]; then
  728. if [ "$DEBUG_MODE" = "true" ]; then
  729. echo " - $WEB_SYSTEM"
  730. fi
  731. $BIN/v-restart-web 'yes'
  732. fi
  733. if [ -n "$PROXY_SYSTEM" ]; then
  734. if [ "$DEBUG_MODE" = "true" ]; then
  735. echo " - $PROXY_SYSTEM"
  736. fi
  737. $BIN/v-restart-proxy 'yes'
  738. fi
  739. if [ -n "$DNS_SYSTEM" ]; then
  740. if [ "$DEBUG_MODE" = "true" ]; then
  741. echo " - $DNS_SYSTEM"
  742. fi
  743. $BIN/v-restart-dns 'yes'
  744. fi
  745. if [ -n "$WEB_BACKEND" ]; then
  746. versions_list=$($BIN/v-list-sys-php plain)
  747. for v in $versions_list; do
  748. if [ "$DEBUG_MODE" = "true" ]; then
  749. echo " - php$v-fpm"
  750. fi
  751. $BIN/v-restart-service "php$v-fpm" 'yes'
  752. done
  753. fi
  754. if [ -n "$FTP_SYSTEM" ]; then
  755. if [ "$DEBUG_MODE" = "true" ]; then
  756. echo " - $FTP_SYSTEM"
  757. fi
  758. $BIN/v-restart-ftp 'yes'
  759. fi
  760. if [ -n "$FIREWALL_EXTENSION" ]; then
  761. if [ "$DEBUG_MODE" = "true" ]; then
  762. echo " - $FIREWALL_EXTENSION"
  763. fi
  764. $BIN/v-restart-service "$FIREWALL_EXTENSION"
  765. fi
  766. # Restart SSH daemon service
  767. if [ "$DEBUG_MODE" = "true" ]; then
  768. echo " - sshd"
  769. fi
  770. $BIN/v-restart-service ssh
  771. fi
  772. # Always restart the Hestia Control Panel service
  773. if [ "$DEBUG_MODE" = "true" ]; then
  774. echo " - hestia"
  775. fi
  776. $BIN/v-restart-service hestia
  777. }