82bf336e5c39adb81c80fc74275a44a783eb9048
[feisty_meow.git] / scripts / 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   export JAVA_HOME=/usr/lib/jvm/java-7-oracle/jre
35 fi
36 if [ ! -d "$JAVA_HOME" ]; then
37   # try using a windows version.
38 #note: this logic is untested.
39 # probably will break due to space in path issues.
40   declare -a any_there=$(find "/c/Program Files/java" -type d -iname "jdk" 2>/dev/null)
41   if [ ${#any_there[*]} -gt 0 ]; then
42     (( last = ${#any_there[@]} - 1 ))
43     JAVA_HOME="${any_there[$last]}"
44   fi
45   if [ ! -d "$JAVA_HOME" ]; then
46     # if no jdk, try a jre.
47     declare -a any_there=$(find "/c/Program Files/java" -type d -iname "jre" 2>/dev/null)
48     if [ ${#any_there[*]} -gt 0 ]; then
49       (( last = ${#any_there[@]} - 1 ))
50       JAVA_HOME="${any_there[$last]}"
51     fi
52   fi
53 fi
54 # this should go last, since it changes the bin dir.
55 if [ ! -d "$JAVA_HOME" ]; then
56   # if that didn't work, try the location for mac os x.
57   JAVA_HOME=/Library/Java/Home
58   JAVA_BIN_PIECE=Commands
59 fi
60 # last thing is to tell them we couldn't find it.
61 if [ ! -d "$JAVA_HOME" ]; then
62   intuition_failure JAVA_HOME
63   unset JAVA_BIN_PIECE
64 fi
65
66 ############################
67
68 # intuit where we have our local eclipse.
69 if [ ! -d "$ECLIPSE_DIR" ]; then
70   export ECLIPSE_DIR=/usr/local/eclipse_jee
71 fi
72 if [ ! -d "$ECLIPSE_DIR" ]; then
73   ECLIPSE_DIR=$HOME/eclipse
74 fi
75 if [ ! -d "$ECLIPSE_DIR" ]; then
76   ECLIPSE_DIR=$HOME/apps/eclipse
77 fi
78 if [ ! -d "$ECLIPSE_DIR" ]; then
79 #uhhh, default on winders?
80   ECLIPSE_DIR="/c/Program Files/eclipse"
81 fi
82 if [ ! -d "$ECLIPSE_DIR" ]; then
83   ECLIPSE_DIR="/c/tools/eclipse"
84 fi
85 if [ ! -d "$ECLIPSE_DIR" ]; then
86   ECLIPSE_DIR="/d/tools/eclipse"
87 fi
88 if [ ! -d "$ECLIPSE_DIR" ]; then
89   ECLIPSE_DIR="/e/tools/eclipse"
90 fi
91 # final option is to whine.
92 if [ ! -d "$ECLIPSE_DIR" ]; then intuition_failure ECLIPSE_DIR; fi
93
94 ############################
95
96 # use the variables we just set in our path, and try to make them override
97 # any other paths to different versions.
98
99 if [ ! -z "$JAVA_HOME" ]; then
100   export PATH=$JAVA_HOME/$JAVA_BIN_PIECE:$PATH
101 fi
102 if [ ! -z "$ECLIPSE_DIR" ]; then
103   export PATH=$ECLIPSE_DIR:$PATH
104 fi
105
106 ############################
107
108