1 |
commit: 561e6cb5b3fefb6c248056aa4d790276433856b3 |
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 08:16:33 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/eselect-java.git/commit/?id=561e6cb5 |
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 |
NEWS | 3 +++ |
14 |
src/modules/java-vm.eselect.in | 55 ++++++++++++++++++++++++++++++++++++++++++ |
15 |
2 files changed, 58 insertions(+) |
16 |
|
17 |
diff --git a/NEWS b/NEWS |
18 |
index 6c331a2..d8ea978 100644 |
19 |
--- a/NEWS |
20 |
+++ b/NEWS |
21 |
@@ -1,3 +1,6 @@ |
22 |
+NEXT: |
23 |
+ * Add "eselect java-vm update" (#853928) |
24 |
+ |
25 |
0.4.3: |
26 |
* install jpackage symlink |
27 |
|
28 |
|
29 |
diff --git a/src/modules/java-vm.eselect.in b/src/modules/java-vm.eselect.in |
30 |
index e332c5a..c7d5a82 100644 |
31 |
--- a/src/modules/java-vm.eselect.in |
32 |
+++ b/src/modules/java-vm.eselect.in |
33 |
@@ -177,3 +177,58 @@ set_symlink() { |
34 |
die -q "Target \"${1}\" doesn't appear to be valid!" |
35 |
fi |
36 |
} |
37 |
+ |
38 |
+describe_update() { |
39 |
+ echo "Automatically update the Java system VM" |
40 |
+} |
41 |
+ |
42 |
+do_update() { |
43 |
+ local targets |
44 |
+ targets=( $(find_targets) ) |
45 |
+ |
46 |
+ if [[ ${#targets[@]} -eq 0 ]]; then |
47 |
+ echo "No installed Java VMs found, can not update" |
48 |
+ return |
49 |
+ fi |
50 |
+ |
51 |
+ if [[ -e "${VM_SYSTEM}" ]]; then |
52 |
+ local current_system_vm_name=$(sym_to_vm "${VM_SYSTEM}") |
53 |
+ echo "Current Java system VM ${current_system_vm_name} is valid, no need to update" |
54 |
+ return |
55 |
+ fi |
56 |
+ |
57 |
+ local new_target old_system_vm_name |
58 |
+ if [[ -L "${VM_SYSTEM}" ]]; then |
59 |
+ # There exists a Java system VM symlink that has become stale, |
60 |
+ # try to find another available VM with the same slot. |
61 |
+ old_system_vm_name=$(sym_to_vm "${VM_SYSTEM}") |
62 |
+ |
63 |
+ local old_system_vm_slot="${old_system_vm_name##*-}" |
64 |
+ |
65 |
+ local target |
66 |
+ for target in "${targets[@]}"; do |
67 |
+ local target_slot="${target##*-}" |
68 |
+ if [[ ${target_slot} -eq ${old_system_vm_slot} ]]; then |
69 |
+ new_target="${target}" |
70 |
+ break |
71 |
+ fi |
72 |
+ done |
73 |
+ fi |
74 |
+ |
75 |
+ if [[ -z "${new_target}" ]]; then |
76 |
+ # There is no Java system VM symlink or we could not find a |
77 |
+ # slot-matching replacement. But there are potential targets, |
78 |
+ # simply choose the first. |
79 |
+ # TODO: We could get more sophisticated here to select the "best" |
80 |
+ # target, but that is far from trivial. |
81 |
+ new_target="${targets[0]}" |
82 |
+ fi |
83 |
+ |
84 |
+ local from_vm_text="" |
85 |
+ if [[ -n "${old_system_vm_name}" ]]; then |
86 |
+ from_vm_text="from ${old_system_vm_name} " |
87 |
+ fi |
88 |
+ |
89 |
+ echo "Updating Java system VM ${from_vm_text}to ${new_target}" |
90 |
+ set_symlink "${new_target}" "${VM_SYSTEM}" |
91 |
+} |