-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path18-readloop.sh
More file actions
54 lines (40 loc) · 1.1 KB
/
18-readloop.sh
File metadata and controls
54 lines (40 loc) · 1.1 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
#!/bin/bash
R="\e[31m"
G="\e[32m"
Y="\e[33m"
B="\e[34m"
N="\e[0m"
USERID=$(id -u)
LOG_FOLDER="/var/log/shellscript-logs"
SCRIPT_NAME=$(echo $0 | cut -d "." -f 1)
LOG_FILE="$LOG_FOLDER/$SCRIPT_NAME.log"
mkdir -p $LOG_FOLDER
if [ $USERID -ne 0 ]
then
echo -e "$R ERROR : Does not have user access $N" | tee -a $LOG_FILE
exit 1
else
echo -e "Its is root access $G Proceed $N " | tee -a $LOG_FILE
fi
#PACKAGEs=( "mysql" "python" "nginx" )
VALIDATE(){
if [ $1 -ne 0 ]
then
echo -e " $2 not successfull installed $R Error pls check $N " | tee -a $LOG_FILE
exit 1
else
echo -e "$2 $G succesfully installed $N" | tee -a $LOG_FILE
fi
}
for package in $@
do
dnf list installed $package &>>$LOG_FILE
if [ $? -ne 0 ]
then
echo -e " $G $package is not installed ..... $Y it is installing $N" | tee -a $LOG_FILE
dnf install $package -y &>>$LOG_FILE
VALIDATE $? "$package"
else
echo -e " $G $package already installed $Y success $B great job $N next" | tee -a $LOG_FILE
fi
done