#! /usr/bin/ksh ########################################################################## # Title : update.ksh - update files based on the modification time # Author : Heiner Steven # Category : File Utilities # Requires : cp, cpio, find, ksh # Date : 1996-05-24 # SCCS-Id. : @(#) update.ksh 1.4 03/12/19 ########################################################################## # Description # ########################################################################## PN=${0##*/} # Program name VER='1.4' CpioFlags=dm CpFlags=p function usage { print -u2 "$PN - update files based on the modification time $VER (hs '96) usage: $PN [-v] file [file ...] directory $PN [-v] file file $PN [-vr] {file|directory} [...] directory" exit 1 } function fatal { print -u2 "$PN:" "$@"; exit 1; } function msg { [[ $Verbose == yes ]] && print -u2 -- "$@"; } set -u # DEBUG Recurse=no Verbose=no MultipleFiles=no while getopts :vrRh Opt do case "$Opt" in (v) CpioFlags="${CpioFlags}v" Verbose=yes;; ([rR]) Recurse=yes;; (h) usage;; (*) usage;; esac done shift OPTIND-1 (( $# < 2 )) && usage (( $# > 3 )) && MultipleFiles=yes eval Dst="\${$#}" if [[ -d $Dst ]] then # Copy files to a directory if [[ $Recurse == no ]] then Files=$( for Path do [[ $Path == $Dst ]] && continue New="$Dst/${Path##*/}" if [[ ! -a $New || $Path -nt $New ]] then echo "$Path" msg "$New" else msg "Existing \"$New\" is same age or newer" fi done) [[ -n $Files ]] && cp -$CpFlags $Files "$Dst" else for Path do [[ $Path == $Dst ]] && continue find "$Path" -print | { [[ $Verbose == no ]] && exec >/dev/null 2>&1 cpio -p$CpioFlags "$Dst" } done fi elif [[ $MultipleFiles == yes ]] then fatal "cannot copy multiple files to file $Dst" elif [[ -f $1 ]] then if [[ ! -a $Dst || $1 -nt $Dst ]] then msg "$Dst" cp -p "$1" "$Dst" else msg "Existing \"$Dst\" is same age or newer" fi else # $1 is no file or non-existing fatal "cannot copy $1 to file $Dst" fi