diff options
author | Florian Schmaus <flow@gentoo.org> | 2022-06-24 09:02:14 +0200 |
---|---|---|
committer | Florian Schmaus <flow@gentoo.org> | 2022-06-24 10:16:33 +0200 |
commit | 561e6cb5b3fefb6c248056aa4d790276433856b3 (patch) | |
tree | 6ef0c1e4e816d53e5a2576ac0216e75888961600 | |
parent | java-vm.eselect: whitespaces fixes (diff) | |
download | eselect-java-561e6cb5b3fefb6c248056aa4d790276433856b3.tar.gz eselect-java-561e6cb5b3fefb6c248056aa4d790276433856b3.tar.bz2 eselect-java-561e6cb5b3fefb6c248056aa4d790276433856b3.zip |
Add "eselect java-vm update"
Bug: https://bugs.gentoo.org/853928
Signed-off-by: Florian Schmaus <flow@gentoo.org>
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | src/modules/java-vm.eselect.in | 55 |
2 files changed, 58 insertions, 0 deletions
@@ -1,3 +1,6 @@ +NEXT: + * Add "eselect java-vm update" (#853928) + 0.4.3: * install jpackage symlink diff --git a/src/modules/java-vm.eselect.in b/src/modules/java-vm.eselect.in index e332c5a..c7d5a82 100644 --- a/src/modules/java-vm.eselect.in +++ b/src/modules/java-vm.eselect.in @@ -177,3 +177,58 @@ set_symlink() { die -q "Target \"${1}\" doesn't appear to be valid!" fi } + +describe_update() { + echo "Automatically update the Java system VM" +} + +do_update() { + local targets + targets=( $(find_targets) ) + + if [[ ${#targets[@]} -eq 0 ]]; then + echo "No installed Java VMs found, can not update" + return + fi + + if [[ -e "${VM_SYSTEM}" ]]; then + local current_system_vm_name=$(sym_to_vm "${VM_SYSTEM}") + echo "Current Java system VM ${current_system_vm_name} is valid, no need to update" + return + fi + + local new_target old_system_vm_name + if [[ -L "${VM_SYSTEM}" ]]; then + # There exists a Java system VM symlink that has become stale, + # try to find another available VM with the same slot. + old_system_vm_name=$(sym_to_vm "${VM_SYSTEM}") + + local old_system_vm_slot="${old_system_vm_name##*-}" + + local target + for target in "${targets[@]}"; do + local target_slot="${target##*-}" + if [[ ${target_slot} -eq ${old_system_vm_slot} ]]; then + new_target="${target}" + break + fi + done + fi + + if [[ -z "${new_target}" ]]; then + # There is no Java system VM symlink or we could not find a + # slot-matching replacement. But there are potential targets, + # simply choose the first. + # TODO: We could get more sophisticated here to select the "best" + # target, but that is far from trivial. + new_target="${targets[0]}" + fi + + local from_vm_text="" + if [[ -n "${old_system_vm_name}" ]]; then + from_vm_text="from ${old_system_vm_name} " + fi + + echo "Updating Java system VM ${from_vm_text}to ${new_target}" + set_symlink "${new_target}" "${VM_SYSTEM}" +} |