#!/bin/sh
#
# devfsd   This script handles the compatability symlinks for devfsd
#	   It relies on environment variables passed from /etc/init.d/devfsd
#

. /etc/default/devfsd

if [ -f /etc/devfs/symlinks.list ]; then
  LINKFILES=`grep -v ^# /etc/devfs/symlinks.list 2>/dev/null`
fi
if [ -f /etc/devfs/devices.list ]; then
  DEVFILES=`grep -v ^# /etc/devfs/devices.list 2>/dev/null`
fi

## set up symlinks
cd $MOUNTPOINT
if [ "$LINKFILES" != "" ]; then
	echo ""
	echo "/etc/devfs/symlinks and /etc/devfs/symlinks.d/* has been discontinued."
	echo "use /etc/devfs/conf.d/ instead, for details see devfsd.conf(5)."
	exit 1
fi
if [ "$DEVFILES" != "" ]; then
	echo -n "Creating extra device nodes..."
	OLDIFS="$IFS"
	IFS='\
'
	for i in `sed -e '/^#/d' $DEVFILES 2>/dev/null`; do
		IFS="$OLDIFS"
		eval set -- $i
		if [ ! -e $1 ]; then
			if [ "$2" = "d" ]; then
				mkdir -p $1
			else
				mknod $1 $2 $3 $4
			fi
		fi
		if [ "$5.$6" != "." ]; then
			chown $5:$6 $1
		fi
		if [ "$7" != "" ]; then
			chmod $7 $1
		fi
	done
	echo "done.  "
fi
