upgrade.sh 32 KB

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