summaryrefslogtreecommitdiffstats
path: root/build/gmg-install.sh
blob: 58491f5c81322933104d68eb068abbc7f7ef6c0a (plain)
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
#!/bin/bash

#------------------------------------------------------------------
# Copyright (c) 2006-2011 Gluster, Inc. <http://www.gluster.com>
# This file is part of Gluster Management Gateway.
#
# Gluster Management Gateway 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.
#
# Gluster Management Gateway 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 this program.  If not, see
# <http://www.gnu.org/licenses/>.
#------------------------------------------------------------------

# Variables
GMG_LOG_DIR="/var/log/glustermg";
GMG_ROOT_DIR="/opt/glustermg"
GMG_KEYS_DIR="${GMG_ROOT_DIR}/keys"
GMG_ETC_DIR="${GMG_ROOT_DIR}/etc"
USAGE_ERR=1
TOMCAT_ERR=2
JAVA_ERR=3
TAR_ERR=4

function quit()
{
	echo ${1}
	echo
	exit ${2} 
} 

function post_install()
{
    if [ ! -f /etc/init.d/$TOMCAT_BIN ]; then
		echo "All operations completed. Please restart tomcat."
    else
		echo "Re-starting [${TOMCAT_BIN}].."
		service $TOMCAT_BIN restart;
    fi
	echo
}

function create_links()
{
	if [ -f ${WEBAPPS_DIR}/glustermg ]; then
    	rm -f ${WEBAPPS_DIR}/glustermg
	fi
	ln -fs ${GMG_HOME_DIR}/glustermg ${WEBAPPS_DIR}

	GMG_SCRIPTS_DIR="${GMG_HOME_DIR}/glustermg/scripts"
    ln -sf ${GMG_SCRIPTS_DIR}/grun.py /usr/bin/grun.py
    ln -sf ${GMG_SCRIPTS_DIR}/add_user_cifs_all.py /usr/sbin/add_user_cifs_all.py
    ln -sf ${GMG_SCRIPTS_DIR}/delete_user_cifs_all.py /usr/sbin/delete_user_cifs_all.py
    ln -sf ${GMG_SCRIPTS_DIR}/setup_cifs_config_all.py /usr/sbin/setup_cifs_config_all.py
    ln -sf ${GMG_SCRIPTS_DIR}/gmg-reset-password.sh /usr/sbin/gmg-reset-password.sh
}

# Update tomcat sysconfig file with java options
function set_java_options()
{
	TOMCAT_CONFIG_FILE="/etc/sysconfig/$TOMCAT_BIN"
	if [ -f ${TOMCAT_CONFIG_FILE} ]; then
    	if ! grep -q '^JAVA_HOME="/usr/lib/jvm/jre-1.6.0-openjdk.x86_64"' ${TOMCAT_CONFIG_FILE}; then
			sed -i 's/^JAVA_HOME=/# JAVA_HOME=/g' ${TOMCAT_CONFIG_FILE}
			echo 'JAVA_HOME="/usr/lib/jvm/jre-1.6.0-openjdk.x86_64"' >> ${TOMCAT_CONFIG_FILE}
    	fi
	
    	if ! grep -q '# Added by Gluster: JAVA_OPTS="${JAVA_OPTS} -Xms1024m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=256m"' ${TOMCAT_CONFIG_FILE}; then
			echo '# Added by Gluster: JAVA_OPTS="${JAVA_OPTS} -Xms1024m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=256m"' >> ${TOMCAT_CONFIG_FILE}
			echo 'JAVA_OPTS="${JAVA_OPTS} -Xms1024m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=256m"' >> ${TOMCAT_CONFIG_FILE}
    	fi
	fi
}

