totally tasty changes for naming
[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   if [ ! -d "$folder" ]; then
15     echo "The folder '$folder' does not exist, so skipping repository update there."
16     return;
17   fi
18   echo getting latest codes in $folder...
19   pushd "$folder"
20   if [ $? -ne 0 ]; then
21     echo Changing to the folder $folder failed.
22     exit 1
23   fi
24   bash "$FEISTY_MEOW_SCRIPTS/rev_control/rcheckin.sh"
25   if [ $? -ne 0 ]; then
26     echo Checking out the latest codes has failed somehow for $folder.
27     exit 1
28   fi
29   popd
30 }
31
32 # this attempts to copy all the contents in a folder called "from" into a folder
33 # called "to".  it's a failure for the "from" folder to not exist, but the "to"
34 # is allowed to not exist (in which case we don't try to synch to it).
35 function synch_directory_to_target()
36 {
37   local from="$1"; shift
38   local to="$1"; shift
39
40   sep
41
42   if [ ! -d "$from" ]; then
43     echo "skipping synch on missing source directory $from; this is not normal!"
44     exit 1
45   fi
46   if [ ! -d "$to" ]; then
47     echo "skipping synch into non-existent directory $to"
48     return
49   fi
50
51   echo "synching from $from into $to"
52   netcp "$from"/* "$to"/
53   if [ $? -ne 0 ]; then
54     echo "The synchronization of $from into $to has failed."
55     exit 1
56   fi
57 }
58
59 # the uber controller method that does the "hard" work of updating.
60 # any items from the MAJOR_ARCHIVE_SOURCES that are on the target will be
61 # updated.  any items found on the target matching the members of the
62 # SOURCECODE_HIERARCHY_LIST will be treated as code hierarchies and updated.
63 function update_archive_drive()
64 {
65   local target_folder="$1"; shift  # where we're backing up to.
66   local currdir  # loop variable.
67
68   sep
69
70   echo Target drive currently has...
71   ls "$target_folder"
72   if [ $? -ne 0 ]; then
73     echo "The target location '$target_folder' is not mounted currently, so cannot be updated."
74     exit 1
75   fi
76
77   # synch all our targets.
78   for currdir in $MAJOR_ARCHIVE_SOURCES; do
79     synch_directory_to_target "$currdir" "$target_folder/$(basename $currdir)"/
80   done
81
82   sep
83
84   # update source code if present.
85   echo getting latest fred repositories...
86   pushd "$target_folder"
87   for currdir in $SOURCECODE_HIERARCHY_LIST; do
88     update_source_folders $currdir
89   done
90   
91   sep
92
93   echo successfully updated all expected portions of the target drive at:
94   echo "  $target_folder"
95 }
96
97