public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/eselect-java:java-vm-update commit in: src/modules/
@ 2022-06-24  7:56 Florian Schmaus
  0 siblings, 0 replies; 3+ messages in thread
From: Florian Schmaus @ 2022-06-24  7:56 UTC (permalink / raw
  To: gentoo-commits

commit:     4aa75266725556940aa1b7dfcfd64989012dc603
Author:     Florian Schmaus <flow <AT> gentoo <DOT> org>
AuthorDate: Fri Jun 24 07:02:14 2022 +0000
Commit:     Florian Schmaus <flow <AT> gentoo <DOT> org>
CommitDate: Fri Jun 24 07:39:59 2022 +0000
URL:        https://gitweb.gentoo.org/proj/eselect-java.git/commit/?id=4aa75266

Add "eselect java-vm update"

Bug: https://bugs.gentoo.org/853928
Signed-off-by: Florian Schmaus <flow <AT> gentoo.org>

 src/modules/java-vm.eselect.in | 55 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

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}"
+}


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-commits] proj/eselect-java:java-vm-update commit in: src/modules/
@ 2022-06-24  7:56 Florian Schmaus
  0 siblings, 0 replies; 3+ messages in thread
From: Florian Schmaus @ 2022-06-24  7:56 UTC (permalink / raw
  To: gentoo-commits

commit:     341c97956e32325cdf25f65005900f3272fa9fec
Author:     Florian Schmaus <flow <AT> gentoo <DOT> org>
AuthorDate: Fri Jun 24 07:49:14 2022 +0000
Commit:     Florian Schmaus <flow <AT> gentoo <DOT> org>
CommitDate: Fri Jun 24 07:51:41 2022 +0000
URL:        https://gitweb.gentoo.org/proj/eselect-java.git/commit/?id=341c9795

Decide based on the UID if system or user VM should be modified

Signed-off-by: Florian Schmaus <flow <AT> gentoo.org>

 src/modules/java-vm.eselect.in | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/modules/java-vm.eselect.in b/src/modules/java-vm.eselect.in
index c7d5a82..d51b200 100644
--- a/src/modules/java-vm.eselect.in
+++ b/src/modules/java-vm.eselect.in
@@ -116,7 +116,7 @@ describe_set_parameters() {
 }
 
 do_set() {
-	local usage="Usage <user|system> <VM>"
+	local usage="Usage [<user|system>] <VM>"
 	local ifunset=0
 
 	if [[ ${1} == "--if-unset" ]]; then
@@ -124,6 +124,22 @@ do_set() {
 		shift
 	fi
 
+	# Automatically decide, based in the invoking user's UID, if the
+	# user or system Java VM should be modified.
+	if [[ ${#} -eq 1 ]]; then
+		if ! is_number "${1}"; then
+			die -q ${usage}
+		fi
+
+		local kind
+		if [[ ${UID} -eq 0 ]]; then
+			kind="system"
+		else
+			kind="user"
+		fi
+		set -- ${kind} ${@}
+	fi
+
 	if [[ ${#} != 2 ]]; then
 		die -q ${usage}
 	elif [[ ${1} == "system" ]]; then


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-commits] proj/eselect-java:java-vm-update commit in: src/modules/
@ 2022-06-24  7:57 Florian Schmaus
  0 siblings, 0 replies; 3+ messages in thread
From: Florian Schmaus @ 2022-06-24  7:57 UTC (permalink / raw
  To: gentoo-commits

commit:     a4a40a8b84cbcc58320c66dbcf046a986d6af530
Author:     Florian Schmaus <flow <AT> gentoo <DOT> org>
AuthorDate: Fri Jun 24 07:49:14 2022 +0000
Commit:     Florian Schmaus <flow <AT> gentoo <DOT> org>
CommitDate: Fri Jun 24 07:57:29 2022 +0000
URL:        https://gitweb.gentoo.org/proj/eselect-java.git/commit/?id=a4a40a8b

Decide based on the UID if system or user VM should be modified

Signed-off-by: Florian Schmaus <flow <AT> gentoo.org>

 src/modules/java-vm.eselect.in | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/modules/java-vm.eselect.in b/src/modules/java-vm.eselect.in
index c7d5a82..571b26e 100644
--- a/src/modules/java-vm.eselect.in
+++ b/src/modules/java-vm.eselect.in
@@ -116,7 +116,7 @@ describe_set_parameters() {
 }
 
 do_set() {
-	local usage="Usage <user|system> <VM>"
+	local usage="Usage [user|system] <VM>"
 	local ifunset=0
 
 	if [[ ${1} == "--if-unset" ]]; then
@@ -124,6 +124,22 @@ do_set() {
 		shift
 	fi
 
+	# Automatically decide, based in the invoking user's UID, if the
+	# user or system Java VM should be modified.
+	if [[ ${#} -eq 1 ]]; then
+		if ! is_number "${1}"; then
+			die -q ${usage}
+		fi
+
+		local kind
+		if [[ ${UID} -eq 0 ]]; then
+			kind="system"
+		else
+			kind="user"
+		fi
+		set -- ${kind} ${@}
+	fi
+
 	if [[ ${#} != 2 ]]; then
 		die -q ${usage}
 	elif [[ ${1} == "system" ]]; then


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-24  7:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-24  7:57 [gentoo-commits] proj/eselect-java:java-vm-update commit in: src/modules/ Florian Schmaus
  -- strict thread matches above, loose matches on Subject: below --
2022-06-24  7:56 Florian Schmaus
2022-06-24  7:56 Florian Schmaus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox