Newer
Older
#
# Copyright (C) 2019 OX Software GmbH
#
# This file is part of OX Automation.
#
# OX Automation is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OX Automation is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OX Automation. If not, see <http://www.gnu.org/licenses/>.
#
#
# Authors:
# Benedikt Kroening <benedikt.kroening@open-xchange.com>
#
# This restarts the provided service name with the configured service managers
function restartService {
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
239
240
241
242
243
244
245
246
247
if [[ "${INSTALL_TYPE}" != "docker" ]]; then
if [[ "${DIST}" == "SLES12" ]] || [[ "${DIST}" == "RHEL7" ]]; then
systemctl restart $1.service
else
service $1 restart
fi
else
#echo "ERROR: Not possible to determine installation type, could not restart service $1"
supvervisorctl restart $1
fi
}
function detectDistribution {
if [[ -f /etc/debian_version ]]; then
REV=$(cat /etc/debian_version)
if [[ "${REV}" == "9."* ]]; then
DIST="DebianStretch"
ANY_DEB=true
MARIADB=true
ADDITIONAL_PACKAGES="mariadb-server"
HTTPD="apache2"
HTTPD_CONF_PATH=/etc/${HTTPD}/conf-enabled/
HTTPD_SITES_PATH=/etc/${HTTPD}/sites-enabled/
HTTPD_WWWROOT_PATH=/var/www/html
HTTPD_LOG_PATH=\$\{APACHE_LOG_DIR\}
HTTPD_TLS_CIPHERS='ECDH+AESGCM:ECDH+AES256:ECDH+AES128:!aNULL'
HTTPD_TLS_PROTOCOLS='-all +TLSv1 +TLSv1.1 +TLSv1.2'
HTTPD_TLS_CRT=/etc/ssl/certs/ssl-cert-snakeoil.pem
HTTPD_TLS_KEY=/etc/ssl/private/ssl-cert-snakeoil.key
DISTRO="DebianStretch"
COMPATIBLE=true
fi
elif [[ -f /etc/SuSE-release ]]; then
# Installing wget to get buildkeys
zypper -n up
zypper -n in wget
DIST=$(tr "\n" ' ' < /etc/SuSE-release | sed s/VERSION.*//)
SLES_PATCHLEVEL=$(cat /etc/SuSE-release | grep PATCHLEVEL)
if [[ "${DIST}" == "SUSE Linux Enterprise Server 12"* ]] && [[ "${SLES_PATCHLEVEL}" != "PATCHLEVEL = 0" ]]; then
DIST="SLES12"
ANY_RPM=true
ANY_SLES=true
ADDITIONAL_PACKAGES="mariadb"
HTTPD="apache2"
HTTPD_CONF_PATH=/etc/${HTTPD}/conf.d/
HTTPD_SITES_PATH=/etc/${HTTPD}/conf.d/
HTTPD_WWWROOT_PATH=/srv/www/htdocs
HTTPD_LOG_PATH=/var/log/apache2
HTTPD_TLS_CIPHERS='ECDH+AESGCM:ECDH+AES256:ECDH+AES128:!aNULL'
HTTPD_TLS_PROTOCOLS='-all +TLSv1 +TLSv1.1 +TLSv1.2'
HTTPD_TLS_CRT=/etc/apache2/ssl.crt/server.crt
HTTPD_TLS_KEY=/etc/apache2/ssl.key/server.key
DISTRO="SLE_12"
COMPATIBLE=true
fi
elif [[ -f /etc/redhat-release ]]; then
REV=$(sed s/.*Red\ Hat\ Enterprise\ Linux\ Server\ release\ // < /etc/redhat-release | sed s/\ .*//)
if [[ "${REV}" == "6."* ]]; then
DIST="RHEL6"
ANY_RPM=true
ANY_RHEL=true
MARIADB=true
ADDITIONAL_PACKAGES="MariaDB-server"
HTTPD="httpd"
HTTPD_CONF_PATH=/etc/${HTTPD}/conf.d/
HTTPD_SITES_PATH=/etc/${HTTPD}/conf.d/
HTTPD_WWWROOT_PATH=/var/www/html
HTTPD_LOG_PATH=logs
HTTPD_TLS_CIPHERS='ECDH+AESGCM:ECDH+AES256:ECDH+AES128:!aNULL'
HTTPD_TLS_PROTOCOLS='-all +TLSv1 +TLSv1.1 +TLSv1.2'
HTTPD_TLS_CRT=/etc/pki/tls/certs/localhost.crt
HTTPD_TLS_KEY=/etc/pki/tls/private/localhost.key
DISTRO="RHEL6"
COMPATIBLE=true
elif [[ "${REV}" == "7."* ]]; then
DIST="RHEL7"
ANY_RPM=true
ANY_RHEL=true
ADDITIONAL_PACKAGES="mariadb-server"
HTTPD="httpd"
HTTPD_CONF_PATH=/etc/${HTTPD}/conf.d/
HTTPD_SITES_PATH=/etc/${HTTPD}/conf.d/
HTTPD_WWWROOT_PATH=/var/www/html
HTTPD_LOG_PATH=logs
HTTPD_TLS_CIPHERS='ECDH+AESGCM:ECDH+AES256:ECDH+AES128:!aNULL'
HTTPD_TLS_PROTOCOLS='-all +TLSv1 +TLSv1.1 +TLSv1.2'
HTTPD_TLS_CRT=/etc/pki/tls/certs/localhost.crt
HTTPD_TLS_KEY=/etc/pki/tls/private/localhost.key
DISTRO="RHEL7"
COMPATIBLE=true
fi
REV=$(sed s/.*CentOS\ release\ // < /etc/redhat-release | sed s/\ .*//)
if [[ "${REV}" == "6."* ]]; then
DIST="CENTOS6"
ANY_RPM=true
ANY_CENTOS=true
MARIADB=true
ADDITIONAL_PACKAGES="MariaDB-server"
HTTPD="httpd"
HTTPD_CONF_PATH=/etc/${HTTPD}/conf.d/
HTTPD_SITES_PATH=/etc/${HTTPD}/conf.d/
HTTPD_WWWROOT_PATH=/var/www/html
HTTPD_LOG_PATH=logs
HTTPD_TLS_CIPHERS='ECDH+AESGCM:ECDH+AES256:ECDH+AES128:!aNULL'
HTTPD_TLS_PROTOCOLS='-all +TLSv1 +TLSv1.1 +TLSv1.2'
HTTPD_TLS_CRT=/etc/pki/tls/certs/localhost.crt
HTTPD_TLS_KEY=/etc/pki/tls/private/localhost.key
DISTRO="RHEL6"
COMPATIBLE=true
fi
REV=$(sed s/.*CentOS\ Linux\ release\ // < /etc/redhat-release | sed s/\ .*//)
if [[ "${REV}" == "7."* ]]; then
DIST="CENTOS7"
ANY_RPM=true
ANY_CENTOS=true
MARIADB=true
ADDITIONAL_PACKAGES="mariadb-server"
HTTPD="httpd"
HTTPD_CONF_PATH=/etc/${HTTPD}/conf.d/
HTTPD_SITES_PATH=/etc/${HTTPD}/conf.d/
HTTPD_WWWROOT_PATH=/var/www/html
HTTPD_LOG_PATH=logs
HTTPD_TLS_CIPHERS='ECDH+AESGCM:ECDH+AES256:ECDH+AES128:!aNULL'
HTTPD_TLS_PROTOCOLS='-all +TLSv1 +TLSv1.1 +TLSv1.2'
HTTPD_TLS_CRT=/etc/pki/tls/certs/localhost.crt
HTTPD_TLS_KEY=/etc/pki/tls/private/localhost.key
DISTRO="RHEL7"
COMPATIBLE=true
fi
elif [[ -f /etc/os-release ]]; then
declare -A OSRELEASE
while IFS='=' read -r col1 col2
do
OSRELEASE[$col1]="${col2//\"/}"
done </etc/os-release
if [[ ${OSRELEASE[ID]} == amzn && ${OSRELEASE[VERSION_ID]} == 2 ]]
then
# Amazon Linux 2
DIST="RHEL7"
ANY_RPM=true
ANY_RHEL=true
ADDITIONAL_PACKAGES="mariadb-server"
HTTPD="httpd"
HTTPD_CONF_PATH=/etc/${HTTPD}/conf.d/
HTTPD_SITES_PATH=/etc/${HTTPD}/conf.d/
HTTPD_WWWROOT_PATH=/var/www/html
HTTPD_LOG_PATH=logs
HTTPD_TLS_CIPHERS='ECDH+AESGCM:ECDH+AES256:ECDH+AES128:!aNULL'
HTTPD_TLS_PROTOCOLS='-all +TLSv1 +TLSv1.1 +TLSv1.2'
HTTPD_TLS_CRT=/etc/pki/tls/certs/localhost.crt
HTTPD_TLS_KEY=/etc/pki/tls/private/localhost.key
DISTRO="RHEL7"
COMPATIBLE=true
fi
fi
if [[ "${COMPATIBLE}" != true ]]; then
echo "unknown."
echo ""
echo "Supported platforms:"
echo "* Debian GNU/Linux 9 (Stretch)"
echo "* Novell SuSE Linux Enterprise Server 12 (SLES12) >= SP1"
echo "* RedHat Enterprise Linux 6 (RHEL6)"
echo "* RedHat Enterprise Linux 7 (RHEL7)"
echo "* Amazon Linux 2"
echo "* CentOS 6"
echo "* CentOS 7"
exit 1
fi
}
function checkRootPrivileges {
echo -n "Checking user..."
if [[ $(whoami) != "root" ]]; then
echo "Failed."
echo "Please run this script as superuser (root)."
exit 1
else
echo "OK."
fi
}
function setOXProperty {
# key value file
if [ ! -f /opt/open-xchange/lib/oxfunctions.sh ]; then
echo "ERROR: oxfunctions.sh file does not exist"
exit 1
fi
source /opt/open-xchange/lib/oxfunctions.sh
if [ ! -f $3 ]; then
echo "File $3 does not exist ... creating ..."
touch $3
fi
echo "Setting ox property: $@"
ox_set_property "$@"
}
function waitPort {
echo "Waiting for port $2 on host $1 ..."
while ! nc -z $1 $2; do
sleep 1
echo ". "
done
echo "Port available"
}
function exportProperties {
#echo "Trying to export variables from $1 ..."
# if [ ! -f "$1" ]; then
# echo "ERROR: Given properties file does not exist"
# exit 1
# fi
# val=$(grep -v '^#' "$1" | xargs)
# export $(eval ${val})
if [ -f "$1" ]
then
echo "$1 found."
while IFS='=' read -r key value
do
if [[ $key != \#* ]] && [[ -n $key ]] ; then
export $key=$(eval echo "$value")
fi
done < "$1"
else
echo "$1 not found."