120221Sjoerg#!/bin/sh -p 220221Sjoerg# 320221Sjoerg# Simple replacement for tar(1), using cpio(1). 420221Sjoerg# 520221Sjoerg# Copyright (c) 1996 Joerg Wunsch 620221Sjoerg# All rights reserved. 720221Sjoerg# 820221Sjoerg# Redistribution and use in source and binary forms, with or without 920221Sjoerg# modification, are permitted provided that the following conditions 1020221Sjoerg# are met: 1120221Sjoerg# 1. Redistributions of source code must retain the above copyright 1220221Sjoerg# notice, this list of conditions and the following disclaimer. 1320221Sjoerg# 2. Redistributions in binary form must reproduce the above copyright 1420221Sjoerg# notice, this list of conditions and the following disclaimer in the 1520221Sjoerg# documentation and/or other materials provided with the distribution. 1620221Sjoerg# 1720221Sjoerg# THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR 1820221Sjoerg# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1920221Sjoerg# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2020221Sjoerg# IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 2120221Sjoerg# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2220221Sjoerg# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2320221Sjoerg# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2420221Sjoerg# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2520221Sjoerg# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2620221Sjoerg# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2720221Sjoerg# 2875328Sobrien# $FreeBSD$ 2975328Sobrien# 3020221Sjoerg 3120221Sjoerg# 3220221Sjoerg# For use on the fixit floppy. External programs required: 3320221Sjoerg# cpio(1), find(1), test(1) 3420221Sjoerg# 3520221Sjoerg 3620221Sjoerg 3760712Sjoergarchive=${TAPE:-/dev/rsa0} 3820221Sjoergblocksize="20" 3920221Sjoergdevice="" 4020221Sjoergmode="none" 4120221Sjoergverbose="" 4220221Sjoerg 4320221Sjoergusage() 4420221Sjoerg{ 4520221Sjoerg echo "usage: tar -{c|t|x} [-v] [-b blocksize] [-f archive] [files...]" 1>&2 4620221Sjoerg exit 64 # EX_USAGE 4720221Sjoerg} 4820221Sjoerg 4920221Sjoerg# 5020221Sjoerg# Prepend a hyphen to the first arg if necessary, so the traditional form 5120221Sjoerg# ``tar xvf /dev/foobar'' will work, too. More kludgy legacy forms are not 5220221Sjoerg# supported however. 5320221Sjoerg# 5420221Sjoerg 5520221Sjoergif [ $# -lt 1 ] ; then 5620221Sjoerg usage 5720221Sjoergfi 5820221Sjoerg 5920221Sjoergcase "$1" in 6020221Sjoerg -*) break 6120221Sjoerg ;; 6220221Sjoerg *) tmp="$1" 6320221Sjoerg shift 6420221Sjoerg set -- -$tmp "$@" 6520221Sjoerg ;; 6620221Sjoergesac 6720221Sjoerg 6820221Sjoergwhile getopts "ctxvb:f:" option 6920221Sjoergdo 7020221Sjoerg case $option in 7120221Sjoerg [ctx]) 7220221Sjoerg if [ $mode = "none" ] ; then 7320221Sjoerg mode=$option 7420221Sjoerg else 7520221Sjoerg usage 7620221Sjoerg fi 7720221Sjoerg ;; 7820221Sjoerg v) 7920221Sjoerg verbose="-v" 8020221Sjoerg ;; 8120221Sjoerg b) 8220221Sjoerg blocksize="${OPTARG}" 8320221Sjoerg ;; 8420221Sjoerg f) 8520221Sjoerg archive="${OPTARG## }" 8620221Sjoerg ;; 8720221Sjoerg *) 8820221Sjoerg usage 8920221Sjoerg ;; 9020221Sjoerg esac 9120221Sjoergdone 9220221Sjoerg 9320221Sjoergshift $(($OPTIND - 1)) 9420221Sjoerg 9520221Sjoergif [ "X${archive}" != "X-" ] ; then 9620221Sjoerg device="-F ${archive}" 9720221Sjoerg# else: use stdin or stdout, which is the default for cpio 9820221Sjoergfi 9920221Sjoerg 10020221Sjoergcase $mode in 10120221Sjoerg none) 10220221Sjoerg usage 10320221Sjoerg ;; 10420221Sjoerg t) 10520221Sjoerg exec cpio -it $verbose $device --block-size="$blocksize" "$@" 10620221Sjoerg ;; 10720221Sjoerg x) 10820221Sjoerg exec cpio -idmu $verbose $device --block-size="$blocksize" "$@" 10920221Sjoerg ;; 11020221Sjoerg c) 11120221Sjoerg if [ $# -eq 0 ] ; then 11220221Sjoerg # use current dir -- slightly bogus 11320221Sjoerg set -- "." 11420221Sjoerg fi 11520221Sjoerg find "$@" -print |\ 11620221Sjoerg cpio -o -H ustar $verbose $device --block-size="$blocksize" 11720221Sjoerg exit $? 11820221Sjoerg ;; 11920221Sjoergesac 120