~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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/sh
#
# Copyright 2009-2010 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 "usage: launchpad-database-setup DEVELOPER_USER"
    echo "THIS SCRIPT WILL DESTROY ALL POSTGRESQL DATA for the given user"
    echo "If you really want that, run it with the username of your "
    echo "local developer account."
    exit 1
fi

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

for pgversion in 8.4 8.3 8.2
do
  sudo grep -q "^auto" /etc/postgresql/$pgversion/main/start.conf
  if [ $? -eq 0 ]; then
    break
  fi
done

if [ -z "$pgversion" ]
then
  echo "Unable to determine your postgres version."
  exit 1
fi

echo "Using postgres $pgversion"

# 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;

if [ -e /etc/init.d/postgresql-$pgversion ]; then
    sudo /etc/init.d/postgresql-$pgversion stop
else
    # This is Maverick.
    sudo /etc/init.d/postgresql stop $pgversion
fi

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,10 @@
 # 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
+host    all         all         ::1/128           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='none'
log_line_prefix='[%t] %q%u@%d '
fsync = off

EOF

if [ "$pgversion" = 8.2 -o "$pgversion" = 8.3 ]
then
  sudo grep -q '^[[:space:]]*max_fsm_relations' /etc/postgresql/$pgversion/main/postgresql.conf || \
  sudo tee -a /etc/postgresql/$pgversion/main/postgresql.conf <<'EOF'
max_fsm_relations=2000

EOF
fi

if [ -e /etc/init.d/postgresql-$pgversion ]; then
    sudo /etc/init.d/postgresql-$pgversion start
else
    # This is Maverick.
    sudo /etc/init.d/postgresql start $pgversion
fi

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