fixed proc/mounts thing.
[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 #function whichable()
12 #{
13 #  to_find="$1"; shift
14 #  which which &>/dev/null
15 #  if [ $? -ne 0 ]; then
16 #    # there is no which command here.  we produce nothing due to this.
17 #    echo
18 #  fi
19 #  echo $(which $to_find)
20 #}
21
22 # this reports when we have totally failed to figure out where a folder
23 # is actually located on the machine.
24 function intuition_failure()
25 {
26   missing="$1"; shift
27   if [ ! -z "$SHELL_DEBUG" ]; then
28     echo "Could not intuit '$missing' variable."
29   fi
30   # remove the variable because its value is busted.
31   unset $missing
32 }
33
34 ############################
35
36 # set some fairly liberal limits for ant.
37 export ANT_OPTS="-Xms512m -Xmx768m -XX:MaxPermSize=768m"
38
39 ############################
40
41 # start guessing some settings...
42
43 # this bin portion works for most javas...
44 export JAVA_BIN_PIECE=bin
45
46 if [ ! -d "$JAVA_HOME" ]; then
47   # first try a recent linux version.
48   export JAVA_HOME=/usr/lib/jvm/java-6-sun
49 fi
50 if [ ! -d "$JAVA_HOME" ]; then
51   # try an even more recent version.
52   export JAVA_HOME=/usr/lib/jvm/java-7-oracle
53 fi
54 if [ ! -d "$JAVA_HOME" ]; then
55   JAVA_HOME="$(ls -d c:/tools/*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 2>/dev/null)" ]; 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=$HOME/apps/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 2>/dev/null)" ]; 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