-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinit-script.sh
115 lines (93 loc) · 2.94 KB
/
init-script.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
if [ -f /etc/allset ]; then
echo "All Set .. Skipping"
exit
fi
Print() {
case $3 in
B) COL="\e[34m" ;;
G) COL="\e[32m" ;;
Y) COL="\e[33m" ;;
R) COL="\e[31m" ;;
esac
if [ "$1" = SL ]; then
echo -n -e "$COL$2\e[0m"
elif [ "$1" = NL ]; then
echo -e "$COL$2\e[0m"
else
echo -e "$COL$2\e[0m"
fi
}
SELINUX() {
Print "SL" "=>> Checking SELINUX.. " "B"
S=$(sestatus |grep 'SELinux status' |awk '{print $NF}')
if [ "$S" = "enabled" ]; then
Print "NL" "Enabled.." "R"
Print "SL" "+>> Disabling SELINUX.." B
sed -i -e '/^SELINUX/ c SELINUX=disabled' /etc/selinux/config
Print "NL" "Success" G
rreq=yes
else
Print NL "Disabled" G
fi
}
PACK() {
Print SL "=>> Installing base Packages.. " B
yum install wget bzip2 zip unzip gzip vim net-tools facter git -y &>/dev/null
Print NL Success G
}
LENV() {
Print SL "=>> Setting Enviornment.. " B
sed -i -e '/TCPKeepAlive/ c TCPKeepAlive yes' -e '/ClientAliveInterval/ c ClientAliveInterval 10' /etc/ssh/sshd_config
curl https://raw.githubusercontent.com/linuxautomations/scripts/master/ps1.sh > /etc/profile.d/ps1.sh 2>/dev/null
chmod +x /etc/profile.d/ps1.sh
curl -s https://raw.githubusercontent.com/linuxautomations/scripts/master/devops-env.sh >/etc/profile.d/devops-env.sh
curl https://raw.githubusercontent.com/linuxautomations/scripts/master/idle.sh -o /boot/idle.sh &>/dev/null
chmod +x /boot/idle.sh
sed -i -e '/idle/ d' /var/spool/cron/root &>/dev/null
echo "*/10 * * * * sh -x /boot/idle.sh &>/tmp/idle.out" >/var/spool/cron/root
chmod 600 /var/spool/cron/root
echo -e "LANG=en_US.utf-8\nLC_ALL=en_US.utf-8" >/etc/environment
Print NL Success G
wget https://raw.githubusercontent.com/carreerit/altus/master/enable-password-auth.sh -O /sbin/enable-password-auth.sh &>/dev/null
chmod +x /sbin/enable-password-auth.sh
wget https://raw.githubusercontent.com/linuxautomations/labautomation/master/labauto -O /sbin/labauto &>/dev/null
chmod +x /sbin/labauto
}
if [ `id -u` -ne 0 ]; then
Print "NL" "You Should be root user to perform this Script" R
exit 2
fi
if [ $(rpm -qa |grep ^base |awk -F . '{print $(NF-1)}') = "el6" ]; then
SELINUX
Print "SL" "=>> Disabling Firewall.. " "B"
service iptables stop &>/dev/null && service ip6tables stop &>/dev/null && chkconfig iptables off && chkconfig ip6tables off
if [ $? -eq 0 ]; then
Print NL Success G
else
Print NL Failure R
fi
LENV
PACK
if [ "$rreq" = "yes" ]; then
Print "NL" "Rebooting Server.. Try to connect back in 15 sec" R
reboot
fi
Print NL "Run of Init Script .. Completed.. System is ready to use" B
exit 0
fi
SELINUX
Print "SL" "=>> Disabling Firewall.. " "B"
systemctl disable firewalld &>/dev/null
if [ $? -eq 0 ]; then
Print NL Success G
else
Print NL Failure R
fi
PACK
LENV
if [ "$rreq" = "yes" ]; then
Print "NL" "Rebooting Server.. Try to connect back in 15 sec" R
reboot
fi
Print NL "Run of Init Script .. Completed.. System is ready to use" B