Rev 12205 | 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 |
||
12205 | obado | 67 | *) conffile=$confdir/conf-enabled/wims.conf;; |
68 | squeeze|wheezy|precise) conffile=$confdir/conf.d/wims.conf;; |
||
10121 | obado | 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 <<@ |
||
15350 | bpr | 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 | ScriptAlias /wims/wims.mp3 "$wimshome/public_html/wims.cgi" |
||
161 | ScriptAlias /wims/wims.ogg "$wimshome/public_html/wims.cgi" |
||
3 | reyssat | 162 | @ |
8375 | obado | 163 | # newer versions of Apache |
164 | else |
||
165 | cat >>$tmpfile <<@ |
||
15350 | bpr | 166 | ScriptAliasMatch ^/~wims/wims\.(.*) "$wimshome/public_html/wims.cgi" |
167 | ScriptAliasMatch ^/wims/wims\.(.*) "$wimshome/public_html/wims.cgi" |
||
168 | ScriptAliasMatch ^/~wims/index\.(.*) "$wimshome/public_html/wims.cgi" |
||
169 | ScriptAliasMatch ^/wims/index\.(.*) "$wimshome/public_html/wims.cgi" |
||
170 | ScriptAliasMatch ^/~wims/.._(.*).html "$wimshome/public_html/wims.cgi" |
||
171 | ScriptAliasMatch ^/wims/.._(.*).html "$wimshome/public_html/wims.cgi" |
||
172 | ScriptAliasMatch ^/~wims/getfile/(.*) "$wimshome/public_html/wims.cgi" |
||
173 | ScriptAliasMatch ^/wims/getfile/(.*) "$wimshome/public_html/wims.cgi" |
||
174 | ScriptAlias /wims/....\.cgi "$wimshome/public_html/wims.cgi" |
||
3 | reyssat | 175 | @ |
176 | fi |
||
8375 | obado | 177 | |
178 | # Apache version >= 2.4 |
||
179 | if [ "$vmajor" -ge "24" ]; then |
||
180 | require_line="Require all granted" |
||
181 | # Older Apache versions |
||
182 | else |
||
183 | require_line="allow from all" |
||
184 | fi |
||
185 | |||
3 | reyssat | 186 | cat >>$tmpfile <<@ |
15350 | bpr | 187 | Alias /wims "$wimshome/public_html" |
188 | Alias /~wims "$wimshome/public_html" |
||
3 | reyssat | 189 | |
15350 | bpr | 190 | <Directory "$wimshome/public_html"> |
8375 | obado | 191 | Options +FollowSymLinks +ExecCGI -Indexes |
192 | AllowOverride All |
||
193 | $require_line |
||
3 | reyssat | 194 | </Directory> |
15350 | bpr | 195 | <Directory "$wimshome/public_html/modules"> |
8375 | obado | 196 | Options FollowSymLinks |
197 | AllowOverride Limit |
||
3 | reyssat | 198 | </Directory> |
199 | |||
200 | ###### $endl! ###### |
||
201 | @ |
||
202 | |||
203 | mv $tmpfile $conffile |
||
204 | |||
10121 | obado | 205 | echo "## WIMS Configuration added to your HTTPd server conf. ##" |
206 | |||
3 | reyssat | 207 | initdir=/etc/init.d |
823 | bpr | 208 | [ -d $initdir ] || initdir=/etc/rc.d/init.d |
3 | reyssat | 209 | initscript=$initdir/httpd |
210 | [ -f $initscript ] || initscript=$initdir/apache |
||
211 | if [ -f $initscript ]; then |
||
212 | $initscript restart |
||
213 | else |
||
15350 | bpr | 214 | echo |
215 | echo Now you must restart your httpd to make the new configuration |
||
216 | echo take effect. |
||
217 | echo If you don\'t know how to do so: just shut down the system then |
||
218 | echo restart it. |
||
219 | echo |
||
3 | reyssat | 220 | fi |