#!/bin/sh

###########################
## UDEV-MTAB INIT SCRIPT ##
###########################

## Callum Dickinson <gcfreak_ag20@hotmail.com>
## Sonic Team Junior <http://www.srb2.org>
## http://mb.srb2.org/showthread.php?t=31137
## svn://code.srb2.org/SRB2/branches/WII

## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
## as published by the Free Software Foundation; either version 2
## of the License, or (at your option) any later version.

## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.


## Any lines in this file preceeded by a hash ('#') indicates a comment, and is not read by the interpreter.

#--------------------#
. /lib/lsb/init-functions
. /etc/profile
LOGFILE="$LOGDIR/$ME.log"
#--------------------#

# copy the rules generated before / was mounted read-write
for file in /dev/.udev/tmp-rules--*; do
  dest=${file##*tmp-rules--}
  [ "$dest" = '*' ] && break
  cat $file >> /etc/udev/rules.d/$dest
  rm -f $file
done


# if it's not, it's probably a symlink to /proc/mounts
[ -w /etc/mtab ] || exit 0

# defaults
tmpfs_size="10M"
udev_root="/dev/"

. /etc/udev/udev.conf

# strip the trailing slash
udev_root=${udev_root%/}

if mountpoint -q $udev_root; then
  grep -E --quiet --no-messages "^[^ ]+ +$udev_root +" /etc/mtab || \
    mount -f -o size=$tmpfs_size,mode=0755 -t tmpfs tmpfs $udev_root
fi

# /dev/.static/dev/ is not added to mtab because /dev/.static/ is not
# world readable and some users are annoyed by the resulting error
# message from df.
exit 0

# mountpoint(1) does not report bind mounts
if [ -e /dev/.static/dev/null ]; then
  grep -E --quiet --no-messages "^[^ ]+ +/dev/\.static/dev +" /etc/mtab || \
    mount -f --bind /dev /dev/.static/dev
fi

exit 0

