1 |
commit: 4aa75266725556940aa1b7dfcfd64989012dc603 |
2 |
Author: Florian Schmaus <flow <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri Jun 24 07:02:14 2022 +0000 |
4 |
Commit: Florian Schmaus <flow <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Jun 24 07:39:59 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/eselect-java.git/commit/?id=4aa75266 |
7 |
|
8 |
Add "eselect java-vm update" |
9 |
|
10 |
Bug: https://bugs.gentoo.org/853928 |
11 |
Signed-off-by: Florian Schmaus <flow <AT> gentoo.org> |
12 |
|
13 |
src/modules/java-vm.eselect.in | 55 ++++++++++++++++++++++++++++++++++++++++++ |
14 |
1 file changed, 55 insertions(+) |
15 |
|
16 |
diff --git a/src/modules/java-vm.eselect.in b/src/modules/java-vm.eselect.in |
17 |
index e332c5a..c7d5a82 100644 |
18 |
--- a/src/modules/java-vm.eselect.in |
19 |
+++ b/src/modules/java-vm.eselect.in |
20 |
@@ -177,3 +177,58 @@ set_symlink() { |
21 |
die -q "Target \"${1}\" doesn't appear to be valid!" |
22 |
fi |
23 |
} |
24 |
+ |
25 |
+describe_update() { |
26 |
+ echo "Automatically update the Java system VM" |
27 |
+} |
28 |
+ |
29 |
+do_update() { |
30 |
+ local targets |
31 |
+ targets=( $(find_targets) ) |
32 |
+ |
33 |
+ if [[ ${#targets[@]} -eq 0 ]]; then |
34 |
+ echo "No installed Java VMs found, can not update" |
35 |
+ return |
36 |
+ fi |
37 |
+ |
38 |
+ if [[ -e "${VM_SYSTEM}" ]]; then |
39 |
+ local current_system_vm_name=$(sym_to_vm "${VM_SYSTEM}") |
40 |
+ echo "Current Java system VM ${current_system_vm_name} is valid, no need to update" |
41 |
+ return |
42 |
+ fi |
43 |
+ |
44 |
+ local new_target old_system_vm_name |
45 |
+ if [[ -L "${VM_SYSTEM}" ]]; then |
46 |
+ # There exists a Java system VM symlink that has become stale, |
47 |
+ # try to find another available VM with the same slot. |
48 |
+ old_system_vm_name=$(sym_to_vm "${VM_SYSTEM}") |
49 |
+ |
50 |
+ local old_system_vm_slot="${old_system_vm_name##*-}" |
51 |
+ |
52 |
+ local target |
53 |
+ for target in "${targets[@]}"; do |
54 |
+ local target_slot="${target##*-}" |
55 |
+ if [[ ${target_slot} -eq ${old_system_vm_slot} ]]; then |
56 |
+ new_target="${target}" |
57 |
+ break |
58 |
+ fi |
59 |
+ done |
60 |
+ fi |
61 |
+ |
62 |
+ if [[ -z "${new_target}" ]]; then |
63 |
+ # There is no Java system VM symlink or we could not find a |
64 |
+ # slot-matching replacement. But there are potential targets, |
65 |
+ # simply choose the first. |
66 |
+ # TODO: We could get more sophisticated here to select the "best" |
67 |
+ # target, but that is far from trivial. |
68 |
+ new_target="${targets[0]}" |
69 |
+ fi |
70 |
+ |
71 |
+ local from_vm_text="" |
72 |
+ if [[ -n "${old_system_vm_name}" ]]; then |
73 |
+ from_vm_text="from ${old_system_vm_name} " |
74 |
+ fi |
75 |
+ |
76 |
+ echo "Updating Java system VM ${from_vm_text}to ${new_target}" |
77 |
+ set_symlink "${new_target}" "${VM_SYSTEM}" |
78 |
+} |