File: install

package info (click to toggle)
sendfile 2.1b.20080616-10
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,148 kB
  • sloc: ansic: 13,128; sh: 4,193; perl: 844; makefile: 132; java: 36; csh: 3
file content (387 lines) | stat: -rwxr-xr-x 11,979 bytes parent folder | download | duplicates (7)
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
#!/bin/sh
#
# File:         install
#
# Author:       Ulli Horlacher (framstag@rus.uni-stuttgart.de)
#
# Contribs:	Stefan Zehl (sec@42.org)
#               Michael Neumayer (eumel@42.org)
#
# History:      
#
#  1995-09-18 Framstag		initial version (insserv)
#  1995-10-24 Framstag		changed SAFT-port
#  1995-11-25 Framstag		new version: install
#  1995-12-18 Framstag		better error checking
#  1995-12-21 Framstag		new default for nosendfile: 
# 				/usr/local/etc/
#  1996-03-24 Framstag		added utf7encode binary
#  1996-04-04 Framstag		better HP-UX support
#  1996-06-23 Framstag		added INLOG and OUTLOG
#  1996-09-13 Framstag		added $BINDIR to check_sendfile
#                       	better /etc/inetd.conf parsing
#  1997-02-24 Framstag		fixed MANDIR
#  1997-03-20 Framstag		added Amiga support
#  1997-06-18 Framstag		added check for new sendfile.cf
#  1997-09-30 Framstag		better (own) spool free-space check
#  1997-11-22 Framstag		added sfconf
#  1997-11-23 Framstag		moved NOSENDFILE to ALLOW and DENY files
#				added sfdconf
#  1998-01-05 Framstag		better sfdconf installation
#  1998-02-27 sec		added reinstall option
#  1998-03-01 sec		fixed "text file busy"
#  1998-03-06 Framstag		better man sections locations
#  1998-03-13 Eumel		fixed rm-logfile-bug
#  1998-04-17 sec		better man-section detection
#  1998-09-29 Framstag		added ewl
#  1999-01-28 Framstag		added symlinks: sf sm rf
#  2005-05-30 Framstag		added xinetd detection
#
# Shell script to install the server, the clients and the man-pages for the 
# sendfile service. It also configures /etc/inetd.conf, /etc/xinetd.d/sendfile,
# /etc/services, /etc/profile and /etc/csh.login
# This script is called by make.
#
# If you want to change the default directories look in file build.
# You should not edit this file!
#
# This file is covered by the GNU General Public License


mkdir_recursive() {
  if [ ! -d $1 ]; then
    mkdir `echo $1 | 
           awk -F/ '{ for (i=2; $i!=""; i++)
                      { for (j=2; j<=i; j++) printf("/"$j)
  		        printf(" ") } }'
          ` 2>/dev/null
  fi
}

make_dirs() {
  mkdir_recursive $BINDIR
  mkdir_recursive $MANDIR/man1
  mkdir_recursive $SERVERDIR
  mkdir_recursive `dirname $DENY`
  mkdir_recursive `dirname $CONFIG`
  mkdir $MANDIR/man$manmisc $MANDIR/man$manadmin 2>/dev/null
}

make_man() {
  sed "s:/usr/local/etc/sendfile.allow:$ALLOW:
       s:/usr/local/etc/sendfile.deny:$DENY:
       s:/usr/local/etc/sendfile.cf:$CONFIG:
       s:/var/spool/sendfile:$SPOOL:
      " doc/$1.$2 >$MANDIR/man$3/$1.$3
}

install_man() {
  make_man sendfile 1 1
  make_man sendmsg 1 1
  make_man receive 1 1
  make_man fetchfile 1 1
  make_man fetchfile 7 $manmisc
  make_man sendfiled 8 $manadmin
  cp doc/wlock.1 doc/utf7encode.1 $MANDIR/man1
  (cd $MANDIR/man1; ln -s utf7encode.1 utf7decode.1 2>/dev/null)
}

SYSTEM=$1
RESTART=false

if [ "$SYSTEM" = "" ]; then 
  echo "To invoke install, type: make install"
  exit
fi

if [ "$LOGNAME" != root ]; then
  if [ "`whoami`" != root ]; then
    echo
    echo "You are not root! You probably run into problems now..."
    echo
  fi
