#!/bin/sh

# Xvnc startup script from inetd (for Debian)
# localhostからの接続に限定して使うこと

TMPD=/dev/shm

KB=
#KB=-kb
#FP='-fp DebianのX環境の標準のfontpath'
FP='-fp /usr/share/fonts/X11/misc,/usr/share/fonts/X11/100dpi/:unscaled,/usr/share/fonts/X11/75dpi/:unscaled,/usr/share/fonts/X11/Type1,/usr/share/fonts/X11/100dpi,/usr/share/fonts/X11/75dpi,built-ins'
GE='-geometry 1200x900'
DP='-depth 24'

if [ $# -ge 2 -a X"$1" = X-g ]; then
	GE="-geometry $2"; shift 2
fi

DISPNO=1
exec 3<"$0"
flock 3
while [ -e /tmp/.X$DISPNO-lock -o -e /tmp/.X11-unix/X$DISPNO -o \
		-e $TMPD/.Xvnclck-$DISPNO ]; do
	DISPNO=`expr $DISPNO + 1`
done
touch $TMPD/.Xvnclck-$DISPNO
flock -u 3
exec 3<&-

logger -it vnc-inetd -- Xvnc :$DISPNO "$GE"

((sleep 5; exec rm -f $TMPD/.Xvnclck-$DISPNO)&)
exec /usr/bin/Xvnc :$DISPNO -inetd -query localhost -once -securitytypes none \
	-br $GE $KB $FP $DP
