#!/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/* use is deprecated."
	echo "It will be removed in a future version."
	echo "See devfsd(8) for how to achieve the same objectives more effectively"
	echo "through /etc/devfs/devfsd.conf, or ask russell@coker.com.au for advice."
	echo ""
	echo -n "Setting up symlinks in $MOUNTPOINT..."
	OLDIFS="$IFS"
	IFS='\
'
	for i in `sed -e '/^#/d' $LINKFILES 2>/dev/null`; do
		IFS="$OLDIFS"
		eval set -- $i
		[ -e $2 ] && continue
		ln -sf $1 $2
	done
	echo "done.    "
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
