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