home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / BASHOS2.ZIP / support / mktarfile.exe < prev   
Text File  |  1992-10-29  |  2KB  |  72 lines

  1. #!/local/bash/bash
  2. # How to make a distribution tarfile.
  3. #
  4. # $1 is the name of the program.
  5. # $2 is the version number.
  6. # Remaining args are files to tar.
  7. # Optional argument of ~+notar" means don't create the actual tar file,
  8. # just create the symlinked directory.
  9.  
  10. tar_inhibited=""
  11. if [ "$1" = "+notar" ]; then
  12.   tar_inhibited=yes
  13.   shift
  14. fi
  15.  
  16. PROGRAM=$1
  17. VERSION=$2
  18.  
  19. shift; shift
  20.  
  21. if [ "$PROGRAM" = "" -o "$VERSION" = "" ]; then
  22.   echo "Usage: mktarfile [+notar] <progname> <version> <file ...>"
  23.   exit 2;
  24. fi
  25.  
  26. TARFILE=$PROGRAM.tar
  27. TARDIR=$PROGRAM-$VERSION
  28.  
  29. # Delete the tarfile if we are to create it.
  30. if [ ! "tar_inhibited" ]; then
  31.   rm -rf $TARFILE
  32. fi
  33.  
  34. # Delete the destination directory if it already exists.
  35. rm -rf $TARDIR
  36.  
  37. # Make the destination directory.
  38. echo "Making directory $TARDIR..."
  39. mkdir $TARDIR
  40.  
  41. topdir=`pwd`
  42. where_I_am=$TARDIR
  43.  
  44. trap "cd $topdir" 3
  45.  
  46. for i in $*; do
  47.   filename=$i
  48.   while [ "$filename" ]; do
  49.     remainder=`echo $filename | sed 's@[-_a-zA-Z~0-9.]*/@@'`
  50.     dir=`echo $filename | sed "s@$remainder@@" | sed "s@/@@"`
  51.     if [ "$dir" ]; then
  52.        if [ ! -d $where_I_am/$dir ]; then
  53.       echo "Making directory $where_I_am/$dir..."
  54.       mkdir $where_I_am/$dir
  55.        fi
  56.        cd $where_I_am/$dir; where_I_am=`pwd`
  57.        filename=$remainder
  58.     else
  59.        break
  60.     fi
  61.   done
  62.   cd $topdir; where_I_am=$TARDIR
  63.   ln -s $topdir/$i $TARDIR/$i
  64. done
  65.  
  66. if [ ! "$tar_inhibited" ]; then
  67.   tar -chf $TARFILE $TARDIR
  68.   rm -rf $TARDIR
  69. fi
  70.  
  71. exit 0
  72.