home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 April / PCO0499.ISO / filesbbs / os2 / apach134.arj / APACH134.ZIP / src / helpers / mkshadow.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1998-12-05  |  2.6 KB  |  111 lines

  1. #!/bin/sh
  2. ##
  3. ##  mkshadow.sh -- create a shadow tree
  4. ##
  5. ##  Written by Ralf S. Engelschall <rse@apache.org>
  6. ##  for the shadow tree generation option (--shadow) of 
  7. ##  Apache's Autoconf-style Interface (APACI) 
  8. ##
  9. #
  10. # This script falls under the Apache License.
  11. # See http://www.apache.org/docs/LICENSE
  12.  
  13.  
  14. #   default IFS
  15. DIFS='     
  16. '
  17.  
  18. #   source and destination directory
  19. src=`echo $1 | sed -e 's:/$::'`
  20. dst=`echo $2 | sed -e 's:/$::'`
  21.  
  22. #   check whether source exists
  23. if [ ! -d $src ]; then
  24.     echo "mkshadow.sh:Error: source directory not found" 1>&2
  25.     exit 1
  26. fi
  27.  
  28. #   determine if one of the paths is an absolute path,
  29. #   because then we have to use an absolute symlink
  30. oneisabs=0
  31. case $src in
  32.     /* ) oneisabs=1 ;;
  33. esac
  34. case $dst in
  35.     /* ) oneisabs=1 ;;
  36. esac
  37.  
  38. #   determine reverse directory for destination directory
  39. dstrevdir=''
  40. if [ $oneisabs = 0 ]; then
  41.     #   (inlined fp2rp)
  42.     OIFS2="$IFS"; IFS='/'
  43.     for pe in $dst; do
  44.         dstrevdir="../$dstrevdir"
  45.     done
  46.     IFS="$OIFS2"
  47. else
  48.     src="`cd $src; pwd`";
  49. fi
  50.  
  51. #   create directory tree at destination
  52. if [ ! -d $dst ]; then
  53.     mkdir $dst
  54. fi
  55. DIRS="`cd $src
  56.        find . -type d -print |\
  57.        sed -e '/\/CVS/d' \
  58.            -e '/^\.$/d' \
  59.            -e 's:^\./::'`"
  60. OIFS="$IFS" IFS="$DIFS"
  61. for dir in $DIRS; do
  62.     mkdir $dst/$dir
  63. done
  64. IFS="$OIFS"
  65.  
  66. #   fill directory tree with symlinks to files
  67. FILES="`cd $src
  68.         find . -depth -print |\
  69.         sed -e '/\.o$/d' \
  70.             -e '/\.a$/d' \
  71.             -e '/\.so$/d' \
  72.             -e '/\.so-o$/d' \
  73.             -e '/\.cvsignore$/d' \
  74.             -e '/\/CVS/d' \
  75.             -e '/\.indent\.pro$/d' \
  76.             -e '/\.apaci.*/d' \
  77.             -e '/Makefile$/d' \
  78.             -e '/\/\.#/d' \
  79.             -e '/\.orig$/d' \
  80.             -e 's/^\.\///'`"
  81. OIFS="$IFS" IFS="$DIFS"
  82. for file in $FILES; do
  83.      #  don't use `-type f' above for find because of symlinks
  84.      if [ -d $file ]; then
  85.          continue
  86.      fi
  87.      basename=`echo $file | sed -e 's:^.*/::'`
  88.      dir=`echo $file | sed -e 's:[^/]*$::' -e 's:/$::' -e 's:$:/:' -e 's:^/$::'`
  89.      from="$src/$file"
  90.      to="$dst/$dir$basename"
  91.      if [ $oneisabs = 0 ]; then
  92.          if [ ".$dir" != . ]; then
  93.              subdir=`echo $dir | sed -e 's:/$::'`
  94.              #   (inlined fp2rp)
  95.              revdir=''
  96.              OIFS2="$IFS"; IFS='/'
  97.              for pe in $subdir; do
  98.                  revdir="../$revdir"
  99.              done
  100.              IFS="$OIFS2"
  101.              #   finalize from
  102.              from="$revdir$from"
  103.          fi
  104.          from="$dstrevdir$from"
  105.      fi
  106.      echo "    $to"
  107.      ln -s $from $to
  108. done
  109. IFS="$OIFS"
  110.  
  111.