relative pathname question!

bob desinger bd at hpsemc.HP.COM
Wed Aug 17 08:45:48 AEST 1988


Doug Gwyn (gwyn at smoke.ARPA) writes:
> In article <453 at infohh.rmi.de> rlj-nbg at infohh.rmi.de (R.L. Jakschewitz) writes:
> -chroot newroot command
> -is one way to extract tar-chives that have been written with
> -absolute pathnames relative to 'newroot'.
>
> Only if you set up things like mkdir in the new /bin first!

Not just mkdir (hm-mmm, my SysV tar calls mkdir() but doesn't fork it
---but I digress).  You'll need the tar binary and the /dev/ device
file path to the tape after running chroot.  The following script does
what you want on System V.  (BSD sites will have to change a few paths
in it, like /dev/rmt/0m.  Strict SysV sites lacking `whoami' will need
to change it to `id' piped to sed.  ...Well, okay, the script works
fine on HP-UX and other modern SysV implementations offering BSD extras.)

-- bd

#! /bin/sh
# This is a shell archive.  Remove anything before this line,
# then unwrap it by saving it in a file and typing "sh file".
#
# Wrapped by bd at hpsemc on Tue Aug 16 12:52:08 1988
# Contents:
#	readtape 	

PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:$PATH; export PATH
echo 'At the end, you should see the message "End of shell archive."'

echo Extracting readtape
cat >readtape <<'@//E*O*F readtape//'
#! /bin/sh
: Reads a tar tape written with absolute pathnames into a relative path.
# @(#)readtape	1.2	10/08/86
# Usage:
#	[1] % cd /some/directory/somewhere
#	[2] % cp `which readtape` readtape
#	[3] % su root -c "cd /some/directory/somewhere && ./readtape"

me=`basename $0`
USAGE="Usage (a three-step process):
	% cd /some/directory/somewhere
	% cp /usr/public/bin/readtape readtape
	% su root -c \"cd \`pwd\` && ./readtape\""

# We assume we're in the place where we want the files to land.
# We also assume that readtape is here already and that you're super-user now,
# but make sure of that first.

if [ ! -f ./readtape ]
then	echo >&2 "$me:  Sorry, no readtape in `pwd`"
	echo >&2 "$USAGE"
	exit 1
elif [ ! -x ./readtape ]
then	echo >&2 "$me:  Sorry, ./readtape isn't executable"
	echo >&2 "$USAGE"
	exit 1
elif [ `whoami` != root ]
then	echo >&2 "$me:  Sorry, you must be root to run readtape"
	echo >&2 "$USAGE"
	exit 1
elif [ $# -ne 0 ]
then	echo >&2 "$USAGE"
	exit 1
fi

# Here we know an executable readtape is here and that we're super-user.
# Get the tar program into a known place.

cp /usr/bin/tar tar

# Create the mag tape device file from which tar will read.

set - `ls -l /dev/rmt/0m`
# crw-rw-rw-   1 root     other      5 0x020000 Aug 22 14:30 /dev/rmt/0m
mkdir dev dev/rmt
mknod dev/rmt/0m c $5 $6
chmod 666 dev/rmt/0m

# Now read in the tape.

/etc/chroot `pwd` ./tar xp
tarstatus=$?

# Clean up after yourself.

dir=`pwd`
test $dir != /		&& rm -rf dev
test $dir != /usr/bin	&& rm -f  tar

# Exit, returning the status returned by tar.
exit $tarstatus
@//E*O*F readtape//

set `wc -lwc <readtape`
if test $1 -ne 61 -o $2 -ne 281 -o $3 -ne 1578
then	echo ! readtape should have 61 lines, 281 words, and 1578 characters
	echo ! but has $1 lines, $2 words, and $3 characters
fi
chmod 555 readtape

echo "End of shell archive."
exit 0



More information about the Comp.unix.wizards mailing list