upgrade.sh 30 KB

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