File: postinst

package info (click to toggle)
slash 2.2.6-8etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 3,672 kB
  • ctags: 1,915
  • sloc: perl: 23,113; sql: 1,878; sh: 433; makefile: 233
file content (231 lines) | stat: -rw-r--r-- 7,265 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
#! /bin/sh
# postinst script for slash
#
# see: dh_installdeb(1)
#
# (c) Eric Van Buggenhaut <ericvb@debian.org>, 2003 under GPL.
# Large parts were contributed by Jay Bonci <jay@bonci.com>.
# Updated by Axel Beckert <abe@deuxchevaux.org> for fixing #278623

set -e

# 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 /usr/doc/packaging-manual/
#
# 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'.



case "$1" in
    configure)

    echo "	Before running slash code, you'll have to create a web site"
    echo "	on your system. I can do it for you now. If you are upgrading"
    echo "	from a previous version of slash, you should answer 'no' to"
    echo "	the next question."
    echo -n "Do you want me to install a slash site on your system ? [y/N] "
    read ANSWER
    if [ "$ANSWER" = "n" -o "$ANSWER" = "N" -o "$ANSWER" = "" ]
	then /etc/init.d/apache restart
	exit 0
    fi
    
      echo
    
    #Create the MySQL DB
    echo "	In order for slash to function properly we need a mysql dedicated"
    echo "	database. You can create it by hand or let me do it for you now."
    echo "	If you already have the database created you can safely answer 'no',"
    echo "	of course."
    echo -n "Shall I create a new database now ? [Y/n] "
    read createdb
    case "$createdb" in
        [yY]* | '' )
		
	    #First we need the root passwd
	    echo
	    while ! $(echo "quit" | mysql -u root --password=$ROOT_PASSWD >/dev/null 2>&1)
	    do
      	      echo -n "Please enter the mySQL root user password: "
	      stty -echo
	      read ROOT_PASSWD
	      stty echo
	      echo ""
	    done
		
	    #Name of the db containing the future slash pages
	    echo -n 'How do you want the slash database of your site to be called ? '
	    read DBASE
	    if  $(echo "SHOW DATABASES" | mysql -u root --password=$ROOT_PASSWD |grep ^$DBASE$ >/dev/null 2>&1); then
	      echo -n "Database $DBASE already exists. Overwrite it ? [Y/n] "
    	      read dropdb
    	      case "$dropdb" in
	        [yY]* | '' )
	          echo "DROP DATABASE $DBASE" | mysql -u root --password=$ROOT_PASSWD
	        ;;
	        *)
         	  echo -n "Please select an alternate database name: "
		  read DBASE
		;;
	      esac
	    fi
 	    echo 
		
	    #Under which id do we access the db ?
	    echo -n "What user should be used by slash to access database $DBASE ? [root] : "
	    read DB_USER
	    if [ "$DB_USER" = "" ] ; then
	      DB_USER="root"
	      PASSWD="$ROOT_PASSWD"
	    else
	      echo -n "Provide the access password to the database for user $DB_USER: "
	      stty -echo
	      read PASSWD
	      stty echo
	    fi
		
		echo
		#Name of the virtual user
		echo "	We need to create a virtual user of the Slash site."
		echo "	This name is used internally by slash and needn't be"
		echo "	a real user of the system."
		echo -n 'Please choose a name for the virtual user: '
		read V_USER

		#Create the DB and grant user privileges to access it
		/usr/bin/mysqladmin create -u root --password="$ROOT_PASSWD" \
		$DBASE
		echo "GRANT ALL PRIVILEGES ON $DBASE.* TO $DB_USER@localhost \
		IDENTIFIED by '$PASSWD' WITH GRANT OPTION;" \
		| /usr/bin/mysql --user=root mysql --password="$ROOT_PASSWD"
		echo "flush PRIVILEGES;" \
		| /usr/bin/mysql --user=root mysql --password="$ROOT_PASSWD"

		#Include the data into the libdbix conf file
		cat >> /etc/dbix-password.conf <<-EOF
		'$V_USER':'$DB_USER':'$PASSWD':'':'$DBASE':'DBI:mysql:database=$DBASE;host=localhost':'mysql':'localhost' 
		EOF
	     ;;
	     * )
	     echo
	     echo '	OK, skipping the creation of the database.'
	     echo -n 'What virtual user must we use ? '
	     read V_USER
	     ;;
	esac
    echo

    #Locate a web server, could be apache, apache-ssl, ...
    echo "	Searching for Apache...(No changes are being made)"

    #we can cheat and try and query apache, since we're in the neighborhood
    #and we're already root

    for bin in /usr/sbin/apache-ssl /usr/sbin/apache /usr/sbin/httpd
    do
        if test -e "$bin"
        then 
	  apachepath="$bin"
        fi
    done

    if [ -z "$apachepath" ]
    then
      echo "	Could not find Apache..."
    else
      echo "	Apache found at $apachepath."
      #Configuring apache, after locating its conf file.
      myconfpath=`$apachepath -V | sed -n "s/ \-D SERVER\_CONFIG\_FILE\=\"\(.*\)\"/\1/p"`
      if [ -n "$myconfpath" ]
      then
      echo "	$apachepath says your conf file is at $myconfpath"
      fi
    fi

    if [ -z "$myconfpath" ]
    then
      #Hmm, can't find the apache binary?  We can also try this:
      for i in /etc/apache-ssl/conf /etc/apache/conf /etc/httpd/conf /etc/apache-ssl /etc/apache /etc/httpd
      do
	if test -e "$i/apache.conf"
	then
	  echo "	Found a conf file at: $i/apache.conf"
          myconfpath="$i/apache.conf"
	else
	  if test -e "$i/httpd.conf"
	  then
	    echo "	Found a conf file at: $i/httpd.conf"
            myconfpath="$i/httpd.conf"
	  fi
	fi
      done
    fi

    if [ -z "$myconfpath" ]
    then
      echo ""
      echo "	We couldn't find your httpd.conf file installed."
      echo "	Is Apache properly configured? You may wish to add: "
      echo "		Include /etc/slash/apache.conf"
      echo "	to your httpd.conf once it is setup properly."
    fi
      echo 
    if ! $(grep -q '^Include /etc/slash/apache.conf' $myconfpath)
	then
	echo "	In order for the slash code to function properly, we must include"
	echo "	the directives of slash in your actual apache config file."
	echo -n 'Do you want me to do it for you now ? [Y/n] '
	read response
	echo
	case "$response" in
		[yY]* | '' )
		cp $myconfpath $myconfpath.slashbkp
		echo "	Your original apache config file $myconfpath as been saved"
		echo "	as $myconfpath.slashbkp."
                echo "#Automatically added by slash for debian setup" >> $myconfpath
		echo 'Include /etc/slash/apache.conf' >> $myconfpath
      		echo "" >> $myconfpath
		;;
		* )
		echo '	OK, skipping the inclusion of slash.conf.'
                echo "	You may wish to add: "
                echo "		Include /etc/slash/apache.conf"
                echo "	to your httpd.conf by hand."
		;;
	esac
    fi
    echo
    echo "Don't forget to load mod_perl module in $myconfpath !"

    echo 
    /usr/bin/install-slashsite -u $V_USER
    ;;

    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