-
Notifications
You must be signed in to change notification settings - Fork 5
/
install
executable file
·238 lines (206 loc) · 5.46 KB
/
install
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#!/bin/bash
# Debug
#set -x
#set -u
#set -e
#exec 1>${TOP_DIR}/stdout.log
#exec 2>${TOP_DIR}/stderr.log
# Version
readonly VER='2.1.1'
if [ $1 = '-v' ] 2>/dev/null;then
echo Moss-${VER}
exit 0
fi
## Reboot Flag
NEED_REBOOT=0
## Global Readonly Variables
## !!! DO NOT Modify These Settings !!!
readonly TOP_DIR="$(cd $(dirname $0);pwd)"
readonly DATE=$(date +%Y%m%d-%H-%M)
readonly ARCH=$(uname -i)
readonly OS_ISSUE=$(head -n 1 /etc/issue | awk '{print $1}')
readonly OS_VER=$(awk '$1~/CentOS/{print $3}' /etc/issue | cut -d. -f1)
readonly STORE_DIR="${TOP_DIR}/src"
readonly INST_LOG="/var/log/moss.log"
readonly CHECK_MD5=1
readonly PATH='/usr/bin:/bin:/usr/sbin:/sbin'
## Shell Environment
export PATH
alias cp='cp'
alias mv='mv'
alias rm='rm'
alias grep='grep --color'
## Include common functions
source ${TOP_DIR}/common/functions.sh
## Check Privilege
[ $(id -u) -ne 0 ] && fail_msg "You must be root!"
## Check Architecture
[ "$ARCH" != 'x86_64' ] && fail_msg "Moss didn't support $ARCH, please install x86_64!"
## Check OS
[ "${OS_ISSUE}" != 'CentOS' ] && fail_msg "Moss can be installed on CentOS release only!\nYour release is ${OS_ISSUE}"
[ "${OS_VER}" -lt 6 ] && fail_msg "Moss require CentOS 6 or above!\nYour release is ${OS_ISSUE}"
## Check Moss Configuration File
if [ ! -f "${TOP_DIR}/etc/moss.conf" ];then
fail_msg "${TOP_DIR}/etc/moss.conf is not found!"
fi
## Weclcome
clear
cat ${TOP_DIR}/etc/banner
succ_msg "Welcome to Moss ${VER}\n"
succ_msg "Moss ia a Linux WEB application environment deployment system."
succ_msg "You need to edit ${TOP_DIR}/etc/moss.conf to modify some settings.\n"
succ_msg "Author: Nanu"
succ_msg "Contact: nanu@inanu.net"
succ_msg "Website: https://github.com/leonanu/moss/\n"
## Moss Options
warn_msg "Please Select Moss Installation Option "
warn_msg "================================================"
warn_msg "1 - Initial & optimize CentOS system only;"
warn_msg "2 - Install Nginx web server standalone;"
warn_msg "3 - Install Nginx web server and PHP FastCGI;"
warn_msg "4 - Install MySQL database server;"
warn_msg "5 - Install Redis NoSQL database;"
warn_msg "6 - Install Zabbix agent;"
warn_msg "7 - Install NTP server;"
warn_msg "u - Uninstall Moss;"
warn_msg "q - Quit Installation;"
warn_msg "================================================\n"
MOSS_OPT=1
read -p "Select an Install Option:" MOSS_OPT
## Import Moss Settings
source ${TOP_DIR}/etc/moss.conf 2>/dev/null
## Import Hardware Information
source ${TOP_DIR}/common/hwinfo.sh 2>/dev/null
## Check Install Directory
[ ! -d ${INST_DIR} ] && mkdir -m 0755 -p ${INST_DIR}
## Check Moss log file
[ ! -f ${INST_LOG} ] && touch ${INST_LOG}
chmod 600 ${INST_LOG}
## Check Moss security Directory
[ ! -d '/root/.moss' ] && mkdir -m 0700 -p /root/.moss
## Check wget command
if ! grep '^YUM_WGET' ${INST_LOG} > /dev/null 2>&1 ;then
yum install -y wget || fail_msg "Install wget Failed!"
## log installed tag
echo 'YUM_WGET' >> ${INST_LOG}
fi
## Install development libs
install_rpm () {
source ${TOP_DIR}/common/install_rpm.sh
}
## Config System
sysconfig () {
source ${TOP_DIR}/common/root.pub.sh
source ${TOP_DIR}/common/config_sys.sh
}
## Build development library
install_libs () {
echo ''
}
## Nginx
web () {
source ${TOP_DIR}/compile/nginx.sh
}
### PHP
php () {
source ${TOP_DIR}/compile/php.sh
if [ $ISREDIS -eq 1 ];then
source ${TOP_DIR}/compile/pecl_redis.sh
fi
}
## MySQL
db () {
source ${TOP_DIR}/compile/mysql.sh
source ${TOP_DIR}/compile/percona-xtrabackup.sh
}
## NoSQL
nosql () {
source ${TOP_DIR}/compile/redis.sh
}
## Zabbix Agent
zagent () {
source ${TOP_DIR}/compile/zabbix_agent.sh
}
## NTP Server
ntp () {
source ${TOP_DIR}/common/ntpd.sh
}
## Uninstall
uninstall () {
source ${TOP_DIR}/common/uninstall.sh
}
case "${MOSS_OPT}" in
1) # Init
install_rpm
sysconfig
;;
2) # WEB Server Only
get_pkginfo
install_rpm
sysconfig
web
;;
3) # WEB + PHP
get_pkginfo
install_rpm
sysconfig
install_libs
web
php
;;
4) # MySQL
get_pkginfo
install_rpm
sysconfig
db
;;
5) # NoSQL
get_pkginfo
install_rpm
sysconfig
nosql
;;
6) # Zabbix Agent
[ -z ${ZABBIX_SERVER_IP} ] && fail_msg "You MUST set ZABBIX_SERVER_IP in ${TOP_DIR}/etc/moss.conf!"
get_pkginfo
install_rpm
sysconfig
zagent
;;
7) # NTP install_rpm
sysconfig
ntp
;;
u) # Uninstall
uninstall
;;
q) # Quit
exit 0
;;
*) # Invalid
fail_msg "You specifid an invalid option!\n"
;;
esac
if [ ${MOSS_OPT} = 'u' ];then
succ_msg '=================================='
succ_msg '= Moss Uninstalled Successfully! ='
succ_msg '=================================='
else
warn_msg '*DO NOT* delete Moss installation directory!'
warn_msg 'Otherwise, you will not be able to uninstall!'
warn_msg 'or UPDATE Moss in the future!'
succ_msg '================================'
succ_msg '= Moss Installed Successfully! ='
succ_msg '================================'
fi
if [ ${NEED_REBOOT} -eq 1 2>/dev/null ];then
warn_msg 'System needs reboot to apply changes.'
y_or_n 'Reboot Now?' 'y'
REBOOT_SYS=${USER_INPUT}
if [ "${REBOOT_SYS}" = 'y' ];then
init 6
fi
fi
## Close I/O redirection
#exec 1>&-
#exec 2>&-