Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!psuvax1!gatech!purdue!mailrus!csd4.csd.uwm.edu!cs.utexas.edu!uunet!mcvax!hp4nl!targon!ruud
From: ruud@targon.UUCP (Ruud Harmsen)
Newsgroups: comp.unix.questions
Subject: Re: extracting tar-archive to directories
Message-ID: <596@targon.UUCP>
Date: 15 Aug 89 17:41:59 GMT
References: <20552@adm.BRL.MIL>
Reply-To: ruud@targon.UUCP (Ruud Harmsen)
Organization: Nixdorf Computer BV., SWP, P.O. Box 29, Vianen, Nederland
Lines: 142

In article <20552@adm.BRL.MIL> rbj@dsys.ncsl.nist.gov (Root Boy Jim) writes:
> From: Geir Arnesen 
>
> Does anyone now if it is possible to extract tar files from tape - to
> another directory/file than it was archived as?

I wrote a program to do this. See included manpage for details.  No
makefile, just "make" should do the job.

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh tarabs.1 <<'END_OF_tarabs.1'
X.TH TARABS 23 Vianen Local\ additions
X.SH NAME
Xtarabs \- read tarfiles with absolute pathnames
X.SH ORIGIN
XNixdorf, SWP-Vianen
X.SH SYNOPSIS
X.B tarabs searcharg
X.SH DESCRIPTION
X.I Tarabs
Xmay be useful if someone sends you a tape written with absolute
Xpathnames, i.e. pathnames that start with a slash ('/').
XTar should not be used that way, because you must have the same
Xdirectory structure as the sender, and if you have you will overwrite
Xany files that are already present there with the same name.
X
X.I Tarabs
Xmakes it possible to read such files with relative pathnames.
XIt converts the pathnames in the tar archive, such that the initial
Xslash and the character directly behind it are interchanged.  This
Xturns the names into relative paths, and the "directory checksums"
Xthat
X.I tar
Xmaintains, are still valid.
X
X.I Tarabs
Xtakes one argument, which is a string to be searched for in the names.
X.
X.SH EXAMPLE
XSuppose someone sends you a tar tape with files like:
X.nf
X/usr/bin/nroff
X/usr/bin/lex
X.fi
X
XYou can read this file by:
X
X.nf
Xcd 
Xcat /dev/rmt0 > file1
Xtarabs /usr/ < file1 > file2
Xtar xof file
X.fi
X
XThe files will now be extracted as:
X
X.nf
Xu/sr/bin/nroff
Xu/sr/bin/lex
X.fi
X
Xrelative to the current directory.
X.
X.SH SEE ALSO
Xtar(1)
END_OF_tarabs.1
if test 1260 -ne `wc -c tarabs.c <<'END_OF_tarabs.c'
X#include 
X#include 
X
X#define BUFLEN 512
X
Xmain (argc, argv) int argc; char ** argv;
X{
X    char buf[BUFLEN];
X    char *bufp;
X    int len, red;
X
X    if (argc != 2)
X    {
X	fprintf (stderr, "Usage %s string\n", argv[0]);
X	fprintf (stderr,
X	    "%s converts tar-files with absolute pathnames\n", argv[0]);
X	fprintf (stderr, "string if converted in pathnames, by\n");
X	fprintf (stderr, "string if converted in pathnames, by\n");
X	fprintf (stderr,
X	    "interchanging the slash and the next character\n");
X    }
X
X    len = strlen (argv[1]);
X
X    while (fread (buf, 1, BUFLEN, stdin) > 0)
X    {
X	if (strncmp (argv[1], buf, len) == 0)
X	{
X	    *buf = *(buf + 1);
X	    *(buf + 1) = '/';
X	    /* Look for link names */
X	    for (bufp = buf; *bufp != '\0' && bufp < buf + BUFLEN; bufp++)
X		;
X	    for (/*go on */; *bufp != '/'  && bufp < buf + BUFLEN; bufp++)
X		;
X	    if (bufp + len < buf + BUFLEN
X		&& strncmp (argv[1], bufp, len) == 0)
X	    {
X		*bufp = *(bufp + 1);
X		*(bufp + 1) = '/';
X	    }
X	}
X	fwrite (buf, 1, BUFLEN, stdout);
X    }
X}
END_OF_tarabs.c
if test 1047 -ne `wc -c