3
# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
4
# GNU Affero General Public License version 3 (see the file LICENSE).
8
echo "Creating Launchpad database for $USER"
10
echo "usage: launchpad-database-setup DEVELOPER_USER"
11
echo "THIS SCRIPT WILL DESTROY ALL POSTGRESQL DATA for the given user"
12
echo "If you really want that, run it with the username of your "
13
echo "local developer account."
17
# This attempts to automate instructions provided on
18
# https://dev.launchpad.net/DatabaseSetup which are intended for
19
# initial Launchpad setup on an otherwise unconfigured postgresql instance
21
for pgversion in 8.4 8.3 8.2
23
sudo grep -q "^auto" /etc/postgresql/$pgversion/main/start.conf
29
if [ -z "$pgversion" ]
31
echo "Unable to determine your postgres version."
35
echo "Using postgres $pgversion"
37
# Make sure that we have the correct version running on port 5432
38
sudo grep -q "port.*5432" /etc/postgresql/$pgversion/main/postgresql.conf
40
echo "Please check /etc/postgresql/$pgversion/main/postgresql.conf and"
41
echo "ensure postgres is running on port 5432."
44
if [ -e /etc/init.d/postgresql-$pgversion ]; then
45
sudo /etc/init.d/postgresql-$pgversion stop
48
sudo /etc/init.d/postgresql stop $pgversion
51
echo Purging postgresql data...
52
sudo pg_dropcluster $pgversion main --stop-server
53
echo Re-creating postgresql database...
54
# Setting locale to C to make the server run in that locale.
55
LC_ALL=C sudo pg_createcluster $pgversion main --encoding UNICODE
57
echo Applying postgresql configuration changes...
59
sudo cp -a /etc/postgresql/$pgversion/main/pg_hba.conf \
60
/etc/postgresql/$pgversion/main/pg_hba.conf.old
61
sudo grep -q Launchpad /etc/postgresql/$pgversion/main/pg_hba.conf || \
62
sudo patch /etc/postgresql/$pgversion/main/pg_hba.conf <<'EOF'
63
--- pg_hba.conf 2005-11-02 17:33:08.000000000 -0800
64
+++ /tmp/pg_hba.conf 2005-11-03 07:32:46.932400423 -0800
66
# on a non-local interface via the listen_addresses configuration parameter,
67
# or via the -i or -h command line switches.
72
+host all all 127.0.0.1/32 trust
73
+host all all ::1/128 trust
78
sudo chown --reference=/etc/postgresql/$pgversion/main/pg_hba.conf.old \
79
/etc/postgresql/$pgversion/main/pg_hba.conf
80
sudo chmod --reference=/etc/postgresql/$pgversion/main/pg_hba.conf.old \
81
/etc/postgresql/$pgversion/main/pg_hba.conf
83
sudo grep -q Launchpad /etc/postgresql/$pgversion/main/postgresql.conf || \
84
sudo tee -a /etc/postgresql/$pgversion/main/postgresql.conf <<'EOF'
87
## Launchpad configuration
89
# Enable launchpad full text searching in database
90
search_path='$user,public,ts2'
91
add_missing_from=false
94
log_line_prefix='[%t] %q%u@%d '
99
if [ "$pgversion" = 8.2 -o "$pgversion" = 8.3 ]
101
sudo grep -q '^[[:space:]]*max_fsm_relations' /etc/postgresql/$pgversion/main/postgresql.conf || \
102
sudo tee -a /etc/postgresql/$pgversion/main/postgresql.conf <<'EOF'
103
max_fsm_relations=2000
108
if [ -e /etc/init.d/postgresql-$pgversion ]; then
109
sudo /etc/init.d/postgresql-$pgversion start
112
sudo /etc/init.d/postgresql start $pgversion
115
echo Waiting 10 seconds for postgresql to come up...
118
echo Creating postgresql user $USER
119
sudo -u postgres /usr/lib/postgresql/$pgversion/bin/createuser -a -d $USER
122
echo Looks like everything went ok.
123
echo Now run '"make schema"' at the top level of the launchpad tree.