[project @ 1996-07-19 18:36:04 by partain]
[ghc-hetmet.git] / glafp-utils / scripts / lndir.sh
1 #! /bin/sh
2
3 # lndir - create shadow link tree
4 #
5 # $XConsortium: lndir.sh,v 1.8 91/04/15 17:55:03 rws Exp $
6 #
7 # Used to create a copy of the a directory tree that has links for all
8 # non- directories (except those named RCS or SCCS).  If you are
9 # building the distribution on more than one machine, you should use
10 # this script.
11 #
12 # If your master sources are located in /usr/local/src/X and you would like
13 # your link tree to be in /usr/local/src/new-X, do the following:
14 #
15 #       %  mkdir /usr/local/src/new-X
16 #       %  cd /usr/local/src/new-X
17 #       %  lndir ../X
18
19 USAGE="Usage: $0 fromdir [todir]"
20
21 if [ $# -lt 1 -o $# -gt 2 ]
22 then
23         echo "$USAGE"
24         exit 1
25 fi
26
27 DIRFROM=$1
28
29 if [ $# -eq 2 ];
30 then
31         DIRTO=$2
32 else
33         DIRTO=.
34 fi
35
36 if [ ! -d $DIRTO ]
37 then
38         echo "$0: $DIRTO is not a directory"
39         echo "$USAGE"
40         exit 2
41 fi
42
43 cd $DIRTO
44
45 if [ ! -d $DIRFROM ]
46 then
47         echo "$0: $DIRFROM is not a directory"
48         echo "$USAGE"
49         exit 2
50 fi
51
52 pwd=`pwd`
53
54 if [ `(cd $DIRFROM; pwd)` = $pwd ]
55 then
56         echo "$pwd: FROM and TO are identical!"
57         exit 1
58 fi
59
60 for file in `ls -af $DIRFROM`
61 do
62     if [ ! -d $DIRFROM/$file ]
63     then
64             ln -s $DIRFROM/$file .
65     else
66             if [ $file != RCS -a $file != SCCS -a $file != . -a $file != .. ]
67             then
68                     echo $file:
69                     mkdir $file
70                     (cd $file
71                      pwd=`pwd`
72                      case "$DIRFROM" in
73                              /*) ;;
74                              *)  DIRFROM=../$DIRFROM ;;
75                      esac
76                      if [ `(cd $DIRFROM/$file; pwd)` = $pwd ]
77                      then
78                             echo "$pwd: FROM and TO are identical!"
79                             exit 1
80                      fi
81                      $0 $DIRFROM/$file
82                     )
83             fi
84     fi
85 done