aboutsummaryrefslogtreecommitdiff
path: root/kvmx
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2017-12-31 00:53:02 -0200
committerSilvio Rhatto <rhatto@riseup.net>2017-12-31 00:53:02 -0200
commit22188879a3d5a2c48e94c55a7f17487eab0d2514 (patch)
treeb9e3c4d099730acacb6325581d2b9f68e1cf16b7 /kvmx
parent858d67a74ff2c373ae64b4a41944670ab5be82a4 (diff)
downloadkvmx-22188879a3d5a2c48e94c55a7f17487eab0d2514.tar.gz
kvmx-22188879a3d5a2c48e94c55a7f17487eab0d2514.tar.bz2
Edit accepting params
Diffstat (limited to 'kvmx')
-rwxr-xr-xkvmx28
1 files changed, 22 insertions, 6 deletions
diff --git a/kvmx b/kvmx
index 979620e..6ef4992 100755
--- a/kvmx
+++ b/kvmx
@@ -1033,14 +1033,30 @@ function kvmx_copy {
# Edit guest config
function kvmx_edit {
- if [ -z "$EDITOR" ]; then
- EDITOR="vi"
- fi
+ if [ -z "$1" ]; then
+ if [ -z "$EDITOR" ]; then
+ EDITOR="vi"
+ fi
- if [ -e "$GLOBAL_USER_CONFIG_FOLDER/$VM" ]; then
- $EDITOR $GLOBAL_USER_CONFIG_FOLDER/$VM
+ if [ -e "$GLOBAL_USER_CONFIG_FOLDER/$VM" ]; then
+ $EDITOR $GLOBAL_USER_CONFIG_FOLDER/$VM
+ else
+ echo "$BASENAME: $GLOBAL_USER_CONFIG_FOLDER/$VM: file not found."
+ fi
else
- echo "$BASENAME: $GLOBAL_USER_CONFIG_FOLDER/$VM: file not found."
+ if [ -z "$2" ]; then
+ echo "usage: $BASENAME $VM edit $1 <value>"
+ exit 1
+ fi
+
+ param="$1"
+ shift
+
+ if ! grep -q "^$param=" $GLOBAL_USER_CONFIG_FOLDER/$VM; then
+ echo "$param=\"$*\"" >> $GLOBAL_USER_CONFIG_FOLDER/$VM
+ else
+ sed -i -e "s#^$param=.*#$param=\"$*\"#" $GLOBAL_USER_CONFIG_FOLDER/$VM
+ fi
fi
}