first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / scripts / rev_control / cvs_importer.sh
1 #!/bin/bash
2 # cvs_importer: this tool does a recursive cvs add.  it takes one or more
3 # directory names and recursively adds them to the cvs hierarchy they are
4 # currently located under (i.e., their parent directory).
5
6 if [ "$#" = "0" ]; then
7   echo "This program needs one or more directory names to recursively add."
8   exit 23
9 fi
10
11 function add_cvs_dir {
12   # loop across all the directories we were handed.  these had better be
13   # arranged in hierarchically descending order or cvs will not like adding
14   # them.
15   for q in $*; do
16     if [ "$(basename $q)" == "CVS"  ]; then
17 #echo "the parameter was cvs! -> $q"
18       continue;
19     fi
20     cvs add "$q"
21 #echo "just added directory $q"
22   done
23 }
24
25 function add_cvs_files {
26   # scans through the list of directories we were given.  each directory is
27   # assumed to have some files which need to be added.  we will add those
28   # files to cvs on a per directory basis to avoid clogging up the command
29   # lines and such.
30   for q in $*; do
31     if [ "$(basename $q)" == "CVS"  ]; then
32 #echo "skipping parameter as cvs! -> $q"
33       continue;
34     fi
35
36     pushd $q &>/dev/null
37     if [ $? -ne 0 ]; then
38       echo "Skipping badly erroneous directory $i.  Logic error?"
39       continue;
40     fi
41
42     # add all the files in this directory, but don't do subdirectories.
43     file_list=$(find . -maxdepth 1 -type f)
44     # make sure there are actually some files there.
45     if [ ! -z "$file_list" ]; then
46       find . -maxdepth 1 -type f -exec cvs add "{}" '+'
47 #echo "just added those files to $q directory"
48     fi
49
50     # go back to where we were before jumping into the directory.
51     popd &>/dev/null
52   done
53 }
54
55 # main activity of script occurs starting here...
56
57 # loop across the directory names we were given on the command line.
58 for i in $*; do
59   # change into the directory just above the directory to add.
60   parent_dir=$(dirname $i)
61   adding_dir=$(basename $i)
62   pushd $parent_dir &>/dev/null
63   if [ $? -ne 0 ]; then
64     echo "Skipping erroneous parent directory $parent_dir."
65     continue;
66   fi
67 #echo dir is now: $(pwd)
68
69   # find all the directories starting at the real directory to add, and add
70   # cvs repositories for each of them.
71   add_cvs_dir $(find $adding_dir -type d)
72
73   # now add all the files, since all of the directories should be listed
74   # in the cvs archive.
75   add_cvs_files $(find $adding_dir -type d) 
76
77   # go back to the directory where we were previously.
78   popd &>/dev/null
79
80 done
81