Subversion Repositories wimsdev

Rev

Rev 8509 | Rev 11204 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 reyssat 1
#! /bin/sh
2
#
3
#	This script adds WIMS-related definitions to Apache config.
4
#	It must be run as root.
5
#
6
#	If you want to prohibit the action of this script,
7
#	insert the following word to httpd.conf (in a commented line):
8
#	manually_configured_for_wims
9
#
10121 obado 10
echo
11
echo  " ## This script adds WIMS-related definitions to Apache config. ##"
12
echo ;
3 reyssat 13
 
824 bpr 14
if [ ! "$(id -ru )" = 0 ]; then
3 reyssat 15
 echo
16
 echo It must be run as root.
17
 echo
18
 echo su to root before running this script!
19
 echo
20
 echo
21
 exit
22
fi
23
 
24
distro=default
25
[ -f /etc/debian_version ] && distro=debian
26
 
27
PATH=$PATH:/usr/sbin:/sbin
28
export PATH
10121 obado 29
 
30
echo "Detecting which HTTP server to execute...";
31
apache2 -v >/dev/null && httpdname=apache2
3 reyssat 32
if [ -z "$httpdname" ]; then apache -v >/dev/null && httpdname=apache; fi
33
if [ -z "$httpdname" ]; then httpd2 -v >/dev/null && httpdname=httpd2; fi
10121 obado 34
if [ -z "$httpdname" ]; then httpd -v >/dev/null && httpdname=httpd; fi
3 reyssat 35
if [ -z "$httpdname" ]; then
36
 cat <<@
37
 
38
Apache is not found on your system.
39
WIMS requires a running web server Apache.
40
Please first install Apache (>=1.3).
41
 
42
@
43
 exit
44
fi
8509 bpr 45
[ -f /etc/apache2/envvars ] && . /etc/apache2/envvars
10121 obado 46
 
47
echo " => HTTP server detected as $httpdname";
48
 
49
echo "Searching $httpdname conf file...";
8375 obado 50
conffile=`$httpdname -V | grep SERVER_CONFIG_FILE | awk -F'=' '{print $2}'  | tr -d ' "'`
3 reyssat 51
confdir=`dirname $conffile`
52
if [ -z "$confdir" ]; then
53
 cat <<@
54
 
55
Unknown web server. Version too early?
56
Please first update your web server to Apache >=1.3.
57
 
58
@
59
 exit
60
fi
61
 
10121 obado 62
echo " # Linux Type: $distro";
63
if [ "$distro" = "debian" ];then
64
  lsb_release=`lsb_release -c | cut -f2`
65
  echo " # Release : $lsb_release";
66
    case $lsb_release in
67
    trusty|jessie|xenial) conffile=$confdir/conf-enabled/wims.conf;;
68
    *)                    conffile=$confdir/conf.d/wims.conf;;
69
    esac
70
fi
8509 bpr 71
 
10121 obado 72
echo " => HTTPd conf file : $conffile";
3 reyssat 73
 
74
cd `dirname $0`/..
75
wimshome=`pwd`
76
 
77
if [ ! -e public_html/wims.cgi ] || [ ! -e bin/apache-config ]; then
78
 echo Error: wrong directory. File wims.cgi not found.
79
 echo
80
 exit
81
fi
82
 
10121 obado 83
echo "Searching HTTPd root..."
3 reyssat 84
httpdroot=`$httpdname -V | grep HTTPD_ROOT | awk -F'=' '{print $2}' \
85
 | tr -d ' "'`
86
if [ ! -z "$httpdroot" ]; then cd $httpdroot; fi
87
 
10121 obado 88
echo " => HTTPd root found : $httpdroot"
89
 
3 reyssat 90
tmpfile=/tmp/wims-apache.conf
91
vtest=`$httpdname -v | grep Apache`
92
if [ -z "$vtest" ]; then
93
 echo
94
 echo You are not running Apache web server!
95
 echo
96
 echo You must configure manually your web server, this script cannot be used.
97
 echo
98
 exit
99
fi
100
 
10121 obado 101
echo "Config test..."
3 reyssat 102
conftest=`grep -i manually_configured_for_wims $conffile`
103
if [ ! -z "$conftest" ]; then
104
 echo Manually configured $conffile not modified.
105
 exit
106
fi
107
 
108
# The next two definitions should NEVER be changed.
109
startl="WIMS definitions start. Do not alter this line"
110
  endl="WIMS definitions end. Do not alter this line"
111
 
112
case $distro in
113
 debian) rm -f $tmpfile
114
 ;;
8509 bpr 115
 *) awk 'BEGIN {a=1};
3 reyssat 116
	/'"$startl"'/ {a=0};
