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

Reply via email to