tarcat 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. # Copyright 2004-2023 Free Software Foundation, Inc.
  6. # This file is part of GNU tar.
  7. # GNU tar is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 3 of the License, or
  10. # (at your option) any later version.
  11. # GNU tar is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. # dump_type FILE [N]
  18. # Print type character from block N (default 0) of tar archive FILE
  19. dump_type() {
  20. dd if="$1" skip=${2:-0} bs=512 count=1 2>/dev/null |
  21. tr '\0' ' ' |
  22. cut -c157
  23. }
  24. case `dump_type "$1"` in
  25. [gx]) PAX=1;;
  26. esac
  27. cat "$1"
  28. shift
  29. for f
  30. do
  31. SKIP=0
  32. T=`dump_type "$f"`
  33. if [ -n "$PAX" ]; then
  34. if [ "$T" = "g" ]; then
  35. # Global extended header.... 2 blocks
  36. # Extended header........... 2 blocks
  37. # Ustar header.............. 1 block
  38. # FIXME: This calculation is will fail for very long file names.
  39. SKIP=5
  40. fi
  41. else
  42. if [ "$T" = "V" ]; then
  43. T=`dump_type "$f" 1`
  44. fi
  45. if [ "$T" = "M" ]; then
  46. SKIP=$(($SKIP + 1))
  47. fi
  48. fi
  49. dd skip=$SKIP if="$f"
  50. done