]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Use APP_BASE variable via __kvmx_set_app_base
authorSilvio Rhatto <rhatto@riseup.net>
Thu, 16 Mar 2017 18:55:10 +0000 (15:55 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Thu, 16 Mar 2017 18:55:10 +0000 (15:55 -0300)
TODO.md
kvmx

diff --git a/TODO.md b/TODO.md
index 82608bebbca3a16e14668bb67f3dbcb0ca647d59..3a912b2c746325a54097b6f3ea62a8d8ac320c95 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -3,7 +3,6 @@ TODO
 
 * Shared folder and mountpoint pairs.
 * Default image image location so putting that info on kvmxfile is optional.
-* Use APP_BASE variable like the Hydra Suite (symlink handling, etc).
 * More kvmx-create params (ssh, serial console, etc).
 * Production mode (systemd service, serial console, no passwordless ssh, etc).
 * Support for more distros at kvmx-create (archlinux, gentoo, slackware, etc).
diff --git a/kvmx b/kvmx
index 15b6468b549b87581f5d2a2a3ecb335caa2b60e8..44800f1ed4055753e6c048411eb1516edd86835f 100755 (executable)
--- a/kvmx
+++ b/kvmx
@@ -26,11 +26,42 @@ ACTION="$1"
 VM="$2"
 GLOBAL_USER_CONFIG_FOLDER="$HOME/.config/kvmx"
 
-# Alias to be used in config files
-KVMX_BASE="$DIRNAME"
+# Set application base
+function __kvmx_set_app_base {
+  local dest
+  local base
+
+  # Determine if we are in a local or system-wide install.
+  if [ -h "$0" ]; then
+    dest="$(readlink $0)"
+
+    # Check again as the caller might be a symlink as well
+    if [ -h "$dest" ]; then
+      base="`dirname $dest`"
+      dest="$(dirname $(readlink $dest))"
+    else
+      base="`dirname $0`"
+      dest="`dirname $dest`"
+    fi
+
+    # Deal with relative or absolute links
+    if [ "`basename $dest`" == "$dest" ]; then
+      export APP_BASE="$base"
+    else
+      export APP_BASE="$dest"
+    fi
+  else
+    export APP_BASE="`dirname $0`"
+  fi
+}
 
 # Initialize
 function __kvmx_initialize {
+  __kvmx_set_app_base
+
+  # Alias to be used in config files
+  KVMX_BASE="$APP_BASE"
+
   if [ "$ACTION" == "init" ] || [ "$ACTION" == "list" ]; then
     return
   fi
@@ -42,7 +73,7 @@ function __kvmx_initialize {
   # Default parameters
   PORT="$(($RANDOM + 1024))"
   SSH="$(($PORT + 22))"
-  SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=FATAL -o ProxyCommand=none -i $DIRNAME/ssh/insecure_private_key"
+  SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=FATAL -o ProxyCommand=none -i $APP_BASE/ssh/insecure_private_key"
   SSH_LOGIN="user"
 
   # Initalize
@@ -408,7 +439,7 @@ function kvmx_init {
 
   # Copy config from template
   if [ ! -e "$FOLDER/kvmxfile" ]; then
-    cp $DIRNAME/kvmxfile $FOLDER/
+    cp $APP_BASE/kvmxfile $FOLDER/
     sed -i -e "s|hostname=\"machine\"|hostname=\"$VM\"|g" $FOLDER/kvmxfile
   fi