117
	a==1 {print};
118
	/'"$endl"'/ {a=1};' $conffile >$tmpfile
119
 ;;
120
esac
121
 
122
if [ "$1" = "uninstall" ]; then
123
 case $distro in
124
  debian) rm -f $conffile $tmpfile
125
  ;;
126
  *) mv $tmpfile $conffile
127
  ;;
128
 esac
129
 killall -HUP $httpdname
130
 exit
131
fi
132
 
133
cat >>$tmpfile <<@
134
###### $startl! ######
135
#
136
# If you manually add things concerning WIMS into this configuration file,
137
# add them BEFORE the 'WIMS definition start' line.
138
# Otherwise the addition will be erased in next update.
139
#
140
  AddHandler cgi-script .cgi
141
@
142
 
8375 obado 143
# $vtest looks like "Server version: Apache/X.Y.Z (Unix)"
144
# $vmajor will be XY
10121 obado 145
echo "Searching HTTPd major version..."
8375 obado 146
vmajor=`echo $vtest | grep 'pache' | perl -pe 's/.*pache\/([\d]+).([\d]+).*/$1$2/'`
147
 
10121 obado 148
echo " => HTTPd major version found : $vmajor"
149
 
8375 obado 150
# Apache version == 1.2
151
if [ "$vmajor" = "12" ]; then
152
  cat >>$tmpfile <<@
3 reyssat 153
  ScriptAlias /wims/wims.cgi $wimshome/public_html/wims.cgi
154
  ScriptAlias /wims/wims.html $wimshome/public_html/wims.cgi
155
  ScriptAlias /wims/index.html $wimshome/public_html/wims.cgi
156
  ScriptAlias /wims/wims.gif $wimshome/public_html/wims.cgi
157
  ScriptAlias /wims/wims.png $wimshome/public_html/wims.cgi
158
  ScriptAlias /wims/wims.jpeg $wimshome/public_html/wims.cgi
159
  ScriptAlias /wims/wims.jpg $wimshome/public_html/wims.cgi
160
@
8375 obado 161
# newer versions of Apache
162
else
163
  cat >>$tmpfile <<@
3 reyssat 164
  ScriptAliasMatch ^/~wims/wims\.(.*) $wimshome/public_html/wims.cgi
165
  ScriptAliasMatch ^/wims/wims\.(.*) $wimshome/public_html/wims.cgi
166
  ScriptAliasMatch ^/~wims/index\.(.*) $wimshome/public_html/wims.cgi
167
  ScriptAliasMatch ^/wims/index\.(.*) $wimshome/public_html/wims.cgi
168
  ScriptAliasMatch ^/~wims/.._(.*).html $wimshome/public_html/wims.cgi
169
  ScriptAliasMatch ^/wims/.._(.*).html $wimshome/public_html/wims.cgi
170
  ScriptAliasMatch ^/~wims/getfile/(.*) $wimshome/public_html/wims.cgi
171
  ScriptAliasMatch ^/wims/getfile/(.*) $wimshome/public_html/wims.cgi
172
  ScriptAlias /wims/....\.cgi $wimshome/public_html/wims.cgi
173
@
174
fi
8375 obado 175
 
176
# Apache version >= 2.4
177
if [ "$vmajor" -ge "24" ]; then
178
  require_line="Require all granted"
179
# Older Apache versions
180
else
181
  require_line="allow from all"
182
fi
183
 
3 reyssat 184
cat >>$tmpfile <<@
185
  Alias /wims $wimshome/public_html
186
  Alias /~wims $wimshome/public_html
187
 
188
  <Directory $wimshome/public_html>
8375 obado 189
    Options +FollowSymLinks +ExecCGI -Indexes
190
    AllowOverride All
191
    $require_line
3 reyssat 192
  </Directory>
193
  <Directory $wimshome/public_html/modules>
8375 obado 194
    Options FollowSymLinks
195
    AllowOverride Limit
3 reyssat 196
  </Directory>
197
 
198
###### $endl! ######
199
@
200
 
201
mv $tmpfile $conffile
202
 
10121 obado 203
echo  "## WIMS Configuration added to your HTTPd server conf. ##"
204
 
3 reyssat 205
initdir=/etc/init.d
823 bpr 206
[ -d $initdir ] || initdir=/etc/rc.d/init.d
3 reyssat 207
initscript=$initdir/httpd
208
[ -f $initscript ] || initscript=$initdir/apache
209
if [ -f $initscript ]; then
210
 $initscript restart
211
else
212
 echo
213
 echo Now you must restart your httpd to make the new configuration
214
 echo take effect.
215
 echo If you don\'t know how to do so: just shut down the system then
216
 echo restart it.
217
 echo
218
fi
219