blob: 04cf4139768bb88dfbd6d7afb0b1f09386077c11 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
# -*-eselect-*- vim: ft=eselect
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
inherit tests multilib
DESCRIPTION="Manage the Java plugin for Netscape-like Browsers"
MAINTAINER="java@gentoo.org"
VERSION="@VERSION@"
PLUGINS_HOME="${EROOT}/usr/share/java-config-2/nsplugin"
SYSTEM_PLUGIN="${EROOT}/usr/lib/nsbrowser/plugins/javaplugin.so"
SYSTEM_PLUGIN_32="${EROOT}/usr/lib32/nsbrowser/plugins/javaplugin.so"
SYSTEM_PLUGIN_64="${EROOT}/usr/lib64/nsbrowser/plugins/javaplugin.so"
ICEDTEA_WEB_VM="${EROOT}/etc/java-config-2/current-icedtea-web-vm"
is_multilib() {
local libdirs=$(list_libdirs)
if has lib32 ${libdirs} && has lib64 ${libdirs}; then
return 0
else
return 1
fi
}
get_icedtea_web_targets() {
local vm
for vm in $(echo /usr/lib/jvm/icedtea-*); do
echo "icedtea-web-$(basename ${vm})"
done
}
get_targets() {
for plugin in $(ls ${PLUGINS_HOME}/*-javaplugin.so 2>/dev/null);
do
local vm=$(plugin_to_vm ${plugin})
case ${MULTILIB_MODE} in
32)
[[ ${vm} = emul-linux-* ]] && echo ${vm}
;;
64)
if [[ ${vm} == icedtea-web ]]; then
get_icedtea_web_targets
elif [[ ${vm} != emul-linux-* ]]; then
echo ${vm}
fi
;;
none)
if [[ ${vm} == icedtea-web ]]; then
get_icedtea_web_targets
else
echo ${vm}
fi
;;
esac
done
}
plugin_to_vm() {
local base=$(basename ${1})
echo ${base%-javaplugin.so}
}
get_system_plugin_vm() {
local plugin;
if [[ ${MULTILIB_MODE} == "32" ]]; then
plugin=$(readlink ${SYSTEM_PLUGIN_32})
elif [[ ${MULTILIB_MODE} == "64" ]]; then
plugin=$(readlink ${SYSTEM_PLUGIN_64})
else
plugin=$(readlink ${SYSTEM_PLUGIN})
fi
plugin=$(basename ${plugin%-javaplugin.so})
if [[ ${plugin} == icedtea-web ]]; then
local icedtea=$(readlink "${ICEDTEA_WEB_VM}")
echo "${plugin}-$(basename ${icedtea})"
else
echo ${plugin}
fi
}
### show action ###
describe_show() {
echo "Show the current Java browser plugin"
}
do_show() {
local system_name=$(get_system_plugin_vm)
write_list_start "Current Java browser plugin"
if [[ -z "${system_name}" ]] ; then
write_kv_list_entry "(unset)" ""
else
write_kv_list_entry "${system_name}" ""
fi
}
### list action ###
describe_list() {
echo "List available Java browser plugins"
}
tweak_list_item() {
local vm=${1}
local system_name=${2}
local mark=""
if [[ ${vm} == ${system_name} ]]; then
mark="${mark} $(highlight 'current')"
fi
echo "${vm} ${mark}"
}
do_list() {
if ! is_multilib; then
MULTILIB_MODE="none"
local system_name=$(get_system_plugin_vm)
local targets=( $(get_targets) )
for (( i = 0 ; i < ${#targets[@]} ; i = i + 1 )) ; do
targets[${i}]=$(tweak_list_item ${targets[${i}]} ${system_name})
done
write_list_start "Available Java browser plugins"
write_numbered_list "${targets[@]}"
else
MULTILIB_MODE="32"
local system_name_32=$(get_system_plugin_vm)
local targets_32=( $(get_targets) )
for (( i = 0 ; i < ${#targets_32[@]} ; i = i + 1 )) ; do
targets_32[${i}]=$(tweak_list_item ${targets_32[${i}]} ${system_name_32})
done
write_list_start "Available 32-bit Java browser plugins"
write_numbered_list "${targets_32[@]}"
MULTILIB_MODE="64"
local system_name_64=$(get_system_plugin_vm)
local targets_64=( $(get_targets) )
for (( i = 0 ; i < ${#targets_64[@]} ; i = i + 1 )) ; do
targets_64[${i}]=$(tweak_list_item ${targets_64[${i}]} ${system_name_64})
done
write_list_start "Available 64-bit Java browser plugins"
write_numbered_list "${targets_64[@]}"
fi
}
### set action ###
describe_set() {
echo "Set the system Java browser plugin"
}
do_set() {
if ! is_multilib; then
if [[ ${#} != 1 ]] ; then
die -q "Usage: set [nsplugin-vm]"
fi
MULTILIB_MODE="none"
else
if [[ ${#} != 2 ]] ; then
die -q "Usage: set [32bit or 64bit] [nsplugin-vm]"
fi
case ${1} in
32bit) ;;
64bit) ;;
*)
die -q "Usage: set [32bit or 64bit] [nsplugin-vm]"
;;
esac
MULTILIB_MODE=${1%bit}
shift
fi
local vm=${1}
if is_number "${vm}" ; then
local targets=( $(get_targets) )
vm=${targets[$(( ${vm} - 1 ))]}
fi
if [[ -z ${vm} ]] ; then
die -q "You didn't specify valid plugin number to set"
fi
local plugin
if [[ ${vm} == icedtea-web-* ]]; then
plugin="${PLUGINS_HOME}/icedtea-web-javaplugin.so"
else
plugin="${PLUGINS_HOME}/${vm}-javaplugin.so"
fi
if [[ ! -f ${plugin} ]]; then
write_error_msg "Expected \"${plugin}\" to exist, but it doesn't."
write_error_msg "Perhaps \"${vm}\" isn't a valid name of VM built with nsplugin?"
return
fi
local system_plugin
case ${MULTILIB_MODE} in
32) system_plugin=${SYSTEM_PLUGIN_32} ;;
64) system_plugin=${SYSTEM_PLUGIN_64} ;;
none) system_plugin=${SYSTEM_PLUGIN} ;;
esac
mkdir -p $(dirname ${system_plugin}) || die -q "Error creating \"$(dirname ${SYSTEM_PLUGIN})\""
if [[ -w $(dirname ${system_plugin}) ]] ; then
ln -sf ${plugin} ${system_plugin} || die -q "Error creating nsplugin symlink"
else
die -q "Sorry, you don't have enough permission to set nsplugin"
fi
if [[ ${vm} == icedtea-web-* ]]; then
rm -f "${ICEDTEA_WEB_VM}"
ln -sf "${EROOT}"/usr/lib/jvm/${vm#icedtea-web-} "${ICEDTEA_WEB_VM}"
fi
}
|