latest.sh 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #!/bin/sh
  2. # Hestia Control Panel upgrade script for target version 1.2.0
  3. #######################################################################################
  4. ####### Place additional commands below. #######
  5. #######################################################################################
  6. # Check iptables paths and add symlinks when necessary
  7. if [ ! -e "/sbin/iptables" ]; then
  8. if which iptables; then
  9. ln -s "$(which iptables)" /sbin/iptables
  10. elif [ -e "/usr/sbin/iptables" ]; then
  11. ln -s /usr/sbin/iptables /sbin/iptables
  12. elif whereis -B /bin /sbin /usr/bin /usr/sbin -f -b iptables; then
  13. autoiptables=$(whereis -B /bin /sbin /usr/bin /usr/sbin -f -b iptables | cut -d '' -f 2)
  14. if [ -x "$autoiptables" ]; then
  15. ln -s "$autoiptables" /sbin/iptables
  16. fi
  17. fi
  18. fi
  19. if [ ! -e "/sbin/iptables-save" ]; then
  20. if which iptables-save; then
  21. ln -s "$(which iptables-save)" /sbin/iptables-save
  22. elif [ -e "/usr/sbin/iptables-save" ]; then
  23. ln -s /usr/sbin/iptables-save /sbin/iptables-save
  24. elif whereis -B /bin /sbin /usr/bin /usr/sbin -f -b iptables-save; then
  25. autoiptables_save=$(whereis -B /bin /sbin /usr/bin /usr/sbin -f -b iptables-save | cut -d '' -f 2)
  26. if [ -x "$autoiptables_save" ]; then
  27. ln -s "$autoiptables_save" /sbin/iptables-save
  28. fi
  29. fi
  30. fi
  31. if [ ! -e "/sbin/iptables-restore" ]; then
  32. if which iptables-restore; then
  33. ln -s "$(which iptables-restore)" /sbin/iptables-restore
  34. elif [ -e "/usr/sbin/iptables-restore" ]; then
  35. ln -s /usr/sbin/iptables-restore /sbin/iptables-restore
  36. elif whereis -B /bin /sbin /usr/bin /usr/sbin -f -b iptables-restore; then
  37. autoiptables_restore=$(whereis -B /bin /sbin /usr/bin /usr/sbin -f -b iptables-restore | cut -d '' -f 2)
  38. if [ -x "$autoiptables_restore" ]; then
  39. ln -s "$autoiptables_restore" /sbin/iptables-restore
  40. fi
  41. fi
  42. fi
  43. if [ -e "/etc/apache2/mods-enabled/status.conf" ]; then
  44. sed -i '/Allow from all/d' /etc/apache2/mods-enabled/status.conf
  45. fi
  46. # Add sury apache2 repository
  47. if [ "$WEB_SYSTEM" = "apache2" ] && [ ! -e "/etc/apt/sources.list.d/apache2.list" ]; then
  48. echo "(*) Configuring sury.org Apache2 repository..."
  49. # Check OS and install related repository
  50. if [ -e "/etc/os-release" ]; then
  51. type=$(grep "^ID=" /etc/os-release | cut -f 2 -d '=')
  52. if [ "$type" = "ubuntu" ]; then
  53. codename="$(lsb_release -s -c)"
  54. echo "deb http://ppa.launchpad.net/ondrej/apache2/ubuntu $codename main" > /etc/apt/sources.list.d/apache2.list
  55. elif [ "$type" = "debian" ]; then
  56. codename="$(cat /etc/os-release |grep VERSION= |cut -f 2 -d \(|cut -f 1 -d \))"
  57. echo "deb https://packages.sury.org/apache2/ $codename main" > /etc/apt/sources.list.d/apache2.list
  58. wget --quiet https://packages.sury.org/apache2/apt.gpg -O /tmp/apache2_signing.key
  59. APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1 apt-key add /tmp/apache2_signing.key > /dev/null 2>&1
  60. fi
  61. fi
  62. fi
  63. # Roundcube fixes for PHP 7.4 compatibility
  64. if [ -d /usr/share/roundcube ]; then
  65. echo "(*) Updating Roundcube configuration..."
  66. [ -f "/usr/share/roundcube/plugins/enigma/lib/enigma_ui.php" ] && sed -i 's/$identities, "\\n"/"\\n", $identities/g' /usr/share/roundcube/plugins/enigma/lib/enigma_ui.php
  67. [ -f "/usr/share/roundcube/program/lib/Roundcube/rcube_contacts.php" ] && sed -i 's/(array_keys($post_search), \x27|\x27)/(\x27|\x27, array_keys($post_search))/g' /usr/share/roundcube/program/lib/Roundcube/rcube_contacts.php
  68. [ -f "/usr/share/roundcube/program/lib/Roundcube/rcube_db.php" ] && sed -i 's/implode($name, \x27.\x27)/implode(\x27.\x27, $name)/g' /usr/share/roundcube/program/lib/Roundcube/rcube_db.php
  69. [ -f "/usr/share/roundcube/program/steps/addressbook/search.inc" ] && sed -i 's/$fields, \x27,\x27/\x27,\x27, $fields/g' /usr/share/roundcube/program/steps/addressbook/search.inc
  70. [ -f "/usr/share/roundcube/program/steps/addressbook/search.inc" ] && sed -i 's/implode($fields, \x27,\x27)/implode(\x27,\x27, $fields)/g' /usr/share/roundcube/program/steps/addressbook/search.inc
  71. [ -f "/usr/share/roundcube/program/steps/mail/sendmail.inc" ] && sed -i 's/implode($bstyle, \x27; \x27)/implode(\x27; \x27, $bstyle)/g' /usr/share/roundcube/program/steps/mail/sendmail.inc
  72. fi
  73. # Enable Roundcube plugins
  74. if [ -d /usr/share/roundcube ]; then
  75. cp -f $HESTIA_INSTALL_DIR/roundcube/plugins/config_newmail_notifier.inc.php /etc/roundcube/plugins/newmail_notifier/config.inc.php
  76. cp -f $HESTIA_INSTALL_DIR/roundcube/plugins/config_zipdownload.inc.php /etc/roundcube/plugins/zipdownload/config.inc.php
  77. [ -f "/etc/roundcube/config.inc.php" ] && sed -i "s/array('password')/array('password','newmail_notifier','zipdownload')/g" /etc/roundcube/config.inc.php
  78. fi
  79. # HELO support for multiple domains and IPs
  80. if [ -e "/etc/exim4/exim4.conf.template" ]; then
  81. echo "(*) Updating exim4 configuration..."
  82. sed -i 's|helo_data = ${primary_hostname}|helo_data = ${if exists {\/etc\/exim4\/mailhelo.conf}{${lookup{$sender_address_domain}lsearch*{\/etc\/exim4\/mailhelo.conf}{$value}{$primary_hostname}}}{$primary_hostname}}|g' /etc/exim4/exim4.conf.template
  83. fi
  84. # Add daily midnight cron
  85. if [ -z "$($BIN/v-list-cron-jobs admin | grep 'v-update-sys-queue daily')" ]; then
  86. echo "(*) Updating cron jobs..."
  87. command="sudo $BIN/v-update-sys-queue daily"
  88. $BIN/v-add-cron-job 'admin' '01' '00' '*' '*' '*' "$command"
  89. fi
  90. [ ! -f "touch $HESTIA/data/queue/daily.pipe" ] && touch $HESTIA/data/queue/daily.pipe
  91. # Remove existing network-up hooks so they get regenerated when updating the firewall
  92. # - network hook will also restore ipset config during start-up
  93. if [ -f "/usr/lib/networkd-dispatcher/routable.d/50-ifup-hooks" ]; then
  94. rm "/usr/lib/networkd-dispatcher/routable.d/50-ifup-hooks"
  95. $BIN/v-update-firewall
  96. fi
  97. if [ -f "/etc/network/if-pre-up.d/iptables" ];then
  98. rm "/etc/network/if-pre-up.d/iptables"
  99. $BIN/v-update-firewall
  100. fi
  101. # Add hestia-event.conf, if the server is running apache2
  102. if [ "$WEB_SYSTEM" = "apache2" ]; then
  103. echo "(*) Updating Apache2 configuration..."
  104. # Cleanup
  105. rm --force /etc/apache2/mods-available/hestia-event.conf
  106. rm --force /etc/apache2/mods-enabled/hestia-event.conf
  107. rm --force /etc/apache2/conf-available/hestia-event.conf
  108. rm --force /etc/apache2/conf-enabled/hestia-event.conf
  109. if [ $(a2query -M) = 'event' ] && [ ! -e "/etc/apache2/conf.d/hestia-event.conf" ]; then
  110. cp -f $HESTIA_INSTALL_DIR/apache2/hestia-event.conf /etc/apache2/conf.d/
  111. fi
  112. # Move apache mod_status config to /mods-available and rename it to prevent losing changes on upgrade
  113. cp -f $HESTIA_INSTALL_DIR/apache2/status.conf /etc/apache2/mods-available/hestia-status.conf
  114. cp -f /etc/apache2/mods-available/status.load /etc/apache2/mods-available/hestia-status.load
  115. a2dismod --quiet status > /dev/null 2>&1
  116. a2enmod --quiet hestia-status > /dev/null 2>&1
  117. rm --force /etc/apache2/mods-enabled/status.conf # a2dismod will not remove the file if it isn't a symlink
  118. fi
  119. # Install Filegator FileManager during upgrade
  120. if [ ! -e "$HESTIA/web/fm/configuration.php" ]; then
  121. echo "(*) Configuring File Manager..."
  122. # Install the FileManager
  123. source $HESTIA_INSTALL_DIR/filemanager/install-fm.sh > /dev/null 2>&1
  124. else
  125. echo "(*) Updating File Manager configuration..."
  126. # Update configuration.php
  127. cp -f $HESTIA_INSTALL_DIR/filemanager/filegator/configuration.php $HESTIA/web/fm/configuration.php
  128. fi
  129. # Enable nginx module loading
  130. if [ -f "/etc/nginx/nginx.conf" ]; then
  131. echo "(*) Updating NGINX configuration..."
  132. if [ ! -d "/etc/nginx/modules-enabled" ]; then
  133. mkdir -p "/etc/nginx/modules-enabled"
  134. fi
  135. if ! grep --silent "include /etc/nginx/modules-enabled" /etc/nginx/nginx.conf; then
  136. sed -i '/^pid/ a include /etc/nginx/modules-enabled/*.conf;' /etc/nginx/nginx.conf
  137. fi
  138. fi
  139. # Fix public_(s)html group ownership
  140. echo "(*) Updating public_(s)html ownership..."
  141. for user in $($HESTIA/bin/v-list-sys-users plain); do
  142. # skip users with missing home folder
  143. [[ -d /home/${user}/ ]] || continue
  144. # skip users without web domains
  145. ls /home/${user}/web/*/public_*html >/dev/null 2>&1 || continue
  146. chown --silent --no-dereference :www-data /home/$user/web/*/public_*html
  147. done
  148. # Fix phpMyAdmin blowfish_secret error message due to incorrect permissions
  149. if [ -e /var/lib/phpmyadmin/blowfish_secret.inc.php ]; then
  150. echo "(*) Updating phpMyAdmin permissions..."
  151. chmod 0644 /var/lib/phpmyadmin/blowfish_secret.inc.php
  152. fi
  153. # Add phpMyAdmin/phpPgAdmin aliases to hestia.conf and correct configuration/templates
  154. if [ -e "/var/lib/phpmyadmin" ]; then
  155. PMA_ALIAS_CHECK=$(cat $HESTIA/conf/hestia.conf | grep DB_PMA_ALIAS)
  156. if [ -z "$PMA_ALIAS_CHECK" ]; then
  157. echo "(*) Updating phpMyAdmin alias..."
  158. $HESTIA/bin/v-change-sys-db-alias "pma" "phpmyadmin"
  159. fi
  160. fi
  161. if [ -e "/var/lib/phppgadmin" ]; then
  162. PGA_ALIAS_CHECK=$(cat $HESTIA/conf/hestia.conf | grep DB_PGA_ALIAS)
  163. if [ -z "$PGA_ALIAS_CHECK" ]; then
  164. echo "(*) Updating phpPgAdmin alias..."
  165. $HESTIA/bin/v-change-sys-db-alias "pga" "phppgadmin"
  166. fi
  167. fi