]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Fix: VM name and folder logic 0.4.1
authorSilvio Rhatto <rhatto@riseup.net>
Tue, 17 Dec 2024 16:51:32 +0000 (13:51 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Tue, 17 Dec 2024 16:51:32 +0000 (13:51 -0300)
ChangeLog.md
kvmx

index 2560e6c53f5c82e5cbdc981ddcaef92e69cfc39d..a95f824a1a497ee87b1612f9100713a3687d7194 100644 (file)
@@ -1,5 +1,13 @@
 # ChangeLog
 
+## 0.4.1 - 2024-12-17
+
+* Fixes the case when the virtual machine guest is registered under a
+  different name, other than the name of the project folder on
+  `__kvmx_initialize`.
+
+* Fixes VM name and folder logic handling on `kvmx_init`.
+
 ## 0.4.0 - 2024-11-22
 
 * Adds `kvmx sshdir` action, which SSH's to the guest and changes to a given
diff --git a/kvmx b/kvmx
index fee8c3ef192862fdf468ba022521763ffc2f3ce0..2f203461d93f5a799a46fa8205217e3e4f92f68c 100755 (executable)
--- a/kvmx
+++ b/kvmx
@@ -19,7 +19,7 @@
 #
 
 # Basic parameters
-VERSION="0.4.0"
+VERSION="0.4.1"
 BASENAME="`basename $0`"
 DIRNAME="`dirname $0`"
 ACTION="$1"
@@ -106,7 +106,20 @@ function __kvmx_initialize {
 
   # Check if second argument is a VM name or option
   if [ -z "$2" ]; then
-    VM="$(basename `pwd`)"
+    CANDIDATE_DEST="`pwd`/kvmxfile"
+    CANDIDATE_SRC="`find $GLOBAL_USER_CONFIG_FOLDER -lname $CANDIDATE_DEST | head -1`"
+
+    if [ ! -z "$CANDIDATE_SRC" ]; then
+      CANDIDATE_SRC="`basename $CANDIDATE_SRC`"
+    fi
+
+    # This covers the case when the VM is configured with a different name then the folder name
+    if [ ! -z "$CANDIDATE_SRC" ] ; then
+      VM="$CANDIDATE_SRC"
+    else
+      VM="$(basename `pwd`)"
+    fi
+
     SHIFTARGS="1"
   elif [ -e 'kvmxfile' ] && [ ! -e "$GLOBAL_USER_CONFIG_FOLDER/$2" ] && [ "$2" != "$(basename `pwd`)" ]; then
     VM="$(basename `pwd`)"
@@ -1536,17 +1549,11 @@ function kvmx_upgrade {
 
 # Initializes a new guest
 function kvmx_init {
-  FOLDER="$1"
-
-  if [ -z "$FOLDER" ]; then
-    if [ -z "$VM" ]; then
-      VM="$(basename `pwd`)"
-      FOLDER="$(dirname `pwd`)/$VM"
-    else
-      FOLDER="$(pwd)/$VM"
-    fi
+  if [ -z "$1" ]; then
+    VM="$(basename `pwd`)"
+    FOLDER="$(dirname `pwd`)/$VM"
   else
-    VM="$FOLDER"
+    VM="$1"
 
     if [ ! -z "$2" ]; then
       FOLDER="$2"