150276Speter#!/bin/sh 2166124Srafan# $Id: tar-copy.sh,v 1.5 2003/10/25 14:40:07 tom Exp $ 350276Speter############################################################################## 4166124Srafan# Copyright (c) 1998,2003 Free Software Foundation, Inc. # 550276Speter# # 650276Speter# Permission is hereby granted, free of charge, to any person obtaining a # 750276Speter# copy of this software and associated documentation files (the "Software"), # 850276Speter# to deal in the Software without restriction, including without limitation # 950276Speter# the rights to use, copy, modify, merge, publish, distribute, distribute # 1050276Speter# with modifications, sublicense, and/or sell copies of the Software, and to # 1150276Speter# permit persons to whom the Software is furnished to do so, subject to the # 1250276Speter# following conditions: # 1350276Speter# # 1450276Speter# The above copyright notice and this permission notice shall be included in # 1550276Speter# all copies or substantial portions of the Software. # 1650276Speter# # 1750276Speter# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # 1850276Speter# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # 1950276Speter# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # 2050276Speter# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # 2150276Speter# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # 2250276Speter# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # 2350276Speter# DEALINGS IN THE SOFTWARE. # 2450276Speter# # 2550276Speter# Except as contained in this notice, the name(s) of the above copyright # 2650276Speter# holders shall not be used in advertising or otherwise to promote the sale, # 2750276Speter# use or other dealings in this Software without prior written # 2850276Speter# authorization. # 2950276Speter############################################################################## 3050276Speter# 31166124Srafan# Author: Thomas E. Dickey 3250276Speter# 3350276Speter# Copy a collection of files using 'tar', so that their dates and links are 3450276Speter# preserved 3550276Speter# 3650276Speter# Parameters: 3750276Speter# $1 = files to copy 3850276Speter# $2 = source directory 3950276Speter# $3 = destination directory 4050276Speter# 4150276Speter#DOIT=echo 4250276SpeterDOIT=eval 4350276Speter 4450276Speterif test $# != 3 ; then 4550276Speter echo "Usage: $0 files source target" 4650276Speter exit 1 4750276Speterelif test ! -d "$2" ; then 4850276Speter echo "Source directory not found: $2" 4950276Speter exit 1 5050276Speterelif test ! -d "$3" ; then 5150276Speter echo "Target directory not found: $3" 5250276Speter exit 1 5350276Speterfi 5450276Speter 5550276SpeterWD=`pwd` 5650276Speter 5750276SpeterTMP=$WD/copy$$ 5850276Speter 5950276Spetercd $2 60166124SrafanTEST=`ls -d $1 2>/dev/null` 61166124Srafanif test -z "$TEST" 6250276Speterthen 63166124Srafan echo "... no match for \"$1\" in $2" 6450276Speterelse 65166124Srafan echo "... installing files matching \"$1\" in $2" 66166124Srafan trap "rm -f $TMP" 0 1 2 5 15 67166124Srafan if ( tar cf $TMP $1 ) 68166124Srafan then 69166124Srafan cd $3 70166124Srafan LIST=`tar tf $TMP 2>&1` 71166124Srafan $DOIT rm -rf $LIST 2>/dev/null 72166124Srafan $DOIT tar xvf $TMP 73166124Srafan else 74166124Srafan echo "Cannot create tar of $1 files" 75166124Srafan exit 1 76166124Srafan fi 7750276Speterfi 78