forked from pka/acts_as_tsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbsetup.sh.old_hell
executable file
·57 lines (51 loc) · 1.17 KB
/
dbsetup.sh.old_hell
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
#
# See if tsearch2.sql exists on the system
#
sqlfile=$(locate /tsearch2.sql)
if [ -z "$sqlfile"]
then
echo "tsearch2.sql was not found on this system - please see http://code.google.com/p/acts-as-tsearch/wiki/PreparingYourPostgreSQLDatabase for details."
exit
fi
#
# Check that they ran this as postgres
#
if [ "$LOGNAME" != "root" ]
then
echo "This script needs to be run as user root"
echo "Try "
echo " su root"
echo " or"
echo " sudo su root"
exit
fi
#
# Check required parameters
#
db=${1}
un=${2}
if [ -z "$1" "$2" ]
then
echo "Usage: `basename $0 $1` db-name db-username"
echo "Example: `basename $0 $1` tsearch wiseleyb"
echo " would setup database tsearch for database username wiseleyb"
exit $E_NOARGS
fi
echo "create user $un;
alter user $un with password '$un';
grant all on database $db to $un;
grant all on public.pg_ts_cfg to $un;
grant all on public.pg_ts_cfgmap to $un;
grant all on public.pg_ts_dict to $un;
grant all on public.pg_ts_parser to $un;" > tmp_db_setup_grant_file.sql
su postgres << EOF
#
# Load sql file
#
psql $db < $sqlfile
#
# Grant permissions
#
psql $db < tmp_db_setup_grant_file.sql
EOF
rm tmp_db_setup_grant_file.sql