diff options
| author | Silvio Rhatto <rhatto@riseup.net> | 2017-03-16 15:55:10 -0300 | 
|---|---|---|
| committer | Silvio Rhatto <rhatto@riseup.net> | 2017-03-16 15:55:10 -0300 | 
| commit | f091d763234d0cc14a29409f9d4474af722051c7 (patch) | |
| tree | 1e7999113a58f9b617f05966d0b302fd14d86e1c | |
| parent | 4aa9f9f50d77a56d91e5f531feb0182da6c3f79f (diff) | |
| download | kvmx-f091d763234d0cc14a29409f9d4474af722051c7.tar.gz kvmx-f091d763234d0cc14a29409f9d4474af722051c7.tar.bz2 | |
Use APP_BASE variable via __kvmx_set_app_base
| -rw-r--r-- | TODO.md | 1 | ||||
| -rwxr-xr-x | kvmx | 39 | 
2 files changed, 35 insertions, 5 deletions
| @@ -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). @@ -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 | 
