File: postinst

package info (click to toggle)
myphpmoney 1.3RC3-13
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,160 kB
  • ctags: 884
  • sloc: php: 18,081; pascal: 2,106; sh: 327; xml: 239; makefile: 137; sql: 130
file content (194 lines) | stat: -rw-r--r-- 6,268 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
#! /bin/sh
# postinst script for myphpmoney

set -e

case "$1" in
	configure)
		. /usr/share/debconf/confmodule || exit
		db_version 2.0
		db_title MyPhpMoney

		db_get "myphpmoney/configuration" || true
		if [ "$RET" = "true" ]; then

			# Make sure created files are not publicly readable
			umask 077

			# Database stuff
			################
			db_get "myphpmoney/databasemgr_server" || true
			dbserver="$RET"
			db_get "myphpmoney/database_name" || true
			dbname="$RET"
		
			if [ -x $(which mysql) ]; then
        	        	db_get "myphpmoney/mysql_dbadmin" || true
				dbadmin="$RET"
				db_get "myphpmoney/dbadmpass" || true
				dbadmpass="$RET"
				db_reset "myphpmoney/dbadmpass" || true
			
				db_get "myphpmoney/mysql_user" || true
				dbuser="$RET"
				db_get "myphpmoney/database_pass" || true
				dbpass="$RET"

				. /usr/share/wwwconfig-common/mysql-createdb.sh
				case $status in
					create)
						sqlfile=`tempfile`
						myphpmoneydbname=$dbname
						dbname="mysql"
						cat > $sqlfile <<EOF
REPLACE INTO user ( host, user, password )
    VALUES (
        'localhost',
        '$dbuser',
        password( '$dbpass' )
    );

REPLACE INTO db ( host, db, user, select_priv, insert_priv, update_priv,
                  delete_priv, create_priv, drop_priv, index_priv, alter_priv)
    VALUES (
        '$dbserver',
        '$myphpmoneydbname',
        '$dbuser',
        'Y', 'Y', 'Y', 'Y',
        'Y', 'Y', 'Y', 'Y'
    );

flush privileges;
EOF
						. /usr/share/wwwconfig-common/mysql-exec.sh
						rm -f $sqlfile
						dbname=$myphpmoneydbname
					;;
					nothing)
						# Nothing to do as there is already a database
					;;
					*)
						echo "Error: failed to set up MyPhpMoney database properly !"
						echo
						echo "MyPhpMoney installation program failed to set up a database properly"
						echo "for its needs.  Please make sure all of parameters you supplied are"
						echo "correct and that your database manager is running.  Install MyPhpMoney"
						echo "again to make it working."
						exit 1
					;;
				esac
			else
				echo "Not configuring MySQL database because we cannot locate"
				echo "the mysql client executable (mysql-client package missing)."
				exit 1
			fi
		
		    	sed -e "s/^\(.*Host'\][^\']*=[^\']*\)'.*';\(.*\)/\1'$dbserver';\2/" \
		    	    -e "s/^\(.*User'\][^\']*=[^\']*\)'.*';\(.*\)/\1'$dbuser';\2/" \
	    		    -e "s/^\(.*Password'\][^\']*=[^\']*\)'.*';\(.*\)/\1'$dbpass';\2/" \
		            -e "s/^\(.*Database'\][^\']*=[^\']*\)'.*';\(.*\)/\1'$dbname';\2/" \
		            < /var/lib/myphpmoney/public_html/config/settings.inc.php.sample \
   	        	    > /var/lib/myphpmoney/public_html/config/settings.inc.php

			# Webserver stuff
			#################
			db_get "myphpmoney/webservers"
			webservers="$(echo $RET | sed -e 's/, / /g')"
			restart=""

			# Currently only apache is supported
			for webserver in $webservers ; do

				case "$webserver" in
					apache|apache-perl|apache-ssl)

					if [ -x /usr/sbin/modules-config ]; then
						if [ -f /usr/lib/apache/1.3/libphp4.so ]; then
							if ! grep "^LoadModule php4_module " /etc/$webserver/modules.conf > /dev/null 2>&1; then
								modules-config $webserver enable mod_php4
							fi
						else
							if [ -f /usr/lib/apache/1.3/mod_actions.so ]; then
								if ! grep "^LoadModule action_module " /etc/$webserver/modules.conf > /dev/null 2>&1; then
									modules-config $webserver enable mod_actions
								fi
							fi
							if [ -f /usr/lib/apache/1.3/mod_cgi.so ]; then
								if ! grep "^LoadModule cgi_module " /etc/$webserver/modules.conf > /dev/null 2>&1; then
									modules-config $webserver enable mod_cgi
								fi
							fi
						fi
					fi
					if grep "^Include /etc/myphpmoney/apache.conf" /etc/$webserver/httpd.conf > /dev/null 2>&1; then
						mv -f /etc/$webserver/httpd.conf /etc/$webserver/httpd.conf.old.myphpmoney
						grep -v "^Include /etc/myphpmoney/apache.conf" /etc/$webserver/httpd.conf.old.myphpmoney \
							> /etc/$webserver/httpd.conf
					fi
					if ! grep "^Include /etc/$webserver/conf.d" /etc/$webserver/httpd.conf > /dev/null 2>&1; then
						cp -f /etc/$webserver/httpd.conf /etc/$webserver/httpd.conf.old.myphpmoney
						echo "Include /etc/$webserver/conf.d" >> /etc/$webserver/httpd.conf
					fi
					if [ -f /etc/$webserver/httpd.conf.old.myphpmoney -a ! -f /etc/$webserver/httpd.conf.old ]; then
						mv -f /etc/$webserver/httpd.conf.old.myphpmoney /etc/$webserver/httpd.conf.old
					fi
					mkdir -p /etc/$webserver/conf.d
					;;
					
				apache2)
					if [ -d /etc/$webserver/mods-enabled ]; then
						if [ ! -f /etc/$webserver/mods-enabled/actions.load -a ! -h /etc/$webserver/mods-enabled/actions.load ]; then
							ln -s /etc/$webserver/mods-available/actions.load /etc/$webserver/mods-enabled/actions.load
						fi
						if [ -f /etc/apache2/mods-available/php4.load ]; then
							if [ ! -f /etc/$webserver/mods-enabled/php4.load -a ! -h /etc/$webserver/mods-enabled/php4.load ]; then
								ln -s /etc/$webserver/mods-available/php4.load /etc/$webserver/mods-enabled/php4.load
							fi
						else
							if [ ! -f /etc/$webserver/mods-enabled/cgi.load -a ! -h /etc/$webserver/mods-enabled/cgi.load ]; then
								ln -s /etc/$webserver/mods-available/cgi.load /etc/$webserver/mods-enabled/cgi.load
							fi
						fi
					fi
					;;
				esac
				if [ ! -f /etc/$webserver/conf.d/myphpmoney -a ! -h /etc/$webserver/conf.d/myphpmoney ]; then
					ln -s /etc/myphpmoney/apache.conf /etc/$webserver/conf.d/myphpmoney
					restart="$restart $webserver"
				fi
			done
			
			chown -R www-data:www-data /var/lib/myphpmoney
			
			for webserver in $restart; do
				if [ -x /usr/sbin/invoke-rc.d ]; then
					invoke-rc.d $webserver restart
				else
					/etc/init.d/$webserver restart
				fi
			done

			db_subst "myphpmoney/installed" "site" "http://127.0.0.1/myphpmoney/"
			db_input "high" myphpmoney/installed || true
			db_get myphpmoney/installed || true
			db_go
			db_stop

			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