minor improvements
[feisty_meow.git] / scripts / archival / general_updater.sh
1 #!/bin/bash
2
3 # a script that handles synchronization of important assets from the MAJOR_ARCHIVE_SOURCES
4 # and the SOURCECODE_HIERARCHY_LIST onto a backup drive of some sort.  it will only copy folders
5 # if there is a target folder of the appropriate name already on the backup medium.
6
7 source "$FEISTY_MEOW_SCRIPTS/core/launch_feisty_meow.sh"
8
9 # given a location in the filesystem, we will go to that location and attempt to
10 # update any revision control repositories stored there to the latest versions.
11 function update_source_folders()
12 {
13   folder="$1"; shift
14   sep
15   if [ ! -d "$folder" ]; then
16     echo "The folder '$folder' does not exist, so skipping repository update there."
17     return;
18   fi
19   echo getting latest codes in $folder...
20   pushd "$folder"
21   if [ $? -ne 0 ]; then
22     echo Changing to the folder $folder failed.
23     return 1
24   fi
25   bash "$FEISTY_MEOW_SCRIPTS/rev_control/rcheckin.sh"
26   if [ $? -ne 0 ]; then
27     echo Checking out the latest codes has failed somehow for $folder.
28     return 1
29   fi
30   popd
31   sep
32 }
33
34 # this attempts to copy all the contents in a folder called "from" into a folder
35 # called "to".  it's a failure for the "from" folder to not exist, but the "to"
36 # is allowed to not exist (in which case we don't try to synch to it).
37 function synch_directory_to_target()
38 {
39   local from="$1"; shift
40   local to="$1"; shift
41
42   sep
43
44   if [ ! -d "$from" ]; then
45     echo "skipping synch on missing source directory: $from"
46     return 0
47   fi
48   if [ ! -d "$to" ]; then
49     echo "skipping synch into non-existent target directory $to"
50     return 0
51   fi
52
53   echo "synching from $from into $to"
54   netcp "$from"/* "$to"/
55   if [ $? -ne 0 ]; then
56     echo "The synchronization of $from into $to has failed."
57     return 1
58   fi
59 }
60
61 # the uber controller method that does the "hard" work of updating.
62 # any items from the MAJOR_ARCHIVE_SOURCES that are on the target will be
63 # updated.  any items found on the target matching the members of the
64 # SOURCECODE_HIERARCHY_LIST will be treated as code hierarchies and updated.
65 function update_archive_drive()
66 {
67   local target_folder="$1"; shift  # where we're backing up to.
68   local currdir  # loop variable.
69
70   sep
71
72   if [ ! -d "$target_folder" -a ! -f "$target_folder" ]; then
73     echo "Target '$target_folder' is not available currently; not updating."
74     return 1
75   fi
76   echo Target drive currently has...
77   dir "$target_folder"
78
79   # synch all our targets.
80   for currdir in $MAJOR_ARCHIVE_SOURCES; do
81     synch_directory_to_target "$currdir" "$target_folder/$(basename $currdir)"/
82   done
83
84   sep
85
86   # update source code if present.
87   echo getting latest fred repositories...
88   pushd "$target_folder"
89   for currdir in $SOURCECODE_HIERARCHY_LIST; do
90     update_source_folders $currdir
91   done
92   
93   sep
94
95   echo successfully updated all expected portions of the target drive at:
96   echo "  $target_folder"
97   echo
98   popd
99 }
100
101 # compares one local well-known folder against the similar folder on a
102 # remote destination.  the first folder is the archive name, with no paths.
103 # the second paramter is the local path component of the archive, such as
104 # "/z" if the archives are found in the /z hierarchy.  the third parameter
105 # is the remote location of the archive, which should just be a host name.
106 # the fourth parameter is the destination path component to match the local
107 # path component (since these can differ).
108 function do_a_folder_compare()
109 {
110   local archname="$1"; shift
111   local pathing="$1"; shift
112   local dest="$1"; shift
113   local destpath="$1"; shift
114   if [ -z "$archname" -o -z "$dest" ]; then
115     echo "do_a_folder_compare needs an archive name and a destination host."
116     return 1
117   fi
118
119   if [ -d "/z/$archname" ]; then
120     sep 14
121     echo "Comparing ${pathing}/${archname} with remote $dest:${destpath}/${archname}"
122     compare_dirs ${pathing}/${archname} ${dest}:${destpath}/${archname}
123     sep 14
124   fi
125 }
126
127 # runs through all the local archives on this host to make sure nothing is
128 # different when compared with the mainline versions on the specified host.
129 # the first parameter is the remote version to compare against.  if there is
130 # a second parameter, it is used as the path on the local machine where the
131 # comparison should be based (e.g. an archive drive rather than /z/).
132 function uber_archive_comparator()
133 {
134   local remote_arch="$1"; shift
135   if [ -z "$remote_arch" ]; then
136     echo uber_archive_comparator needs the remote archive host to compare with.
137     return 1
138   fi
139   local local_place="$1"; shift
140   if [ -z "$local_place" ]; then
141     local_place="/z"
142   fi
143
144   sep 14
145   echo "comparing against host '$remote_arch'"
146   sep 14
147
148 #hmmm: shouldn't this be a list in a variable someplace?
149   for archicle in \
150     basement \
151     imaginations \
152     musix \
153     toaster \
154     walrus \
155     ; do
156       do_a_folder_compare ${archicle} ${local_place} ${remote_arch} "/z"
157   done
158 }
159
160
161 #hmmm: abstractable piece?  the runtime plug at the end of a library script?
162 # this block should execute when the script is actually run, rather
163 # than when it's just being sourced.
164 if [[ $0 =~ .*general_updater\.sh.* ]]; then
165   source "$FEISTY_MEOW_SCRIPTS/core/launch_feisty_meow.sh"
166   exit_on_error "sourcing the feisty meow environment"
167   update_archive_drive "${@}"
168   exit_on_error "updating archive drive at: $*"
169 fi
170