File: install-apache.sh

package info (click to toggle)
fusionforge 5.3.2%2B20141104-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 60,472 kB
  • sloc: php: 271,846; sql: 36,817; python: 14,575; perl: 6,406; sh: 5,980; xml: 4,294; pascal: 1,411; makefile: 911; cpp: 52; awk: 27
file content (269 lines) | stat: -rwxr-xr-x 8,008 bytes parent folder | download | duplicates (3)
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
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#! /bin/sh
# 
# Configure apache for GForge
# Christian Bayle, Roland Mas, debian-sf (GForge for Debian)
#
# Reset fb color mode
RESET="]R"
# ANSI COLORS
# Erase to end of line
CRE="
"
# Clear and reset Screen
CLEAR="c"
# Normal color
NORMAL=""
# RED: Failure or error message
RED=""
# GREEN: Success message
GREEN=""

set -e

ARG=$@
if [ $(id -u) != 0 ] ; then
    echo "You must be root to run this, please enter passwd"
    exec su -c "$0 $1"
fi

remove_gforge_insert(){
			cp -a $1 $1.gforge-new
			echo "Removing Gforge inserted lines from $1.gforge-new"
			set +e
			vi -e $1.gforge-new > /dev/null 2>&1 <<-FIN
/### Next line inserted by GForge install
:d
:d
:w
:x
FIN
set -e
}

search_conf_file(){
CONFFILE=$1
shift
echo -n "Searching $CONFFILE config file	"
RESULT=""
for i in $*
do
	if [ -f "$i" ]
	then
		RESULT="$i $RESULT"
	fi
done
if [ -z "$RESULT" ]
then
	echo "$RED[Failed]$NORMAL" 
	echo "${CONFFILE} conf file not found at $*"
	echo "Please set ${CONFFILE}_ETC_SEARCH" ; exit 1
else
	echo "$GREEN[OK]$NORMAL"
fi
}

get_conf(){
if [ "$HAVECONF" != "true" ]
then
if [ -z "$APACHE_ETC_SEARCH" ] 
then 
	APACHE_ETC_SEARCH="/etc/apache2/apache2.conf /etc/apache/httpd.conf /etc/apache-perl/httpd.conf /etc/apache-ssl/httpd.conf"
fi
if [ -z "$GFORGE_ETC_SEARCH" ] 
then 
	GFORGE_ETC_SEARCH="$(forge_get_config config_path)/httpd.conf"
fi
if [ -z "$PHP_ETC_SEARCH" ] 
then 
	PHP_ETC_SEARCH="/etc/php5/apache2/php.ini /etc/php5/cgi/php.ini"
fi
export APACHE_ETC_SEARCH GFORGE_ETC_SEARCH PHP_ETC_SEARCH

search_conf_file APACHE "$APACHE_ETC_SEARCH"
APACHE_ETC_LIST="$RESULT"
search_conf_file GFORGE "$GFORGE_ETC_SEARCH"
GFORGE_ETC_LIST="$RESULT"
search_conf_file PHP "$PHP_ETC_SEARCH"
PHP_ETC_LIST="$RESULT"
export APACHE_ETC_LIST GFORGE_ETC_LIST PHP_ETC_LIST

gforgebin=$(forge_get_config binary_path)
set $GFORGE_ETC_LIST
gforgeconffile=$1
echo Using $gforgeconffile
export gforgeconffile
HAVECONF=true
export HAVECONF
fi
}

