|
7 | 7 | # My ref: http://www.linode.com/?r=aadfce9845055011e00f0c6c9a5c01158c452deb |
8 | 8 |
|
9 | 9 | function postgresql_install { |
10 | | - aptitude -y install postgresql postgresql-contrib postgresql-dev postgresql-client libpq-dev |
11 | | -} |
12 | | - |
13 | | - |
14 | | -function postgresql_recreate_cluster { |
15 | | - # WARNING: this procedure removes all data in the main cluster |
16 | | - # drop default cluster and recreate it with UTF-8 encoding |
17 | | - # $1 - root data dicrecotry, i.e. /var/lib or /srv |
18 | | - BASE_DIRECTORY=$1 |
19 | | - pg_dropcluster -stop 8.4 main |
20 | | - if [ -z "$BASE_DIRECTORY" ]; then |
21 | | - pg_createcluster -start -e UTF-8 8.4 main |
22 | | - else |
23 | | - DATA_DIRECTORY="$BASE_DIRECTORY/postgresql" |
24 | | - mkdir -p "$DATA_DIRECTORY/8.4/main" |
25 | | - chown -R postgres:postgres "$DATA_DIRECTORY" |
26 | | - pg_createcluster -start -e UTF-8 -d "$DATA_DIRECTORY/8.4/main" 8.4 main |
27 | | - fi; |
| 10 | + aptitude -y install postgresql postgresql-contrib postgresql-dev libpq-dev |
28 | 11 | } |
29 | 12 |
|
30 | 13 | function postgresql_create_user { |
31 | | - # $1 - the user to create |
32 | | - # $2 - their password |
33 | | - |
34 | | - if [ ! -n "$1" ]; then |
| 14 | + # postgresql_create_user(username, password) |
| 15 | + if [ -z "$1" ]; then |
35 | 16 | echo "postgresql_create_user() requires username as the first argument" |
36 | 17 | return 1; |
37 | 18 | fi |
38 | | - if [ ! -n "$2" ]; then |
| 19 | + if [ -z "$2" ]; then |
39 | 20 | echo "postgresql_create_user() requires a password as the second argument" |
40 | 21 | return 1; |
41 | 22 | fi |
42 | 23 |
|
43 | | - echo "CREATE ROLE $1 WITH LOGIN ENCRYPTED PASSWORD '$2';" | sudo -u postgres psql |
| 24 | + echo "CREATE ROLE $1 WITH LOGIN ENCRYPTED PASSWORD '$2';" | sudo -i -u postgres psql |
44 | 25 | } |
45 | 26 |
|
46 | 27 | function postgresql_create_database { |
47 | | - # $1 - the db name to create |
48 | | - # $2 - the db owner user |
49 | | - |
50 | | - if [ ! -n "$1" ]; then |
| 28 | + # postgresql_create_database(dbname, owner) |
| 29 | + if [ -z "$1" ]; then |
51 | 30 | echo "postgresql_create_database() requires database name as the first argument" |
52 | 31 | return 1; |
53 | 32 | fi |
54 | | - if [ ! -n "$2" ]; then |
| 33 | + if [ -z "$2" ]; then |
55 | 34 | echo "postgresql_create_database() requires an owner username as the second argument" |
56 | 35 | return 1; |
57 | 36 | fi |
58 | 37 |
|
59 | | - sudo -u postgres createdb --owner=$2 $1 |
| 38 | + sudo -i -u postgres createdb --owner=$2 $1 |
60 | 39 | } |
0 commit comments