fi

eval `awk -F\" '/define BINDIR/    {print "BINDIR="$2} 
                /define MANDIR/    {print "MANDIR="$2} 
                /define SERVERDIR/ {print "SERVERDIR="$2}
                /define SPOOL/     {print "SPOOL="$2}
                /define CONFIG/    {print "CONFIG="$2}
                /define DENY/	   {print "DENY="$2}
                /define ALLOW/	   {print "ALLOW="$2}
                /define ALIASES/   {print "ALIASES="$2}
                /define INLOG/     {print "INLOG="$2}
                /define OUTLOG/    {print "OUTLOG="$2}
	       ' src/globals.h`

if [ "$BINDIR" = "" ]; then	BINDIR=/usr/local/bin; fi
if [ "$MANDIR" = "" ]; then	MANDIR=/usr/local/man; fi
if [ "$SERVERDIR" = "" ]; then	SERVERDIR=/usr/local/sbin; fi
if [ "$CONFIG" = "" ]; then	CONFIG=/usr/local/etc/sendfile.cf; fi
if [ "$DENY" = "" ]; then	DENY=/usr/local/etc/sendfile.deny; fi
if [ "$ALLOW" = "" ]; then	ALLOW=/usr/local/etc/sendfile.allow; fi
if [ "$ALIASES" = "" ]; then	ALIASES=/usr/local/etc/sendfile.aliases; fi
if [ "$SPOOL" = "" ]; then	SPOOL=/var/spool/sendfile; fi
if [ "$INLOG" = "" ]; then	INLOG=$SPOOL/LOG/in; fi
if [ "$OUTLOG" = "" ]; then	OUTLOG=$SPOOL/LOG/out; fi
if [ "$INETDCONF" = "" ]; then	INETDCONF=/etc/inetd.conf; fi
if [ "$SERVICES" = "" ]; then	SERVICES=/etc/services; fi

if [ -f /etc/xinetd.conf -a -d /etc/xinetd.d ]; then
  INETDCONF=/etc/xinetd.d/sendfile
fi  

case "$SYSTEM" in
  *BSD*) manmisc=7; manadmin=8;;
      *) manmisc=5; manadmin=1m;;
esac

# purge old logfiles (bug from sendfile revision < 19980310)
rm -f $SPOOL*/.sendfile*.log

if [ "$2"  = "reinstall" ] ; then
	umask 022
	cd src || exit 1
	make_dirs
	cp sendfile sendmsg receive utf7encode fetchfile wlock $BINDIR/
	[ -x $SERVERDIR/sendfiled ] && mv $SERVERDIR/sendfiled $SERVERDIR/sendfiled.old && rm -f $SERVERDIR/sendfiled.old
	cp sendfiled $SERVERDIR
	cd ../etc
	cp sfconf sfdconf $BINDIR/
	cd ..
	install_man
	echo Done.
	exit 0
fi

cat <<EOD
WARNING: this sendfile install script will create or write to:

	spool directory =	$SPOOL
	binary directory =	$BINDIR
	manual directory =	$MANDIR
	sendfiled directory =	$SERVERDIR
	configuration files =	$CONFIG
				$DENY

In /etc/services and /etc/inetd.conf apropriate ads will be inserted.
In /etc/profile and /etc/csh.login a call to sendfile_check will be added.

To deinstall the sendfile-daemon, simply type: 	rm -f $SERVERDIR/sendfiled

EOD
echo 'If you are satisfied with these defaults, then type "ok" now:'
read answer
if [ "$answer" != ok ]; then
  echo
  echo "You can install sendfile manually, too. Please type: more doc/README"
  echo
  exit
fi

umask 022

echo "checking for directories"
make_dirs

echo "installing the clients in $BINDIR"
cd etc || exit 1
sed "s:/usr/local/etc/sendfile.cf:$CONFIG:
     s:/var/spool/sendfile:$SPOOL:" sf_cleanup \
     > $BINDIR/sf_cleanup
