Contents of /tags/javaupdate-1_3/java-update.in
Parent Directory | Revision Log
Revision 2028 -
(show annotations)
(download)
Mon Jan 7 11:36:13 2013 UTC (11 years, 8 months ago) by niro
File size: 5819 byte(s)
Mon Jan 7 11:36:13 2013 UTC (11 years, 8 months ago) by niro
File size: 5819 byte(s)
tagged 'javaupdate-1_3'
1 | #!/bin/bash |
2 | # Copyright 1999-2004 Gentoo Foundation |
3 | # Distributed under the terms of the GNU General Public License v2 |
4 | # $Header: /home/cvsd/magellan-cvs/magellan-src/opengl-update/opengl-update.sh,v 1.10 2007-11-14 19:19:16 niro Exp $ |
5 | # Author: Martin Schlemmer <azarah@gentoo.org> |
6 | # Further modifications by Donnie Berkholz <spyderous@gentoo.org> |
7 | # Further modifications based off submissions to bug #54984 <cyfred@gentoo.org> |
8 | # Further modifications by Jeremy Huddleston <eradicator@gentoo.org> |
9 | # |
10 | # hacked for use with magellan-linux |
11 | # <niro@magellan-linux.de> |
12 | # |
13 | |
14 | hasq() |
15 | { |
16 | local x |
17 | |
18 | local me=$1 |
19 | shift |
20 | |
21 | for x in $@ |
22 | do |
23 | [[ ${x} = ${me} ]] && return 0 |
24 | done |
25 | |
26 | return 1 |
27 | } |
28 | |
29 | check_user() |
30 | { |
31 | if [[ $(id -u) -ne 0 ]] |
32 | then |
33 | echo "$0: Must be run as root." |
34 | exit 1 |
35 | fi |
36 | } |
37 | |
38 | get_current_implem() |
39 | { |
40 | local implem |
41 | |
42 | # jre does always exist! |
43 | if [ -f ${ENV_D_JRE} ] |
44 | then |
45 | source "${ENV_D_JRE}" |
46 | if [[ -n ${JAVA_PROFILE} ]] |
47 | then |
48 | implem="${JAVA_PROFILE}" |
49 | fi |
50 | unset JAVA_PROFILE |
51 | fi |
52 | |
53 | echo "${implem}" |
54 | } |
55 | |
56 | get_implementations() |
57 | { |
58 | local implems |
59 | |
60 | for dir in ${PREFIX}/java/* |
61 | do |
62 | if [ -d ${dir} ] && |
63 | [[ ${dir##*/} != global ]] && |
64 | ! hasq "${dir##*/}" "${implems}" |
65 | then |
66 | implems="${implems:+${implems} }${dir##*/}" |
67 | fi |
68 | done |
69 | |
70 | echo "${implems}" |
71 | } |
72 | |
73 | print_version() |
74 | { |
75 | echo "java-update ${VERSION}" |
76 | } |
77 | |
78 | print_usage() |
79 | { |
80 | # Get grammar right in message |
81 | local IS_ARE IMPLEM_PLURAL |
82 | |
83 | if [[ $(echo ${AVAIL_IMPLEMS} | wc -w) -eq 1 ]] |
84 | then |
85 | IS_ARE="is" |
86 | IMPLEM_PLURAL="" |
87 | else |
88 | IS_ARE="are" |
89 | IMPLEM_PLURAL="s" |
90 | fi |
91 | |
92 | print_version |
93 | |
94 | cat << FOO |
95 | Usage: ${0##*/} [<options>] <Java implementation> |
96 | Set the Java implementation. |
97 | Valid options: |
98 | --help|-h|-?: Prints this help. |
99 | --version: Shows the version of this utility. |
100 | --use-old: If an implementation is already set, use that one. |
101 | |
102 | Usage: ${0##*/} --get-implementation |
103 | Print the current implementaion |
104 | |
105 | This utility switches between Java implementations. There ${IS_ARE} |
106 | $(echo ${AVAIL_IMPLEMS} | wc -w) available implementation${IMPLEM_PLURAL}: ${AVAIL_IMPLEMS} |
107 | |
108 | Examples: |
109 | ${0##*/} java6-sun |
110 | This will setup things to use Java Version 6 from Sun. |
111 | |
112 | ${0##*/} java7-openjdk |
113 | This will setup things to use OpenJDK Version 7. |
114 | |
115 | FOO |
116 | exit 1 |
117 | } |
118 | |
119 | parse_options() |
120 | { |
121 | local opt |
122 | |
123 | while [[ ${#} -gt 0 ]] |
124 | do |
125 | opt=$1 |
126 | shift |
127 | case ${opt} in |
128 | --use-old) |
129 | if [[ -n ${ACTION} ]] |
130 | then |
131 | ACTION="error" |
132 | echo "Invalid usage." |
133 | else |
134 | if [[ -n "${CURRENT_JAVA_IMPLEM}" ]] && |
135 | hasq "${CURRENT_JAVA_IMPLEM}" "${AVAIL_IMPLEMS}" |
136 | then |
137 | ACTION="old-implementation" |
138 | fi |
139 | fi |
140 | ;; |
141 | |
142 | --get-implementation) |
143 | if [[ -n ${ACTION} ]] |
144 | then |
145 | ACTION="error" |
146 | echo "Invalid usage." |
147 | else |
148 | ACTION="get-implementation" |
149 | fi |
150 | ;; |
151 | |
152 | --help|-h|-?) ACTION="usage" ;; |
153 | --version) ACTION="version" ;; |
154 | *) |
155 | if hasq "${opt}" "${AVAIL_IMPLEMS}" |
156 | then |
157 | if [[ ${ACTION} != old-implementation ]] |
158 | then |
159 | if [[ -n ${ACTION} ]] |
160 | then |
161 | ACTION="error" |
162 | echo "Invalid usage." |
163 | else |
164 | ACTION="set-implementation" |
165 | NEW_JAVA_IMPLEM="${opt}" |
166 | fi |
167 | fi |
168 | else |
169 | echo "Unrecognized option: ${opt}" |
170 | ACTION="error" |
171 | fi |
172 | ;; |
173 | esac |
174 | done |
175 | } |
176 | |
177 | set_new_implementation() |
178 | { |
179 | local JAVA_IMPLEM="$1" |
180 | local JAVA_LOCAL |
181 | |
182 | check_user |
183 | |
184 | # Set a sane umask... bug #83115 |
185 | umask 022 |
186 | |
187 | if ! hasq "${JAVA_IMPLEM}" "${AVAIL_IMPLEMS}" |
188 | then |
189 | echo "Invalid profile selected." |
190 | exit 1 |
191 | fi |
192 | |
193 | echo "Switching to ${JAVA_IMPLEM} Java interface" |
194 | |
195 | [ -f ${ENV_D_JRE} ] && rm -f ${ENV_D_JRE} |
196 | [ -f ${ENV_D_JDK} ] && rm -f ${ENV_D_JDK} |
197 | [ -f ${ENV_D_GLOBAL_CLASSPATH} ] && rm -f ${ENV_D_GLOBAL_CLASSPATH} |
198 | [ -f ${ENV_D_EOF_CLASSPATH} ] && rm -f ${ENV_D_EOF_CLASSPATH} |
199 | |
200 | cat ${PREFIX}/java/${JAVA_IMPLEM}/jre.conf >> ${ENV_D_JRE} |
201 | echo "JAVA_PROFILE=\"${JAVA_IMPLEM}\"" >> ${ENV_D_JRE} |
202 | |
203 | # set global classpath |
204 | if [ -f ${PREFIX}/java/${JAVA_IMPLEM}/global-classpath.conf ] |
205 | then |
206 | cat ${PREFIX}/java/${JAVA_IMPLEM}/global-classpath.conf >> ${ENV_D_GLOBAL_CLASSPATH} |
207 | elif [ -f ${PREFIX}/java/global/global-classpath.conf ] |
208 | then |
209 | cat ${PREFIX}/java/global/global-classpath.conf >> ${ENV_D_GLOBAL_CLASSPATH} |
210 | else |
211 | echo "Warning: global-classpath.conf is missing!" |
212 | fi |
213 | |
214 | # set eof classpath |
215 | if [ -f ${PREFIX}/java/${JAVA_IMPLEM}/eof-classpath.conf ] |
216 | then |
217 | cat ${PREFIX}/java/${JAVA_IMPLEM}/eof-classpath.conf >> ${ENV_D_EOF_CLASSPATH} |
218 | elif [ -f ${PREFIX}/java/global/eof-classpath.conf ] |
219 | then |
220 | cat ${PREFIX}/java/global/eof-classpath.conf >> ${ENV_D_EOF_CLASSPATH} |
221 | else |
222 | echo "Warning: eof-classpath.conf is missing!" |
223 | fi |
224 | |
225 | # set jdk too if installed |
226 | if [ -f ${PREFIX}/java/${JAVA_IMPLEM}/jdk.conf ] |
227 | then |
228 | cat ${PREFIX}/java/${JAVA_IMPLEM}/jdk.conf >> ${ENV_D_JDK} |
229 | echo "JAVA_PROFILE=\"${JAVA_IMPLEM}\"" >> ${ENV_D_JDK} |
230 | fi |
231 | |
232 | env-rebuild |
233 | |
234 | return 0 |
235 | } |
236 | |
237 | ## START PROGRAM ## |
238 | |
239 | ENV_D_JRE="/etc/env.d/21java" |
240 | ENV_D_JDK="/etc/env.d/22java-jdk" |
241 | ENV_D_GLOBAL_CLASSPATH="/etc/env.d/22java-global-classpath" |
242 | ENV_D_EOF_CLASSPATH="/etc/env.d/30java-eof-classpath" |
243 | NEW_JAVA_IMPLEM="" |
244 | ACTION="" |
245 | PREFIX="/etc" |
246 | AVAIL_IMPLEMS=$(get_implementations) |
247 | CURRENT_JAVA_IMPLEM=$(get_current_implem) |
248 | VERSION="@@VERSION@@" |
249 | |
250 | parse_options $@ |
251 | |
252 | case ${ACTION} in |
253 | get-implementation) |
254 | if [[ -n ${CURRENT_JAVA_IMPLEM} ]] |
255 | then |
256 | echo ${CURRENT_JAVA_IMPLEM} |
257 | retval=0 |
258 | else |
259 | retval=2 |
260 | fi |
261 | ;; |
262 | |
263 | old-implementation) |
264 | set_new_implementation ${CURRENT_JAVA_IMPLEM} |
265 | retval=$? |
266 | ;; |
267 | |
268 | set-implementation) |
269 | if [[ -n ${NEW_JAVA_IMPLEM} ]] |
270 | then |
271 | set_new_implementation ${NEW_JAVA_IMPLEM} |
272 | retval=$? |
273 | else |
274 | print_usage |
275 | retval=1 |
276 | fi |
277 | ;; |
278 | |
279 | version) print_version; retval=0 ;; |
280 | usage) print_usage; retval=0 ;; |
281 | error) print_usage; retval=1 ;; |
282 | *) print_usage; retval=1;; |
283 | esac |
284 | |
285 | exit "${retval}" |