function configure_ssl()
{
	TOMCAT_SERVER_CONFIG_FILE=${TOMCAT_DIR}/conf/server.xml
	SSL_KEYSTORE_FILE=${WEBAPPS_DIR}/glustermg/ssl/gmg-ssl.keystore
    if ! grep -q ${SSL_KEYSTORE_FILE} ${TOMCAT_SERVER_CONFIG_FILE}; then
		sed -i '/<\/Service>/i \
    	<Connector SSLEnabled="true" \
               clientAuth="false" \
               executor="tomcatThreadPool" \
               maxThreads="150" \
               port="8443" \
               keystoreFile="$TOMCAT_DIR/webapps/glustermg/ssl/gmg-ssl.keystore" \
               keystorePass="gluster" \
               protocol="org.apache.coyote.http11.Http11Protocol" \
               scheme="https" \
               secure="true" \
               sslProtocol="TLS" />' ${TOMCAT_SERVER_CONFIG_FILE}
		sed -i "s,keystoreFile=\"\$TOMCAT_DIR/webapps/glustermg/ssl/gmg-ssl.keystore\",keystoreFile=\"${SSL_KEYSTORE_FILE}\"," ${TOMCAT_SERVER_CONFIG_FILE}
    fi
}

function enable_proxy_caching()
{
    if ! grep -q "org.apache.catalina.authenticator.NonLoginAuthenticator" $TOMCAT_DIR/conf/context.xml; then
		sed -i '/<\/Context>/i \
    	<Valve className="org.apache.catalina.authenticator.NonLoginAuthenticator" \
           	disableProxyCaching="false" />' $TOMCAT_DIR/conf/context.xml
    fi
}

function configure_server()
{
	set_java_options
	configure_ssl
	enable_proxy_caching	
}

function make_dirs()
{
    mkdir -p $GMG_HOME_DIR $GMG_KEYS_DIR $GMG_ETC_DIR $GMG_LOG_DIR
    if [ ! -f ${GMG_KEYS_DIR}/gluster.pem ]; then
		ssh-keygen -t rsa -f /opt/glustermg/keys/gluster.pem -N ''
		mv -f /opt/glustermg/keys/gluster.pem.pub /opt/glustermg/keys/gluster.pub
    fi
    chown -R tomcat:tomcat $GMG_ROOT_DIR $GMG_LOG_DIR;
}

function check_tar_gz()
{
    file $GMG_ARCHIVE_PATH | grep "gzip" > /dev/null;
    if [ $? != 0 ] ; then
		quit "The given filename is not a gunzipped tarball. The file name must be of the form glustermg-version.war.tar.gz" ${TAR_ERR}
    fi
}

function get_gmg_version()
{
	# Format is /path/to/glustermg-version.war.tar.gz
	# Remove prefix
	PART1=${GMG_ARCHIVE_PATH#*glustermg-}
	# Remove suffix
	GMG_VERSION=${PART1%.war.tar.gz}

	GMG_HOME_DIR="${GMG_ROOT_DIR}/${GMG_VERSION}";
}

function check_tomcat_dir()
{
	WEBAPPS_DIR="${TOMCAT_DIR}/webapps"
    if [ ! -d "${WEBAPPS_DIR}" ]; then
		quit "There is no webapps directory in [${TOMCAT_DIR}]." ${TOMCAT_ERR}
    fi
    TOMCAT_BIN=$(basename /usr/sbin/tomcat* );
}

function check_java_version()
{
	java -version 2>/dev/null || quit "java command not available. Please make sure that Java >=1.6.0 is installed and is present in \$PATH" ${JAVA_ERR}
	JAVA_VERSION=`java -version 2>&1 |awk 'NR==1{ gsub(/"/,""); gsub(/_.*/, ""); print $3 }'`
	MINVERSION=1.6

	if expr ${JAVA_VERSION} \>= ${MINVERSION} > /dev/null; then
		echo "Found java version [${JAVA_VERSION}]"
	else
		quit "Java minimum version expected [${MINVERSION}], found [${JAVA_VERSION}]!" ${JAVA_ERR}
	fi
}

function install_gmg()
{
	tar -xvf ${GMG_ARCHIVE_PATH} -C ${GMG_HOME_DIR}
	create_links
}

#-----------------------------------
# Main Action Body
#-----------------------------------

if [ "x$1" == "x" ] || [ "x$1$2" == "x$1" ] || [ $# -gt 2 ]; then
	quit "Usage: $0 <path to glustermg-version.war.tar.gz> <path to tomcat directory>" ${USAGE_ERR}
fi

GMG_ARCHIVE_PATH="$1";
TOMCAT_DIR="$2";

check_tomcat_dir
check_java_version
check_tar_gz
get_gmg_version

make_dirs
install_gmg

configure_server
post_install