f493ddbaa0877680d94ddd7079612faf5bb3d9b8
[feisty_meow.git] / scripts / rev_control / getem.sh
1 #!/bin/bash
2
3 # gets any updates for the repository folders present in the REPOSITORY_LIST variable.
4
5 source "$FEISTY_MEOW_SCRIPTS/rev_control/rev_control.sh"
6
7 # trickery to ensure we can always update this file, even when the operating system has some
8 # rude behavior with regard to file locking (ahem, windows...).
9 # and even more rudeness is that the pwd and $TMP may not always be in the same form,
10 # which causes endless confusion and badness.  that's why we get the pwd reading for TMP
11 # first so we can do an orange-to-orange compare.
12 tmpdir="$(cd $TMP; \pwd)"
13 if [ "$(\pwd)" != "$tmpdir" ]; then
14   if [ ! -z "$SHELL_DEBUG" ]; then
15     echo "Moving to the TMP directory to avoid file access conflicts..."
16   fi
17   new_name="$TMP/zz_$(basename $0)"
18   cp -f "$0" "$new_name"
19   if [ $? -ne 0 ]; then
20     echo "failed to copy this script up to the TMP directory.  exploit attempted?"
21     exit 1
22   fi
23   cd "$TMP"
24   chmod a+x "$new_name"
25   exec "$new_name"
26 fi
27
28 # selects the checkout method based on where we are (the host the script runs on).
29 function do_update()
30 {
31   directory="$1"; shift
32
33   if [ -d "CVS" ]; then
34     cvs update .
35   elif [ -d ".svn" ]; then
36     svn update .
37   elif [ -d ".git" ]; then
38     git pull
39   else
40     echo unknown repository for $directory...
41   fi
42 }
43
44 # gets all the updates for a list of folders under revision control.
45 function checkout_list {
46   list=$*
47   for i in $list; do
48     # turn repo list back into an array.
49     eval "repository_list=( ${REPOSITORY_LIST[*]} )"
50     for j in "${repository_list[@]}"; do
51       # add in the directory for our purposes here.
52       j="$i/$j"
53       if [ ! -d $j ]; then
54         if [ ! -z "$SHELL_DEBUG" ]; then
55           echo "No directory called $j exists."
56         fi
57         continue
58       fi
59
60       pushd $j &>/dev/null
61       echo -n "retrieving '$j'...  "
62       do_update $j
63       popd &>/dev/null
64     done
65   done
66 }
67
68 ##############
69
70 export TMPO_CHK=$TMP/zz_chk.log
71
72 rm -f "$TMPO_CHK"
73
74 # perform the checkouts as appropriate per OS.
75 if [ "$OS" != "Windows_NT" ]; then
76   checkout_list $HOME 2>&1 | tee -a "$TMPO_CHK"
77 else
78   checkout_list $HOME c:/ d:/ e:/ 2>&1 | tee -a "$TMPO_CHK"
79 fi
80
81 less $TMPO_CHK
82
83 ##############
84
85 # we now regenerate the scripts after getme, to ensure it's done automatically.
86 bash "$FEISTY_MEOW_SCRIPTS/core/bootstrap_shells.sh"
87 perl "$FEISTY_MEOW_SCRIPTS/core/generate_aliases.pl"
88 echo
89 nechung
90
91 ##############
92