aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Le Cuirot <chewi@gentoo.org>2017-12-30 22:53:25 +0000
committerJames Le Cuirot <chewi@gentoo.org>2018-01-02 22:54:55 +0000
commit8c334ae2a91edbb44b2c7b9a472dfe3fc4d73276 (patch)
treea0230ffab7887af90bedff8223c343985aa95181
parentFix insufficient quoting in java-vm module (diff)
downloadeselect-java-8c334ae2a91edbb44b2c7b9a472dfe3fc4d73276.tar.gz
eselect-java-8c334ae2a91edbb44b2c7b9a472dfe3fc4d73276.tar.bz2
eselect-java-8c334ae2a91edbb44b2c7b9a472dfe3fc4d73276.zip
Add --if-unset option to java-vm's set action
-rw-r--r--NEWS1
-rw-r--r--src/modules/java-vm.eselect.in22
2 files changed, 18 insertions, 5 deletions
diff --git a/NEWS b/NEWS
index 8e0d519..6895cbc 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@
* Sort java-vm targets in version order rather than alphanumeric
* Fix showing and highlighting current ecj + mvn targets (#585224)
* Fix insufficient quoting in java-vm module
+ * Add --if-unset option to java-vm's set action
0.3.0:
diff --git a/src/modules/java-vm.eselect.in b/src/modules/java-vm.eselect.in
index b9043e6..b8654e3 100644
--- a/src/modules/java-vm.eselect.in
+++ b/src/modules/java-vm.eselect.in
@@ -103,20 +103,30 @@ describe_set() {
echo "Set a new system or user vm"
}
+describe_set_options() {
+ echo "--if-unset : do not change if already set"
+}
+
do_set() {
local usage="Usage [user|system] [vm]"
+ local ifunset=0
+
+ if [[ ${1} == "--if-unset" ]]; then
+ ifunset=1
+ shift
+ fi
+
if [[ ${#} != 2 ]]; then
die -q ${usage}
-
elif [[ ${1} == "system" ]]; then
if [[ -w ${VM_SYSTEM%/*} ]]; then
- my_set "${VM_SYSTEM}" "${2}"
+ my_set "${VM_SYSTEM}" "${2}" ${ifunset}
else
die -q "Sorry, you don't have enough permission to set system"
fi
elif [[ ${1} == "user" ]]; then
if [[ ${UID} != 0 ]]; then
- my_set "${VM_USER}" "${2}"
+ my_set "${VM_USER}" "${2}" ${ifunset}
else
die -q "Sorry, you cannot set a user vm as root. Set the system vm instead"
fi
@@ -126,12 +136,14 @@ do_set() {
}
my_set() {
- local target=${2} symlink=${1}
+ local symlink=${1} target=${2} ifunset=${3}
if [[ -z ${target} ]] ; then
die -q "You didn't tell me what to set the symlink to"
elif [[ -L "${symlink}" ]] ; then
- set_symlink "${target}" "${symlink}" || die -q "Couldn't set a new symlink"
+ if [[ ${ifunset} == 0 || ! -d ${symlink} ]]; then
+ set_symlink "${target}" "${symlink}" || die -q "Couldn't set a new symlink"
+ fi
elif [[ -e ${symlink} ]] ; then
die -q "Target file already exists and is not a symlink: ${symlink}"