-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSql.sh
95 lines (82 loc) · 2.18 KB
/
Sql.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/sh
# Download|Create|import Database#
# By Github/Saleh7 #
E=`tput setaf 1`
G=`tput setaf 2`
A=`tput setaf 3`
C=`tput setaf 6`
B=`tput bold`
R=`tput sgr0`
help() {
echo "
Use: Sql.sh ${E}[OPTION]${R}
-u, --username Enter the Username
-p, --password Enter the Password
-n, --namesql Enter the Name Sql
-c, --urlsql Enter the URL Sql
${C}Example:${R}${G} sudo bash Sql.sh${R} -u root -p saleh -n datab -c https://gist.github.com
"
}
while [ "$1" != "" ]; do
case "$1" in
-u | --username ) user=$2;shift 2;;
-p | --password ) pass=$2;shift 2;;
-n | --namesql ) sql=$2;shift 2;;
-c | --urlsql ) urlsql=$2;shift 2;;
-h | --help ) echo "$(help)";
exit;shift;break;;
esac
done
if [ -z "$user" ]
then
echo "+--------------------------+"
echo "|${b}${A}Enter the Username(root): ${R}|"
echo "+--------------------------+"
read input_Username
user="$input_Username"
fi
if [ -z "$pass" ]
then
echo "+--------------------------+"
echo "|${b}${A}Enter the Password(saleh):${R}|"
echo "+--------------------------+"
read input_Password
pass="$input_Password"
fi
if [ -z "$sql" ]
then
echo "+--------------------------+"
echo "|${b}${A}Enter the Name Sql(datab):${R}|"
echo "+--------------------------+"
read input_Sql
sql="$input_Sql"
fi
if [ -z "$urlsql" ]
then
echo "+--------------------------+"
echo "|${b}${A}Enter the URL Sql ( URL ):${R}|"
echo "+--------------------------+"
read input_URL
urlsql="$input_URL"
fi
# Clear
echo -en "\ec"
# Running
echo "${b}${A}Running Sql.sh...${R}"
echo "+--------------------------+"
echo "| Update apt-get |"
echo "+--------------------------+"
apt-get update
# Clear
echo -en "\ec"
echo "+--------------------------+"
echo "| Download database |"
echo "+--------------------------+"
git clone $urlsql $sql
echo "+--------------------------+"
echo "| Create database |"
echo "+--------------------------+"
echo "create database $sql" | mysql --user=$user --password=$pass
mysql --user=$user --password=$pass $sql < $sql/$sql.sql
echo "${b}${A}done${R}"
exit 0