equal
deleted
inserted
replaced
|
1 #!/bin/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 ## main |
|
38 |
|
39 function copy () |
|
40 { |
|
41 local PREFIX="$1" |
|
42 local TYPE NAME REST |
|
43 |
|
44 [ -d "$FROMDIR/${PREFIX}CVS" ] || fail "Bad CVS directory '$FROMDIR/${PREFIX}.'" |
|
45 |
|
46 { cat "$FROMDIR/${PREFIX}CVS/Entries" || \ |
|
47 fail "Cannot read '$FROMDIR/${PREFIX}CVS/Entries'"; } | \ |
|
48 { |
|
49 ORIG_IFS="$IFS" |
|
50 IFS="/" |
|
51 while read TYPE NAME REST |
|
52 do |
|
53 if [ -n "$NAME" ]; then |
|
54 if [ "$TYPE" = D ]; then |
|
55 echo "${PREFIX}$NAME" |
|
56 mkdir -p "$TODIR/${PREFIX}$NAME" || fail "Bad directory '$TODIR/${PREFIX}$NAME'" |
|
57 copy "${PREFIX}$NAME/" || return "$?" |
|
58 else |
|
59 { [ ! -d "$TODIR/${PREFIX}$NAME" ] && \ |
|
60 cp -af "$FROMDIR/${PREFIX}$NAME" "$TODIR/${PREFIX}$NAME"; } || \ |
|
61 fail "Cannot install '$TODIR/${PREFIX}$NAME'" |
|
62 fi |
|
63 fi |
|
64 done |
|
65 IFS="$ORIG_IFS" |
|
66 } |
|
67 } |
|
68 |
|
69 mkdir -p "$TODIR" || fail "Bad directory '$TODIR'" |
|
70 copy "" |