Merge branch 'master' of feistymeow.org:feisty_meow
[feisty_meow.git] / scripts / rev_control / rev_control.sh
1 #!/bin/bash
2
3 # these are helper functions for doing localized revision control.
4 # this script should be sourced into other scripts that use it.
5
6 # one unpleasantry to take care of first; cygwin barfs aggressively if the TMP directory
7 # is a DOS path, but we need it to be a DOS path for our XSEDE testing, so that blows.
8 # to get past this, TMP gets changed below to a hopefully generic and safe place.
9
10 export TMP=/tmp/rev_control_$USER
11 if [ ! -d "$TMP" ]; then
12   mkdir $TMP
13 fi
14 if [ ! -d "$TMP" ]; then
15   echo "Could not create the temporary directory TMP in: $TMP"
16   echo "This script will not work properly without an existing TMP directory."
17 fi
18
19 this_host=
20 # gets the machine's hostname and stores it in the variable "this_host".
21 function get_our_hostname()
22 {
23   if [ "$OS" == "Windows_NT" ]; then
24     this_host=$(hostname)
25   elif [ ! -z "$(echo $MACHTYPE | grep apple)" ]; then
26     this_host=$(hostname)
27   elif [ ! -z "$(echo $MACHTYPE | grep suse)" ]; then
28     this_host=$(hostname --long)
29   else
30     this_host=$(hostname)
31   fi
32   #echo "hostname is $this_host"
33 }
34
35 # this function sets a variable called "home_system" to "true" if the
36 # machine is considered one of fred's home machines.  if you are not
37 # fred, you may want to change the machine choices.
38 export home_system=
39 function is_home_system()
40 {
41   # load up the name of the host.
42   get_our_hostname
43   # reset the variable that we'll be setting.
44   home_system=
45   if [[ $this_host == *.gruntose.blurgh ]]; then
46     home_system=true
47 #temp code
48 elif [[ $this_host == buildy ]]; then
49 home_system=true
50 elif [[ $this_host == simmy ]]; then
51 home_system=true
52 #temp code
53   fi
54 }
55
56 # we only want to totally personalize this script if the user is right.
57 function check_user()
58 {
59   if [ "$USER" == "fred" ]; then
60     export SVNUSER=fred_t_hamster@
61     export EXTRA_PROTOCOL=+ssh
62   else
63     export SVNUSER=
64     export EXTRA_PROTOCOL=
65   fi
66 }
67
68 # calculates the right modifier for hostnames / repositories.
69 modifier=
70 function compute_modifier()
71 {
72   modifier=
73   directory="$1"; shift
74   in_or_out="$1"; shift
75   check_user
76   # some project specific overrides.
77   if [[ "$directory" == hoople* ]]; then
78     modifier="svn${EXTRA_PROTOCOL}://${SVNUSER}svn.code.sf.net/p/hoople2/svn/"
79   fi
80   if [[ "$directory" == yeti* ]]; then
81     modifier="svn${EXTRA_PROTOCOL}://${SVNUSER}svn.code.sf.net/p/yeti/svn/"
82   fi
83   # see if we're on one of fred's home machines.
84   is_home_system
85   # special override to pick local servers when at home.
86   if [ "$home_system" == "true" ]; then
87     if [ "$in_or_out" == "out" ]; then
88       # need the right home machine for modifier when checking out.
89       modifier="svn://shaggy/"
90     else 
91       # no modifier for checkin.
92       modifier=
93     fi
94   fi
95 }
96