4
0

tarcat 936 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #! /bin/sh
  2. # Usage: tarcat volume1 volume2 ...
  3. # concatenates a GNU tar multi-volume archive into a single tar archive.
  4. # Author: Bruno Haible <[email protected]>, Sergey Poznyakoff <[email protected]>
  5. # dump_type FILE [N]
  6. # Print type character from block N (default 0) of tar archive FILE
  7. dump_type() {
  8. dd if="$1" skip=${2:-0} bs=512 count=1 2>/dev/null |
  9. tr '\0' ' ' |
  10. cut -c157
  11. }
  12. case `dump_type "$1"` in
  13. [gx]) PAX=1;;
  14. esac
  15. cat "$1"
  16. shift
  17. for f
  18. do
  19. SKIP=0
  20. T=`dump_type "$f"`
  21. if [ -n "$PAX" ]; then
  22. if [ "$T" = "g" ]; then
  23. # Global extended header.... 2 blocks
  24. # Extended header........... 2 blocks
  25. # Ustar header.............. 1 block
  26. # FIXME: This calculation is will fail for very long file names.
  27. SKIP=5
  28. fi
  29. else
  30. if [ "$T" = "V" ]; then
  31. T=`dump_type "$f" 1`
  32. fi
  33. if [ "$T" = "M" ]; then
  34. SKIP=$(($SKIP + 1))
  35. fi
  36. fi
  37. dd skip=$SKIP if="$f"
  38. done