get_conf
set $ARG
case "$1" in
    configure-files)
	# Make sure Apache sees us
	for apacheconffile in $APACHE_ETC_LIST
	do
		APACHE_ETC_DIR=`dirname $apacheconffile`
		if [ -d "$APACHE_ETC_DIR/conf.d" ]
		then
			# New apache conf	
			# Remove old hack to have Apache see us
	    		if [ -e $apacheconffile ] && grep -q "Include $gforgeconffile" $apacheconffile ; then
				remove_gforge_insert $apacheconffile
	    		fi
		else	
			# Old fashion Apache
			if [ -e $apacheconffile ] ; then
	    			cp -a $apacheconffile $apacheconffile.gforge-new
	    			perl -pi -e "s/# *LoadModule php5_module/LoadModule php5_module/gi" $apacheconffile.gforge-new
	    			perl -pi -e "s/# *LoadModule ssl_module/LoadModule ssl_module/gi" $apacheconffile.gforge-new
	    			perl -pi -e "s/# *LoadModule env_module/LoadModule env_module/gi" $apacheconffile.gforge-new
	    			perl -pi -e "s/# *LoadModule vhost_alias_module/LoadModule vhost_alias_module/gi" $apacheconffile.gforge-new
	    
	    			if ! grep -q "^Include $gforgeconffile" $apacheconffile.gforge-new ; then
					# File cleaning, just in case
					remove_gforge_insert $apacheconffile
					echo "### Next line inserted by GForge install" >> $apacheconffile.gforge-new
					echo "Include $gforgeconffile" >> $apacheconffile.gforge-new
				else
					echo "Found Include $gforgeconffile in $apacheconffile"
	    			fi
			fi
		fi
	done
	# Make sure pgsql, ldap and gd are enabled in the PHP config files
	
	for phpconffile in $PHP_ETC_LIST
	do
		cp -a $phpconffile $phpconffile.gforge-new
		if [ -f $phpconffile.gforge-new ]; then
	    		if ! grep -q "^[[:space:]]*extension[[:space:]]*=[[:space:]]*pgsql.so" $phpconffile.gforge-new; then
				echo "Enabling pgsql in $phpconffile"
				echo "extension=pgsql.so" >> $phpconffile.gforge-new
	    		fi
	    		if ! grep -q "^[[:space:]]*extension[[:space:]]*=[[:space:]]*gd.so" $phpconffile.gforge-new; then
				echo "Enabling gd in $phpconffile"
				echo "extension=gd.so" >> $phpconffile.gforge-new
	    		fi
		fi
	done
	;;
	
    configure)
	[ -f $gforgebin/prepare-vhosts-file.pl ] && su -s /bin/sh gforge -c $gforgebin/prepare-vhosts-file.pl
	if [ -f /usr/sbin/modules-config ] ; then
		for flavour in apache apache-perl apache-ssl ; do
			if [ -e /etc/$flavour/httpd.conf ] ; then
				if [ "`/usr/sbin/modules-config $flavour query mod_php5`" == "" ] ; then
	    				DEBIAN_FRONTEND=noninteractive /usr/sbin/modules-config $flavour enable mod_php5
				fi
				if [ $flavour != apache-ssl ] ; then
					if [ "`/usr/sbin/modules-config $flavour query mod_ssl`" == "" ] ; then
	    					DEBIAN_FRONTEND=noninteractive /usr/sbin/modules-config $flavour enable mod_ssl
					fi
				fi
				if [ "`/usr/sbin/modules-config $flavour query mod_env`" == "" ] ; then
	    				DEBIAN_FRONTEND=noninteractive /usr/sbin/modules-config $flavour enable mod_env
				fi
				if [ "`/usr/sbin/modules-config $flavour query mod_vhost_alias`" == "" ] ; then
	    				DEBIAN_FRONTEND=noninteractive /usr/sbin/modules-config $flavour enable mod_vhost_alias
				fi

				LINK=`ls -l /etc/$flavour/conf.d/gforge.httpd.conf | sed 's/.*-> \(.*\)$/\1/'`
				if [ "$LINK" != "$GFORGE_ETC_LIST" ] ; then 
					echo Removing symlink
					rm -f /etc/$flavour/conf.d/gforge.httpd.conf
				fi
				if [ -d /etc/$flavour/conf.d ] ; then
					[ ! -e /etc/$flavour/conf.d/gforge.httpd.conf ] && ln -s $GFORGE_ETC_LIST /etc/$flavour/conf.d/gforge.httpd.conf
				fi
			fi
		done
	fi
	# do configuring for apache2, loop through flavours not necessary
	# but it's here in case other flavours of apache2 come along
	if [ -f /usr/sbin/a2enmod ] ; then
		for flavour in apache2 ;  do
			if [ -e /etc/$flavour/httpd.conf ] ; then
				DEBIAN_FRONTEND=noninteractive /usr/sbin/a2enmod php5 || true
				DEBIAN_FRONTEND=noninteractive /usr/sbin/a2enmod ssl || true
				DEBIAN_FRONTEND=noninteractive /usr/sbin/a2enmod suexec || true
				DEBIAN_FRONTEND=noninteractive /usr/sbin/a2enmod vhost_alias || true
				DEBIAN_FRONTEND=noninteractive /usr/sbin/a2enmod headers || true
				DEBIAN_FRONTEND=noninteractive /usr/sbin/a2enmod rewrite || true
				DEBIAN_FRONTEND=noninteractive /usr/sbin/a2enmod proxy || true
				DEBIAN_FRONTEND=noninteractive /usr/sbin/a2enmod proxy_http || true

				LINK=`ls -l /etc/$flavour/conf.d/gforge.httpd.conf | sed 's/.*-> \(.*\)$/\1/'`
				if [ "$LINK" != "$GFORGE_ETC_LIST" ] ; then 
					echo Removing symlink
					rm -f /etc/$flavour/conf.d/gforge.httpd.conf
				fi
				if [ -d /etc/$flavour/conf.d ] ; then
					[ ! -e /etc/$flavour/conf.d/gforge.httpd.conf ] && ln -s $GFORGE_ETC_LIST /etc/$flavour/conf.d/gforge.httpd.conf
				fi
			fi
		done
	fi
	# Check apache 2 is running
	test -f /etc/default/apache2 && . /etc/default/apache2
	for flavour in apache2 ;  do
	    if [ -x /usr/sbin/$flavour ]; then
		invoke-rc.d $flavour restart || true
	    fi
	done
	;;

    purge-files)
	for apacheconffile in $APACHE_ETC_LIST
	do
	echo "Looking at $apacheconffile"
	    	#if [ -e $apacheconffile ] && grep -q "Include $gforgeconffile" $apacheconffile ; then
	    	if [ -e $apacheconffile ] && grep -q "### Next line inserted by GForge install" $apacheconffile ; then
			remove_gforge_insert $apacheconffile
	    	fi
	done
	;;

    purge)
    	for flavour in apache apache-perl apache-ssl apache2; do
		[ -e /etc/$flavour/conf.d/gforge.httpd.conf ] && rm -f /etc/$flavour/conf.d/gforge.httpd.conf
		if [ -x /usr/sbin/$flavour ]; then
			invoke-rc.d $flavour restart < /dev/null > /dev/null 2>&1 || true
		fi
	done
	;;

    setup)
    	$0 configure-files
	for conffile in $APACHE_ETC_LIST $PHP_ETC_LIST
	do
		if [ -f $conffile.gforge-new ] 
		then
			cp $conffile $conffile.gforge-old
			mv $conffile.gforge-new $conffile
		fi
	done
	$0 configure
	;;

    cleanup)
    	$0 purge-files
	for conffile in $APACHE_ETC_LIST $PHP_ETC_LIST
	do
		if [ -f $conffile.gforge-new ] 
		then
			cp $conffile $conffile.gforge-old
			mv $conffile.gforge-new $conffile
		fi
	done
	$0 purge
	;;

    *)
	echo "Usage: $0 {configure|configure-files|purge|purge-files|setup|cleanup}"
	exit 1
	;;
	
esac