1 |
commit: 8c334ae2a91edbb44b2c7b9a472dfe3fc4d73276 |
2 |
Author: James Le Cuirot <chewi <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Dec 30 22:53:25 2017 +0000 |
4 |
Commit: James Le Cuirot <chewi <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Jan 2 22:54:55 2018 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/eselect-java.git/commit/?id=8c334ae2 |
7 |
|
8 |
Add --if-unset option to java-vm's set action |
9 |
|
10 |
NEWS | 1 + |
11 |
src/modules/java-vm.eselect.in | 22 +++++++++++++++++----- |
12 |
2 files changed, 18 insertions(+), 5 deletions(-) |
13 |
|
14 |
diff --git a/NEWS b/NEWS |
15 |
index 8e0d519..6895cbc 100644 |
16 |
--- a/NEWS |
17 |
+++ b/NEWS |
18 |
@@ -5,6 +5,7 @@ |
19 |
* Sort java-vm targets in version order rather than alphanumeric |
20 |
* Fix showing and highlighting current ecj + mvn targets (#585224) |
21 |
* Fix insufficient quoting in java-vm module |
22 |
+ * Add --if-unset option to java-vm's set action |
23 |
|
24 |
0.3.0: |
25 |
|
26 |
|
27 |
diff --git a/src/modules/java-vm.eselect.in b/src/modules/java-vm.eselect.in |
28 |
index b9043e6..b8654e3 100644 |
29 |
--- a/src/modules/java-vm.eselect.in |
30 |
+++ b/src/modules/java-vm.eselect.in |
31 |
@@ -103,20 +103,30 @@ describe_set() { |
32 |
echo "Set a new system or user vm" |
33 |
} |
34 |
|
35 |
+describe_set_options() { |
36 |
+ echo "--if-unset : do not change if already set" |
37 |
+} |
38 |
+ |
39 |
do_set() { |
40 |
local usage="Usage [user|system] [vm]" |
41 |
+ local ifunset=0 |
42 |
+ |
43 |
+ if [[ ${1} == "--if-unset" ]]; then |
44 |
+ ifunset=1 |
45 |
+ shift |
46 |
+ fi |
47 |
+ |
48 |
if [[ ${#} != 2 ]]; then |
49 |
die -q ${usage} |
50 |
- |
51 |
elif [[ ${1} == "system" ]]; then |
52 |
if [[ -w ${VM_SYSTEM%/*} ]]; then |
53 |
- my_set "${VM_SYSTEM}" "${2}" |
54 |
+ my_set "${VM_SYSTEM}" "${2}" ${ifunset} |
55 |
else |
56 |
die -q "Sorry, you don't have enough permission to set system" |
57 |
fi |
58 |
elif [[ ${1} == "user" ]]; then |
59 |
if [[ ${UID} != 0 ]]; then |
60 |
- my_set "${VM_USER}" "${2}" |
61 |
+ my_set "${VM_USER}" "${2}" ${ifunset} |
62 |
else |
63 |
die -q "Sorry, you cannot set a user vm as root. Set the system vm instead" |
64 |
fi |
65 |
@@ -126,12 +136,14 @@ do_set() { |
66 |
} |
67 |
|
68 |
my_set() { |
69 |
- local target=${2} symlink=${1} |
70 |
+ local symlink=${1} target=${2} ifunset=${3} |
71 |
if [[ -z ${target} ]] ; then |
72 |
die -q "You didn't tell me what to set the symlink to" |
73 |
|
74 |
elif [[ -L "${symlink}" ]] ; then |
75 |
- set_symlink "${target}" "${symlink}" || die -q "Couldn't set a new symlink" |
76 |
+ if [[ ${ifunset} == 0 || ! -d ${symlink} ]]; then |
77 |
+ set_symlink "${target}" "${symlink}" || die -q "Couldn't set a new symlink" |
78 |
+ fi |
79 |
|
80 |
elif [[ -e ${symlink} ]] ; then |
81 |
die -q "Target file already exists and is not a symlink: ${symlink}" |