dolibarr.postinst 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. #!/bin/sh
  2. # postinst script for dolibarr
  3. set -e
  4. # summary of how this script can be called:
  5. # * <postinst> `configure' <most-recently-configured-version>
  6. # * <old-postinst> `abort-upgrade' <new version>
  7. # * <conflictor's-postinst> `abort-remove' `in-favour' <package>
  8. # <new-version>
  9. # * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
  10. # <failed-install-package> <version> `removing'
  11. # <conflicting-package> <version>
  12. # for details, see /usr/share/doc/packaging-manual/
  13. if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
  14. # Needs to be run outside of functions to have access to parameters
  15. . /usr/share/apache2/apache2-maintscript-helper
  16. fi
  17. setup_empty_conf() {
  18. echo Create empty file $config
  19. mkdir -p /etc/dolibarr
  20. touch /etc/dolibarr/conf.php
  21. chown root:www-data /etc/dolibarr/conf.php
  22. chmod 660 /etc/dolibarr/conf.php
  23. }
  24. is_new_upstream_version() {
  25. # $1 can be empty (not installed) and will result in a true value
  26. # for the check
  27. old_version=$(echo "$1" | sed -e 's/-[^-]*$//' -e 's/^[0-9]*://')
  28. new_version=$(dpkg-query -f '${Version}' -W dolibarr | \
  29. sed -e 's/-[^-]*$//' -e 's/^[0-9]*://')
  30. test "$old_version" != "$new_version"
  31. }
  32. enable_install_upgrade_wizard() {
  33. echo Enable install wizard by removing install.lock file if present
  34. rm -f /var/lib/dolibarr/documents/install.lock
  35. }
  36. php_install() {
  37. if which php5enmod >/dev/null 2>&1 ;then
  38. # php5endmod exists for ubuntu only
  39. echo "Enable php module mysqli with php5enmod"
  40. php5enmod mysqli
  41. fi
  42. }
  43. apache_install() {
  44. webserver=$1
  45. # Enable Apache 2 alias module
  46. if which a2enmod >/dev/null 2>&1 ;then
  47. echo "Enable apache module alias with a2enmod"
  48. a2enmod alias
  49. fi
  50. # Enable dolibarr conf
  51. if which a2enconf >/dev/null 2>&1 ;then
  52. # a2enconf exists for ubuntu only
  53. echo "Enable link for Apache config file with a2enconf"
  54. a2enconf dolibarr
  55. else
  56. if [ -d /etc/$webserver/conf.d ] && [ ! -e /etc/$webserver/conf.d/dolibarr.conf ]; then
  57. echo "Add link for Apache config file"
  58. ln -s /etc/$webserver/conf-available/dolibarr.conf /etc/$webserver/conf.d/dolibarr.conf
  59. fi
  60. fi
  61. }
  62. lighttpd_install() {
  63. if which lighty-enable-mod >/dev/null 2>&1 ; then
  64. echo "Enable lighttpd link for dolibarr config file"
  65. lighty-enable-mod dolibarr fastcgi-php
  66. else
  67. echo "Lighttpd not installed, skipping"
  68. fi
  69. }
  70. . /usr/share/debconf/confmodule
  71. db_version 2.0
  72. echo Run the dolibarr postinst script
  73. # Define vars
  74. docdir='/var/lib/dolibarr/documents'
  75. installfileorig="/etc/dolibarr/install.forced.php.install"
  76. installconfig="/etc/dolibarr/install.forced.php"
  77. config="/etc/dolibarr/conf.php"
  78. case "$1" in
  79. configure)
  80. if [ -z "$2" ]; then
  81. echo First install
  82. #setup_empty_conf
  83. else
  84. echo This is not a first install
  85. fi
  86. php_install
  87. apache_install
  88. lighttpd_install
  89. # Remove lock file
  90. if is_new_upstream_version "$2"; then
  91. enable_install_upgrade_wizard
  92. fi
  93. # Create document directory for uploaded data files
  94. mkdir -p $docdir
  95. chown -R www-data:www-data $docdir
  96. chmod -R 775 $docdir
  97. chmod -R g+s $docdir
  98. # Copy install config file (with matching Debian values) into target directory
  99. superuserlogin=''
  100. superuserpassword=''
  101. if [ -f /etc/mysql/debian.cnf ] ; then
  102. # Load superuser login and pass
  103. superuserlogin=$(grep --max-count=1 "user" /etc/mysql/debian.cnf | sed -e 's/^user[ =]*//g')
  104. superuserpassword=$(grep --max-count=1 "password" /etc/mysql/debian.cnf | sed -e 's/^password[ =]*//g')
  105. fi
  106. echo Mysql superuser found to use is $superuserlogin
  107. if [ -z "$superuserlogin" ] ; then
  108. cat $installfileorig | sed -e 's/__SUPERUSERLOGIN__/root/g' | sed -e 's/__SUPERUSERPASSWORD__//g' > $installconfig
  109. else
  110. cat $installfileorig | sed -e 's/__SUPERUSERLOGIN__/'$superuserlogin'/g' | sed -e 's/__SUPERUSERPASSWORD__/'$superuserpassword'/g' > $installconfig
  111. fi
  112. chown -R root:www-data $installconfig
  113. chmod -R 660 $installconfig
  114. # If a conf already exists and its content was already completed by installer
  115. if [ ! -s $config ] || ! grep -q "File generated by" $config
  116. then
  117. # Create an empty conf.php with permission to web server
  118. setup_empty_conf
  119. #else
  120. # File already exist. We add params not found.
  121. #echo Add new params to overwrite path to use shared libraries/fonts
  122. ##grep -q -c "dolibarr_lib_GEOIP_PATH" $config || echo "<?php \$dolibarr_lib_GEOIP_PATH=''; ?>" >> $config
  123. #grep -q -c "dolibarr_lib_NUSOAP_PATH" $config || [ ! -d "/usr/share/php/nusoap" ] || echo "<?php \$dolibarr_lib_NUSOAP_PATH='/usr/share/php/nusoap'; ?>" >> $config
  124. #grep -q -c "dolibarr_lib_ODTPHP_PATHTOPCLZIP" $config || [ ! -d "/usr/share/php/libphp-pclzip" ] || echo "<?php \$dolibarr_lib_ODTPHP_PATHTOPCLZIP='/usr/share/php/libphp-pclzip'; ?>" >> $config
  125. ##grep -q -c "dolibarr_lib_TCPDF_PATH" $config || echo "<?php \$dolibarr_lib_TCPDF_PATH=''; ?>" >> $config
  126. #grep -q -c "dolibarr_js_CKEDITOR" $config || [ ! -d "/usr/share/javascript/ckeditor" ] || echo "<?php \$dolibarr_js_CKEDITOR='/javascript/ckeditor'; ?>" >> $config
  127. #grep -q -c "dolibarr_js_JQUERY" $config || [ ! -d "/usr/share/javascript/jquery" ] || echo "<?php \$dolibarr_js_JQUERY='/javascript/jquery'; ?>" >> $config
  128. #grep -q -c "dolibarr_js_JQUERY_UI" $config || [ ! -d "/usr/share/javascript/jquery-ui" ] || echo "<?php \$dolibarr_js_JQUERY_UI='/javascript/jquery-ui'; ?>" >> $config
  129. #grep -q -c "dolibarr_js_JQUERY_FLOT" $config || [ ! -d "/usr/share/javascript/flot" ] || echo "<?php \$dolibarr_js_JQUERY_FLOT='/javascript/flot'; ?>" >> $config
  130. #grep -q -c "dolibarr_font_DOL_DEFAULT_TTF_BOLD" $config || echo "<?php \$dolibarr_font_DOL_DEFAULT_TTF_BOLD='/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf'; ?>" >> $config
  131. fi
  132. db_get dolibarr/reconfigure-webserver
  133. webservers="$RET"
  134. # Set up web server.
  135. for webserver in $webservers ; do
  136. webserver=${webserver%,}
  137. echo Complete config of server $webserver
  138. # Detect webuser and webgroup
  139. webuser=
  140. webgroup=
  141. if [ -z "$webuser" ] ; then
  142. webuser=www-data
  143. fi
  144. if [ -z "$webgroup" ] ; then
  145. webgroup=www-data
  146. fi
  147. echo Web user.group used is $webuser.$webgroup
  148. # Set permissions to web server
  149. chown -R $webuser:$webgroup /usr/share/dolibarr
  150. chown -R root:$webgroup $config
  151. done
  152. # Restart web server.
  153. for webserver in $webservers; do
  154. webserver=${webserver%,}
  155. if [ "$webserver" = "lighttpd" ] ; then
  156. lighttpd_install
  157. else
  158. apache_install $webserver
  159. fi
  160. # Reload webserver in any case, configuration might have changed
  161. # Redirection of 3 is needed because Debconf uses it and it might
  162. # be inherited by webserver. See bug #446324.
  163. if [ -f /etc/init.d/$webserver ] ; then
  164. if [ -x /usr/sbin/invoke-rc.d ]; then
  165. echo Restart web server $server using invoke-rc.d
  166. # This works with Debian (5.05,...) and Ubuntu (9.10,10.04,...)
  167. invoke-rc.d $webserver reload 3>/dev/null || true
  168. else
  169. echo Restart web server $server using $server reload
  170. /etc/init.d/$webserver reload 3>/dev/null || true
  171. fi
  172. fi
  173. done
  174. echo ----------
  175. echo "Call Dolibarr page http://localhost/dolibarr/ to complete the setup and use Dolibarr."
  176. echo ----------
  177. ;;
  178. abort-upgrade|abort-remove|abort-deconfigure)
  179. ;;
  180. *)
  181. echo "postinst called with unknown argument $1" >&2
  182. exit 0
  183. ;;
  184. esac
  185. #DEBHELPER#
  186. db_stop
  187. exit 0