-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmakedb.sh
More file actions
executable file
·27 lines (25 loc) · 1019 Bytes
/
makedb.sh
File metadata and controls
executable file
·27 lines (25 loc) · 1019 Bytes
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
#!/bin/sh
echo "сreate a new database"
if psql -lqt | cut -d \| -f 1 | grep -qw cad_keysafe; then
# database exists
echo -n "DATABASE ALREADY CREATED, DO YOU WANT TO -DELETE- EXISTING DATABASE AND CREATE NEW ONE? (y/n)"
read answer
if echo "$answer" | grep -iq "^y" ;then
dropdb cad_keysafe
echo "database was removed"
createdb cad_keysafe
echo "database created"
psql -d postgres -c "CREATE USER cad_root WITH PASSWORD 'root_pass';" || echo "User 'cad_root' already exists "
psql -d postgres -c "GRANT ALL PRIVILEGES ON DATABASE cad_keysafe to cad_root;"
echo "done"
else
echo "aborded"
fi
else
createdb cad_keysafe
echo "database created"
psql -d postgres -c "CREATE USER cad_root WITH PASSWORD 'root_pass';" || echo "User 'cad_root' already exists "
psql -d postgres -c "GRANT ALL PRIVILEGES ON DATABASE cad_keysafe to cad_root;"
echo "user 'cad_root' with password 'root_pass' created"
echo "done"
fi