]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Library support
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 31 Mar 2017 13:18:33 +0000 (10:18 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 31 Mar 2017 13:18:33 +0000 (10:18 -0300)
kvmx
kvmx-create
kvmx-keygen [deleted file]
lib/kvmx/functions [new file with mode: 0755]

diff --git a/kvmx b/kvmx
index 7a5b3ed411a4a18f9f172b9adb980f697313bce1..4ee105582bdb23533a65738318c686a002a393f4 100755 (executable)
--- a/kvmx
+++ b/kvmx
@@ -27,8 +27,8 @@ VM="$2"
 GLOBAL_USER_CONFIG_FOLDER="$HOME/.config/kvmx"
 GLOBAL_USER_CONFIG_FILE="$HOME/.config/kvmxconfig"
 
-# Set application base
-function __kvmx_set_app_base {
+# Get the application base
+function kvmx_app_base {
   local dest
   local base
 
@@ -47,13 +47,15 @@ function __kvmx_set_app_base {
 
     # Deal with relative or absolute links
     if [ "`basename $dest`" == "$dest" ]; then
-      export APP_BASE="$base"
+      APP_BASE="$base"
     else
-      export APP_BASE="$dest"
+      APP_BASE="$dest"
     fi
   else
-    export APP_BASE="`dirname $0`"
+    APP_BASE="`dirname $0`"
   fi
+
+  echo $APP_BASE
 }
 
 # Build a SSH command
@@ -72,11 +74,18 @@ function __kvmx_create_config_entry {
 
 # Initialize
 function __kvmx_initialize {
-  __kvmx_set_app_base
+  if [ "$ACTION" == "app_base" ]; then
+    return
+  fi
+
+  # Load basic functions
+  export APP_BASE="`$DIRNAME/kvmx app_base`"
+  source $APP_BASE/lib/kvmx/functions || exit 1
 
   # Alias to be used in config files
   KVMX_BASE="$APP_BASE"
 
+  # Stop processing here for some actions
   if [ "$ACTION" == "init" ] || [ "$ACTION" == "list" ]; then
     return
   fi
@@ -98,7 +107,7 @@ function __kvmx_initialize {
   fi
 
   # Load and check guest config
-  if [ "$ACTION" != "init" ] && [ "$ACTION" != "list" ] && [ "$ACTION" != "ls" ] && [ "$ACTION" != "edit" ] && [ "$ACTION" != "usage" ]; then
+  if [ "$ACTION" != "ls" ] && [ "$ACTION" != "edit" ] && [ "$ACTION" != "usage" ]; then
     if [ ! -e "$GLOBAL_USER_CONFIG_FOLDER/$VM" ]; then
       if [ -e "kvmxfile" ]; then
         # Existing kvmxfile but not registered at the global user config
@@ -720,7 +729,7 @@ function kvmx_rotate_sshkeys {
   # Generate new keypair
   mkdir -p "$STORAGE/ssh"
   SSHKEY="$STORAGE/ssh/$VM.key"
-  $DIRNAME/kvmx-keygen $SSHKEY.new "$user@`basename $image .img`"
+  __kvmx_ssh_keygen $SSHKEY.new "$user@`basename $image .img`"
 
   # Replace pubkey on server
   echo "touch ~/.ssh/authorized_keys.new && chmod 600 ~/.ssh/authorized_keys.new" | kvmx_ssh
index 4ea87556e1564684be031f2828d51bf101d3dba1..5fb2ca454047d0635d1f8e9616f98a5ef6d0964d 100755 (executable)
@@ -23,6 +23,10 @@ BASENAME="`basename $0`"
 DIRNAME="`dirname $0`"
 GLOBAL_USER_CONFIG_FILE="$HOME/.config/kvmxconfig"
 
+# Load basic functions
+export APP_BASE="`$DIRNAME/kvmx app_base`"
+source $APP_BASE/lib/kvmx/functions || exit 1
+
 # Load configuration
 function kvmx_config_load {
   if [ ! -z "$1" ] && [ -e "$1" ]; then
@@ -261,7 +265,7 @@ function kvmx_create_custom {
       privkey="`dirname $image`/ssh/`basename $image .img`.key"
       pubkey="${privkey}.pub"
       mkdir -p "`dirname $privkey`"
-      $DIRNAME/kvmx-keygen $privkey "$user@`basename $image .img`"
+      __kvmx_ssh_keygen $privkey "$user@`basename $image .img`"
     else
       pubkey="$DIRNAME/share/ssh/insecure_private_key.pub"
     fi
diff --git a/kvmx-keygen b/kvmx-keygen
deleted file mode 100755 (executable)
index 3784e52..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/usr/bin/env bash
-#
-# kvmx-keygen -- ssh-keygen wrapper for kvmx
-#
-# Copyright (C) 2017 Silvio Rhatto - rhatto at riseup.net
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published
-# by the Free Software Foundation, either version 3 of the License,
-# or any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-#
-
-# Parameters
-BASENAME="`basename $0`"
-PRIVKEY="$1"
-COMMENT="$2"
-
-# Generate a keypair
-ssh-keygen -t rsa -b 4096 -f $PRIVKEY -N '' -C $COMMENT
diff --git a/lib/kvmx/functions b/lib/kvmx/functions
new file mode 100755 (executable)
index 0000000..df1bd7a
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/bash
+#
+# Common functions.
+#
+
+# Source required functions
+#source $APP_BASE/lib/kvmx/misc
+
+# Setup environment
+#kvmx_set_env $*
+
+# Generate a keypair
+function __kvmx_ssh_keygen {
+  if [ ! -z "$2" ]; then
+    ssh-keygen -t rsa -b 4096 -f $1 -N '' -C $2
+  fi
+}