File: postinst

package info (click to toggle)
moodle 1.6.3-2%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 37,172 kB
  • ctags: 51,688
  • sloc: php: 231,916; sql: 5,631; xml: 2,688; sh: 1,185; perl: 638; makefile: 48; pascal: 36
file content (234 lines) | stat: -rw-r--r-- 5,831 bytes parent folder | download | duplicates (2)
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
232
233
234
#! /bin/sh -e
# postinst script for moodle 
#
# see: dh_installdeb(1)
#
# 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 http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
#
# quoting from the policy:
#     Any necessary prompting should almost always be confined to the
#     post-installation script, and should be protected with a conditional
#     so that unnecessary prompting doesn't happen if a package's
#     installation fails and the `postinst' is called with `abort-upgrade',
#     `abort-remove' or `abort-deconfigure'.

get_config() {
    db_get moodle/webserver
    webserver="$RET"

    db_get moodle/db_server
    db_server="$RET"

    db_get moodle/db_host
    db_host="$RET"

    case $db_server in
	"postgresql")
	    db_type="postgres7"
	    db_port=5432 ;;

	"mysql-server")
	    db_type="mysql"
	    db_port=3306 ;;
    esac

    db_get moodle/dba_name
    dba_name="$RET"

    db_get moodle/dba_password
    dba_password="$RET"

    db_get moodle/dbu_name
    dbu_name="$RET"

    db_get moodle/dbu_password
    dbu_password="$RET"
}

handle_config() {
	 if [ "$webserver" = "apache-ssl" ]
	 then
		 protocol="https"
	 else
	    protocol="http"
	 fi

    cfile=/etc/moodle/config.php
    tempcfile=`tempfile`
    cat > $tempcfile <<EOF
<?
 # This file has been generated by debconf
 # You can find a commented config file in /usr/share/doc/moodle/

 unset(\$CFG);

 \$CFG->dbtype = '${db_type}';
 \$CFG->dbhost = '${db_host}';
 \$CFG->dbname = 'moodle';
 \$CFG->dbuser = '${dbu_name}';
 \$CFG->dbpass = '${dbu_password}';
 \$CFG->prefix = 'mdl_';

 \$CFG->dbpersist = "false";

 \$CFG->wwwroot = '${protocol}://localhost/moodle';
 \$CFG->dirroot = '/usr/share/moodle';
 \$CFG->dataroot = '/var/lib/moodle';
 \$CFG->directorypermissions = 0750;
 \$CFG->admin = 'admin';

 \$CFG->respectsessionsettings = 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 "<p>Could not find this file: \$CFG->dirroot/lib/setup.php</p>";
			echo "<p>Are you sure all your files have been uploaded?</p>";
		} else {
			echo "<p>Error detected in config.php</p>";
			echo "<p>Error in: \\\$CFG->dirroot = '\$CFG->dirroot';</p>";
			echo "<p>Try this: \\\$CFG->dirroot = '".dirname(__FILE__)."';</p>";
		}
		die;
	}
?>
EOF
    ucf $tempcfile $cfile
    chmod 640 $cfile
    chown www-data:www-data $cfile
}

db_not_installed() {
    echo "Please install the chosen Moodle SGBD: $db_server, then try"
    echo "dpkg-reconfigure moodle"
}

case "$1" in
    configure)
	. /usr/share/debconf/confmodule
	db_version 2.0

	# care about config files
	moodledir=/usr/share/moodle
	
	# Read debconf and edit the config file accordingly
	get_config
	db_stop
	exec 0<&1
	handle_config

	if [ -r /etc/moodle/config.php ]; then
	      [ -f $moodledir/config.php ] && rm $moodledir/config.php
	      ln -s /etc/moodle/config.php $moodledir/config.php
	fi

	# Care about the repository
	repository=/var/lib/moodle
	if [ -d $repository ]; then
	    # set the owner and change rights accordingly
	    chown -R www-data:www-data $repository
	    chmod 0755 $repository
	fi

	# Add the Apache configuration file to Apache conf.d directory
	if [ ! -e /etc/${webserver}/conf.d/moodle ]
	then
	   if [ -d /etc/${webserver}/conf.d/ ]
	   then
	      ln -s /etc/moodle/apache.conf /etc/${webserver}/conf.d/moodle
	   else
		  echo "---------------------------------------------------------"
		  echo "The selected web server doesn't seem to be installed"
		  echo "You should select a web server which is installed or"
		  echo "configure your web server manually"
		  echo "---------------------------------------------------------"

	   fi
	fi
	server=${webserver}
	servers="apache apache-ssl apache-perl apache2"
	# if [ "$status" = "uncomment" -o "$status" = "include" ]; then
	    restart=" ${server} ${restart}"
	# fi
	. /usr/share/wwwconfig-common/restart.sh

	# care about the database creation

	dbname=moodle
	dbserver=$db_host
	dbadmin=$dba_name
	dbadmpass=$dba_password
	dbuser=$dbu_name
	dbpass=$dbu_password

	case $db_server in
	    "postgresql")
			. /usr/share/wwwconfig-common/pgsql-createuser.sh
			if [ "$status" = "error" ]
			then
				err=1
				echo $error
			fi
			. /usr/share/wwwconfig-common/pgsql-createdb.sh
			if [ "$status" = "error" ]
			then
				err=1
				echo $error
			fi
		;;

	    "mysql-server")
			. /usr/share/wwwconfig-common/mysql-createuser.sh
			if [ "$status" = "error" ]
			then
				err=1
				echo $error
			fi
			. /usr/share/wwwconfig-common/mysql-createdb.sh
			if [ "$status" = "error" ]
			then
				err=1
				echo $error
			fi
		;;
	esac
	if [ "$err" = "1" ]
	then
		echo "---------------------------------------------------------"
		echo "I've tried my best to create the moodle user and database"
		echo "but an error has occurred"
		echo "---------------------------------------------------------"
		echo "You will have to set up the moodle user and database yourself"
		echo "---------------------------------------------------------"
	fi

    ;;

    abort-upgrade|abort-remove|abort-deconfigure)

    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0