worldstone: add -s for statistical profiling
[minix.git] / etc / mtree.sh
blob96e794ac980d38bf3f22ece1c298575b6265b8a8
1 #!/bin/sh
2 set -e
4 if [ $# -ne 4 -a $# -ne 5 ]
5 then echo "Usage: $0 mtreefile TOOL_AWK TOOL_STAT UNPRIV DESTDIR"
6 exit 1
7 fi
9 AWK=$2
10 STAT=$3
11 UNPRIV=$4
13 if [ $# -eq 5 ]
14 then DESTDIR=$5
15 else DESTDIR="/" # If not set, default to root (i.e., normal case)
18 cat "$1" | while read line
20 NF="`echo $line | ${AWK} '{ print NF }'`"
21 if [ $NF = 4 ]
22 then mode="`echo $line | ${AWK} '{ print $1 }'`"
23 owner="`echo $line | ${AWK} '{ print $2 }'`"
24 group="`echo $line | ${AWK} '{ print $3 }'`"
25 dir="${DESTDIR}`echo $line | ${AWK} '{ print $4 }'`"
26 mkdir -p $dir
27 echo $dir
28 targetdev="`${STAT} -f %d $dir/.`"
29 if [ $targetdev -lt 256 ]
30 then echo "skipping non-dev $dir properties"
31 elif [ $UNPRIV != yes ]
32 then
33 chown $owner $dir
34 chmod $mode $dir
35 chgrp $group $dir
37 elif [ $NF = 3 ]
38 then target="`echo $line | ${AWK} '{ print $3 }'`"
39 linkfile="${DESTDIR}`echo $line | ${AWK} '{ print $1 }'`"
40 rm -f $linkfile
41 ln -s $target $linkfile
42 else echo odd line.
43 exit 1
45 done