-
Notifications
You must be signed in to change notification settings - Fork 2
/
install-api-and-configure.sh
executable file
·95 lines (84 loc) · 1.81 KB
/
install-api-and-configure.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
#!/bin/bash
configureEtcd() {
cat > /etc/tendrl/etcd.yml <<EOF
---
:development:
:base_key: ''
:host: '127.0.0.1'
:port: 2379
:user_name: 'username'
:password: 'password'
:test:
:base_key: ''
:host: '127.0.0.1'
:port: 2379
:user_name: 'username'
:password: 'password'
:production:
:base_key: ''
:host: '${APISERVER}'
:port: 2379
:user_name: ''
:password: ''
EOF
}
gethostip() {
local _ip _myip _line _nl=$'\n'
while IFS=$': \t' read -a _line ;do
[ -z "${_line%inet}" ] &&
_ip=${_line[${#_line[1]}>4?1:2]} &&
[ "${_ip#127.0.0.1}" ] && _myip=$_ip
done< <(LANG=C /sbin/ip addr)
printf ${1+-v} $1 "%s${_nl:0:$[${#1}>0?0:1]}" $_myip | cut -f1 -d'/'
}
for i in "$@"
do
case $i in
-p=*|--package=*)
PACKAGE="${i#*=}"
;;
-s=*|--configure=*)
CONFIGURE="${i#*=}"
;;
--default)
DEFAULT=YES
;;
*)
# unknown option
;;
esac
done
echo PACKAGE = ${PACKAGE}
#APISERVER="hostname --ip-address" will work if the name is in DNS
APISERVER=`gethostip`
if ! rpm -qa | grep ${PACKAGE} 2>&1 > /dev/null; then
# api not installed
echo "Installing the package ${PACKAGE} in server ${APISERVER}..."
yum install ${PACKAGE} -y
if [ ! $? -eq 0 ]; then
echo "Failed to install the package!"
exit 0
fi
else
echo "Updating package ${PACKAGE} ..."
# api installed, only update is required
yum update ${PACKAGE} -y
if [ ! $? -eq 0 ]; then
echo "Failed to update the package!"
exit 0
fi
fi
if [[ ${PACKAGE} == *"api"* ]]; then
echo "Configuring etcd ..."
rm -fr /etc/tendrl/etcd.yml
configureEtcd
if [ ! $? -eq 0 ]; then
echo "Etcd configuration failed!"
exit 0
fi
fi
echo "Selinux permissive"
res=$(/usr/sbin/getenforce) || :
if [ "$res" == "Enforcing" ]; then
setenforce 0
fi