home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / ade-misc-src.tgz / ade-misc-src.tar / scripts / creatediffs.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1996-10-13  |  5KB  |  140 lines

  1. #! /bin/sh
  2. #============================================================================
  3. # This shell script takes care of building diff files for individual products
  4. # in the ADE tree, using the baseline archives for each product.
  5. #
  6. # Takes the following arguments:
  7. #
  8. #    --to=<dir>    The directory in which to create the diff archives,
  9. #            typically something like "ADE-dist:951208".
  10. #
  11. #    --from=<dir>    The directory which contains the baseline and amiga
  12. #            source archives.  Typically the same as --to.
  13. #
  14. #    -tmp=<dir>    A temporary directory in which to create temporary
  15. #            subdirs used in creating the diffs.
  16. #
  17. # It creates a temporary work directory in the location specified by
  18. # the --tmp argument, dearchives the baseline archive in that directory,
  19. # dearchives the amiga source archive in that directory, builds a diff file
  20. # in that directory, and then archives it in a compressed tar archive.
  21. # If everything goes well, the diff archive is moved to the correct location
  22. # as specified by the --to argument.
  23. #
  24. # FIXME:  We used to use a pipe below to feed the gzip output into tar
  25. # however while finalizing FreshFish 10 this broke on dejagnu-1.2.tar.gz
  26. # for some unknown reason.  Doing it in two steps with an intermediate
  27. # temporary file works fine.  This should be investigated further. -fnf
  28.  
  29. to=
  30. from=
  31. tmp=
  32. for option
  33. do
  34.     # If the previous option needs an argument, assign it.
  35.     if test -n "$prev"; then
  36.         eval "$prev=\$option"
  37.         prev=
  38.         continue
  39.     fi
  40.  
  41.     case "$option" in
  42.         -*=*) optarg=`/bin/echo "$option" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
  43.         *) optarg= ;;
  44.     esac
  45.  
  46.     case "$option" in
  47.         --to)        prev=to ;;
  48.         --to=*)        to="$optarg" ;;
  49.         --from)        prev=from ;;
  50.         --from=*)    from="$optarg" ;;
  51.         --tmp)        prev=tmp ;;
  52.         --tmp=*)    tmp="$optarg" ;;
  53.         -*) { echo "error: $option: invalid option" 1>&2; exit 1; } ;;
  54.     esac
  55. done
  56.  
  57. # Verify that we have all the options we expect to have.
  58.  
  59. if test -z "$to"; then
  60.     echo "error: no --to=<dir> argument given" 1>&2
  61.     exit 1
  62. fi
  63.  
  64. if test -z "$from"; then
  65.     echo "error: no --from=<dir> argument given" 1>&2
  66.     exit 1
  67. fi
  68.  
  69. if test -z "$tmp"; then
  70.     echo "error: no --tmp=<dir> argument given" 1>&2
  71.     exit 1
  72. fi
  73.  
  74. # Check to see that the output directory exists.  If not, create it.
  75.  
  76. if test ! -d "$to"
  77. then
  78.     echo "mkdir -p $to"
  79.     mkdir -p $to
  80. fi
  81.  
  82. # Check to see that the temporary directory exists.  If not, create it.
  83.  
  84. WORKDIR="$tmp/ade-tmp"
  85. if test ! -d "$WORKDIR"
  86. then
  87.     echo "mkdir -p $WORKDIR"
  88.     mkdir -p $WORKDIR
  89. fi
  90.  
  91. for srcarchive in $from/*-src.tgz
  92. do
  93.     tool=`basename $srcarchive .tgz | sed "s/-src$//"`
  94.     if test -f $to/$tool-diffs.gz
  95.     then
  96.         continue
  97.     fi
  98.     basearchive="$from/$tool-base.tgz"
  99.     if test ! -f $srcarchive.pi
  100.     then
  101.         echo "WARNING: $srcarchive has no Product-Info file."
  102.     fi
  103.     if test ! -f "$basearchive"
  104.     then
  105.         echo "WARNING: no baseline archive found for $tool, skipped."
  106.     else
  107.         echo "==== $srcarchive ====="
  108.         # Remove any old baseline and amiga sources.
  109.         echo "rm -rf $WORKDIR/baseline $WORKDIR/amiga $WORKDIR/*-diffs.gz"
  110.         rm -rf $WORKDIR/baseline $WORKDIR/amiga $WORKDIR/*-diffs.gz
  111.         echo "mkdir $WORKDIR/baseline $WORKDIR/amiga"
  112.         mkdir $WORKDIR/baseline $WORKDIR/amiga
  113.         # Extract the baseline and amiga sources
  114.         echo "(cd $WORKDIR/baseline && gzip -d <$basearchive | tar -xpf -)"
  115.         (cd $WORKDIR/baseline && gzip -d <$basearchive | tar -xpf -)
  116.         echo "(cd $WORKDIR/amiga && gzip -d <$srcarchive | tar -xpf -)"
  117.         (cd $WORKDIR/amiga && gzip -d <$srcarchive | tar -xpf -)
  118.         # Create the diff file
  119.         out=$WORKDIR/$tool-diffs
  120.         echo >>$out "This file contains patches that transform the baseline version into" 
  121.         echo >>$out "the amiga version.  Assuming that you have unarchived the baseline"
  122.         echo >>$out "version in the current directory, just run the command:"
  123.         echo >>$out ""
  124.         echo >>$out "    patch -p1 -E -b .pbak <diff-file"
  125.         echo >>$out ""
  126.         echo >>$out "where 'diff-file' is this patch file.  After running patch you should"
  127.         echo >>$out "remove all the generated *.pbak files, and look for any *.rej files"
  128.         echo >>$out "that indicate a problem patching the baseline source."
  129.         echo >>$out ""
  130.         echo "(cd $WORKDIR && diff -rup --new-file baseline amiga) >>$out"
  131.         (cd $WORKDIR && diff -rup --new-file baseline amiga) >>$out
  132.         # Compress the diffs file and copy it to the destination.
  133.         echo "(cd $WORKDIR && gzip -9 $tool-diffs && cp $tool-diffs.gz $to/$tool-diffs.gz)"
  134.         (cd $WORKDIR && gzip -9 $tool-diffs && cp $tool-diffs.gz $to/$tool-diffs.gz)
  135.         # Add the product info file.
  136.         echo "cp $srcarchive.pi $to/$tool-diffs.gz.pi"
  137.         cp $srcarchive.pi $to/$tool-diffs.gz.pi
  138.     fi
  139. done
  140.