sed "s:SPOOL=/var/spool/sendfile:SPOOL=$SPOOL:
     s:INLOG=/var/spool/sendfile/LOG/in:INLOG=$INLOG:
     s:OUTLOG=/var/spool/sendfile/LOG/in:OUTLOG=$OUTLOG:
     s:CONFIG=/usr/local/etc/sendfile.cf:CONFIG=$CONFIG:
     s:ALIASES=/usr/local/etc/sendfile.aliases:ALIASES=$ALIASES:
     s:DENY=/usr/local/etc/sendfile.deny:DENY=$DENY:
     s:ALLOW=/usr/local/etc/sendfile.allow:ALLOW=$ALLOW:
    " sfdconf \
    | awk '{if ($0 != "CONFIG") print $0; else system("cat sendfile.cf")}' \
    > $BINDIR/sfdconf
sed "s:/var/spool/sendfile:$SPOOL:" sfconf >$BINDIR/sfconf
sed "s:receive :$BINDIR/receive :" check_sendfile >$BINDIR/check_sendfile
cd ../src || exit 1
cp sendfile sendmsg receive utf7encode fetchfile wlock $BINDIR/
cd ..
(cd $BINDIR
 ln -s utf7encode utf7decode 2>/dev/null
 ln -s sendfile sf 2>/dev/null
 ln -s sendmsg  sm 2>/dev/null
 ln -s receive  rf 2>/dev/null
 chmod 755 sfconf sfdconf <sf_cleanup check_sendfile \
           sendfile sendmsg receive fetchfile utf7encode)

echo "installing the man-pages in $MANDIR/*"
install_man

echo "installing the sendfile-daemon in $SERVERDIR"
[ -x $SERVERDIR/sendfiled ] && mv $SERVERDIR/sendfiled $SERVERDIR/sendfiled.old && rm -f $SERVERDIR/sendfiled.old
cp src/sendfiled $SERVERDIR  || exit 1

NOSENDFILE=`dirname $DENY 2>/dev/null`/nosendfile
if [ -f $NOSENDFILE ]; then 
  if grep ^allow-only $NOSENDFILE >/dev/null; then 
    echo "Information: $NOSENDFILE is now $ALLOW (autoconverted)"
    grep -v ^allow-only $NOSENDFILE > $ALLOW
  else  
    echo "Information: $NOSENDFILE is now $DENY (autoconverted)"
    mv $NOSENDFILE $DENY
  fi
fi
if [ ! -f $DENY -a ! -f $ALLOW ]; then 
  echo "installing the sendfile deny file as $DENY"
  cp etc/sendfile.deny $DENY
  chmod 644 $DENY
fi

if [ ! -f $CONFIG ]; then 
  echo "installing the global sendfile config file as $CONFIG"
  cp etc/sendfile.cf $CONFIG
  chmod 644 $CONFIG
else 
  if [ "`diff etc/sendfile.cf $CONFIG`" ]; then
    echo "Warning: `pwd`/etc/sendfile.cf differs from $CONFIG !"
    echo "Please take a look what has been changed!"
  fi
fi

if [ "$SYSTEM" = NEXT ]; then
  SERVICE="`nidump services . | awk '/[ \t]487\/tcp/'`"
else
  SERVICE="`awk '/[ \t]487\/tcp/' /etc/services`"
fi
if [ "$SERVICE" != "" ]; then
  case "$SERVICE" in 
    saft*)	;;
        *)	echo "ERROR: tcp-port 487 is already in use!"; exit 1;;
  esac
else
  if [ "$SYSTEM" = NEXT ]; then
    echo "configuring services"
    echo "saft	487/tcp		# simple asynchronous file transfer" | niload services .
  else
    echo "configuring $SERVICES"
    echo "#" >>$SERVICES
    echo "saft	487/tcp		# simple asynchronous file transfer" >>$SERVICES
  fi
fi

