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