~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
91
92
93
94
95
96
97
98
99
100
#!/bin/sh
#
# Copyright 2009 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

if [ -n "$1" ]; then
    USER=$1
    echo "Creating Launchpad database for $USER"
else
    echo "THIS SCRIPT WILL DESTROY ALL OF YOUR POSTGRESQL DATA"
    echo "If you really want that, run it with a username as "
    echo "an argument"
    exit 1
fi

# 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

if [ -e /etc/init.d/postgresql-8.3 ]; then
  pgversion=8.3
  echo "Using postgres 8.3"
elif [ -e /etc/init.d/postgresql-8.2]; then
  pgversion=8.2
  echo "Using postgres 8.2"
else
  echo "Unable to determine your postgres version."
  exit 1
fi

# Make sure that we have the correct version running on port 5432
sudo grep -q "port.*5432" /etc/postgresql/$pgversion/main/postgresql.conf
if [ $? -ne 0 ]; then
  echo "Please check /etc/postgresql/$pgversion/main/postgresql.conf and"
  echo "ensure postgres is running on port 5432."
fi;

sudo /etc/init.d/postgresql-$pgversion stop

echo Purging postgresql data...
sudo pg_dropcluster $pgversion main --stop-server
echo Re-creating postgresql database...
# Setting locale to C to make the server run in that locale.
LC_ALL=C sudo pg_createcluster $pgversion main --encoding UNICODE

echo Applying postgresql configuration changes...

sudo cp -a /etc/postgresql/$pgversion/main/pg_hba.conf \
    /etc/postgresql/$pgversion/main/pg_hba.conf.old
sudo grep -q Launchpad /etc/postgresql/$pgversion/main/pg_hba.conf || \
sudo patch /etc/postgresql/$pgversion/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/32      trust



EOF
sudo chown --reference=/etc/postgresql/$pgversion/main/pg_hba.conf.old \
    /etc/postgresql/$pgversion/main/pg_hba.conf
sudo chmod --reference=/etc/postgresql/$pgversion/main/pg_hba.conf.old \
    /etc/postgresql/$pgversion/main/pg_hba.conf

sudo grep -q Launchpad /etc/postgresql/$pgversion/main/postgresql.conf || \
sudo tee -a /etc/postgresql/$pgversion/main/postgresql.conf <<'EOF'

##
## Launchpad configuration
##
# Enable launchpad full text searching in database
search_path='$user,public,ts2'
add_missing_from=false
#enable_seqscan=false
log_statement='all'
log_line_prefix='[%t] %q%u@%d '
fsync = off
max_fsm_relations=2000

EOF

sudo /etc/init.d/postgresql-$pgversion start

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

echo Creating postgresql user $USER
sudo -u postgres /usr/lib/postgresql/$pgversion/bin/createuser -a -d $USER

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

exit 0