extracting tar-archive to directories

Ruud Harmsen ruud at targon.UUCP
Wed Aug 16 03:41:59 AEST 1989


In article <20552 at adm.BRL.MIL> rbj at dsys.ncsl.nist.gov (Root Boy Jim) writes:
> From: Geir Arnesen <arnesen at aftp.uucp>
>
> 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 <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  tarabs.1 tarabs.c
# Wrapped by ruud at swpvia on Tue Aug 15 19:36:13 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f tarabs.1 -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"tarabs.1\"
else
echo shar: Extracting \"tarabs.1\" \(1260 characters\)
sed "s/^X//" >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 <where-ever you wish>
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.1`; then
    echo shar: \"tarabs.1\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f tarabs.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"tarabs.c\"
else
echo shar: Extracting \"tarabs.c\" \(1047 characters\)
sed "s/^X//" >tarabs.c <<'END_OF_tarabs.c'
X#include <stdio.h>
X#include <string.h>
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 <tarabs.c`; then
    echo shar: \"tarabs.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0



More information about the Comp.unix.questions mailing list