3 # Note: bash is required, sh will fail to output anything to the client
4 # Probably related to interactions beteween & and output redirections
7 # You can use the evironment variable $QUERY_STRING for the query
9 [ "$ADDR" = "" ] && ADDR
=127.0.0.1
10 [ "$LOG" = "" ] && LOG
=/tmp
/gopher.service.err
11 [ "$PIDF" = "" ] && PIDF
="`mktemp`"
12 [ "$TIMEOUT" = "" ] && TIMEOUT
=10
13 [ "$MAXCON" = "" ] && MAXCON
=1024
17 [ "$port" = "" ] && port
=70
19 if [ "$prog" = "" ]; then
21 echo "Syntax: $0 [prog] ([port])" >&2
22 echo ' You can use the evironment variable $QUERY_STRING for the query' >&2
23 echo ' The default port is 70' >&2
24 echo ' A filename will be displayed, you can delete it to stop the service' >&2
25 echo ' (with a grace time of $TIMEOUT seconds)' >&2
29 tmpd
=`mktemp -t -d .gopher-service.XXXXXX`
30 if [ ! -d "$tmpd" ]; then
32 echo "Cannot create temporary directory, aborting..." >&2
40 while [ -e "$PIDF" ]; do
42 [ $i -gt "$MAXCON" ] && i
=1
44 rm -f "$fifo" 2>/dev
/null
46 < "$fifo" nc
-l -q0 -w"$TIMEOUT" "$ADDR" -p "$port" |
(
48 query
="`echo "$query" | cut -f2 -d' ' | sed 's:[\r\n]::g'`"
49 QUERY_STRING
="$query" "$prog" 2>> "$LOG" &
52 rm -rf "$tmpd" 2>/dev
/null