506cc518d047eebc7237f2a5f92590784d549f6b
[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 whichable()
10 {
11   to_find="$1"; shift
12   which which &>/dev/null
13   if [ $? -ne 0 ]; then
14     # there is no which command here.  we produce nothing due to this.
15     echo
16   fi
17   echo $(which $to_find)
18 }
19
20 # this reports when we have totally failed to figure out where a folder
21 # is actually located on the machine.
22 function intuition_failure()
23 {
24   missing="$1"; shift
25   if [ ! -z "$SHELL_DEBUG" ]; then
26     echo "Could not intuit '$missing' variable."
27   fi
28   # remove the variable because its value is busted.
29   unset $missing
30 }
31
32 ############################
33
34 # set some fairly liberal limits for ant.
35 export ANT_OPTS="-Xms512m -Xmx768m -XX:MaxPermSize=768m"
36
37 ############################
38
39 # start guessing some settings...
40
41 # this bin portion works for most javas...
42 export JAVA_BIN_PIECE=bin
43
44 if [ ! -d "$JAVA_HOME" ]; then
45   # first try a recent linux version.
46   export JAVA_HOME=/usr/lib/jvm/java-6-sun/jre
47 fi
48 if [ ! -d "$JAVA_HOME" ]; then
49   # try an even more recent version.
50   export JAVA_HOME=/usr/lib/jvm/java-7-oracle/jre
51 fi
52 if [ ! -d "$JAVA_HOME" ]; then
53   # try using a windows version.
54   JAVA_HOME=d:/tools/java6-jre
55 fi
56 # this should go last, since it changes the bin dir.
57 if [ ! -d "$JAVA_HOME" ]; then
58   # if that didn't work, try the location for mac os x.
59   JAVA_HOME=/Library/Java/Home
60   JAVA_BIN_PIECE=Commands
61 fi
62 # last thing is to tell them we couldn't find it.
63 if [ ! -d "$JAVA_HOME" -a -z "$(whichable java 2>/dev/null)" ]; then
64   intuition_failure JAVA_HOME
65   unset JAVA_BIN_PIECE
66 fi
67
68 ############################
69
70 if [ ! -d "$JDK_HOME" ]; then
71   # try using a windows version.
72   JDK_HOME="d:/tools/java6-jdk"
73   if [ -d "$JDK_HOME/jre" ]; then
74     # reset java home.
75     JAVA_HOME="$JDK_HOME/jre"
76   fi
77 fi
78 if [ ! -d "$JDK_HOME" ]; then
79   intuition_failure JDK_HOME
80 fi
81
82 ############################
83
84 # intuit where we have our local eclipse.
85 if [ ! -d "$ECLIPSE_DIR" ]; then
86   export ECLIPSE_DIR=/usr/local/eclipse_jee
87 fi
88 if [ ! -d "$ECLIPSE_DIR" ]; then
89   ECLIPSE_DIR=$HOME/eclipse
90 fi
91 if [ ! -d "$ECLIPSE_DIR" ]; then
92   ECLIPSE_DIR=$HOME/apps/eclipse
93 fi
94 if [ ! -d "$ECLIPSE_DIR" ]; then
95 #uhhh, default on winders?
96   ECLIPSE_DIR="/c/Program Files/eclipse"
97 fi
98 if [ ! -d "$ECLIPSE_DIR" ]; then
99   ECLIPSE_DIR="c:/tools/eclipse"
100 fi
101 if [ ! -d "$ECLIPSE_DIR" ]; then
102   ECLIPSE_DIR="d:/tools/eclipse"
103 fi
104 if [ ! -d "$ECLIPSE_DIR" ]; then
105   ECLIPSE_DIR="e:/tools/eclipse"
106 fi
107 # final option is to whine.
108 if [ ! -d "$ECLIPSE_DIR" -a -z "$(whichable eclipse 2>/dev/null)" ]; then
109   intuition_failure ECLIPSE_DIR
110 fi
111
112 ############################
113
114 # use the variables we just set in our path, and try to make them override
115 # any other paths to different versions.
116
117 if [ ! -z "$JAVA_HOME" ]; then
118   export PATH=$JAVA_HOME/$JAVA_BIN_PIECE:$PATH
119 fi
120 if [ ! -z "$JDK_HOME" ]; then
121 #may have to do bin piece if support mac with jdk bit.
122   export PATH=$JDK_HOME/bin:$PATH
123 fi
124 if [ ! -z "$ECLIPSE_DIR" ]; then
125   export PATH=$ECLIPSE_DIR:$PATH
126 fi
127
128 ############################
129
130