Path: utzoo!utgpu!water!watmath!clyde!bellcore!decvax!ucbvax!hplabs!hpda!hpsemc!bd From: bd@hpsemc.HP.COM (bob desinger) Newsgroups: comp.unix.wizards Subject: Re: Re: Tar and absolute pathnames Message-ID: <570001@hpsemc.HP.COM> Date: 12 Feb 88 01:37:31 GMT References: <3990@hoptoad.uucp> Organization: HP SEMC, Cupertino, CA Lines: 111 I received tar tapes with absolute pathnames enough times to write a script to fix the problem, at least on System V. The basic idea is to do a chroot to the local directory (say, your $HOME) before reading the tape. Complications set in because you need to have the tar binary under the new root; easy to fix by copying tar to the current directory. Additionally, you need to make the node of the tape device from which tar reads. Only root can do the mknod on System V, so this script wants you to be root. The below script has System-V-isms in it (the pathname to tar is hardwired, cringe; the /dev entry is specific to SysV; the chroot command is in SysIII/V/Xenix but not BSD). But at least it works. Come to think of it, it runs `whoami', a BSD-ism that runs on several System V implementations including HP-UX. So it's not vanilla SysV. Okay, for both of you who don't have `whoami' on your SysV box out there, replace whoami with: id | sed -e 's/^[^(][^(]*(//' -e 's/).*$//' bob desinger bd%hpsemc@hplabs.HP.COM {ucbvax, uunet}!hpda!hpsemc!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 Thu Feb 11 17:17:36 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