tarcat 1.6 KB

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