1.2.0.sh 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 File Manager during upgrade if environment variable oesn't already exist and isn't set to false
  120. # so that we don't override preference
  121. FILE_MANAGER_CHECK=$(cat $HESTIA/conf/hestia.conf | grep "FILE_MANAGER='false'")
  122. if [ -z "$FILE_MANAGER_CHECK" ]; then
  123. if [ ! -e "$HESTIA/web/fm/configuration.php" ]; then
  124. echo "[ ! ] Installing File Manager..."
  125. # Install the File Manager
  126. $HESTIA/bin/v-add-sys-filemanager quiet
  127. else
  128. echo "[ * ] Updating File Manager configuration..."
  129. # Update configuration.php
  130. cp -f $HESTIA_INSTALL_DIR/filemanager/filegator/configuration.php $HESTIA/web/fm/configuration.php
  131. # Set environment variable for interface
  132. $HESTIA/bin/v-change-sys-config-value 'FILE_MANAGER' 'true'
  133. fi
  134. fi
  135. # Enable nginx module loading
  136. if [ -f "/etc/nginx/nginx.conf" ]; then
  137. echo "[ * ] Updating NGINX configuration..."
  138. if [ ! -d "/etc/nginx/modules-enabled" ]; then
  139. mkdir -p "/etc/nginx/modules-enabled"
  140. fi
  141. if ! grep --silent "include /etc/nginx/modules-enabled" /etc/nginx/nginx.conf; then
  142. sed -i '/^pid/ a include /etc/nginx/modules-enabled/*.conf;' /etc/nginx/nginx.conf
  143. fi
  144. fi
  145. # Fix public_(s)html group ownership
  146. echo "[ * ] Updating public_(s)html ownership..."
  147. for user in $($HESTIA/bin/v-list-sys-users plain); do
  148. # skip users with missing home folder
  149. [[ -d /home/${user}/ ]] || continue
  150. # skip users without web domains
  151. ls /home/${user}/web/*/public_*html >/dev/null 2>&1 || continue
  152. chown --silent --no-dereference :www-data /home/$user/web/*/public_*html
  153. done
  154. # Fix phpMyAdmin blowfish_secret error message due to incorrect permissions
  155. if [ -e /var/lib/phpmyadmin/blowfish_secret.inc.php ]; then
  156. echo "[ * ] Updating phpMyAdmin permissions..."
  157. chmod 0644 /var/lib/phpmyadmin/blowfish_secret.inc.php
  158. fi
  159. # Ensure that backup compression level is correctly set
  160. GZIP_LVL_CHECK=$(cat $HESTIA/conf/hestia.conf | grep BACKUP_GZIP)
  161. if [ -z "$GZIP_LVL_CHECK" ]; then
  162. echo "[ * ] Updating backup compression level variable..."
  163. $BIN/v-change-sys-config-value "BACKUP_GZIP" '9'
  164. fi
  165. # Update phpMyAdmin/phpPgAdmin templates and set missing alias variables if necessary
  166. if [ -e "/var/lib/phpmyadmin" ]; then
  167. PMA_ALIAS_CHECK=$(cat $HESTIA/conf/hestia.conf | grep DB_PMA_ALIAS)
  168. if [ -z "$PMA_ALIAS_CHECK" ]; then
  169. echo "[ * ] Updating phpMyAdmin alias..."
  170. $HESTIA/bin/v-change-sys-db-alias "pma" "phpMyAdmin"
  171. else
  172. echo "[ * ] Updating phpMyAdmin configuration..."
  173. $HESTIA/bin/v-change-sys-db-alias "pma" "$DB_PMA_ALIAS"
  174. fi
  175. fi
  176. if [ -e "/var/lib/phppgadmin" ]; then
  177. PGA_ALIAS_CHECK=$(cat $HESTIA/conf/hestia.conf | grep DB_PGA_ALIAS)
  178. if [ -z "$PGA_ALIAS_CHECK" ]; then
  179. echo "[ * ] Updating phpPgAdmin alias..."
  180. $HESTIA/bin/v-change-sys-db-alias "pga" "phpPgAdmin"
  181. else
  182. echo "[ * ] Updating phpPgAdmin configuration..."
  183. $HESTIA/bin/v-change-sys-db-alias "pga" "$DB_PGA_ALIAS"
  184. fi
  185. fi
  186. # Ensure that backup compression level is correctly set
  187. GZIP_LVL_CHECK=$(cat $HESTIA/conf/hestia.conf | grep BACKUP_GZIP)
  188. if [ -z "$GZIP_LVL_CHECK" ]; then
  189. echo "[ * ] Updating backup compression level variable..."
  190. $BIN/v-change-sys-config-value "BACKUP_GZIP" '9'
  191. fi