File: postinst

package info (click to toggle)
dotlrn 2.5.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 108,252 kB
  • ctags: 19,369
  • sloc: tcl: 219,601; sql: 202,152; xml: 127,658; java: 7,268; php: 4,780; sh: 2,428; perl: 1,207; makefile: 134
file content (205 lines) | stat: -rw-r--r-- 6,187 bytes parent folder | download
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
#! /bin/sh -e
# postinst script for dotlrn 
#
# 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 dotlrn/db_host
    db_host="$RET"

    db_type="postgres7"
    db_port=5432 

    db_get dotlrn/dba_name
    dba_name="$RET"

    db_get dotlrn/dba_password
    dba_password="$RET"

    db_get dotlrn/dbu_name
    dbu_name="$RET"

    db_get dotlrn/dbu_password
    dbu_password="$RET"
 
    db_get dotlrn/pg_grant_access
    if [ ! -z "$RET" ]; then
        grant_access="$RET"
    else
        grant_access="false"
    fi
}

db_not_installed() {
    echo "Please install the chosen dotLRN SGBD: postgresql, then try"
    echo "dpkg-reconfigure dotlrn"
}

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

	# Read debconf and edit the config file accordingly
	get_config
	db_stop
	exec 0<&1
	
	 # Care about the repository
        repository=/var/lib/dotlrn
        if [ -d $repository ]; then
            # set the owner and change rights accordingly
            chown -R www-data:www-data $repository
            chmod 0755 $repository
        fi

	# Care about the log directory
	logdir=/var/log/aolserver4/dotlrn
        if [ -d $logdir ]; then
            # set the owner and change rights accordingly
            chown -R www-data:www-data $logdir
            chmod 0755 $logdir
        fi
	
	# Care about the app dir
        appdir=/usr/share/dotlrn
        if [ -d $appdir ]; then
            # set the owner and change rights accordingly
            chown -R www-data:www-data $appdir
        fi

	# care about the database creation
	dbname=dotlrn
	dbserver=$db_host
	dbadmin=$dba_name
	dbadmpass=$dba_password
	dbuser=$dbu_name
        dbpass=$dbu_password

	# is the database server available? Then create the user.
	. /usr/share/wwwconfig-common/pgsql-createuser.sh > /dev/null
	if [ "$status" = "error" ]
        then
                err=1
		echo "* Error trying to connect to Postgresql server."
		if [ "$db_host" = "localhost" ]
		then
			echo "(TIP: is the postgresql package installed?)"
		fi
        else
		. /usr/share/wwwconfig-common/pgsql-createdb.sh
		if [ "$status" = "error" ]
		then
			err=1
			echo $error
		fi
	
		# Modify the pg_hba.conf to grant dotlrn user access to postgresql
		# 1- Do we want to do that?
		if [ "$grant_access" = true ]; then

			# 2- Where is the pg_hba.conf from this database instance?
			dbuser=$dba_name
                	dbpass=$dba_password
			. /usr/share/wwwconfig-common/pgsql.get
			pg_hba_file=$($pgsqlcmd -c "SELECT * from pg_settings where name='hba_file';" 2>/dev/null | grep hba | cut -d\| -f2)
			pg_version=$(echo "$pg_hba_file" | cut -d\/ -f4)
			if [ "$status" = "error" ]
        	  		then
                		err=1
                		echo $error
	          	else
				# 3- Modify the file
				# Select connection method
				if [ "A$dbu_password" != "A" ]; then 	
					# No Blank Password
					pg_conn_method="md5"
				else
					# Blank Password
					pg_conn_method="trust"
				fi
				# Delete all lines between ## dotLRN ... ## and ########### from previous configurations.
				# Insert connection line after the first local connection line (the postgres user connection line).
				sed -i "/^## dotLRN package debconf changes (DO NOT EDIT BYHAND) ##/,/^##########################################################/d;1,/^local/{
        /^local/a ## dotLRN package debconf changes (DO NOT EDIT BYHAND) ##\nlocal   dotlrn     $dbu_name                        $pg_conn_method\n##########################################################
} " $pg_hba_file
			
				# 4-Reload postgresql conf
				/etc/init.d/postgresql reload
			fi
		fi
		# Modify config.tcl with debconf values
		dbuser=$dbu_name
        	dbpass=$dbu_password	
		sed -i "/^    set db_host/,/^    set db_user/d;s/## Debconf changes (DO NOT EDIT BYHAND) ##/&\n    set db_host               $dbserver\n    set db_password           \"$dbpass\"\n    set db_port               \"5432\"\n    set db_user               $dbuser/" /etc/dotlrn/config.tcl

		# Install plpgsql on database and enable compatibility options
		dbuser=$dba_name
		dbpass=$dba_password
		sqlfile=$(mktemp)
		echo "CREATE LANGUAGE plpgsql;
			ALTER DATABASE dotlrn SET add_missing_from = on;
			ALTER DATABASE dotlrn SET default_with_oids = on;
			ALTER DATABASE dotlrn SET regex_flavor = extended;
			" > $sqlfile
        	. /usr/share/wwwconfig-common/pgsql-exec.sh
		rm -f $sqlfile

		# Restart aolserver
		invoke-rc.d aolserver4 restart

	        if [ "$status" = "error" ]
        	then
                	err=1
	                echo $error
        	fi

		if [ "$err" = "1" ]
		then
			echo "-------------------------------------------------------------"
			echo "I've tried my best to create the dotLRN user and database"
			echo "but an error has occurred"
			echo "-------------------------------------------------------------"
			echo "You will have to set up the dotLRN user and database yourself"
			echo "-------------------------------------------------------------"
		fi
	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