summaryrefslogtreecommitdiff
path: root/ApacheJServ.spec
blob: 8710cdc1073b63fa2aea625b3270c00d7bf1d7ea (plain)
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
#%define libexecdir `apxs -q LIBEXECDIR`
%define libexecdir /usr/lib/apache

#%define httpdconf `apxs -q SYSCONFDIR`
%define httpdconf  /etc/httpd/conf

%define jservconf  %{httpdconf}/jserv
%define logdir	   /var/log/httpd
%define servletdir /home/httpd/servlets
%define classesdir /home/httpd/classes
%define jsdkversion 19991120

Summary:	Servlet engine with support for the leading web server
Name:		ApacheJServ
Version:	1.1
Release:	3
Source0:	http://java.apache.org/jserv/dist/%{name}-%{version}.tar.gz
Source1:	http://www.euronet.nl/~pauls/java/servlet/download/%{version}%{name}classpathx_servlet-%{jsdkversion}.tar.gz
Patch0:		ApacheJServ-enable-secret.patch
Patch1:		ApacheJServ-DESTDIR.patch
URL:		http://java.apache.org/
Copyright:	Freely distributable & usable
Group:		Networking/Daemons
Group(pl):	Sieciowe/Serwery
Requires:	apache >= 1.3.6
Provides:	jserv jsdk20
BuildRoot:	%{tmpdir}/%{name}-%{version}-root-%(id -u -n)

#BuildRequires:	any-java-compiler

BuildRequires:	automake     >= 1.4
BuildRequires:	autoconf     >= 2.13
BuildRequires:	libtool      >= 1.3.3 
BuildRequires:	apache-devel >= 1.3.9-8

%description
Apache JServ is a servlet engine, developed by the Java Apache Project
<http://java.apache.org/>. The Apache JServ servlet engine is written
in 100pc Java application, and listens for servlet requests using the
Apache Java protocol (AJp). Typically, these requests will originate
from the mod_jserv Apache module (DSO included). This package contains
a LGPL'ed implementation of sun's java servlet api version 2.0 by Paul
Siegmann <http://www.euronet.nl/~pauls/java/servlet/>

%prep
rm -rf $RPM_BUILD_ROOT
%setup -q -a 1

%patch0
%patch1 -p1

# final position of GNU JSDK-Classes 
sed 's|@JSDK_CLASSES@|%{classesdir}/servlet-2.0.jar|g' \
    < conf/jserv.properties.in  > conf/jserv.properties.in.new
mv conf/jserv.properties.in.new conf/jserv.properties.in

# do not load module in provided jserv.conf; we do this in httpd.conf
sed 's|@LOAD_OR_NOT@|#|g' \
    < conf/jserv.conf.in  > conf/jserv.conf.in.new
mv conf/jserv.conf.in.new conf/jserv.conf.in

# prepare compilation
aclocal
autoconf
automake

%build
make -C classpathx_servlet-%{jsdkversion} jar_2_0
make -C classpathx_servlet-%{jsdkversion}/apidoc

# copy API-doc
mkdir jsdk-doc
cp classpathx_servlet-%{jsdkversion}/README \
	classpathx_servlet-%{jsdkversion}/AUTHORS \
	classpathx_servlet-%{jsdkversion}/COPYING.LIB \
	jsdk-doc
cp -r classpathx_servlet-%{jsdkversion}/apidoc jsdk-doc

### JSERV

# find apxs utility ..
# .. in PATH
APXS_UTIL=`type -p apxs || true`

# .. from RPM
if test "x$APXS_UTIL" = x ; then
  # mmh, is it possible to query just for
  # the executeables  (like -qd and -qc) ?
  APXSMATCH=`rpm -ql apache-devel apache | grep apxs`
  for f in $APXSMATCH ; do
    if test -x "$f"  ; then
       APXS_UTIL=$f
       break
    fi
  done
fi

# .. at usual places
if test "x$APXS_UTIL" = x ; then
   for loc in \
    %{_bindir}               \
    %{_sbindir}              \
    %{_prefix}/local/apache/bin  \
    %{_prefix}/local/apache/sbin \
    %{_prefix}/local/httpd/bin   \
    %{_prefix}/local/httpd/sbin 
  do
    if test -x "$loc/apxs" ; then
       APXS_UTIL="$loc/apxs"
       break
    fi
  done
fi

if test "x$APXS_UTIL" = x ; then
   echo "Didn't find apxs .. exiting"
   exit -1
fi

APXS_CFLAGS=`$APXS_UTIL -q CFLAGS`
CFLAGS="$APXS_CFLAGS $RPM_OPT_FLAGS" ./configure \
	--prefix=%{_prefix}          \
	--disable-debugging           \
	--with-apxs=$APXS_UTIL        \
	--with-logdir=%{logdir}       \
	--with-servlets=%{servletdir} \
	--with-JSDK=`pwd`/classpathx_servlet-%{jsdkversion}/servlet-2.0.jar
make

%install
rm -rf $RPM_BUILD_ROOT

make DESTDIR=$RPM_BUILD_ROOT install

