#! /bin/sh
#
#   Copyright (C) 2001-2004, 2006 Ola Lundqvist <opal@debian.org>
#
# This 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, or (at your option) any later
# version.
# 
# This 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.
# 
# You should have received a copy of the GNU General Public License with
# the source package as the file COPYING.  If not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA.
#

NFSROOTDIR=/mnt/nfsroot

if [ -r /etc/nfsbooted/mountfix.conf ] ; then
    . /etc/nfsbooted/mountfix.conf
fi

case "$1" in
    'start')
    TMPDIRS=$(mount | grep ramfs | sed -e "s|.*on ||;s| .*||;")
    
    for TD in $TMPDIRS ; do
	find $NFSROOTDIR$TD -type d -printf "%m %u %g %p\n" | sed -e "s|$NFSROOTDIR||;" \
	    | while read MODE OWN GRP CPATH ; do
	    mkdir -p $CPATH
	    chown $OWN.$GRP $CPATH
	    chmod $MODE $CPATH
	done
    done
    ;;
    'stop')
    ;;
    'restart')
	$0 stop
	$0 start
    ;;
    'force-reload')
	$0 stop
	$0 start
    ;;
    *)
    ;;
esac
