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