612308e698b791000c8b3186f797b1bbd2c36fbb
[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   JAVA_HOME="$(ls -d c:/tools/*jdk* 2>/dev/null)"
54 fi
55 if [ ! -d "$JAVA_HOME" ]; then
56   if [ ! -z "$(grep 'd:' /proc/mounts 2>/dev/null)" ]; then
57     # try using a windows version.
58     JAVA_HOME="$(ls -d d:/tools/*jdk* 2>/dev/null)"
59   fi
60 fi
61 # this should go last, since it changes the bin dir.
62 if [ ! -d "$JAVA_HOME" ]; then
63   # if that didn't work, try the location for mac os x.
64   JAVA_HOME=/Library/Java/Home
65   JAVA_BIN_PIECE=Commands
66 fi
67 # last thing is to tell them we couldn't find it.
68 if [ ! -d "$JAVA_HOME" ]; then
69   unset JAVA_HOME
70   unset JAVA_BIN_PIECE
71   if [ -z "$(whichable java 2>/dev/null)" ]; then
72     intuition_failure JAVA_HOME
73   fi
74 fi
75
76 ############################
77
78 # intuit where we have our local eclipse.
79 if [ ! -d "$ECLIPSE_DIR" ]; then
80   export ECLIPSE_DIR=/usr/local/eclipse_jee
81 fi
82 if [ ! -d "$ECLIPSE_DIR" ]; then
83   ECLIPSE_DIR=$HOME/eclipse
84 fi
85 if [ ! -d "$ECLIPSE_DIR" ]; then
86   ECLIPSE_DIR=$HOME/apps/eclipse
87 fi
88 if [ ! -d "$ECLIPSE_DIR" ]; then
89   ECLIPSE_DIR="c:/tools/eclipse"
90 fi
91 if [ ! -d "$ECLIPSE_DIR" ]; then
92   if [ ! -z "$(grep 'd:' /proc/mounts)" ]; then
93     ECLIPSE_DIR="d:/tools/eclipse"
94   fi
95 fi
96 if [ ! -d "$ECLIPSE_DIR" ]; then
97   if [ ! -z "$(grep 'e:' /proc/mounts)" ]; then
98     ECLIPSE_DIR="e:/tools/eclipse"
99   fi
100 fi
101 # final option is to whine.
102 if [ ! -d "$ECLIPSE_DIR" ]; then
103   unset ECLIPSE_DIR
104 else
105   if [ ! -z "$(uname -a | grep -i cygwin)" ]; then
106     # fix the path for cygwin's bizarre requirement of /cygdrive/X.
107     ECLIPSE_DIR=$(echo $ECLIPSE_DIR | sed -e 's/^\(.\):/\/cygdrive\/\1/')
108   fi
109 fi
110 if [ -z "$ECLIPSE_DIR" -a -z "$(whichable eclipse 2>/dev/null)" ]; then
111   intuition_failure ECLIPSE_DIR
112 fi
113
114 ############################
115
116 # use the variables we just set in our path, and try to make them override
117 # any other paths to different versions.
118
119 if [ ! -z "$JAVA_HOME" ]; then
120   j="$JAVA_HOME"
121   if [ ! -z "$(uname -a | grep -i cygwin)" ]; then
122     j=$(echo $j | sed -e 's/^\(.\):/\/cygdrive\/\1/')
123   fi
124   export PATH=$PATH:$j/$JAVA_BIN_PIECE
125 fi
126 if [ ! -z "$ECLIPSE_DIR" ]; then
127   e="$ECLIPSE_DIR"
128   if [ ! -z "$(uname -a | grep -i cygwin)" ]; then
129     e=$(echo $e | sed -e 's/^\(.\):/\/cygdrive\/\1/')
130   fi
131   export PATH=$PATH:$e
132 fi
133
134 ############################
135
136