echo "default - change on install `date`" > $RPM_BUILD_ROOT/%{jservconf}/jserv.secret.key
chmod 600 $RPM_BUILD_ROOT/%{jservconf}/jserv.secret.key

# currently disabled
#install -d $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d
#install -d $RPM_BUILD_ROOT%{_sysconfdir}/profile.d
#install -d $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d
#install -m755 src/scripts/package/rpm/jserv.init      $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d/jserv
#install -m755 src/scripts/package/rpm/jserv.sh        $RPM_BUILD_ROOT%{_sysconfdir}/profile.d
#install -m644 src/scripts/package/rpm/jserv.logrotate $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/jserv

### GNU JSDK-classes
install -d ${RPM_BUILD_ROOT}%{classesdir}
install classpathx_servlet-%{jsdkversion}/servlet-2.0.jar ${RPM_BUILD_ROOT}%{classesdir}

%clean
rm -rf $RPM_BUILD_ROOT

%post

# use fortune + install-date + process-list to create pseudo-random, hardly
# guessable secret key. Use md5sum to create a hash from this, if available:
(%{_prefix}/games/fortune 2>/dev/null ; date ; ps -eal 2>/dev/null)   \
		    | (md5sum 2>/dev/null || cat)   		\
		    > %{jservconf}/jserv.secret.key 
chmod 600 %{jservconf}/jserv.secret.key

#
# determine apache-USER and chown the jserv.secrect.key - file
#
APACHEUSER=`grep "^User[	 ]\+" %{httpdconf}/httpd.conf | awk '{print $2}'`
if test ! "x$APACHEUSER" = x ; then
   USERCOMMENT="(which is '$APACHEUSER' ?)"
else
   # assumption:	
   APACHEUSER=nobody
fi
chown $APACHEUSER %{jservconf}/jserv.secret.key

#
# determine apache-GROUP and allow this group to write to %{logdir}
APACHEGROUP=`grep "^Group[	 ]\+" %{httpdconf}/httpd.conf | awk '{print $2}'`
if test "x$APACHEGROUP" = x ; then
   APACHEGROUP=nobody
fi
chgrp $APACHEGROUP %{logdir}
chmod g+w %{logdir}

#
# Add 'jserv' as an independent service (manual mode)
#/sbin/chkconfig --add jserv
#/etc/rc.d/init.d/jserv start

#
# Find Include Statement or add it if necessary
#
cp %{httpdconf}/httpd.conf %{httpdconf}/httpd.conf.rpmorig
grep '#\?.*[iI]nclude.*/jserv.conf' %{httpdconf}/httpd.conf \
     >/dev/null
if test $? -eq 0 ; then
   # found. Insert our include statement here
   ## this depends on GNU-sed ('|') .. but we're on a RedHat system anyway
   sed 's|^#\?\(.*Include\).*/jserv.conf.*$|\1 %{jservconf}/jserv.conf|g' \
       < %{httpdconf}/httpd.conf.rpmorig                 \
       > %{httpdconf}/httpd.conf
else
   # append it
   ( 
     echo "<IfModule mod_jserv.c>"
     echo "	     Include %{jservconf}/jserv.conf"
     echo "</IfModule>"
   ) >> %{httpdconf}/httpd.conf
fi

#
# LoadModule; uncomment or insert
#
grep '#\?.*LoadModule.*jserv_module.*mod_jserv.so' %{httpdconf}/httpd.conf \
     >/dev/null
if test $? -eq 0 ; then
   # found. Remove any comment
   sed 's|^#.*\(LoadModule.*mod_jserv.so\)|\1|g' \
       < %{httpdconf}/httpd.conf                 \
       > %{httpdconf}/httpd.conf.loadMod
   mv %{httpdconf}/httpd.conf.loadMod %{httpdconf}/httpd.conf
else
   # Insert LoadModule line before first valid LoadModule
   ( echo "/^LoadModule"
     echo "i"
     echo "LoadModule jserv_module	modules/mod_jserv.so"
     echo "."
     echo "wq"
   ) | ed %{httpdconf}/httpd.conf > /dev/null 2>&1
fi

#
# AddModule; uncomment or insert
#
grep '#\?.*AddModule.*mod_jserv.c' %{httpdconf}/httpd.conf >/dev/null
if test $? -eq 0  ; then
   # found. Remove any comment
   sed 's|^#.*\(AddModule.*mod_jserv.c\)|\1|g' \
       < %{httpdconf}/httpd.conf               \
       > %{httpdconf}/httpd.conf.addMod
   mv %{httpdconf}/httpd.conf.addMod %{httpdconf}/httpd.conf
else
   ( echo "/^AddModule"
     echo "i"
     echo "AddModule mod_jserv.c"
     echo "."
     echo "wq"
   ) | ed %{httpdconf}/httpd.conf > /dev/null 2>&1
fi

