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