case "$INETDCONF" in
  *xinetd*) 
    if [ -f $INETDCONF ]; then
      echo $INETDCONF does already exist -skipping
    else
      echo installing $INETDCONF
      sed "s:/usr/local/sbin/sendfiled:$SERVERDIR/sendfiled:" etc/xinetd >$INETDCONF
      RESTART=true
    fi
    SENDFILED=`awk '/[ \t]*server[ \t]*=/ { print $3 }' $INETDCONF`
    ;;  
  *) 
    SENDFILED=`awk '/^saft/ { sfd=$6;
    	if (index($7,"/sendfiled")>0) sfd=$7;
        if (substr(sfd,1,1)=="?") sfd=substr(sfd,2);
        print sfd; }' $INETDCONF`
    if [ "$SENDFILED" = "" ]; then
      if [ -f /usr/sbin/tcpd ]; then 
        SFD="/usr/sbin/tcpd $SERVERDIR/sendfiled"
      else
        SFD="$SERVERDIR/sendfiled sendfiled"
      fi
      RESTART=true
      echo "configuring $INETDCONF"
      echo "#" >>$INETDCONF
      echo "# simple asynchronous file transfer" >>$INETDCONF
      echo "saft	stream	tcp	nowait	root	$SFD" >>$INETDCONF
    fi
    ;;  
esac

if [ "$SENDFILED" != "$SERVERDIR/sendfiled" -a "$SENDFILED" != "" ]; then
 echo "WARNING: you have specified $SENDFILED in $INETDCONF, but"
 echo "         there is $SERVERDIR/sendfiled in makeconfig! Check it!"
fi

if [ -f /etc/inetd.sec ]; then
  if [ "`grep '^saft' /etc/inetd.sec`" = "" ]; then
    echo >> /etc/inetd.sec
    echo "saft allow" >> /etc/inetd.sec
  fi
fi

if [ -f /etc/profile ]; then
  if [ "`grep check_sendfile /etc/profile`" = "" ]; then
    echo "adding check_sendfile to /etc/profile"
    echo >>/etc/profile
    echo "test -x $BINDIR/check_sendfile && $BINDIR/check_sendfile"\
          >>/etc/profile
  fi
fi
if [ -f /etc/csh.login ]; then
  if [ "`grep check_sendfile /etc/csh.login`" = "" ]; then
    echo "adding check_sendfile to /etc/csh.login"
    echo >>/etc/csh.login
    echo "test -x $BINDIR/check_sendfile && $BINDIR/check_sendfile" \
         >>/etc/csh.login
  fi
fi
				
if [ ! -d "$SPOOL/OUTGOING" ]; then
  echo "creating $SPOOL"
  mkdir_recursive $SPOOL/OUTGOING
  chmod 755  $SPOOL || exit 1
  chmod 1777 $SPOOL/OUTGOING
fi
if [ ! -d `dirname "$INLOG"` ]; then 
  mkdir_recursive `dirname $INLOG`
  chmod 700 `dirname $INLOG`
fi
if [ ! -d `dirname "$OUTLOG"` ]; then 
  mkdir_recursive `dirname $OUTLOG`
  chmod 700 `dirname $OUTLOG`
fi
if [ ! -f "$INLOG" ]; then 
  echo "# use \"utf7decode $INLOG\" to view this file" > $INLOG
  echo >> $INLOG
  chmod 600 $INLOG
fi
if [ ! -f "$OUTLOG" ]; then 
  echo "# use \"utf7decode $OUTLOG\" to view this file" > $OUTLOG
  echo >> $OUTLOG
  chmod 600 $OUTLOG
fi

free=`$SERVERDIR/sendfiled -f`
minfree=`awk '/minfree =/{print $3}' $CONFIG`
if [ "$free" -le "$minfree" ]; then
  cat <<EOD
		! WARNING ! 
You have not enough free disk space in $SPOOL !
Either give the spool directory more space or lower the value for the 
minfree option in $CONFIG
EOD
fi

echo
echo "You may want to add the following line to your system bootup script:"
echo "    $SERVERDIR/sendfiled -Q"
echo "This will start an outgoing spooling sendfile daemon on boot time"
echo "which processes any old files in the outgoing spool."
echo

if [ "$RESTART" = true ]; then
  if [ -f /etc/init.d/xinetd ]; then
    echo reloading xinetd:
    if fgrep reload\) /etc/init.d/xinetd >/dev/null; then
      /etc/init.d/xinetd reload
    else
      /etc/init.d/xinetd stop
      /etc/init.d/xinetd start
    fi
  else
    echo
    echo "please restart now your inetd ( or simply reboot :-) )"
    echo
  fi
fi