changes accidentally checked into main branch
[feisty_meow.git] / scripts / customize / 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 "$DEBUG_FEISTY_MEOW" ]; 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 # start guessing some settings...
26
27 # whatever we figure out, we want to export the java home variable.
28 export JAVA_HOME
29
30 # this bin portion works for most javas...
31 export JAVA_BIN_PIECE=bin
32
33 # try using java itself to locate the JAVA_HOME if we can.
34 if [ ! -d "$JAVA_HOME" ]; then
35   JAVA_HOME=$(java -XshowSettings:properties -version 2>&1 | grep -i java.home | sed -e 's/.*java.home = \(.*\)$/\1/')
36 fi
37
38 # if that didn't work, then we try a series of random bizarro places where
39 # we have seen java live before.
40
41 #hmmm: below list is way out of date.  we really hope the first attempt above works.
42
43 if [ ! -d "$JAVA_HOME" ]; then
44   # try a recent version.
45   export JAVA_HOME=/usr/lib/jvm/java-8-oracle
46 fi
47 if [ ! -d "$JAVA_HOME" ]; then
48   # or an older version.
49   export JAVA_HOME=/usr/lib/jvm/java-7-oracle
50 fi
51 if [ ! -d "$JAVA_HOME" ]; then
52   JAVA_HOME="$(ls -d c:/tools/*jdk* 2>/dev/null)"
53 fi
54 if [ ! -d "$JAVA_HOME" ]; then
55   JAVA_HOME="$(ls -d "c:/Program Files"/*jdk* 2>/dev/null)"
56 fi
57 if [ ! -d "$JAVA_HOME" ]; then
58   JAVA_HOME="$(ls -d "c:/Program Files (x86)"/*jdk* 2>/dev/null)"
59 fi
60 if [ ! -d "$JAVA_HOME" ]; then
61   if [ ! -z "$(grep -i 'd:' /proc/mounts 2>/dev/null)" ]; then
62     # try using a windows version.
63     JAVA_HOME="$(ls -d d:/tools/*jdk* 2>/dev/null)"
64   fi
65 fi
66 # this should go last, since it changes the bin dir.
67 if [ ! -d "$JAVA_HOME" ]; then
68   # if that didn't work, try the location for mac os x.
69   JAVA_HOME=/Library/Java/Home
70   JAVA_BIN_PIECE=Commands
71 fi
72 # last thing is to tell them we couldn't find it.
73 if [ ! -d "$JAVA_HOME" ]; then
74   unset JAVA_HOME
75   unset JAVA_BIN_PIECE
76   if [ -z "$(whichable java)" ]; then
77     intuition_failure JAVA_HOME
78   fi
79 fi
80
81 ############################
82
83 # intuit where we have our local eclipse.
84 if [ ! -d "$ECLIPSE_DIR" ]; then
85   export ECLIPSE_DIR=/usr/local/eclipse
86 fi
87 if [ ! -d "$ECLIPSE_DIR" ]; then
88   ECLIPSE_DIR=$HOME/eclipse
89 fi
90 if [ ! -d "$ECLIPSE_DIR" ]; then
91   ECLIPSE_DIR=/usr/local/fred/eclipse
92 fi
93 if [ ! -d "$ECLIPSE_DIR" ]; then
94   ECLIPSE_DIR="c:/tools/eclipse"
95 fi
96 if [ ! -d "$ECLIPSE_DIR" ]; then
97   if [ ! -z "$(grep -i 'd:' /proc/mounts 2>/dev/null)" ]; then
98     ECLIPSE_DIR="d:/tools/eclipse"
99   fi
100 fi
101 if [ ! -d "$ECLIPSE_DIR" ]; then
102   if [ ! -z "$(grep -i 'e:' /proc/mounts 2>/dev/null)" ]; then
103     ECLIPSE_DIR="e:/tools/eclipse"
104   fi
105 fi
106 # final option is to whine.
107 if [ ! -d "$ECLIPSE_DIR" ]; then
108   unset ECLIPSE_DIR
109 else
110   if [ ! -z "$(uname -a | grep -i cygwin)" ]; then
111     # fix the path for cygwin's bizarre requirement of /cygdrive/X.
112     ECLIPSE_DIR=$(echo $ECLIPSE_DIR | sed -e 's/^\(.\):/\/cygdrive\/\1/')
113   fi
114 fi
115 if [ -z "$ECLIPSE_DIR" -a -z "$(whichable eclipse)" ]; then
116   intuition_failure ECLIPSE_DIR
117 fi
118
119 ############################
120
121 # use the variables we just set in our path, and try to make them override
122 # any other paths to different versions.
123
124 if [ ! -z "$JAVA_HOME" ]; then
125   j="$JAVA_HOME"
126   if [ ! -z "$(uname -a | grep -i cygwin)" ]; then
127     j=$(echo $j | sed -e 's/^\(.\):/\/cygdrive\/\1/')
128   fi
129   export PATH=$j/$JAVA_BIN_PIECE:$PATH
130 fi
131 if [ ! -z "$ECLIPSE_DIR" ]; then
132   e="$ECLIPSE_DIR"
133   if [ ! -z "$(uname -a | grep -i cygwin)" ]; then
134     e=$(echo $e | sed -e 's/^\(.\):/\/cygdrive\/\1/')
135   fi
136   export PATH=$e:$PATH
137 fi
138 # add in our personal bin path.
139 if [ -d "/usr/local/fred/bin" ]; then
140   export PATH=/usr/local/fred/bin:$PATH
141 fi
142
143 ############################
144
145 #echo "java_profile: JAVA_HOME='$JAVA_HOME' ECLIPSE_DIR='$ECLIPSE_DIR'"
146