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