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