#!/bin/sh # postinst script for moodle # # see: dh_installdeb(1) # # summary of how this script can be called: # * `configure' # * `abort-upgrade' # * `abort-remove' `in-favour' # # * `abort-remove' # * `abort-deconfigure' `in-favour' # `removing' # # for details, see http://www.debian.org/doc/debian-policy/ or # the debian-policy package set -e #set -x if [ -f /etc/dbconfig-common/moodle.conf ] ; then . /etc/dbconfig-common/moodle.conf fi # source debconf stuff . /usr/share/debconf/confmodule # source dbconfig-common stuff . /usr/share/dbconfig-common/dpkg/postinst check_php5mysql_notinstalled() { dpkg -s php5-mysql | grep Status | grep -q installed >/dev/null 2>&1 && return 1 return 0 } check_php5psql_notinstalled() { dpkg -s php5-pgsql | grep Status | grep -q installed >/dev/null 2>&1 && return 1 return 0 } moodle_config() { local cfile=/etc/moodle/config.php local tempfile=`tempfile` local wwwroot db_get moodle/www wwwroot="$RET" if [ -z "$dbc_dbserver" ]; then dbc_dbserver="localhost"; fi if [ "$dbc_dbtype" = "pgsql" ]; then dbc_dbtype="postgres7" fi cat > $tempfile <dbtype = '${dbc_dbtype}'; \$CFG->dbhost = '${dbc_dbserver}'; \$CFG->dbname = '${dbc_dbname}'; \$CFG->dbuser = '${dbc_dbuser}'; \$CFG->dbpass = '${dbc_dbpass}'; \$CFG->prefix = 'mdl_'; \$CFG->wwwroot = '${wwwroot}'; \$CFG->dirroot = '/usr/share/moodle'; \$CFG->dataroot = '/var/lib/moodle'; \$CFG->directorypermissions = 0750; \$CFG->admin = 'admin'; \$CFG->pathtodu = '/usr/bin/du'; \$CFG->unzip = '/usr/bin/unzip'; \$CFG->zip = '/usr/bin/zip'; \$CFG->respectsessionsettings = true; # For improved security, make sure html purifier is used. \$CFG->enablehtmlpurifier = true; if (file_exists("\$CFG->dirroot/lib/setup.php")) { // Do not edit include_once("\$CFG->dirroot/lib/setup.php"); } else { if (\$CFG->dirroot == dirname(__FILE__)) { echo "

Could not find this file: \$CFG->dirroot/lib/setup.php

"; echo "

Are you sure all your files have been uploaded?

"; } else { echo "

Error detected in config.php

"; echo "

Error in: \\\$CFG->dirroot = '\$CFG->dirroot';

"; echo "

Try this: \\\$CFG->dirroot = '".dirname(__FILE__)."';

"; } die; } // MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES, // RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE. ?> EOF ucf --debconf-ok $tempfile $cfile chmod 640 $cfile chown www-data:www-data $cfile } apache_config() { local wwwroot local alias local tmp local tempfile=`tempfile` local cfile="/etc/moodle/apache.conf" local php_settings php_settings=" php_flag magic_quotes_gpc Off php_flag magic_quotes_runtime Off php_flag file_uploads On php_flag short_open_tag On php_flag session.auto_start Off php_flag session.bug_compat_warn Off php_value upload_max_filesize 2M php_value post_max_size 2M " db_get moodle/www wwwroot="$RET" #check if it's possible to do the alias tmp=`echo $wwwroot | sed 's#^https*://[^/]*/*##'` if [ -n "$tmp" ]; then tmp_alias="#Uncomment the line below if you want to use alias #This will not work well with virtual hosts Alias /${tmp} /usr/share/moodle/" else tmp_alias="#You can't use alias becuse you Moodls is not in a sub-directory #Create appropriate virtual host insted." fi cat > $tempfile < Options +FollowSymLinks AllowOverride None order deny,allow deny from all allow from 127.0.0.0/255.0.0.0 allow from localhost #comment out the line below to allow remote access #allow from all ${php_settings} DirectoryIndex index.php EOF ucf --debconf-ok $tempfile $cfile chmod 640 $cfile chown www-data:www-data $cfile #Sample config for the virtual host tempfile=`tempfile` cfile="/etc/moodle/apache.vhost.conf" server=`echo $wwwroot |cut -d'/' -f3` cat > $tempfile < ServerAdmin webmaster@${server} ServerName ${server} DocumentRoot /usr/share/moodle/ Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all ${php_settings} ErrorLog \${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog \${APACHE_LOG_DIR}/access.log combined EOF ucf --debconf-ok $tempfile $cfile chmod 640 $cfile chown www-data:www-data $cfile } dbc_mysql_createdb_encoding="UTF8" dbc_pgsql_createdb_encoding="UTF8" dbc_first_version="1.9.8-1" dbc_go moodle $@ #wwwroot="http://localhost/moodle" case "$1" in configure) # tempcfile=`tempfile` moodle_config apache_config # ucf --debconf-ok $tempfile $cfile # chmod 640 $cfile # chown www-data:www-data $cfile cfile=/etc/moodle/config.php moodledir=/usr/share/moodle # if [ -r /etc/moodle/config.php ]; then [ -f $moodledir/config.php ] && rm $moodledir/config.php ln -s $cfile $moodledir/config.php # fi # Make sure the link is correct (#603255) rm -rf /usr/share/moodle/lib/yui/2.9.0/build ln -s /usr/share/javascript/yui /usr/share/moodle/lib/yui/2.9.0/build repository=/var/lib/moodle if [ -d $repository ]; then chown -R www-data:www-data $repository chmod 0750 $repository fi if [ "$dbc_dbtype" = "mysql" ] && check_php5mysql_notinstalled ; then echo 'Error - You have specified that you wish to use a mysql' >&2 echo 'database, but php5-mysql is not installed. You must install' >&2 echo 'php5-mysql before you can complete your moodle installation.' >&2 fi if [ "$dbc_dbtype" = "postgresql" ] && check_php5psql_notinstalled ; then echo 'Error - You have specified that you wish to use a postgresql' >&2 echo 'database, but php5-pgsql is not installed. You must install' >&2 echo 'php5-pgsql before you can complete your moodle installation.' >&2 fi ;; abort-upgrade|abort-remove|abort-deconfigure) ;; *) echo "postinst called with unknown argument \`$1'" >&2 exit 1 ;; esac #DEBHELPER# exit 0