~launchpad-pqm/launchpad/devel

2778.1.2 by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of
1
#!/bin/sh
2
3
if [ "$1" != $(id -un) ]; then
4
	echo "THIS SCRIPT WILL DESTROY ALL OF YOUR POSTGRESQL DATA"
5
	echo "If you really want that, run it with your username as"
6
	echo "an argument"
7
	exit 1
8
fi
9
10
set -e
11
12
# This attempts to automate instructions provided on
2903.1.143 by Matthew Paul Thomas
Fixes remaining occurrences from outside lib/canonical/launchpad/.
13
# https://launchpad.canonical.com/DatabaseSetup which are intended for
2778.1.2 by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of
14
# initial Launchpad setup on an otherwise unconfigured postgresql instance
15
2976.8.2 by Robert Collins
resync with rocketfuel.
16
sudo /etc/init.d/postgresql-8.1 stop
17
18
19
main=/var/lib/postgresql/8.1/main
2778.1.2 by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of
20
echo Purging postgresql data...
21
sudo -u postgres sh -c "rm -rf $main/*"
22
echo Re-creating postgresql database...
2976.8.2 by Robert Collins
resync with rocketfuel.
23
sudo -u postgres /usr/lib/postgresql/8.1/bin/initdb \
2778.1.2 by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of
24
	--pgdata=$main \
25
	--encoding=UNICODE --locale=C
26
sudo -u postgres ln -s /etc/postgresql-common/root.crt $main
27
sudo -u postgres ln -s /etc/postgresql-common/postgresql.crt $main/server.crt
28
sudo -u postgres ln -s /etc/postgresql-common/postgresql.pem $main/server.key
29
30
echo Applying postgresql configuration changes...
31
2976.8.2 by Robert Collins
resync with rocketfuel.
32
sudo cp -a /etc/postgresql/8.1/main/pg_hba.conf /etc/postgresql/8.1/main/pg_hba.conf.old
33
sudo grep -q Launchpad /etc/postgresql/8.1/main/pg_hba.conf || \
34
sudo patch /etc/postgresql/8.1/main/pg_hba.conf <<'EOF'
2778.1.2 by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of
35
--- pg_hba.conf 2005-11-02 17:33:08.000000000 -0800
36
+++ /tmp/pg_hba.conf    2005-11-03 07:32:46.932400423 -0800
37
@@ -58,7 +58,9 @@
38
 # on a non-local interface via the listen_addresses configuration parameter,
39
 # or via the -i or -h command line switches.
40
 #
41
-
42
+# Launchpad users
43
+local   all         all                                          trust
44
+host    all         all         127.0.0.1       255.255.255.255  trust
45
46
47
48
EOF
2976.8.2 by Robert Collins
resync with rocketfuel.
49
sudo chown --reference=/etc/postgresql/8.1/main/pg_hba.conf.old /etc/postgresql/8.1/main/pg_hba.conf
50
sudo chmod --reference=/etc/postgresql/8.1/main/pg_hba.conf.old /etc/postgresql/8.1/main/pg_hba.conf
2778.1.2 by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of
51
2976.8.2 by Robert Collins
resync with rocketfuel.
52
sudo grep -q Launchpad /etc/postgresql/8.1/main/postgresql.conf || \
53
sudo patch /etc/postgresql/8.1/main/postgresql.conf <<'EOF'
54
--- /etc/postgresql/8.1/main/postgresql.conf    2005-11-03 07:56:27.000000000 -0800
2778.1.2 by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of
55
+++ /tmp/postgresql.conf        2005-11-03 07:57:28.156973216 -0800
2976.8.2 by Robert Collins
resync with rocketfuel.
56
@@ -423,3 +423,11 @@
2778.1.2 by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of
57
 # - Other Platforms & Clients -
58
59
 #transform_null_equals = false
60
+##
61
+## Launchpad configuration
62
+##
63
+# Enable launchpad full text searching in database
64
+search_path='$user,public,ts2'
65
+add_missing_from=false
66
+# Force use of indexes, to assist in tuning queries
67
+enable_seqscan=false
68
EOF
69
2976.8.2 by Robert Collins
resync with rocketfuel.
70
if [ -f /etc/postgresql/8.1/main/start.conf ]; then
71
    sudo sed -i -e 's/^manual/auto/' /etc/postgresql/8.1/main/start.conf
3024.1.4 by Christian Reis
Only patch start.conf if it actually exists; patch by Matt Zimmerman <mdz@canonical.com>
72
fi
2778.1.2 by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of
73
2976.8.2 by Robert Collins
resync with rocketfuel.
74
sudo /etc/init.d/postgresql-8.1 start
2778.1.2 by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of
75
76
echo Waiting 10 seconds for postgresql to come up...
77
sleep 10
78
79
echo Creating postgresql user $(id -un)
2976.8.2 by Robert Collins
resync with rocketfuel.
80
sudo -u postgres /usr/lib/postgresql/8.1/bin/createuser -a -d $(id -un)
2778.1.2 by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of
81
82
echo
83
echo Looks like everything went ok.
3024.1.2 by Christian Reis
Fix up launchpad-database-setup to cope with a modern PostgreSQL. Patch by Matt Zimmerman <mdz@canonical.com>
84
echo Now run '"make schema"' at the top level of the launchpad tree.
2778.1.2 by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of
85
86
exit 0