Skip to content

Commit f4a1593

Browse files
committed
Function postgresql_recreate_cluster is not needed anymore.
Minor style and sudo invocation tweaks.
1 parent c6db011 commit f4a1593

File tree

1 file changed

+9
-30
lines changed

1 file changed

+9
-30
lines changed

125 - lib-postgresql.sh

+9-30
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,33 @@
77
# My ref: http://www.linode.com/?r=aadfce9845055011e00f0c6c9a5c01158c452deb
88

99
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
2811
}
2912

3013
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
3516
echo "postgresql_create_user() requires username as the first argument"
3617
return 1;
3718
fi
38-
if [ ! -n "$2" ]; then
19+
if [ -z "$2" ]; then
3920
echo "postgresql_create_user() requires a password as the second argument"
4021
return 1;
4122
fi
4223

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
4425
}
4526

4627
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
5130
echo "postgresql_create_database() requires database name as the first argument"
5231
return 1;
5332
fi
54-
if [ ! -n "$2" ]; then
33+
if [ -z "$2" ]; then
5534
echo "postgresql_create_database() requires an owner username as the second argument"
5635
return 1;
5736
fi
5837

59-
sudo -u postgres createdb --owner=$2 $1
38+
sudo -i -u postgres createdb --owner=$2 $1
6039
}

0 commit comments

Comments
 (0)