Revert "WIP"
[dragonfly.git] / tools / tools / genreadmedeleted / genreadmedeleted
1 #!/bin/sh
2
3 # $DragonFly: src/tools/tools/genreadmedeleted/genreadmedeleted,v 1.2 2006/09/27 10:24:15 corecode Exp $
4
5 if [ $# -lt 2 -o $# -gt 3 ]
6 then
7         echo "$0 <origdir> <trim'ddir> [readmefile]" >&2
8         echo "    readmefile defaults to trim'ddir/README.DELETED" >&2
9         echo "    you can use '-' as readmefile to force output to stdout" >&2
10         exit 1
11 fi
12
13 origdir=`realpath $1`/; shift
14 trimdir=`realpath $1`/; shift
15 readme=${1:-$trimdir/README.DELETED}
16
17 trimdir() {
18         local curdir=$1
19         local isdir
20         cd "$origdir$curdir"
21         set -- .* *
22         for f
23         do
24                 case "$f" in
25                 .|..)
26                         continue
27                         ;;
28                 esac
29
30                 if [ -d "$f" ]
31                 then
32                         isdir=/
33                 else
34                         isdir=
35                 fi
36
37                 if [ ! -e "$trimdir$curdir$f" ]
38                 then
39                         printf '%s%s\n' "$curdir$f" "$isdir"
40                         continue
41                 fi
42
43                 case "$isdir" in
44                 /)
45                         (trimdir "$curdir$f/")
46                         ;;
47                 esac
48         done
49 }
50
51 case "$readme" in
52 -)
53         ;;
54 *)
55         exec > $readme
56         ;;
57 esac
58
59 trimdir ""