Admin/cvs-copy
author wenzelm
Mon Jun 20 22:13:58 2005 +0200 (2005-06-20)
changeset 16485 77ae3bfa8b76
parent 16280 d7f8c48d5acb
permissions -rwxr-xr-x
get_thm instead of obsolete Goals.get_thm;
improved msg;
     1 #!/usr/bin/env bash
     2 #
     3 # $Id$
     4 #
     5 # cvs-copy - make copy of CVS controlled directory hierarchy
     6 #
     7 
     8 ## diagnostics
     9 
    10 PRG=$(basename "$0")
    11 THIS=$(cd $(dirname "$0"); echo "$PWD")
    12 
    13 function usage()
    14 {
    15   echo
    16   echo "Usage: $PRG FROMDIR TODIR"
    17   echo
    18   echo "  Make copy of CVS controlled directory hierarchy"
    19   exit 1
    20 }
    21 
    22 function fail()
    23 {
    24   echo "$1" >&2
    25   exit 2
    26 }
    27 
    28 
    29 ## process command line
    30 
    31 [ "$#" -ne 2 ] && usage
    32 
    33 FROMDIR="$1"; shift
    34 TODIR="$1"; shift
    35 
    36 
    37 ## GNU cp required
    38 
    39 CP=cp
    40 type -path gcp >/dev/null && CP=gcp
    41 
    42 
    43 ## main
    44 
    45 function copy ()
    46 {
    47   local PREFIX="$1"
    48   local TYPE NAME REST
    49 
    50   [ -d "$FROMDIR/${PREFIX}CVS" ] || fail "Bad CVS directory '$FROMDIR/${PREFIX}.'"
    51 
    52   { cat "$FROMDIR/${PREFIX}CVS/Entries" || \
    53     fail "Cannot read '$FROMDIR/${PREFIX}CVS/Entries'"; } | \
    54   {
    55     ORIG_IFS="$IFS"
    56     IFS="/"
    57     while read TYPE NAME REST
    58     do
    59       if [ -n "$NAME" ]; then
    60         if [ "$TYPE" = D ]; then
    61           echo "X ${PREFIX}$NAME"
    62           mkdir -p "$TODIR/${PREFIX}$NAME" || fail "Bad directory '$TODIR/${PREFIX}$NAME'"
    63           copy "${PREFIX}$NAME/" || return "$?"
    64         else
    65           { [ ! -d "$TODIR/${PREFIX}$NAME" ] && \
    66             $CP -af "$FROMDIR/${PREFIX}$NAME" "$TODIR/${PREFIX}$NAME"; } || \
    67           fail "Cannot install '$TODIR/${PREFIX}$NAME'"
    68         fi
    69       fi
    70     done
    71     IFS="$ORIG_IFS"
    72   }
    73 }
    74 
    75 mkdir -p "$TODIR" || fail "Bad directory '$TODIR'"
    76 copy ""