lndir.sh 1.5 KB

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