| 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 | |
| 6 | # dump_type FILE [N] |
| 7 | # Print type character from block N (default 0) of tar archive FILE |
| 8 | dump_type() { |
| 9 | dd if="$1" skip=${2:-0} bs=512 count=1 2>/dev/null | |
| 10 | tr '\0' ' ' | |
| 11 | cut -c157 |
| 12 | } |
| 13 | |
| 14 | case `dump_type "$1"` in |
| 15 | [gx]) PAX=1;; |
| 16 | esac |
| 17 | |
| 18 | cat "$1" |
| 19 | shift |
| 20 | for f |
| 21 | do |
| 22 | SKIP=0 |
| 23 | T=`dump_type "$f"` |
| 24 | if [ -n "$PAX" ]; then |
| 25 | if [ "$T" = "g" ]; then |
| 26 | # Global extended header.... 2 blocks |
| 27 | # Extended header........... 2 blocks |
| 28 | # Ustar header.............. 1 block |
| 29 | # FIXME: This calculation is will fail for very long file names. |
| 30 | SKIP=5 |
| 31 | fi |
| 32 | else |
| 33 | if [ "$T" = "V" ]; then |
| 34 | T=`dump_type "$f" 1` |
| 35 | fi |
| 36 | if [ "$T" = "M" ]; then |
| 37 | SKIP=$(($SKIP + 1)) |
| 38 | fi |
| 39 | fi |
| 40 | dd skip=$SKIP if="$f" |
| 41 | done |
| 42 |