1 | #!/bin/sh |
---|
2 | # postinst script for moodle |
---|
3 | # |
---|
4 | # see: dh_installdeb(1) |
---|
5 | # |
---|
6 | # summary of how this script can be called: |
---|
7 | # * <postinst> `configure' <most-recently-configured-version> |
---|
8 | # * <old-postinst> `abort-upgrade' <new version> |
---|
9 | # * <conflictor's-postinst> `abort-remove' `in-favour' <package> |
---|
10 | # <new-version> |
---|
11 | # * <postinst> `abort-remove' |
---|
12 | # * <deconfigured's-postinst> `abort-deconfigure' `in-favour' |
---|
13 | # <failed-install-package> <version> `removing' |
---|
14 | # <conflicting-package> <version> |
---|
15 | # for details, see http://www.debian.org/doc/debian-policy/ or |
---|
16 | # the debian-policy package |
---|
17 | |
---|
18 | set -e |
---|
19 | #set -x |
---|
20 | |
---|
21 | if [ -f /etc/dbconfig-common/moodle.conf ] ; then |
---|
22 | . /etc/dbconfig-common/moodle.conf |
---|
23 | fi |
---|
24 | |
---|
25 | # source debconf stuff |
---|
26 | . /usr/share/debconf/confmodule |
---|
27 | # source dbconfig-common stuff |
---|
28 | . /usr/share/dbconfig-common/dpkg/postinst |
---|
29 | |
---|
30 | check_php5mysql_notinstalled() { |
---|
31 | dpkg -s php7.0-lliurex-mysql | grep Status | grep -q installed >/dev/null 2>&1 && return 1 |
---|
32 | return 0 |
---|
33 | } |
---|
34 | |
---|
35 | check_php5psql_notinstalled() { |
---|
36 | dpkg -s php7.0-lliurex-pgsql | grep Status | grep -q installed >/dev/null 2>&1 && return 1 |
---|
37 | return 0 |
---|
38 | } |
---|
39 | |
---|
40 | moodle_config() { |
---|
41 | local cfile=/etc/moodle/config.php |
---|
42 | local tempfile=`tempfile` |
---|
43 | local wwwroot |
---|
44 | |
---|
45 | db_get moodle/www |
---|
46 | wwwroot="$RET" |
---|
47 | if [ -z "$dbc_dbserver" ]; then |
---|
48 | dbc_dbserver="localhost"; |
---|
49 | fi |
---|
50 | if [ "$dbc_dbtype" = "pgsql" ]; then |
---|
51 | dbc_dbtype="postgres7" |
---|
52 | fi |
---|
53 | cat > $tempfile <<EOF |
---|
54 | <?php |
---|
55 | # This file has been generated by debconf |
---|
56 | # You can find a commented config file in /usr/share/doc/moodle/ |
---|
57 | |
---|
58 | unset(\$CFG); |
---|
59 | \$CFG = new stdClass(); |
---|
60 | |
---|
61 | \$CFG->dbtype = '${dbc_dbtype}'; |
---|
62 | \$CFG->dbhost = '${dbc_dbserver}'; |
---|
63 | \$CFG->dbname = '${dbc_dbname}'; |
---|
64 | \$CFG->dbuser = '${dbc_dbuser}'; |
---|
65 | \$CFG->dbpass = '${dbc_dbpass}'; |
---|
66 | \$CFG->prefix = 'mdl_'; |
---|
67 | |
---|
68 | \$CFG->wwwroot = '${wwwroot}'; |
---|
69 | \$CFG->dirroot = '/usr/share/moodle'; |
---|
70 | \$CFG->dataroot = '/var/lib/moodle'; |
---|
71 | \$CFG->directorypermissions = 0750; |
---|
72 | \$CFG->admin = 'admin'; |
---|
73 | |
---|
74 | \$CFG->pathtodu = '/usr/bin/du'; |
---|
75 | \$CFG->unzip = '/usr/bin/unzip'; |
---|
76 | \$CFG->zip = '/usr/bin/zip'; |
---|
77 | |
---|
78 | \$CFG->respectsessionsettings = true; |
---|
79 | |
---|
80 | # For improved security, make sure html purifier is used. |
---|
81 | \$CFG->enablehtmlpurifier = true; |
---|
82 | |
---|
83 | if (file_exists("\$CFG->dirroot/lib/setup.php")) { // Do not edit |
---|
84 | include_once("\$CFG->dirroot/lib/setup.php"); |
---|
85 | } else { |
---|
86 | if (\$CFG->dirroot == dirname(__FILE__)) { |
---|
87 | echo "<p>Could not find this file: \$CFG->dirroot/lib/setup.php</p>"; |
---|
88 | echo "<p>Are you sure all your files have been uploaded?</p>"; |
---|
89 | } else { |
---|
90 | echo "<p>Error detected in config.php</p>"; |
---|
91 | echo "<p>Error in: \\\$CFG->dirroot = '\$CFG->dirroot';</p>"; |
---|
92 | echo "<p>Try this: \\\$CFG->dirroot = '".dirname(__FILE__)."';</p>"; |
---|
93 | } |
---|
94 | die; |
---|
95 | } |
---|
96 | // MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES, |
---|
97 | // RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE. |
---|
98 | ?> |
---|
99 | EOF |
---|
100 | ucf --debconf-ok $tempfile $cfile |
---|
101 | chmod 640 $cfile |
---|
102 | chown www-data:www-data $cfile |
---|
103 | } |
---|
104 | |
---|
105 | apache_config() { |
---|
106 | local wwwroot |
---|
107 | local alias |
---|
108 | local tmp |
---|
109 | local tempfile=`tempfile` |
---|
110 | local cfile="/etc/moodle/apache.conf" |
---|
111 | local php_settings |
---|
112 | |
---|
113 | php_settings="<IfModule mod_php5.c> |
---|
114 | php_flag magic_quotes_gpc Off |
---|
115 | php_flag magic_quotes_runtime Off |
---|
116 | php_flag file_uploads On |
---|
117 | php_flag short_open_tag On |
---|
118 | php_flag session.auto_start Off |
---|
119 | php_flag session.bug_compat_warn Off |
---|
120 | |
---|
121 | php_value upload_max_filesize 2M |
---|
122 | php_value post_max_size 2M |
---|
123 | </IfModule>" |
---|
124 | |
---|
125 | db_get moodle/www |
---|
126 | wwwroot="$RET" |
---|
127 | |
---|
128 | #check if it's possible to do the alias |
---|
129 | tmp=`echo $wwwroot | sed 's#^https*://[^/]*/*##'` |
---|
130 | |
---|
131 | if [ -n "$tmp" ]; then |
---|
132 | tmp_alias="#Uncomment the line below if you want to use alias |
---|
133 | #This will not work well with virtual hosts |
---|
134 | Alias /${tmp} /usr/share/moodle/" |
---|
135 | else |
---|
136 | tmp_alias="#You can't use alias becuse you Moodls is not in a sub-directory |
---|
137 | #Create appropriate virtual host insted." |
---|
138 | fi |
---|
139 | |
---|
140 | cat > $tempfile <<EOF |
---|
141 | # This file has been generated by debconf |
---|
142 | |
---|
143 | ${tmp_alias} |
---|
144 | |
---|
145 | <DirectoryMatch /usr/share/moodle/> |
---|
146 | |
---|
147 | Options +FollowSymLinks |
---|
148 | AllowOverride None |
---|
149 | |
---|
150 | order deny,allow |
---|
151 | deny from all |
---|
152 | |
---|
153 | allow from 127.0.0.0/255.0.0.0 |
---|
154 | allow from localhost |
---|
155 | #comment out the line below to allow remote access |
---|
156 | #allow from all |
---|
157 | |
---|
158 | ${php_settings} |
---|
159 | |
---|
160 | <IfModule mod_dir.c> |
---|
161 | DirectoryIndex index.php |
---|
162 | </IfModule> |
---|
163 | |
---|
164 | </DirectoryMatch> |
---|
165 | EOF |
---|
166 | ucf --debconf-ok $tempfile $cfile |
---|
167 | chmod 640 $cfile |
---|
168 | chown www-data:www-data $cfile |
---|
169 | |
---|
170 | |
---|
171 | #Sample config for the virtual host |
---|
172 | tempfile=`tempfile` |
---|
173 | cfile="/etc/moodle/apache.vhost.conf" |
---|
174 | server=`echo $wwwroot |cut -d'/' -f3` |
---|
175 | cat > $tempfile <<EOF |
---|
176 | <VirtualHost *:80> |
---|
177 | ServerAdmin webmaster@${server} |
---|
178 | ServerName ${server} |
---|
179 | DocumentRoot /usr/share/moodle/ |
---|
180 | AddDefaultCharset utf-8 |
---|
181 | <Directory /usr/share/moodle/> |
---|
182 | Options Indexes FollowSymLinks MultiViews |
---|
183 | AllowOverride None |
---|
184 | Order allow,deny |
---|
185 | allow from all |
---|
186 | ${php_settings} |
---|
187 | </Directory> |
---|
188 | |
---|
189 | ErrorLog \${APACHE_LOG_DIR}/error.log |
---|
190 | |
---|
191 | # Possible values include: debug, info, notice, warn, error, crit, |
---|
192 | # alert, emerg. |
---|
193 | LogLevel warn |
---|
194 | |
---|
195 | CustomLog \${APACHE_LOG_DIR}/access.log combined |
---|
196 | </VirtualHost> |
---|
197 | EOF |
---|
198 | |
---|
199 | ucf --debconf-ok $tempfile $cfile |
---|
200 | chmod 640 $cfile |
---|
201 | chown www-data:www-data $cfile |
---|
202 | |
---|
203 | } |
---|
204 | |
---|
205 | dbc_mysql_createdb_encoding="UTF8" |
---|
206 | dbc_pgsql_createdb_encoding="UTF8" |
---|
207 | dbc_first_version="1.9.8-1" |
---|
208 | dbc_go moodle $@ |
---|
209 | #wwwroot="http://localhost/moodle" |
---|
210 | |
---|
211 | case "$1" in |
---|
212 | configure) |
---|
213 | # tempcfile=`tempfile` |
---|
214 | moodle_config |
---|
215 | apache_config |
---|
216 | # ucf --debconf-ok $tempfile $cfile |
---|
217 | # chmod 640 $cfile |
---|
218 | # chown www-data:www-data $cfile |
---|
219 | cfile=/etc/moodle/config.php |
---|
220 | moodledir=/usr/share/moodle |
---|
221 | |
---|
222 | # if [ -r /etc/moodle/config.php ]; then |
---|
223 | [ -f $moodledir/config.php ] && rm $moodledir/config.php |
---|
224 | ln -s $cfile $moodledir/config.php |
---|
225 | # fi |
---|
226 | |
---|
227 | repository=/var/lib/moodle |
---|
228 | if [ -d $repository ]; then |
---|
229 | chown -R www-data:www-data $repository |
---|
230 | chmod 0750 $repository |
---|
231 | fi |
---|
232 | |
---|
233 | if [ "$dbc_dbtype" = "mysql" ] && check_php5mysql_notinstalled ; then |
---|
234 | echo 'Error - You have specified that you wish to use a mysql' >&2 |
---|
235 | echo 'database, but php5-mysql is not installed. You must install' >&2 |
---|
236 | echo 'php5-mysql before you can complete your moodle installation.' >&2 |
---|
237 | fi |
---|
238 | |
---|
239 | if [ "$dbc_dbtype" = "postgresql" ] && check_php5psql_notinstalled ; then |
---|
240 | echo 'Error - You have specified that you wish to use a postgresql' >&2 |
---|
241 | echo 'database, but php5-pgsql is not installed. You must install' >&2 |
---|
242 | echo 'php5-pgsql before you can complete your moodle installation.' >&2 |
---|
243 | fi |
---|
244 | ;; |
---|
245 | |
---|
246 | abort-upgrade|abort-remove|abort-deconfigure) |
---|
247 | ;; |
---|
248 | |
---|
249 | *) |
---|
250 | echo "postinst called with unknown argument \`$1'" >&2 |
---|
251 | exit 1 |
---|
252 | ;; |
---|
253 | esac |
---|
254 | |
---|
255 | |
---|
256 | #DEBHELPER# |
---|
257 | |
---|
258 | exit 0 |
---|