Adding postini and prerm scripts for sipb-xen-database-server
[invirt/packages/invirt-database.git] / debian / sipb-xen-database-server.postinst
1 #!/bin/sh
2 # postinst script for #PACKAGE#
3 #
4 # see: dh_installdeb(1)
5
6 set -e
7
8 # summary of how this script can be called:
9 #        * <postinst> `configure' <most-recently-configured-version>
10 #        * <old-postinst> `abort-upgrade' <new version>
11 #        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
12 #          <new-version>
13 #        * <postinst> `abort-remove'
14 #        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
15 #          <failed-install-package> <version> `removing'
16 #          <conflicting-package> <version>
17 # for details, see http://www.debian.org/doc/debian-policy/ or
18 # the debian-policy package
19
20
21 case "$1" in
22     configure)
23         # Don't fail if the user/database already exists
24         su postgres -c 'createuser sipb-xen -S -d -R'    || true
25         su postgres -c 'createdb sipb_xen -O sipb-xen'   || true
26         PG_HBA=/etc/postgresql/8.1/main/pg_hba.conf
27         perl -ni -e 'print unless /^# ===BEGIN ADDED BY sipb-xen-dabase server$/ ..
28                                   /^# ===END ADDED BY sipb-xen-dabase server$/' \
29                                   "$PG_HBA"
30         cat<<EOF >> "$PG_HBA"
31 # ===BEGIN ADDED BY sipb-xen-dabase server
32 # DO NOT EDIT
33 host    sipb_xen    sipb-xen    127.0.0.1/32          trust
34 local   sipb_xen    sipb-xen                          trust
35 # ===END ADDED BY sipb-xen-dabase server
36 EOF
37
38         if hash invoke-rc.d; then
39             invoke-rc.d postgresql-8.1 restart
40         else
41             /etc/init.d/postgresql-8.1 restart
42         fi
43
44         sipb-xen-database-tables create
45     ;;
46
47     abort-upgrade|abort-remove|abort-deconfigure)
48     ;;
49
50     *)
51         echo "postinst called with unknown argument \`$1'" >&2
52         exit 1
53     ;;
54 esac
55
56 # dh_installdeb will replace this with shell code automatically
57 # generated by other debhelper scripts.
58
59 #DEBHELPER#
60
61 exit 0
62
63