upgrade.sh 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. #!/bin/bash
  2. # Hestia Control Panel - Upgrade Control Script
  3. #####################################################################
  4. ####### Functions & Initialization #######
  5. #####################################################################
  6. upgrade_welcome_message() {
  7. echo
  8. echo ' _ _ _ _ ____ ____ '
  9. echo ' | | | | ___ ___| |_(_) __ _ / ___| _ \ '
  10. echo ' | |_| |/ _ \/ __| __| |/ _` | | | |_) | '
  11. echo ' | _ | __/\__ \ |_| | (_| | |___| __/ '
  12. echo ' |_| |_|\___||___/\__|_|\__,_|\____|_| '
  13. echo " "
  14. echo " Hestia Control Panel Software Update "
  15. echo " Version: $new_version "
  16. echo "========================================================================"
  17. echo
  18. echo "[ ! ] IMPORTANT INFORMATION: "
  19. echo
  20. echo "Default configuration files and templates may be modified or replaced "
  21. echo "during the upgrade process. You may restore these files from: "
  22. echo ""
  23. echo "Backup directory: $HESTIA_BACKUP/ "
  24. echo
  25. echo "This process may take a few minutes, please wait... "
  26. echo
  27. echo "========================================================================"
  28. echo
  29. }
  30. upgrade_complete_message() {
  31. # Add notification to panel
  32. $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> or e-mail <a href="mailto:info@hestiacp.com?Subject="['$new_version'] Bug Report: ">info@hestiacp.com</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'
  33. # Echo message to console output
  34. echo
  35. echo "========================================================================"
  36. echo
  37. echo "Upgrade complete! If you encounter any issues or find a bug, "
  38. echo "please take a moment to report it to us on GitHub at the URL below: "
  39. echo "https://github.com/hestiacp/hestiacp/issues "
  40. echo
  41. echo "We hope that you enjoy using this version of Hestia Control Panel, "
  42. echo "have a wonderful day! "
  43. echo
  44. echo "Sincerely, "
  45. echo "The Hestia Control Panel development team "
  46. echo
  47. echo "Web: https://www.hestiacp.com/ "
  48. echo "Forum: https://forum.hestiacp.com/ "
  49. echo "GitHub: https://github.com/hestiacp/hestiacp/ "
  50. echo "E-mail: info@hestiacp.com "
  51. echo
  52. echo "Made with love & pride by the open-source community around the world. "
  53. echo
  54. echo
  55. }
  56. upgrade_init_backup() {
  57. # Ensure that backup directories are created
  58. mkdir -p $HESTIA_BACKUP/conf/
  59. mkdir -p $HESTIA_BACKUP/packages/
  60. mkdir -p $HESTIA_BACKUP/templates/
  61. }
  62. upgrade_refresh_config() {
  63. source /usr/local/hestia/conf/hestia.conf
  64. source /usr/local/hestia/func/main.sh
  65. }
  66. upgrade_start_routine() {
  67. #####################################################################
  68. ####### Ensure that release branch variable exists #######
  69. #####################################################################
  70. release_branch_check=$(cat $HESTIA/conf/hestia.conf | grep RELEASE_BRANCH)
  71. if [ -z "$release_branch_check" ]; then
  72. echo "[ * ] Adding global release branch variable to system configuration..."
  73. $BIN/v-change-sys-config-value 'RELEASE_BRANCH' 'release'
  74. fi
  75. #####################################################################
  76. ####### Start standard upgrade process #######
  77. ####### Place instructions for all post v1.0.1 builds below #######
  78. #####################################################################
  79. # Ensure that latest upgrade commands are processed if version is the same
  80. if [ $VERSION = "$new_version" ]; then
  81. echo "[ ! ] The latest version of Hestia Control Panel is already installed."
  82. echo " Verifying configuration..."
  83. echo ""
  84. source $HESTIA/install/upgrade/versions/latest.sh
  85. VERSION="$new_version"
  86. upgrade_set_version $VERSION
  87. upgrade_refresh_config
  88. fi
  89. if [ $VERSION = "0.9.8-25" ] || [ $VERSION = "0.9.8-26" ] || [ $VERSION = "0.9.8-27" ] || [ $VERSION = "0.9.8-28" ] || [ $VERSION = "0.9.8-29" ] || [ $VERSION = "0.10.0" ] || [ $VERSION = "1.00.0-190618" ] || [ $VERSION = "1.00.0-190621" ] || [ $VERSION = "1.0.0" ]; then
  90. source $HESTIA/install/upgrade/versions/previous/0.9.8-29.sh
  91. source $HESTIA/install/upgrade/versions/previous/1.00.0-190618.sh
  92. source $HESTIA/install/upgrade/versions/previous/1.0.1.sh
  93. VERSION="1.0.1"
  94. upgrade_set_version $VERSION
  95. upgrade_refresh_config
  96. fi
  97. # Upgrade to Version 1.0.2
  98. if [ $VERSION = "1.0.1" ]; then
  99. source $HESTIA/install/upgrade/versions/previous/1.0.2.sh
  100. VERSION="1.0.2"
  101. upgrade_set_version $VERSION
  102. upgrade_refresh_config
  103. fi
  104. # Upgrade to Version 1.0.3
  105. if [ $VERSION = "1.0.2" ]; then
  106. source $HESTIA/install/upgrade/versions/previous/1.0.3.sh
  107. VERSION="1.0.3"
  108. upgrade_set_version $VERSION
  109. upgrade_refresh_config
  110. fi
  111. # Upgrade to Version 1.0.4
  112. if [ $VERSION = "1.0.3" ]; then
  113. source $HESTIA/install/upgrade/versions/previous/1.0.4.sh
  114. VERSION="1.0.4"
  115. upgrade_set_version $VERSION
  116. upgrade_refresh_config
  117. fi
  118. # Upgrade to Version 1.0.5
  119. if [ $VERSION = "1.0.4" ]; then
  120. source $HESTIA/install/upgrade/versions/previous/1.0.5.sh
  121. VERSION="1.0.5"
  122. upgrade_set_version $VERSION
  123. upgrade_refresh_config
  124. fi
  125. # Upgrade to Version 1.0.6
  126. if [ $VERSION = "1.0.5" ]; then
  127. source $HESTIA/install/upgrade/versions/previous/1.0.6.sh
  128. VERSION="1.0.6"
  129. upgrade_set_version $VERSION
  130. upgrade_refresh_config
  131. fi
  132. # Upgrade to Version 1.1.0
  133. if [ $VERSION = "1.0.6" ]; then
  134. source $HESTIA/install/upgrade/versions/previous/1.1.0.sh
  135. VERSION="1.1.0"
  136. upgrade_set_version $VERSION
  137. upgrade_refresh_config
  138. fi
  139. # Upgrade to Version 1.1.1
  140. if [ $VERSION = "1.1.0" ]; then
  141. source $HESTIA/install/upgrade/versions/previous/1.1.1.sh
  142. VERSION="1.1.1"
  143. upgrade_set_version $VERSION
  144. upgrade_refresh_config
  145. fi
  146. # Upgrade to Version 1.2.0
  147. if [ $VERSION = "1.1.1" ] || [ $VERSION = "1.1.2" ]; then
  148. source $HESTIA/install/upgrade/versions/latest.sh
  149. VERSION="$new_version"
  150. upgrade_refresh_config
  151. fi
  152. #####################################################################
  153. ####### End version-specific upgrade instruction sets #######
  154. #####################################################################
  155. }
  156. upgrade_phpmyadmin() {
  157. # Check if MariaDB/MySQL is installed on the server before attempting to install or upgrade phpMyAdmin
  158. if [ "$DB_SYSTEM" = "mysql" ]; then
  159. # Define version check function
  160. function version_ge(){ test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" -o ! -z "$1" -a "$1" = "$2"; }
  161. pma_release_file=$(ls /usr/share/phpmyadmin/RELEASE-DATE-* 2>/dev/null |tail -n 1)
  162. if version_ge "${pma_release_file##*-}" "$pma_v"; then
  163. echo "[ ! ] phpMyAdmin v${pma_release_file##*-} is already installed, skipping update..."
  164. else
  165. # Display upgrade information
  166. echo "[ * ] Upgrading phpMyAdmin to version v$pma_v..."
  167. [ -d /usr/share/phpmyadmin ] || mkdir -p /usr/share/phpmyadmin
  168. # Download latest phpMyAdmin release
  169. wget --quiet https://files.phpmyadmin.net/phpMyAdmin/$pma_v/phpMyAdmin-$pma_v-all-languages.tar.gz
  170. # Unpack files
  171. tar xzf phpMyAdmin-$pma_v-all-languages.tar.gz
  172. # Delete file to prevent error
  173. rm -fr /usr/share/phpmyadmin/doc/html
  174. # Overwrite old files
  175. cp -rf phpMyAdmin-$pma_v-all-languages/* /usr/share/phpmyadmin
  176. # Set config and log directory
  177. sed -i "s|define('CONFIG_DIR', ROOT_PATH);|define('CONFIG_DIR', '/etc/phpmyadmin/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
  178. sed -i "s|define('TEMP_DIR', ROOT_PATH . 'tmp/');|define('TEMP_DIR', '/var/lib/phpmyadmin/tmp/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
  179. # Create temporary folder and change permissions
  180. if [ ! -d /usr/share/phpmyadmin/tmp ]; then
  181. mkdir /usr/share/phpmyadmin/tmp
  182. chmod 777 /usr/share/phpmyadmin/tmp
  183. fi
  184. # Clean up source files
  185. rm -fr phpMyAdmin-$pma_v-all-languages
  186. rm -f phpMyAdmin-$pma_v-all-languages.tar.gz
  187. fi
  188. fi
  189. }
  190. update_php_templates() {
  191. echo "[ * ] Updating default PHP templates..."
  192. # Update default template
  193. cp -f $HESTIA_INSTALL_DIR/templates/web/php-fpm/default.tpl \
  194. $HESTIA/data/templates/web/php-fpm/default.tpl
  195. # Update no-php template
  196. cp -f $HESTIA_INSTALL_DIR/templates/web/php-fpm/no-php.tpl \
  197. $HESTIA/data/templates/web/php-fpm/no-php.tpl
  198. # Update socket template
  199. cp -f $HESTIA_INSTALL_DIR/templates/web/php-fpm/socket.tpl \
  200. $HESTIA/data/templates/web/php-fpm/socket.tpl
  201. for version in $($HESTIA/bin/v-list-sys-php plain); do
  202. echo "[ * ] Updating templates for PHP ${version}..."
  203. cp -f $HESTIA_INSTALL_DIR/php-fpm/multiphp.tpl \
  204. $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl;
  205. done
  206. }
  207. upgrade_get_version() {
  208. # Retrieve new version number for Hestia Control Panel from .deb package
  209. new_version=$(dpkg -l | awk '$2=="hestia" { print $3 }')
  210. }
  211. upgrade_set_version() {
  212. # Set new version number in hestia.conf
  213. sed -i "/VERSION/d" $HESTIA/conf/hestia.conf
  214. echo "VERSION='$@'" >> $HESTIA/conf/hestia.conf
  215. }
  216. upgrade_rebuild_users() {
  217. for user in $($HESTIA/bin/v-list-sys-users plain); do
  218. echo "[ * ] Rebuilding domains and account for user: $user..."
  219. if [ ! -z "$WEB_SYSTEM" ]; then
  220. $BIN/v-rebuild-web-domains $user 'no' >/dev/null 2>&1
  221. fi
  222. if [ ! -z "$DNS_SYSTEM" ]; then
  223. $BIN/v-rebuild-dns-domains $user 'no' >/dev/null 2>&1
  224. fi
  225. if [ ! -z "$MAIL_SYSTEM" ]; then
  226. $BIN/v-rebuild-mail-domains $user 'no' >/dev/null 2>&1
  227. fi
  228. done
  229. }
  230. upgrade_restart_services() {
  231. # Refresh user interface theme
  232. if [ "$THEME" ]; then
  233. if [ "$THEME" != "default" ]; then
  234. echo "[ * ] Applying user interface updates..."
  235. $BIN/v-change-sys-theme $THEME
  236. fi
  237. fi
  238. echo "[ * ] Restarting services..."
  239. sleep 5
  240. if [ ! -z "$MAIL_SYSTEM" ]; then
  241. $BIN/v-restart-mail $restart
  242. fi
  243. if [ ! -z "$WEB_SYSTEM" ]; then
  244. $BIN/v-restart-web $restart
  245. $BIN/v-restart-proxy $restart
  246. fi
  247. if [ ! -z "$DNS_SYSTEM" ]; then
  248. $BIN/v-restart-dns $restart
  249. fi
  250. for v in `ls /etc/php/`; do
  251. if [ -e /etc/php/$v/fpm ]; then
  252. $BIN/v-restart-service php$v-fpm $restart
  253. fi
  254. done
  255. if [ ! -z "$FTP_SYSTEM" ]; then
  256. $BIN/v-restart-ftp $restart
  257. fi
  258. if [ ! -z "$FIREWALL_EXTENSION" ]; then
  259. $BIN/v-restart-service $FIREWALL_EXTENSION yes
  260. fi
  261. # Restart SSH daemon and Hestia Control Panel service
  262. $BIN/v-restart-service ssh $restart
  263. $BIN/v-restart-service hestia $restart
  264. }