-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysql.sh
More file actions
55 lines (44 loc) · 1.41 KB
/
mysql.sh
File metadata and controls
55 lines (44 loc) · 1.41 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
#!/bin/bash
START_TIME=$(date +%s)
USERID=$(id -u)
R="\e[31m"
G="\e[32m"
Y="\e[33m"
N="\e[0m"
LOGS_FOLDER="/var/log/roboshop-logs"
SCRIPT_NAME=$(echo $0 | cut -d "." -f1)
LOG_FILE="$LOGS_FOLDER/$SCRIPT_NAME.log"
SCRIPT_DIR=$PWD
mkdir -p $LOGS_FOLDER
echo "Script started executing at: $(date)" | tee -a $LOG_FILE
# check the user has root priveleges or not
if [ $USERID -ne 0 ]
then
echo -e "$R ERROR:: Please run this script with root access $N" | tee -a $LOG_FILE
exit 1 #give other than 0 upto 127
else
echo "You are running with root access" | tee -a $LOG_FILE
fi
echo "Please enter root password to setup"
read -s MYSQL_ROOT_PASSWORD
# validate functions takes input as exit status, what command they tried to install
VALIDATE(){
if [ $1 -eq 0 ]
then
echo -e "$2 is ... $G SUCCESS $N" | tee -a $LOG_FILE
else
echo -e "$2 is ... $R FAILURE $N" | tee -a $LOG_FILE
exit 1
fi
}
dnf install mysql-server -y &>>$LOG_FILE
VALIDATE $? "Installing MySQL server"
systemctl enable mysqld &>>$LOG_FILE
VALIDATE $? "Enabling MySQL"
systemctl start mysqld &>>$LOG_FILE
VALIDATE $? "Starting MySQL"
mysql_secure_installation --set-root-pass $MYSQL_ROOT_PASSWORD &>>$LOG_FILE
VALIDATE $? "Setting MySQL root password"
END_TIME=$(date +%s)
TOTAL_TIME=$(( $END_TIME - $START_TIME ))
echo -e "Script exection completed successfully, $Y time taken: $TOTAL_TIME seconds $N" | tee -a $LOG_FILE