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