~launchpad-pqm/launchpad/devel

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
#!/bin/sh

if [ "$1" != $(id -un) ]; then
	echo "THIS SCRIPT WILL DESTROY ALL OF YOUR POSTGRESQL DATA"
	echo "If you really want that, run it with your username as"
	echo "an argument"
	exit 1
fi

set -e

# This attempts to automate instructions provided on
# https://launchpad.canonical.com/DatabaseSetup which are intended for
# initial Launchpad setup on an otherwise unconfigured postgresql instance

sudo /etc/init.d/postgresql-8.1 stop


main=/var/lib/postgresql/8.1/main
echo Purging postgresql data...
sudo -u postgres sh -c "rm -rf $main/*"
echo Re-creating postgresql database...
sudo -u postgres /usr/lib/postgresql/8.1/bin/initdb \
	--pgdata=$main \
	--encoding=UNICODE --locale=C
sudo -u postgres ln -s /etc/postgresql-common/root.crt $main
sudo -u postgres ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem $main/server.crt
sudo -u postgres ln -s /etc/ssl/private/ssl-cert-snakeoil.key $main/server.key

echo Applying postgresql configuration changes...

sudo cp -a /etc/postgresql/8.1/main/pg_hba.conf /etc/postgresql/8.1/main/pg_hba.conf.old
sudo grep -q Launchpad /etc/postgresql/8.1/main/pg_hba.conf || \
sudo patch /etc/postgresql/8.1/main/pg_hba.conf <<'EOF'
--- pg_hba.conf 2005-11-02 17:33:08.000000000 -0800
+++ /tmp/pg_hba.conf    2005-11-03 07:32:46.932400423 -0800
@@ -58,7 +58,9 @@
 # on a non-local interface via the listen_addresses configuration parameter,
 # or via the -i or -h command line switches.
 #
-
+# Launchpad users
+local   all         all                                          trust
+host    all         all         127.0.0.1       255.255.255.255  trust



EOF
sudo chown --reference=/etc/postgresql/8.1/main/pg_hba.conf.old /etc/postgresql/8.1/main/pg_hba.conf
sudo chmod --reference=/etc/postgresql/8.1/main/pg_hba.conf.old /etc/postgresql/8.1/main/pg_hba.conf

sudo grep -q Launchpad /etc/postgresql/8.1/main/postgresql.conf || \
sudo patch /etc/postgresql/8.1/main/postgresql.conf <<'EOF'
--- /etc/postgresql/8.1/main/postgresql.conf    2005-11-03 07:56:27.000000000 -0800
+++ /tmp/postgresql.conf        2005-11-03 07:57:28.156973216 -0800
@@ -423,6 +423,14 @@
 # - Other Platforms & Clients -

 #transform_null_equals = off

+##
+## Launchpad configuration
+##
+# Enable launchpad full text searching in database
+search_path='$user,public,ts2'
+add_missing_from=false
+# Force use of indexes, to assist in tuning queries
+enable_seqscan=false

 #---------------------------------------------------------------------------
 # CUSTOMIZED OPTIONS
EOF

if [ -f /etc/postgresql/8.1/main/start.conf ]; then
    sudo sed -i -e 's/^manual/auto/' /etc/postgresql/8.1/main/start.conf
fi

sudo /etc/init.d/postgresql-8.1 start

echo Waiting 10 seconds for postgresql to come up...
sleep 10

echo Creating postgresql user $(id -un)
sudo -u postgres /usr/lib/postgresql/8.1/bin/createuser -a -d $(id -un)

echo
echo Looks like everything went ok.
echo Now run '"make schema"' at the top level of the launchpad tree.

exit 0