-
Notifications
You must be signed in to change notification settings - Fork 24
/
mysql.sh
58 lines (38 loc) · 1.11 KB
/
mysql.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
#!/bin/bash
ID=$(id -u)
R="\e[31m"
G="\e[32m"
Y="\e[33m"
N="\e[0m"
MONGDB_HOST=mongodb.daws76s.online
TIMESTAMP=$(date +%F-%H-%M-%S)
LOGFILE="/tmp/$0-$TIMESTAMP.log"
echo "script stareted executing at $TIMESTAMP" &>> $LOGFILE
VALIDATE(){
if [ $1 -ne 0 ]
then
echo -e "$2 ... $R FAILED $N"
exit 1
else
echo -e "$2 ... $G SUCCESS $N"
fi
}
if [ $ID -ne 0 ]
then
echo -e "$R ERROR:: Please run this script with root access $N"
exit 1 # you can give other than 0
else
echo "You are root user"
fi # fi means reverse of if, indicating condition end
dnf module disable mysql -y &>> $LOGFILE
VALIDATE $? "Disable current MySQL version"
cp mysql.repo /etc/yum.repos.d/mysql.repo &>> $LOGFILE
VALIDATE $? "Copied MySQl repo"
dnf install mysql-community-server -y &>> $LOGFILE
VALIDATE $? "Installing MySQL Server"
systemctl enable mysqld &>> $LOGFILE
VALIDATE $? "Enabling MySQL Server"
systemctl start mysqld &>> $LOGFILE
VALIDATE $? "Starting MySQL Server"
mysql_secure_installation --set-root-pass RoboShop@1 &>> $LOGFILE
VALIDATE $? "Setting MySQL root password"