-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnginx
45 lines (38 loc) · 1.57 KB
/
nginx
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
#!/bin/bash
# This script will build out a basic nginx testing environment.
# To destroy, use nginx-destroy. See below for more information.
DATE=`date +%x`
DAY=$(date '+DATE: %m/%d/%y%tTIME:%H:%M:%S')
LAB='Nginx lab build'
NC='\033[0m' # No Color
GREEN='\033[0;32m'
RED='\033[0;31m'
FILE='/var/log/lab-environment.log'
# This script must be ran as root, check to see if UID matches 0.
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# How we're called...
case "$1" in
build)
( [ -e "$FILE" ] || touch "$FILE" ) && [ ! -w "$FILE" ] && echo cannot write to $FILE && exit 1
echo -e "${RED}$LAB started on $DAY...${NC}" >> $FILE
# Install nginx depending on operating system.
if python -mplatform | grep -iq Ubuntu && apt-get install nginx -y | tee -a $file || yum install nginx -y | tee -a $file ; then
echo -e "${GREEN}Nginx successfully installed.${NC}"
else
echo -e "${RED}Nginx failed to install. Please check package-manger's log and try again.${NC}"
fi
;;
destroy)
( [ -e "$FILE" ] || touch "$FILE" ) && [ ! -w "$FILE" ] && echo cannot write to $FILE && exit 1
echo -e "${RED}$LAB destroy started on $DAY...${NC}" >> $FILE
# Remove nginx depending on operating system.
if python -mplatform | grep -iq Ubuntu && apt-get remove nginx -y | tee -a $FILE || yum remove nginx -y | tee -a $FILE ; then
echo -e "${GREEN}$LAB successfully removed.${NC}"
else
echo -e "${RED}Nginx failed to be removed. Please check package-manger's log and try again.${NC}"
fi
;;
esac