-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstall.sh
201 lines (168 loc) · 6.6 KB
/
install.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/bin/bash
set -u
# Setting text colors
TXT_GRN='\e[0;32m'
TXT_RED='\e[0;31m'
TXT_YLW='\e[0;33m'
TXT_RST='\e[0m'
# Some fancy echoing
_echo_OK()
{
echo -e "${TXT_GRN}OK${TXT_RST}"
}
_echo_FAIL()
{
echo -e "${TXT_RED}FAIL${TXT_RST}"
}
_echo_result()
{
local result=$@
if [[ "$result" -eq 0 ]]; then
_echo_OK
else
_echo_FAIL
exit 1
fi
}
# Detect OS
_detect_os()
{
local issue_file='/etc/issue'
local os_release_file='/etc/os-release'
local redhat_release_file='/etc/redhat-release'
local os=''
# First of all, trying os-relese file
if [ -f $os_release_file ]; then
local name=`grep '^NAME=' $os_release_file | awk -F'[" ]' '{print $2}'`
local version=`grep '^VERSION_ID=' $os_release_file | awk -F'[". ]' '{print $2}'`
os="${name}${version}"
else
# If not, trying redhat-release file (mainly because of bitrix-env)
if [ -f $redhat_release_file ]; then
os=`head -1 /etc/redhat-release | sed -re 's/([A-Za-z]+)[^0-9]*([0-9]+).*$/\1\2/'`
else
# Else, trying issue file
if [ -f $issue_file ]; then
os=`head -1 $issue_file | sed -re 's/([A-Za-z]+)[^0-9]*([0-9]+).*$/\1\2/'`
else
# If none of that files worked, exit
echo -e "${TXT_RED}Cannot detect OS. Exiting now"'!'"${TXT_RST}"
exit 1
fi
fi
fi
echo "${os}"
}
# Warn user that we need ping utility
_check_ping()
{
echo -ne "Testing ping utility... "
if type ping &>/dev/null; then
_echo_OK
else
_echo_FAIL
fi
}
_install()
{
local os=$1
case $os in
Debian[8-9]|Debian1[0-2]|Ubuntu1[6-8]|Ubuntu2[0-4])
echo -ne "Downloading config... "
wget https://raw.githubusercontent.com/FastVPSEestiOu/debian_netconsole/master/netconsole_conf -O /etc/default/netconsole --no-check-certificate -q
_echo_result $?
echo -ne "Downloading systemd service... "
wget https://raw.githubusercontent.com/FastVPSEestiOu/debian_netconsole/master/netconsole.service -O /etc/systemd/system/netconsole.service --no-check-certificate -q
_echo_result $?
echo -ne "Downloading stop-start script... "
wget https://raw.githubusercontent.com/FastVPSEestiOu/debian_netconsole/master/netconsole.sh -O /usr/local/bin/netconsole --no-check-certificate -q
_echo_result $?
echo -ne "Installing net-tools .. "
apt-get update -qq && apt-get install -qq net-tools > /dev/null
_echo_result $?
echo -ne "Performing chmod... "
chmod +x /usr/local/bin/netconsole
_echo_result $?
echo -ne "Performing daemon-reload... "
systemctl daemon-reload
_echo_result $?
echo -ne "Starting netconsole... "
systemctl start netconsole.service
_echo_result $?
echo -ne "Enabling netconsole on boot... "
systemctl -q enable netconsole.service > /dev/null
_echo_result $?
exit 0
;;
Debian7|Ubuntu12|Ubuntu14)
echo -ne "Downloading config... "
wget https://raw.githubusercontent.com/FastVPSEestiOu/debian_netconsole/master/netconsole_conf -O /etc/default/netconsole --no-check-certificate -q
_echo_result $?
echo -ne "Downloading init script... "
wget https://raw.githubusercontent.com/FastVPSEestiOu/debian_netconsole/master/netconsole_sysv -O /etc/init.d/netconsole --no-check-certificate -q
_echo_result $?
echo -ne "Performing chmod... "
chmod +x /etc/init.d/netconsole
_echo_result $?
echo -ne "Installing net-tools .. "
apt-get update -qq && apt-get install -qq net-tools > /dev/null
_echo_result $?
echo -ne "Starting netconsole... "
/etc/init.d/netconsole start > /dev/null
_echo_result $?
echo -ne "Enabling netconsole on boot... "
update-rc.d netconsole defaults > /dev/null
_echo_result $?
exit 0
;;
Debian6)
echo -ne "Downloading config... "
wget https://raw.githubusercontent.com/FastVPSEestiOu/debian_netconsole/master/netconsole_conf -O /etc/default/netconsole --no-check-certificate -q
_echo_result $?
echo -ne "Downloading init script... "
wget https://raw.githubusercontent.com/FastVPSEestiOu/debian_netconsole/master/netconsole_sysv -O /etc/init.d/netconsole --no-check-certificate -q
_echo_result $?
echo -ne "Performing chmod... "
chmod +x /etc/init.d/netconsole
_echo_result $?
echo -ne "Installing net-tools .. "
apt-get update -o Acquire::Check-Valid-Until=false -qq && apt-get install --allow-unauthenticated -qq net-tools > /dev/null
_echo_result $?
echo -ne "Starting netconsole... "
/etc/init.d/netconsole start > /dev/null
_echo_result $?
echo -ne "Enabling netconsole on boot... "
update-rc.d netconsole defaults > /dev/null
_echo_result $?
exit 0
;;
AlmaLinux[8-9]|CentOS[5-8]|Rocky[8-9])
if yum list available netconsole-service &> /dev/null; then
echo -ne "Installing netconsole-service... "
yum install -q -y netconsole-service > /dev/null
_echo_result $?
fi
echo -ne "Setting remote server IP..."
sed -i -e '/^SYSLOGADDR=/d' -e 's|\(# SYSLOGADDR=.*$\)|# SYSLOGADDR=\nSYSLOGADDR=148.251.39.245|g' /etc/sysconfig/netconsole
_echo_result $?
echo -ne "Setting remote server port..."
sed -i -e '/^SYSLOGPORT=/d' -e 's|\(# SYSLOGPORT=.*$\)|\1\nSYSLOGPORT=614|g' /etc/sysconfig/netconsole
_echo_result $?
echo -ne "Starting netconsole... "
service netconsole start > /dev/null
_echo_result $?
echo -ne "Enabling netconsole on boot... "
chkconfig netconsole on > /dev/null
_echo_result $?
exit 0
;;
*)
echo "We can do nothing on $os. Exiting."
exit 1
;;
esac
}
OS=$(_detect_os)
echo -e "OS: ${TXT_YLW}${OS}${TXT_RST}"
_check_ping
_install "$OS"