source: moodle/trunk/fuentes/debian/postinst @ 1331

Last change on this file since 1331 was 1331, checked in by jrpelegrina, 4 years ago

Updated to moodle 3.0.3

File size: 6.3 KB
Line 
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
18set -e
19#set -x
20
21if [ -f /etc/dbconfig-common/moodle.conf ] ; then
22        . /etc/dbconfig-common/moodle.conf
23fi
24
25# source debconf stuff
26. /usr/share/debconf/confmodule
27# source dbconfig-common stuff
28. /usr/share/dbconfig-common/dpkg/postinst
29
30check_php5mysql_notinstalled() {
31    dpkg -s php5-mysql | grep Status | grep -q installed >/dev/null 2>&1 && return 1
32    return 0
33}
34
35check_php5psql_notinstalled() {
36    dpkg -s php5-pgsql | grep Status | grep -q installed >/dev/null 2>&1 && return 1
37    return 0
38}
39
40moodle_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 global \$CFG;
60 \$CFG = new stdClass();
61
62 \$CFG->dbtype = '${dbc_dbtype}';
63 \$CFG->dbhost = '${dbc_dbserver}';
64 \$CFG->dbname = '${dbc_dbname}';
65 \$CFG->dbuser = '${dbc_dbuser}';
66 \$CFG->dbpass = '${dbc_dbpass}';
67 \$CFG->prefix = 'mdl_';
68
69 \$CFG->wwwroot = '${wwwroot}';
70 \$CFG->dirroot = '/usr/share/moodle';
71 \$CFG->dataroot = '/var/lib/moodle';
72 \$CFG->directorypermissions = 0750;
73 \$CFG->admin = 'admin';
74
75 \$CFG->pathtodu = '/usr/bin/du';
76 \$CFG->unzip = '/usr/bin/unzip';
77 \$CFG->zip = '/usr/bin/zip';
78
79 \$CFG->respectsessionsettings = true;
80
81 \$CFG->disableupdatenotifications = true;
82
83 # For improved security, make sure html purifier is used.
84 \$CFG->enablehtmlpurifier = true;
85
86        if (file_exists("\$CFG->dirroot/lib/setup.php"))  {       // Do not edit
87                include_once("\$CFG->dirroot/lib/setup.php");
88        } else {
89                if (\$CFG->dirroot == dirname(__FILE__)) {
90                        echo "<p>Could not find this file: \$CFG->dirroot/lib/setup.php</p>";
91                        echo "<p>Are you sure all your files have been uploaded?</p>";
92                } else {
93                        echo "<p>Error detected in config.php</p>";
94                        echo "<p>Error in: \\\$CFG->dirroot = '\$CFG->dirroot';</p>";
95                        echo "<p>Try this: \\\$CFG->dirroot = '".dirname(__FILE__)."';</p>";
96                }
97                die;
98        }
99EOF
100    ucf --debconf-ok $tempfile $cfile
101    chmod 640 $cfile
102    chown root:www-data $cfile
103}
104
105apache_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 session.auto_start Off
118        php_flag session.bug_compat_warn Off
119
120        php_value upload_max_filesize 2M
121        php_value post_max_size 2M
122</IfModule>"
123       
124        db_get moodle/www
125        wwwroot="$RET"
126       
127        #check if it's possible to do the alias
128        tmp=`echo $wwwroot | sed 's#^https*://[^/]*/*##'`
129
130        if [ -n "$tmp" ]; then
131                tmp_alias="#Uncomment the line below if you want to use alias
132#This will not work well with virtual hosts
133Alias /${tmp} /usr/share/moodle/"
134        else
135                tmp_alias="#You can't use alias because your Moodle is not in a sub-directory
136#Create appropriate virtual host insted."
137        fi
138
139        cat > $tempfile <<EOF
140# This file has been generated by debconf
141
142${tmp_alias}
143
144<Directory /usr/share/moodle/>
145
146Options +FollowSymLinks
147AllowOverride None
148
149order deny,allow
150deny from all
151
152allow from 127.0.0.0/8
153allow from localhost
154#comment out the line below to allow remote access
155#allow from all
156
157${php_settings}
158
159<IfModule mod_dir.c>
160        DirectoryIndex index.php
161</IfModule>
162
163</Directory>
164EOF
165    ucf --debconf-ok $tempfile $cfile
166    chmod 640 $cfile
167    chown root:www-data $cfile
168
169    #Sample config for the virtual host
170    tempfile=`tempfile`
171    cfile="/etc/moodle/apache.vhost.conf"
172    server=`echo $wwwroot |cut -d'/' -f3`
173    cat > $tempfile <<EOF
174<VirtualHost *:80>
175        ServerAdmin webmaster@${server}
176        ServerName ${server}
177        DocumentRoot /usr/share/moodle/
178        <Directory /usr/share/moodle/>
179                Options FollowSymLinks MultiViews
180                AllowOverride None
181                Order allow,deny
182                allow from all
183${php_settings}
184        </Directory>
185
186        ErrorLog \${APACHE_LOG_DIR}/error.log
187
188        # Possible values include: debug, info, notice, warn, error, crit,
189        # alert, emerg.
190        LogLevel warn
191
192        CustomLog \${APACHE_LOG_DIR}/access.log combined
193</VirtualHost>
194EOF
195
196    ucf --debconf-ok $tempfile $cfile
197    chmod 640 $cfile
198    chown root:www-data $cfile
199}
200
201dbc_mysql_createdb_encoding="UTF8"
202dbc_pgsql_createdb_encoding="UTF8"
203dbc_first_version="1.9.8-1"
204dbc_go moodle $@
205
206case "$1" in
207    configure)
208        moodle_config
209        apache_config
210        cfile=/etc/moodle/config.php
211        moodledir=/usr/share/moodle
212
213        [ -f $moodledir/config.php ] && rm $moodledir/config.php
214        ln -s $cfile $moodledir/config.php
215
216        if [ "$dbc_dbtype" = "mysql" ] && check_php5mysql_notinstalled ; then
217                echo 'Error - You have specified that you wish to use a mysql' >&2
218                echo 'database, but php5-mysql is not installed. You must install' >&2
219                echo 'php5-mysql before you can complete your moodle installation.' >&2
220        fi
221
222        if [ "$dbc_dbtype" = "postgresql" ] && check_php5psql_notinstalled ; then
223                echo 'Error - You have specified that you wish to use a postgresql' >&2
224                echo 'database, but php5-pgsql is not installed. You must install' >&2
225                echo 'php5-pgsql before you can complete your moodle installation.' >&2
226        fi
227    ;;
228
229    abort-upgrade|abort-remove|abort-deconfigure)
230    ;;
231
232    *)
233        echo "postinst called with unknown argument \`$1'" >&2
234        exit 1
235    ;;
236esac
237
238
239#DEBHELPER#
240
241exit 0
Note: See TracBrowser for help on using the repository browser.