cleaned stderr out of output.
[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 # this reports when we have totally failed to figure out where a folder
10 # is actually located on the machine.
11 function intuition_failure()
12 {
13   missing="$1"; shift
14   if [ ! -z "$SHELL_DEBUG" ]; then
15     echo "Could not intuit '$missing' variable."
16   fi
17   # remove the variable because its value is busted.
18   unset $missing
19 }
20
21 ############################
22
23 # set some fairly liberal limits for ant.
24 export ANT_OPTS="-Xms512m -Xmx768m -XX:MaxPermSize=768m"
25
26 ############################
27
28 # start guessing some settings...
29
30 # this bin portion works for most javas...
31 export JAVA_BIN_PIECE=bin
32
33 if [ ! -d "$JAVA_HOME" ]; then
34   # first try a recent linux version.
35   export JAVA_HOME=/usr/lib/jvm/java-6-sun/jre
36 fi
37 if [ ! -d "$JAVA_HOME" ]; then
38   # try an even more recent version.
39   export JAVA_HOME=/usr/lib/jvm/java-7-oracle/jre
40 fi
41 if [ ! -d "$JAVA_HOME" ]; then
42   # try using a windows version.
43 #note: this logic is untested.
44 # probably will break due to space in path issues.
45   declare -a any_there=$(find "/c/Program Files/java" -type d -iname "jdk" 2>/dev/null)
46   if [ ${#any_there[*]} -gt 0 ]; then
47     (( last = ${#any_there[@]} - 1 ))
48     JAVA_HOME="${any_there[$last]}"
49   fi
50   if [ ! -d "$JAVA_HOME" ]; then
51     # if no jdk, try a jre.
52     declare -a any_there=$(find "/c/Program Files/java" -type d -iname "jre" 2>/dev/null)
53     if [ ${#any_there[*]} -gt 0 ]; then
54       (( last = ${#any_there[@]} - 1 ))
55       JAVA_HOME="${any_there[$last]}"
56     fi
57   fi
58 fi
59 # this should go last, since it changes the bin dir.
60 if [ ! -d "$JAVA_HOME" ]; then
61   # if that didn't work, try the location for mac os x.
62   JAVA_HOME=/Library/Java/Home
63   JAVA_BIN_PIECE=Commands
64 fi
65 # last thing is to tell them we couldn't find it.
66 if [ ! -d "$JAVA_HOME" -a -z "$(which java 2>/dev/null)" ]; then
67   intuition_failure JAVA_HOME
68   unset JAVA_BIN_PIECE
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" -a -z "$(which eclipse 2>/dev/null)" ]; then
98   intuition_failure ECLIPSE_DIR
99 fi
100
101 ############################
102
103 # use the variables we just set in our path, and try to make them override
104 # any other paths to different versions.
105
106 if [ ! -z "$JAVA_HOME" ]; then
107   export PATH=$JAVA_HOME/$JAVA_BIN_PIECE:$PATH
108 fi
109 if [ ! -z "$ECLIPSE_DIR" ]; then
110   export PATH=$ECLIPSE_DIR:$PATH
111 fi
112
113 ############################
114
115