1#!/bin/sh
2#
3# this tries to install ldapdns in a sane manner
4if [ "X$1" != "X" ]; then
5	prefix=$1
6fi
7if [ "X$prefix" = "X" ]; then
8	if [ "X$TRUEPREFIX" = "X" ]; then
9		prefix=$TRUEPREFIX
10	else
11		prefix="/usr/local"
12	fi
13fi
14
15if [ "X$bin" = "X" ]; then
16	bin=bin
17fi
18
19if [ "X$builddir" = "X" ]; then
20	builddir=`dirname $0`
21fi
22mkdir -p $DESTDIR$prefix/$bin
23
24cp $builddir/ldapdns $DESTDIR$prefix/$bin/.
25chmod 0555 $DESTDIR$prefix/$bin/ldapdns
26
27tcpservers_ok=0
28
29savepath=$PATH
30PATH=$DESTDIR$prefix/bin:$DESTDIR$prefix/sbin:/sbin:/bin:/usr/sbin:/usr/bin:$PATH
31export PATH
32if which tcpserver >/dev/null 2>&1; then
33	# ucspi ok...
34	tcpservers_ok=1
35fi
36if which svc >/dev/null 2>&1; then
37	# daemontools ok...
38	daemontools_ok=1
39fi
40
41PATH=$savepath
42export PATH
43
44if [ -x $DESTDIR/command/svc ]; then
45	daemontools_ok=1;
46fi
47if [ -x $DESTDIR/command/tcpserver ]; then
48	tcpservers_ok=1;
49fi
50
51# if we're using daemontools...
52if [ "X$NO_DAEMONTOOLS" != 'X' ]; then
53	daemontools_ok=0
54elif [ "X$DAEMONTOOLS" != 'X' ]; then
55	daemontools_ok=1
56fi
57
58if [ "X$NO_TCPSERVERS" != 'X' ]; then
59	tcpservers_ok=0
60elif [ "X$TCPSERVERS" != 'X' ]; then
61	tcpservers_ok=1
62fi
63
64if [ "X$INITRC" != "X" ]; then
65	if [ "X$RUN_USER" != "X" ]; then
66		RUN_UID=`id -u $RUN_USER`
67		RUN_GID=`id -g $RUN_USER`
68	fi
69	if [ "X$RUN_UID" = "X" ]; then
70		echo '$RUN_UID not set'
71		exit 1
72	fi
73	if [ "X$RUN_GID" = "X" ]; then
74		echo '$RUN_GID not set'
75		exit 1
76	fi
77	if echo $RUN_UID | egrep '[^0-9]' >/dev/null 2>&1; then
78		echo '$RUN_UID must be numeric (or use $RUN_USER)'
79		exit 1
80	fi
81	if echo $RUN_GID | egrep '[^0-9]' >/dev/null 2>&1; then
82		echo '$RUN_GID must be numeric (or use $RUN_USER)'
83		exit 1
84	fi
85
86	if [ "X$FORCE_INITRC" != "X" ]; then
87		mkdir -p $DESTDIR/etc/init.d
88		cp $builddir/sysvinit/ldapaxfr $DESTDIR/etc/init.d/ldapaxfr
89		cp $builddir/sysvinit/ldapdns $DESTDIR/etc/init.d/ldapdns
90	elif [ -d /etc/init.d -o -d $DESTDIR/etc/init.d ]; then
91		mkdir -p $DESTDIR/etc/init.d
92		cp $builddir/sysvinit/ldapaxfr $DESTDIR/etc/init.d/ldapaxfr
93		cp $builddir/sysvinit/ldapdns $DESTDIR/etc/init.d/ldapdns
94	else
95		echo 'initrc cannot be installed without an /etc/init.d'
96		exit 1
97	fi
98
99	# make other parts
100	mkdir -p $DESTDIR/var/lib/ldapdns
101	chmod 0700 $DESTDIR/var/lib/ldapdns
102	chown $RUN_UID:$RUN_GID $DESTDIR/var/lib/ldapdns
103
104	cp $builddir/ldapdns $DESTDIR$prefix/$bin/ldapdns
105	chmod 0555 $DESTDIR$prefix/$bin/ldapdns
106
107	cp $builddir/ldapaxfr $DESTDIR$prefix/$bin/ldapaxfr
108	chmod 0555 $DESTDIR$prefix/$bin/ldapaxfr
109
110	cfile=$DESTDIR/etc/ldapdns.conf
111	if [ -d "/etc/sysconfig" -o -d "$DESTDIR/etc/sysconfig" ]; then
112		mkdir -p $DESTDIR/etc/sysconfig
113		cfile=$DESTDIR/etc/sysconfig/ldapdns
114	fi
115
116	# copy the configuration file (and add running uid/gid)
117	cp $builddir/sample/ldapdns.conf $cfile
118	echo "RUN_UID=$RUN_UID" >> $cfile
119	echo "RUN_GID=$RUN_GID" >> $cfile
120
121	# copy the default axfr rules
122	cp $builddir/sample/axfr $DESTDIR/var/lib/ldapdns/axfr
123fi
124
125if [ "X$tcpservers_ok" = "X1" ]; then
126	# ldapaxfr
127	cp $builddir/ldapaxfr $DESTDIR$prefix/$bin/.
128	chmod 0555 $DESTDIR$prefix/$bin/ldapaxfr
129elif [ "X$NO_TCPSERVERS" = 'X' ]; then
130	echo 'tcpservers (ucspi-tcp) is not installed.'
131	echo 'cannot install ldapaxfr without it'
132	echo '(set $TCPSERVERS=1 to force)'
133fi
134
135if [ "X$daemontools_ok" = "X1" ]; then
136	# confs
137	cp $builddir/ldapdns-conf $DESTDIR$prefix/bin/.
138	chmod 0555 $DESTDIR$prefix/bin/ldapdns-conf
139	if [ "X$tcpservers_ok" = "X1" ]; then
140		cp $builddir/ldapaxfr-conf $DESTDIR$prefix/bin/.
141		chmod 0555 $DESTDIR$prefix/bin/ldapaxfr-conf
142	fi
143	if [ "X$no_domainname_sh" != "X1" ]; then
144		cp $builddir/domainname.sh $DESTDIR$prefix/bin/domainname.sh
145		chmod 0755 $DESTDIR$prefix/bin/domainname.sh
146	fi
147elif [ "X$NO_DAEMONTOOLS" = 'X' ]; then
148	echo 'daemontools is not installed.'
149	echo '(skipping install of config tools)'
150	echo '(set $DAEMONTOOLS=1 to force)'
151fi
152
153