#
# Search vor JAVA at possible locations and edit wrapper.bin
#
unset JAVABIN
for lookfor in java jre ; do
  for loc in \
    $JAVA_HOME	          \
    $JDK_HOME	          \
    /usr/local/java       \
    /usr/local/jdk       \
    /usr/local/jdk117_v3  \
    /usr/local/jdk117_v1a
  do
    if test -x "$loc/bin/$lookfor" ; then
       JAVABIN="$loc/bin/$lookfor"
       break
    fi
  done

  if test -z "$JAVABIN" ; then
    for prefix in /usr/jdk /usr/jdk- /usr/local/jdk /usr/local/jdk- ; do
      for jplatform in 2 1 ; do
        for subvers in .9 .8 .7 .6 .5 .4 .3 .2 .1 "" ; do
          if test -x "${prefix}1.$jplatform$subvers/bin/$lookfor" ; then
	     JAVABIN="${prefix}1.$jplatform$subvers/bin/$lookfor"
	     break
	  fi
        done
	if test ! -z "$JAVABIN" ; then break ; fi
      done
      if test ! -z "$JAVABIN" ; then break ; fi
    done
  fi
  if test ! -z "$JAVABIN" ; then break ; fi
done

if test ! -z "$JAVABIN" ; then
   sed "s|^wrapper.bin=.*$|wrapper.bin=$JAVABIN|" \
       < %{jservconf}/jserv.properties \
       > %{jservconf}/jserv.properties.new
   mv %{jservconf}/jserv.properties.new %{jservconf}/jserv.properties
fi

#
# Get Server Port to echo right URL below
#
SERVERPORT=`grep "^Port" %{httpdconf}/httpd.conf | \
			head -1 | awk '{print ":" $2}'`
if test "$SERVERPORT" = ":80" ; then
	SERVERPORT=""
fi

#FIXME:		make this i18n-aware

if test ! "x$JAVABIN" = x ; then
   echo "using java VM $JAVABIN"
else
   echo "## didn't find java or jre. Please install it and edit the"
   echo "## wrapper.bin property in %{jservconf}/jserv.properties"
fi
echo ""
echo "In order to enable JServ, restart the webserver and try"
echo "		 http://localhost$SERVERPORT/servlets/IsItWorking"
echo "	 and"
echo "		 http://localhost$SERVERPORT/jserv/"
echo "-- ENJOY! --"
echo ""

## we hopefully may distribute SUN-jsdk.jar with jserv once ..
echo " | NOTE that this distribution contains a fully functional"
echo " | free jsdk replacement, see <http://www.euronet.nl/~pauls/java/servlet/>."
echo " | If you want to use the SUN-jsdk, replace the servlet-2.0.jar"
echo " | in the wrapper.classpath - line in the file"
echo " |		 %{jservconf}/jserv.properties"
echo " | with the SUN jsdk."
echo " | Get it from <http://java.sun.com/products/servlet/>."
echo " | Only JSDK 2.0 (Java Servlet Development Kit)"
echo " | is supported (_EXACTLY_ 2.0)."
echo ""

echo "Please send comments/suggestions regarding"
echo "this RPM to <zeller@to.com>."

%preun
# do not remove the configured stuff if we upgrade.
# the $1 argument contains the number of packages _after_ installation.
if [ ! $1 -eq 0 ] ; then
   exit 0
fi

# Remove 'jserv' service (manual mode)
#/etc/rc.d/init.d/jserv stop
#/sbin/chkconfig --del jserv

#
# Find jserv related configuration settings and comment
# them out
#
cp %{httpdconf}/httpd.conf %{httpdconf}/httpd.conf.rpmorig
sed 's|.*\(Include.*%{jservconf}/jserv.conf\)|#\1|g' \
    < %{httpdconf}/httpd.conf.rpmorig                \
    | sed 's|^\(AddModule.*mod_jserv.c\)|#\1|g'      \
    | sed 's|^\(LoadModule.*mod_jserv.so\)|#\1|g'    \
    > %{httpdconf}/httpd.conf
# remove old logs
/bin/rm -fr %{logdir}/mod_jserv.log
/bin/rm -fr %{logdir}/jserv.log

%files
%defattr(644,root,root,755)
# mmh, we can't give %{_prefix}/docs to %doc ..
%doc index.html README docs jsdk-doc

%dir %{jservconf}
%config %{jservconf}/jserv.properties
%config %{jservconf}/zone.properties
%config %{jservconf}/jserv.conf

# these are just for demonstration and thus,
# no %config-files per-se; do not install
# them for the RPM-packet
#%{jservconf}/jserv.properties.default
#%{jservconf}/zone.properties.default
#%{jservconf}/jserv.conf.default

%attr(-,nobody,nobody) %{jservconf}/jserv.secret.key
#%config %{_sysconfdir}/rc.d/init.d/jserv
#%config %{_sysconfdir}/logrotate.d/jserv
#%config %{_sysconfdir}/profile.d/jserv.sh

%{libexecdir}/mod_jserv.so
%{libexecdir}/ApacheJServ.jar

%dir %{classesdir}
%{classesdir}/servlet-2.0.jar

%dir %{servletdir}
%{servletdir}/IsItWorking.java
%{servletdir}/IsItWorking.class

# we need to have write access here
%attr(-,nobody,-) %dir %{logdir}