-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreatefingerprintdb.sh
executable file
·79 lines (66 loc) · 3.38 KB
/
createfingerprintdb.sh
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
SCRIPTDIR=$(dirname "${0}")
DBCONFIG="${SCRIPTDIR}"/FINGERPRINTDB_CONFIG.txt
usage(){
echo "This script will configure a database, users and login profiles"
echo "Usage: -c (create database) -u (create user) -h (help)"
}
_error_check(){
#verify success of operation
if [ "$?" != "0" ]; then
echo -e "\033[1;103;95mERROR:Please confirm inputs and try again.\033[0m"
mysql_config_editor remove --login-path=tempsetting
exit 1
fi
}
if [ -f "${DBCONFIG}" ] ; then
echo "DB CONFIG ALREADY EXISTS. PLEASE DELETE OR MOVE TO CONFIGURE NEW DATABASE. EXITING." && exit
fi
#get input for database creation
echo "This script will create the database used for fingerprinting on your localhost."
echo "Please enter root password for mysql:"
mysql_config_editor set --login-path=tempsetting --host=localhost --user=root --password
echo "Please enter name of DB to be created"
read -r DB_NAME
#create database
echo "CREATE DATABASE "$DB_NAME"" | mysql --login-path=tempsetting
_error_check
echo "CREATE TABLE object (objectIdentifierValueID bigint NOT NULL AUTO_INCREMENT,objectIdentifierValue varchar(1000) NOT NULL UNIQUE,objectDB_Insertion datetime NOT NULL DEFAULT NOW(),object_LastTouched datetime NOT NULL,PRIMARY KEY (objectIdentifierValueID))" | mysql --login-path=tempsetting "$DB_NAME"
echo "CREATE TABLE fingerprints (hashNumber bigint NOT NULL AUTO_INCREMENT, objectIdentifierValue varchar(1000) NOT NULL,startframe varchar(100),endframe varchar(100),hash1 varchar(27),hash2 varchar(27),hash3 varchar(27),hash4 varchar(27),hash5 varchar(27),hash6 varchar(27),hash7 varchar(27),hash8 varchar(27),hash9 varchar(27), PRIMARY KEY (hashNumber))" | mysql --login-path=tempsetting "$DB_NAME"
echo "CREATE INDEX hashindex ON fingerprints (hash1(27))" | mysql --login-path=tempsetting "$DB_NAME"
_error_check
#remove root config
mysql_config_editor remove --login-path=tempsetting
#get input for user creation
echo "This will create a user on the fingerprint database"
if [ -z "$DB_NAME" ] ; then
echo "Please enter the name of target database"
read -r DB_NAME
fi
echo "Please enter the name of user to be created"
read -r USER_NAME
echo "Please enter the password for the new user"
read -r USER_PASSWORD
echo "Creating user at localhost"
USER_HOST="localhost"
echo "Please enter mysql root password"
mysql_config_editor set --login-path=tempsetting --host=localhost --user=root --password
#create user
echo "CREATE USER \""$USER_NAME"\"@\""$USER_HOST"\" IDENTIFIED BY \""$USER_PASSWORD"\"" | mysql --login-path=tempsetting
_error_check
echo "GRANT ALL PRIVILEGES ON "$DB_NAME".* TO \""$USER_NAME"\"@\""$USER_HOST"\"" | mysql --login-path=tempsetting
_error_check
echo "FLUSH PRIVILEGES" | mysql --login-path=tempsetting
#show commands to create sql login path
if [ "$USER_HOST" = "localhost" ] ; then
db_host="localhost"
else
db_host=$(ifconfig |grep inet | tail -n1 | cut -d ' ' -f2)
fi
echo -e "\033[1;103;95mTo finalize, run the following command on your user machine. Corresponding settings have been added to the DB config file\033[0m"
echo -e "\033[1;103;95mmysql_config_editor set --login-path="$USER_NAME"_config --host="$db_host" --user="$USER_NAME" --password\033[0m"
echo -e "\033[1;103;95mFollowed by the user password: "$USER_PASSWORD"\033[0m"
#remove root config
mysql_config_editor remove --login-path=tempsetting
echo "DBNAME=\"${DB_NAME}\"" > "${DBCONFIG}"
echo "DBLOGINPATH=\"${USER_NAME}_config\"" >> "${DBCONFIG}"