-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabaseSetup.sh
More file actions
63 lines (47 loc) · 1.87 KB
/
Copy pathdatabaseSetup.sh
File metadata and controls
63 lines (47 loc) · 1.87 KB
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
#!/bin/bash
mysqlSetup() {
mysql -f -h $DNS -P 3306 -u $username -p << EOF
SHOW DATABASES;
EOF
read -p "please enter the name of the database you wish to create: " tableName
mysql -f -h $DNS -P 3306 -u $username -p << EOF
DROP DATABASE $tableName;
EOF
mysql -f -h $DNS -P 3306 -u $username -p << EOF
CREATE DATABASE $tableName;
DELETE FROM mysql.user WHERE user = '';
FLUSH PRIVILEGES;
EOF
echo "this is a standard error check"
echo "we have just connected to the database,"
echo "dropped and recreated the database you mentioned"
echo "if you don't see any errors then press the enter key to continue"
read -p "otherwise exit this script and troubleshoot"
}
postgres() {
echo "no actions required for postgres"
}
choosedb() {
echo "you are now going to configure your AWS tools, please have your access keys and secret access keys to hand. It is reccomended that this be an IAM access key, this will make your life easier in the event of a compromise."
aws configure
aws rds describe-db-instances | egrep "DBInstanceIdentifier|Address|MasterUsername" | sed 's/"//g'
echo "above you see the various databases in the default region, please select which RDS database Identifier you would like to use according to the main database name. You will get a chance to change this later if you like."
read DBName
DNS=$(aws rds describe-db-instances --db-instance-identifier $DBName | egrep "Address" | sed 's/.*| //;s/ .*//')
username=$(aws rds describe-db-instances --db-instance-identifier $DBName | egrep "MasterUsername" | sed 's/.*| //;s/ .*//')
}
echo "mysql (1)"
echo "postgres (2)"
read -p "please enter the number of the database you wish to use: " choice
case "$choice" in
1)
choosedb
mysqlSetup
;;
2)
postgres
;;
*)
echo "else"
;;
esac