upgrade.sh 31 KB

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