-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathequip.sh
188 lines (149 loc) · 4.51 KB
/
equip.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
#!/bin/sh
# Equip script wrapper
# Author: Brian Lee <[email protected]>, GitHub Username: brian-dlee
# Licence: MIT
# To run, see https://github.com/brian-dlee/centos-equip
EQUIP_LOCATION=$(cd $(dirname $0) && pwd)
EQUIP_OPT_FORCE_UPDATE=0
GITHUB_ROOT="https://github.com/brian-dlee/centos-equip"
GITHUB_URL="${GITHUB_ROOT}/raw/master"
which 1>&2 2>/dev/null
if [[ ${?} == 127 ]]; then
yum install -y -q which 2>/dev/null
if [[ ${?} != 0 ]]; then
echo >&2 "The package 'which' could not be installed. Install 'which' and rerun."
exit 1
fi
fi
WGET_CMD=$(which wget 2>/dev/null)
WGET_OPTS="--quiet --no-check-certificate"
export EQUIP_SELINUX_ENABLED=0
export EQUIP_FIREWALL_ENABLED=0
sestatus 1>&2 2>/dev/null
if [[ ${?} != 127 && -z $(sestatus | egrep 'SELinux status:\s+disabled') ]]; then
export EQUIP_SELINUX_ENABLED=1
fi
firewall-cmd 1>&2 2>/dev/null
if [[ ${?} != 127 && -n $(systemctl --all | grep 'firewalld.service') ]]; then
export EQUIP_FIREWALL_ENABLED=1
fi
# Make sure only root can run our script
if [[ ${EUID} -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
if [[ -z ${WGET_CMD} ]]; then
yum install -y -q wget 2>/dev/null
WGET_CMD=$(which wget 2>/dev/null)
if [[ ${?} != 0 ]]; then
echo >&2 "The package 'wget' could not be installed. Install 'wget' and rerun."
exit 1
fi
fi
function collapseComponents {
list=($1)
shift
while [[ ! -z ${1} ]]; do
if [[ $(echo ${list[@]} | grep -v "${1}") ]]; then
list+=("${1}")
fi
shift
done
echo ${list[@]}
}
function runInstallScript {
if [[ -n $(echo ${skips[@]} | grep "${1}") ]]; then
echo "Skipping installation of ${1}."
return 0
fi
echo "Running installation for '${1}'"
component=${1}
args=""
if [[ $(echo ${component} | grep ':') ]]; then
parts=($(echo ${component} | sed -r 's/:/ /g'))
component=${parts[0]}
args=${parts[@]:1}
fi
script_destination="${EQUIP_LOCATION}/equip_${component}.sh"
found_component_script=0
if [[ ! -e ${script_destination} || ${EQUIP_OPT_FORCE_UPDATE} == 1 ]]; then
if [[ -e ${script_destination} ]]; then
found_component_script=1
fi
${WGET_CMD} -P ${EQUIP_LOCATION} ${GITHUB_URL}/equip_${component}.sh
else
echo "Found existing component script. Executing ${script_destination}."
found_component_script=1
fi
bash --login ${script_destination} ${args[@]}
result=${?}
if [[ -e equip_${component}.sh && ! ${found_component_script} ]]; then
rm -f equip_${component}.sh
fi
if [[ ${result} != 0 ]]; then
echo >&2 "Failed install for '${1}'";
return 1
else
echo "Successfully ran installation for '${1}'"
return 0
fi
}
function showUsage {
echo "Usage: equip.sh [OPTIONS] [COMPONENTS]"
echo " -d --disable-base: Prevent execution of equip_base.sh (by default this always runs)"
echo " -u --force-update: The default is to use local component installation scripts if possible, this prevents it"
echo " -h --help: Shows this usage dialog"
}
components=('base')
skips=()
if [[ ${#} == 0 ]]; then
echo "No components provided."
echo "For usage, see ${GITHUB_ROOT}."
exit 1
fi
while [[ ${#} > 0 ]]; do
case ${1} in
base);;
bamboo-remote-agent:*)
components+=("java:8 ${1}")
;;
java|java:7)
components+=("java:7");;
java:8)
components+=("java:8");;
maven|maven:3)
components+=("java:7" "maven:3");;
tomcat|tomcat:7)
components+=("java:7" "tomcat:7");;
tomcat:8)
components+=("java:7" "tomcat:8");;
--disable-base|-d)
skips+=("base");;
--force-update|-u)
EQUIP_OPT_FORCE_UPDATE=1;;
--skip=*)
skips+=("${1#*=}");;
-s)
shift
skips+=("${1}");;
--help|-h)
showUsage
exit 0
;;
*)
echo >&2 "Unknown installation request: '${1}'"
exit 2
;;
esac
shift
done
skips=($(collapseComponents ${skips[@]}))
components=($(collapseComponents ${components[@]}))
yum update -y -q
for component in ${components[@]}; do
runInstallScript ${component}
if [[ ${?} != 0 ]]; then
echo "Exiting due to failed component installations."
exit 3
fi
done