updated to stop using java 6.
[feisty_meow.git] / customizing / 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 source $FEISTY_MEOW_SCRIPTS/core/functions.sh
10
11 # this reports when we have totally failed to figure out where a folder
12 # is actually located on the machine.
13 function intuition_failure()
14 {
15   missing="$1"; shift
16   if [ ! -z "$SHELL_DEBUG" ]; then
17     echo "Could not intuit '$missing' variable."
18   fi
19   # remove the variable because its value is busted.
20   unset $missing
21 }
22
23 ############################
24
25 # set some fairly liberal limits for ant.
26 export ANT_OPTS="-Xms512m -Xmx768m -XX:MaxPermSize=768m"
27
28 ############################
29
30 # start guessing some settings...
31
32 # this bin portion works for most javas...
33 export JAVA_BIN_PIECE=bin
34
35 if [ ! -d "$JAVA_HOME" ]; then
36   # try a recent version.
37   export JAVA_HOME=/usr/lib/jvm/java-7-oracle
38 fi
39 if [ ! -d "$JAVA_HOME" ]; then
40   JAVA_HOME="$(ls -d c:/tools/*jdk* 2>/dev/null)"
41 fi
42 if [ ! -d "$JAVA_HOME" ]; then
43   JAVA_HOME="$(ls -d "c:/Program Files"/*jdk* 2>/dev/null)"
44 fi
45 if [ ! -d "$JAVA_HOME" ]; then
46   JAVA_HOME="$(ls -d "c:/Program Files (x86)"/*jdk* 2>/dev/null)"
47 fi
48 if [ ! -d "$JAVA_HOME" ]; then
49   if [ ! -z "$(grep -i 'd:' /proc/mounts 2>/dev/null)" ]; then
50     # try using a windows version.
51     JAVA_HOME="$(ls -d d:/tools/*jdk* 2>/dev/null)"
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   unset JAVA_HOME
63   unset JAVA_BIN_PIECE
64   if [ -z "$(whichable java 2>/dev/null)" ]; then
65     intuition_failure JAVA_HOME
66   fi
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
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   ECLIPSE_DIR="c:/tools/eclipse"
83 fi
84 if [ ! -d "$ECLIPSE_DIR" ]; then
85   if [ ! -z "$(grep -i 'd:' /proc/mounts 2>/dev/null)" ]; then
86     ECLIPSE_DIR="d:/tools/eclipse"
87   fi
88 fi
89 if [ ! -d "$ECLIPSE_DIR" ]; then
90   if [ ! -z "$(grep -i 'e:' /proc/mounts 2>/dev/null)" ]; then
91     ECLIPSE_DIR="e:/tools/eclipse"
92   fi
93 fi
94 # final option is to whine.
95 if [ ! -d "$ECLIPSE_DIR" ]; then
96   unset ECLIPSE_DIR
97 else
98   if [ ! -z "$(uname -a | grep -i cygwin)" ]; then
99     # fix the path for cygwin's bizarre requirement of /cygdrive/X.
100     ECLIPSE_DIR=$(echo $ECLIPSE_DIR | sed -e 's/^\(.\):/\/cygdrive\/\1/')
101   fi
102 fi
103 if [ -z "$ECLIPSE_DIR" -a -z "$(whichable eclipse 2>/dev/null)" ]; then
104   intuition_failure ECLIPSE_DIR
105 fi
106
107 ############################
108
109 # use the variables we just set in our path, and try to make them override
110 # any other paths to different versions.
111
112 if [ ! -z "$JAVA_HOME" ]; then
113   j="$JAVA_HOME"
114   if [ ! -z "$(uname -a | grep -i cygwin)" ]; then
115     j=$(echo $j | sed -e 's/^\(.\):/\/cygdrive\/\1/')
116   fi
117   export PATH=$j/$JAVA_BIN_PIECE:$PATH
118 fi
119 if [ ! -z "$ECLIPSE_DIR" ]; then
120   e="$ECLIPSE_DIR"
121   if [ ! -z "$(uname -a | grep -i cygwin)" ]; then
122     e=$(echo $e | sed -e 's/^\(.\):/\/cygdrive\/\1/')
123   fi
124   export PATH=$e:$PATH
125 fi
126
127 ############################
128
129 #echo "java_profile: JAVA_HOME='$JAVA_HOME' ECLIPSE_DIR='$ECLIPSE_DIR'"
130