rumblings of change; got custom scripts sorted, improved approach to
[feisty_meow.git] / scripts / custom / examples / fred / java_profile.sh
1 #!/bin/bash
2 # this script tries to intuit where java is installed on this machine.
3
4 ############################
5
6 function intuition_failure()
7 {
8   missing="$1"; shift
9   echo "We cannot intuit your $missing variable for this host."
10   # remove the variable because its value is busted.
11   unset $missing
12 }
13
14 ############################
15
16 # set some fairly liberal limits for ant.
17 export ANT_OPTS="-Xms512m -Xmx768m -XX:MaxPermSize=768m"
18
19 ############################
20
21 # start guessing some settings...
22
23 # this bin portion works for most javas...
24 export JAVA_BIN_PIECE=bin
25
26 if [ ! -d "$JAVA_HOME" ]; then
27   # first try a recent linux version.
28   export JAVA_HOME=/usr/lib/jvm/java-6-sun/jre
29 fi
30 if [ ! -d "$JAVA_HOME" ]; then
31   # try using a windows version.
32 #note: this logic is untested.
33 # probably will break due to space in path issues.
34   declare -a any_there=$(find "/c/Program Files/java" -type d -iname "jdk" 2>/dev/null)
35   if [ ${#any_there[*]} -gt 0 ]; then
36     (( last = ${#any_there[@]} - 1 ))
37     JAVA_HOME="${any_there[$last]}"
38   fi
39   if [ ! -d "$JAVA_HOME" ]; then
40     # if no jdk, try a jre.
41     declare -a any_there=$(find "/c/Program Files/java" -type d -iname "jre" 2>/dev/null)
42     if [ ${#any_there[*]} -gt 0 ]; then
43       (( last = ${#any_there[@]} - 1 ))
44       JAVA_HOME="${any_there[$last]}"
45     fi
46   fi
47 fi
48 # this should go last, since it changes the bin dir.
49 if [ ! -d "$JAVA_HOME" ]; then
50   # if that didn't work, try the location for mac os x.
51   JAVA_HOME=/Library/Java/Home
52   JAVA_BIN_PIECE=Commands
53 fi
54 # last thing is to tell them we couldn't find it.
55 if [ ! -d "$JAVA_HOME" ]; then
56   intuition_failure JAVA_HOME
57   unset JAVA_BIN_PIECE
58 fi
59
60 ############################
61
62 # intuit where we have our local eclipse.
63 if [ ! -d "$ECLIPSE_DIR" ]; then
64   export ECLIPSE_DIR=/usr/local/eclipse_jee
65 fi
66 if [ ! -d "$ECLIPSE_DIR" ]; then
67   ECLIPSE_DIR=$HOME/eclipse
68 fi
69 if [ ! -d "$ECLIPSE_DIR" ]; then
70   ECLIPSE_DIR=$HOME/apps/eclipse
71 fi
72 if [ ! -d "$ECLIPSE_DIR" ]; then
73 #uhhh, default on winders?
74   ECLIPSE_DIR="/c/Program Files/eclipse"
75 fi
76 if [ ! -d "$ECLIPSE_DIR" ]; then
77   ECLIPSE_DIR="/c/tools/eclipse"
78 fi
79 if [ ! -d "$ECLIPSE_DIR" ]; then
80   ECLIPSE_DIR="/d/tools/eclipse"
81 fi
82 if [ ! -d "$ECLIPSE_DIR" ]; then
83   ECLIPSE_DIR="/e/tools/eclipse"
84 fi
85 # final option is to whine.
86 if [ ! -d "$ECLIPSE_DIR" ]; then intuition_failure ECLIPSE_DIR; fi
87
88 ############################
89
90 # use the variables we just set in our path, and try to make them override
91 # any other paths to different versions.
92
93 if [ ! -z "$JAVA_HOME" ]; then
94   export PATH=$JAVA_HOME/$JAVA_BIN_PIECE:$PATH
95 fi
96 if [ ! -z "$ECLIPSE_DIR" ]; then
97   export PATH=$ECLIPSE_DIR:$PATH
98 fi
99
100