-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16-loops.sh
More file actions
47 lines (42 loc) · 1.21 KB
/
16-loops.sh
File metadata and controls
47 lines (42 loc) · 1.21 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
#!/bin/bash
USERID=$(id -u)
R="\e[31m"
G="\e[32m"
Y="\e[33m"
N="\e[0m"
LOGS_FOLDER="/var/log/shellscript-logs"
SCRIPT_NAME=$(echo $0 | cut -d "." -f1)
LOG_FILE="$LOGS_FOLDER/$SCRIPT_NAME.log"
PACKAGES=("mysql" "python" "nginx" "httpd")
mkdir -p $LOGS_FOLDER
echo "Script started executing at: $(date)" | tee -a $LOG_FILE
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
# validate functions takes input as exit status, what command they tried to install
VALIDATE(){
if [ $1 -eq 0 ]
then
echo -e "Installing $2 is ... $G SUCCESS $N" | tee -a $LOG_FILE
else
echo -e "Installing $2 is ... $R FAILURE $N" | tee -a $LOG_FILE
exit 1
fi
}
#for package in ${PACKAGES[@]}
for package in $@
do
dnf list installed $package &>>$LOG_FILE
if [ $? -ne 0 ]
then
echo "$package is not installed... going to install it" | tee -a $LOG_FILE
dnf install $package -y &>>$LOG_FILE
VALIDATE $? "$package"
else
echo -e "Nothing to do $package... $Y already installed $N" | tee -a $LOG_FILE
fi
done