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