upgrade.sh 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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. # Hestia Control Panel configuration files
  59. mkdir -p $HESTIA_BACKUP/conf/hestia/
  60. # Hosting Packages
  61. mkdir -p $HESTIA_BACKUP/packages/
  62. # Domain template files
  63. mkdir -p $HESTIA_BACKUP/templates/
  64. # System services (apache2, nginx, bind9, vsftpd, etc).
  65. if [ ! -z "$WEB_SYSTEM" ]; then
  66. mkdir -p $HESTIA_BACKUP/conf/$WEB_SYSTEM/
  67. fi
  68. if [ ! -z "$IMAP_SYSTEM" ]; then
  69. mkdir -p $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
  70. fi
  71. if [ ! -z "$MAIL_SYSTEM" ]; then
  72. mkdir -p $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
  73. fi
  74. if [ ! -z "$DNS_SYSTEM" ]; then
  75. mkdir -p $HESTIA_BACKUP/conf/$DNS_SYSTEM/
  76. fi
  77. if [ ! -z "$PROXY_SYSTEM" ]; then
  78. mkdir -p $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  79. fi
  80. if [ ! -z "$DB_SYSTEM" ]; then
  81. if [[ "$DB_SYSTEM" =~ "mysql" ]]; then
  82. mkdir -p $HESTIA_BACKUP/conf/mysql/
  83. fi
  84. if [[ "$DB_SYSTEM" =~ "pgsql" ]]; then
  85. mkdir -p $HESTIA_BACKUP/conf/pgsql/
  86. fi
  87. fi
  88. if [ ! -z "$FTP_SYSTEM" ]; then
  89. mkdir -p $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  90. fi
  91. if [ ! -z "$FIREWALL_SYSTEM" ]; then
  92. mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_SYSTEM/
  93. fi
  94. if [ ! -z "$FIREWALL_EXTENSION" ]; then
  95. mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  96. fi
  97. if [ -e "/etc/ssh/sshd_config" ]; then
  98. mkdir -p $HESTIA_BACKUP/conf/ssh/
  99. fi
  100. echo "[ * ] Backing up existing templates and configuration files..."
  101. cp -rf $HESTIA/data/packages/* $HESTIA_BACKUP/packages/
  102. cp -rf $HESTIA/data/templates/* $HESTIA_BACKUP/templates/
  103. # Hestia Control Panel configuration files
  104. cp -rf $HESTIA/conf/* $HESTIA_BACKUP/conf/hestia/
  105. # System service configuration files (apache2, nginx, bind9, vsftpd, etc).
  106. if [ ! -z "$WEB_SYSTEM" ]; then
  107. cp -f /etc/$WEB_SYSTEM/*.conf $HESTIA_BACKUP/conf/$WEB_SYSTEM/
  108. cp -f /etc/$WEB_SYSTEM/conf.d/*.conf $HESTIA_BACKUP/conf/$WEB_SYSTEM/
  109. fi
  110. if [ ! -z "$PROXY_SYSTEM" ]; then
  111. cp -f /etc/$PROXY_SYSTEM/*.conf $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  112. cp -f /etc/$PROXY_SYSTEM/conf.d/*.conf $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  113. cp -f /etc/$PROXY_SYSTEM/conf.d/*.inc $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
  114. fi
  115. if [ ! -z "$IMAP_SYSTEM" ]; then
  116. cp -f /etc/$IMAP_SYSTEM/*.conf $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
  117. cp -f /etc/$IMAP_SYSTEM/conf.d/*.conf $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
  118. fi
  119. if [ ! -z "$MAIL_SYSTEM" ]; then
  120. cp -f /etc/$MAIL_SYSTEM/*.conf $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
  121. fi
  122. if [ ! -z "$DNS_SYSTEM" ]; then
  123. if [ "$DNS_SYSTEM" = "bind9" ]; then
  124. cp -f /etc/bind/*.conf $HESTIA_BACKUP/conf/$DNS_SYSTEM/
  125. fi
  126. fi
  127. if [ ! -z "$DB_SYSTEM" ]; then
  128. if [[ "$DB_SYSTEM" =~ "mysql" ]]; then
  129. cp -f /etc/mysql/*.cnf $HESTIA_BACKUP/conf/mysql/
  130. cp -f /etc/mysql/conf.d/*.cnf $HESTIA_BACKUP/conf/mysql/
  131. fi
  132. if [[ "$DB_SYSTEM" =~ "pgsql" ]]; then
  133. cp -f /etc/mysql/*.cnf $HESTIA_BACKUP/conf/pgsql/
  134. cp -f /etc/mysql/conf.d/*.cnf $HESTIA_BACKUP/conf/pgsql/
  135. fi
  136. fi
  137. if [ ! -z "$FTP_SYSTEM" ]; then
  138. if [ "$FTP_SYSTEM" = "vsftpd" ]; then
  139. cp -f /etc/$FTP_SYSTEM.conf $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  140. fi
  141. if [ "$FTP_SYSTEM" = "proftpd" ]; then
  142. cp -f /etc/proftpd/proftpd.conf $HESTIA_BACKUP/conf/$FTP_SYSTEM/
  143. fi
  144. fi
  145. if [ ! -z "$FIREWALL_EXTENSION" ]; then
  146. cp -f /etc/$FIREWALL_EXTENSION/*.conf $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  147. cp -f /etc/$FIREWALL_EXTENSION/*.local $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
  148. fi
  149. if [ -e "/etc/ssh/sshd_config" ]; then
  150. cp -f /etc/ssh/sshd_config $HESTIA_BACKUP/conf/ssh/sshd_config
  151. fi
  152. }
  153. upgrade_refresh_config() {
  154. source /usr/local/hestia/conf/hestia.conf
  155. source /usr/local/hestia/func/main.sh
  156. }
  157. upgrade_start_routine() {
  158. #####################################################################
  159. ####### Ensure that release branch variable exists #######
  160. #####################################################################
  161. release_branch_check=$(cat $HESTIA/conf/hestia.conf | grep RELEASE_BRANCH)
  162. if [ -z "$release_branch_check" ]; then
  163. echo "[ * ] Adding global release branch variable to system configuration..."
  164. $BIN/v-change-sys-config-value 'RELEASE_BRANCH' 'release'
  165. fi
  166. #####################################################################
  167. ####### Start standard upgrade process #######
  168. ####### Place instructions for all post v1.0.1 builds below #######
  169. #####################################################################
  170. # Ensure that latest upgrade commands are processed if version is the same
  171. if [ $VERSION = "$new_version" ]; then
  172. echo "[ ! ] The latest version of Hestia Control Panel is already installed."
  173. echo " Verifying configuration..."
  174. echo ""
  175. source $HESTIA/install/upgrade/versions/latest.sh
  176. VERSION="$new_version"
  177. upgrade_set_version $VERSION
  178. upgrade_refresh_config
  179. fi
  180. 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
  181. source $HESTIA/install/upgrade/versions/previous/0.9.8-29.sh
  182. source $HESTIA/install/upgrade/versions/previous/1.00.0-190618.sh
  183. source $HESTIA/install/upgrade/versions/previous/1.0.1.sh
  184. VERSION="1.0.1"
  185. upgrade_set_version $VERSION
  186. upgrade_refresh_config
  187. fi
  188. # Upgrade to Version 1.0.2
  189. if [ $VERSION = "1.0.1" ]; then
  190. source $HESTIA/install/upgrade/versions/previous/1.0.2.sh
  191. VERSION="1.0.2"
  192. upgrade_set_version $VERSION
  193. upgrade_refresh_config
  194. fi
  195. # Upgrade to Version 1.0.3
  196. if [ $VERSION = "1.0.2" ]; then
  197. source $HESTIA/install/upgrade/versions/previous/1.0.3.sh
  198. VERSION="1.0.3"
  199. upgrade_set_version $VERSION
  200. upgrade_refresh_config
  201. fi
  202. # Upgrade to Version 1.0.4
  203. if [ $VERSION = "1.0.3" ]; then
  204. source $HESTIA/install/upgrade/versions/previous/1.0.4.sh
  205. VERSION="1.0.4"
  206. upgrade_set_version $VERSION
  207. upgrade_refresh_config
  208. fi
  209. # Upgrade to Version 1.0.5
  210. if [ $VERSION = "1.0.4" ]; then
  211. source $HESTIA/install/upgrade/versions/previous/1.0.5.sh
  212. VERSION="1.0.5"
  213. upgrade_set_version $VERSION
  214. upgrade_refresh_config
  215. fi
  216. # Upgrade to Version 1.0.6
  217. if [ $VERSION = "1.0.5" ]; then
  218. source $HESTIA/install/upgrade/versions/previous/1.0.6.sh
  219. VERSION="1.0.6"
  220. upgrade_set_version $VERSION
  221. upgrade_refresh_config
  222. fi
  223. # Upgrade to Version 1.1.0
  224. if [ $VERSION = "1.0.6" ]; then
  225. source $HESTIA/install/upgrade/versions/previous/1.1.0.sh
  226. VERSION="1.1.0"
  227. upgrade_set_version $VERSION
  228. upgrade_refresh_config
  229. fi
  230. # Upgrade to Version 1.1.1
  231. if [ $VERSION = "1.1.0" ]; then
  232. source $HESTIA/install/upgrade/versions/previous/1.1.1.sh
  233. VERSION="1.1.1"
  234. upgrade_set_version $VERSION
  235. upgrade_refresh_config
  236. fi
  237. # Upgrade to Version 1.2.0
  238. if [ $VERSION = "1.1.1" ] || [ $VERSION = "1.1.2" ]; then
  239. source $HESTIA/install/upgrade/versions/previous/1.2.0.sh
  240. VERSION="1.2.1"
  241. upgrade_set_version $VERSION
  242. upgrade_refresh_config
  243. fi
  244. # Upgrade to Version 1.2.1
  245. if [ $VERSION = "1.2.0" ]; then
  246. # Process steps which may not have correctly executed from v1.1.0.
  247. echo
  248. echo "[ ! ] Reprocessing steps from v1.1.0 due to a previous installer bug..."
  249. echo
  250. source $HESTIA/install/upgrade/versions/previous/1.1.0.sh
  251. source $HESTIA/install/upgrade/versions/previous/1.2.0.sh
  252. VERSION="1.2.1"
  253. upgrade_refresh_config
  254. fi
  255. # Upgrade to Version 1.2.2
  256. if [ $VERSION = "1.2.1" ]; then
  257. source $HESTIA/install/upgrade/versions/latest.sh
  258. VERSION="$new_version"
  259. upgrade_refresh_config
  260. fi
  261. #####################################################################
  262. ####### End version-specific upgrade instruction sets #######
  263. #####################################################################
  264. }
  265. upgrade_phpmyadmin() {
  266. # Check if MariaDB/MySQL is installed on the server before attempting to install or upgrade phpMyAdmin
  267. if [ "$DB_SYSTEM" = "mysql" ]; then
  268. # Define version check function
  269. function version_ge(){ test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" -o ! -z "$1" -a "$1" = "$2"; }
  270. pma_release_file=$(ls /usr/share/phpmyadmin/RELEASE-DATE-* 2>/dev/null |tail -n 1)
  271. if version_ge "${pma_release_file##*-}" "$pma_v"; then
  272. echo "[ ! ] phpMyAdmin v${pma_release_file##*-} is already installed, skipping update..."
  273. else
  274. # Display upgrade information
  275. echo "[ * ] Upgrading phpMyAdmin to version v$pma_v..."
  276. [ -d /usr/share/phpmyadmin ] || mkdir -p /usr/share/phpmyadmin
  277. # Download latest phpMyAdmin release
  278. wget --quiet https://files.phpmyadmin.net/phpMyAdmin/$pma_v/phpMyAdmin-$pma_v-all-languages.tar.gz
  279. # Unpack files
  280. tar xzf phpMyAdmin-$pma_v-all-languages.tar.gz
  281. # Delete file to prevent error
  282. rm -fr /usr/share/phpmyadmin/doc/html
  283. # Overwrite old files
  284. cp -rf phpMyAdmin-$pma_v-all-languages/* /usr/share/phpmyadmin
  285. # Set config and log directory
  286. sed -i "s|define('CONFIG_DIR', ROOT_PATH);|define('CONFIG_DIR', '/etc/phpmyadmin/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
  287. sed -i "s|define('TEMP_DIR', ROOT_PATH . 'tmp/');|define('TEMP_DIR', '/var/lib/phpmyadmin/tmp/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
  288. # Create temporary folder and change permissions
  289. if [ ! -d /usr/share/phpmyadmin/tmp ]; then
  290. mkdir /usr/share/phpmyadmin/tmp
  291. chmod 777 /usr/share/phpmyadmin/tmp
  292. fi
  293. # Clean up source files
  294. rm -fr phpMyAdmin-$pma_v-all-languages
  295. rm -f phpMyAdmin-$pma_v-all-languages.tar.gz
  296. fi
  297. fi
  298. }
  299. upgrade_get_version() {
  300. # Retrieve new version number for Hestia Control Panel from .deb package
  301. new_version=$(dpkg -l | awk '$2=="hestia" { print $3 }')
  302. }
  303. upgrade_set_version() {
  304. # Set new version number in hestia.conf
  305. sed -i "/VERSION/d" $HESTIA/conf/hestia.conf
  306. echo "VERSION='$@'" >> $HESTIA/conf/hestia.conf
  307. }
  308. upgrade_rebuild_users() {
  309. for user in $($HESTIA/bin/v-list-sys-users plain); do
  310. echo "[ * ] Rebuilding domains and account for user: $user..."
  311. if [ ! -z "$WEB_SYSTEM" ]; then
  312. $BIN/v-rebuild-web-domains $user 'no' >/dev/null 2>&1
  313. fi
  314. if [ ! -z "$DNS_SYSTEM" ]; then
  315. $BIN/v-rebuild-dns-domains $user 'no' >/dev/null 2>&1
  316. fi
  317. if [ ! -z "$MAIL_SYSTEM" ]; then
  318. $BIN/v-rebuild-mail-domains $user 'no' >/dev/null 2>&1
  319. fi
  320. $BIN/v-rebuild-user $user 'no' >/dev/null 2>&1
  321. done
  322. }
  323. upgrade_restart_services() {
  324. # Refresh user interface theme
  325. if [ "$THEME" ]; then
  326. if [ "$THEME" != "default" ]; then
  327. echo "[ * ] Applying user interface updates..."
  328. $BIN/v-change-sys-theme $THEME
  329. fi
  330. fi
  331. echo "[ * ] Restarting services..."
  332. sleep 5
  333. if [ ! -z "$MAIL_SYSTEM" ]; then
  334. $BIN/v-restart-mail $restart
  335. fi
  336. if [ ! -z "$WEB_SYSTEM" ]; then
  337. $BIN/v-restart-web $restart
  338. $BIN/v-restart-proxy $restart
  339. fi
  340. if [ ! -z "$DNS_SYSTEM" ]; then
  341. $BIN/v-restart-dns $restart
  342. fi
  343. for v in `ls /etc/php/`; do
  344. if [ -e /etc/php/$v/fpm ]; then
  345. $BIN/v-restart-service php$v-fpm $restart
  346. fi
  347. done
  348. if [ ! -z "$FTP_SYSTEM" ]; then
  349. $BIN/v-restart-ftp $restart
  350. fi
  351. if [ ! -z "$FIREWALL_EXTENSION" ]; then
  352. $BIN/v-restart-service $FIREWALL_EXTENSION yes
  353. fi
  354. # Restart SSH daemon and Hestia Control Panel service
  355. $BIN/v-restart-service ssh $restart
  356. $BIN/v-restart-service hestia $restart
  357. }