summaryrefslogtreecommitdiffstats
path: root/build/gmg-backend-install.sh
blob: 1dc051e08113b0955cbc949bd8ff571572ff7274 (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
#!/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
USAGE_ERR=1
FUSE_ERR=2
CHKCONFIG_ERR=3
TAR_ERR=4
GMGBE_ROOT_DIR="/opt/glustermg"

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

function pre()
{
	modprobe -q fuse
	if ! lsmod | grep -qw fuse; then
    	quit "fuse kernel module is not found!" ${FUSE_ERR}
	fi

	if [ ! -f /sbin/chkconfig ]; then
		quit "/sbin/chkconfig not found!" ${CHKCONFIG_ERR}
	fi

	if ! which python 1>/dev/null 2>/dev/null; then
	    quit "python not found" -2
	fi

	if python -c 'import sys; sys.exit(sys.version_info >= (2,4,0) and sys.version_info < (3,0,0))'; then
	    python -c 'import sys; print "Python", sys.version'
	    quit "python version 2.4+ and less than 3.0 is required" -2
	fi

	if ! which perl 1>/dev/null 2>/dev/null; then
	    quit "perl not found" -2
	fi

	if ! perl -MRRDs -e 1 2>/dev/null; then
	    quit "perl::RRDs not found" -2
	fi

	if ! which smbd 1>/dev/null 2>/dev/null; then
	    quit "samba not found" -2
	fi

	if [ ! -f /usr/lib64/libxml2.so.2 ]; then
	    quit "libxml2 not found" -2
	fi
}

function check_tar_gz()
{
    file $GMGBE_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-backend-version.tar.gz" ${TAR_ERR}
    fi
}

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

	GMGBE_DIR="${GMGBE_ROOT_DIR}/${GMG_VERSION}/backend";
}

function make_dirs()
{
    mkdir -p $GMGBE_DIR /var/lib/rrd
}

function extract_archive()
{
	tar xvfz ${GMGBE_ARCHIVE_PATH}

	# The tar contains files in path glustermg-backend-version/gmg-scripts/*.py
	SRC_DIR=glustermg-backend-${GMG_VERSION}
	mv ${SRC_DIR}/gmg-scripts/* ${GMGBE_DIR}
	rm -rf ${SRC_DIR}
}

function create_links()
{
	ln -fs ${GMGBE_DIR}/multicast-discoverd.py /usr/sbin/multicast-discoverd
	ln -fs ${GMGBE_DIR}/gluster_cifs_volume_startup.py /usr/sbin/gluster_cifs_volume_startup
	ln -fs ${GMGBE_DIR}/multicast-discoverd.init.d /etc/init.d/multicast-discoverd
	ln -fs ${GMGBE_DIR}/gluster-volume-settings.init.d /etc/init.d/gluster-volume-settings
}

function post()
{
	if [ -f /etc/sudoers ]; then
		chmod 644 /etc/sudoers
		sed -i '/^Defaults.*requiretty/d' /etc/sudoers
		chmod 0440 /etc/sudoers
	fi

	if ! grep -q rrd_cpu.pl /etc/crontab; then
		echo "*/5 * * * * root /opt/glustermg/${GMG_VERSION}/backend/rrd_cpu.pl" >> /etc/crontab
	fi
	if ! grep -q rrd_mem.pl /etc/crontab; then
		echo "*/5 * * * * root /opt/glustermg/${GMG_VERSION}/backend/rrd_mem.pl" >> /etc/crontab
	fi
	if ! grep -q rrd_net.pl /etc/crontab; then
		echo "*/5 * * * * root /opt/glustermg/${GMG_VERSION}/backend/rrd_net.pl" >> /etc/crontab
	fi
	/sbin/chkconfig --add multicast-discoverd
	/sbin/chkconfig --level 345 multicast-discoverd on
	if /etc/init.d/multicast-discoverd status >/dev/null; then
		/etc/init.d/multicast-discoverd restart
	else
		/etc/init.d/multicast-discoverd start
	fi
	/etc/init.d/crond reload
	/sbin/chkconfig smb on
	/sbin/chkconfig --add gluster-volume-settings
}

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

if [ $# -ne 1 ]; then
	quit "Usage: $0 <path to glustermg-backend-version.tar.gz>" ${USAGE_ERR}
fi

GMGBE_ARCHIVE_PATH=${1}

pre
check_tar_gz
get_gmg_version

make_dirs
extract_archive
create_links
post