1251881Speter#!/bin/sh 2251881Speter# $Id: tar-copy.sh,v 1.5 2003/10/25 14:40:07 tom Exp $ 3251881Speter############################################################################## 4251881Speter# Copyright (c) 1998,2003 Free Software Foundation, Inc. # 5251881Speter# # 6251881Speter# Permission is hereby granted, free of charge, to any person obtaining a # 7251881Speter# copy of this software and associated documentation files (the "Software"), # 8251881Speter# to deal in the Software without restriction, including without limitation # 9251881Speter# the rights to use, copy, modify, merge, publish, distribute, distribute # 10251881Speter# with modifications, sublicense, and/or sell copies of the Software, and to # 11251881Speter# permit persons to whom the Software is furnished to do so, subject to the # 12251881Speter# following conditions: # 13251881Speter# # 14251881Speter# The above copyright notice and this permission notice shall be included in # 15251881Speter# all copies or substantial portions of the Software. # 16251881Speter# # 17251881Speter# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # 18251881Speter# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # 19251881Speter# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # 20251881Speter# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # 21251881Speter# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # 22251881Speter# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # 23251881Speter# DEALINGS IN THE SOFTWARE. # 24251881Speter# # 25251881Speter# Except as contained in this notice, the name(s) of the above copyright # 26251881Speter# holders shall not be used in advertising or otherwise to promote the sale, # 27251881Speter# use or other dealings in this Software without prior written # 28251881Speter# authorization. # 29251881Speter############################################################################## 30251881Speter# 31251881Speter# Author: Thomas E. Dickey 32251881Speter# 33251881Speter# Copy a collection of files using 'tar', so that their dates and links are 34251881Speter# preserved 35251881Speter# 36251881Speter# Parameters: 37251881Speter# $1 = files to copy 38251881Speter# $2 = source directory 39251881Speter# $3 = destination directory 40251881Speter# 41251881Speter#DOIT=echo 42251881SpeterDOIT=eval 43251881Speter 44251881Speterif test $# != 3 ; then 45251881Speter echo "Usage: $0 files source target" 46251881Speter exit 1 47251881Speterelif test ! -d "$2" ; then 48251881Speter echo "Source directory not found: $2" 49251881Speter exit 1 50251881Speterelif test ! -d "$3" ; then 51251881Speter echo "Target directory not found: $3" 52251881Speter exit 1 53251881Speterfi 54251881Speter 55251881SpeterWD=`pwd` 56251881Speter 57251881SpeterTMP=$WD/copy$$ 58251881Speter 59251881Spetercd $2 60251881SpeterTEST=`ls -d $1 2>/dev/null` 61251881Speterif test -z "$TEST" 62251881Speterthen 63251881Speter echo "... no match for \"$1\" in $2" 64251881Speterelse 65251881Speter echo "... installing files matching \"$1\" in $2" 66251881Speter trap "rm -f $TMP" 0 1 2 5 15 67251881Speter if ( tar cf $TMP $1 ) 68251881Speter then 69251881Speter cd $3 70251881Speter LIST=`tar tf $TMP 2>&1` 71251881Speter $DOIT rm -rf $LIST 2>/dev/null 72251881Speter $DOIT tar xvf $TMP 73251881Speter else 74251881Speter echo "Cannot create tar of $1 files" 75251881Speter exit 1 76251881Speter fi 77251881Speterfi 78251881Speter