diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2017-03-16 15:49:25 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2017-03-16 15:49:25 -0300 |
commit | 4aa9f9f50d77a56d91e5f531feb0182da6c3f79f (patch) | |
tree | 725c251f2a4ac835445ad61387f439aebcff7f0e | |
parent | f4ecde28fa994d28257ea476f9760d0192c62d6d (diff) | |
download | kvmx-4aa9f9f50d77a56d91e5f531feb0182da6c3f79f.tar.gz kvmx-4aa9f9f50d77a56d91e5f531feb0182da6c3f79f.tar.bz2 |
Rename kvmx_initialize to __kvmx_initialize so it stays as a private action
-rwxr-xr-x | kvmx | 104 |
1 files changed, 52 insertions, 52 deletions
@@ -29,6 +29,57 @@ GLOBAL_USER_CONFIG_FOLDER="$HOME/.config/kvmx" # Alias to be used in config files KVMX_BASE="$DIRNAME" +# Initialize +function __kvmx_initialize { + if [ "$ACTION" == "init" ] || [ "$ACTION" == "list" ]; then + return + fi + + if [ -z "$VM" ]; then + VM="$(basename `pwd`)" + fi + + # 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_LOGIN="user" + + # Initalize + mkdir -p $GLOBAL_USER_CONFIG_FOLDER + + # Load and check guest config + if [ "$ACTION" != "init" ] && [ "$ACTION" != "list" ] && [ "$ACTION" != "edit" ] && [ "$ACTION" != "usage" ]; then + if [ ! -e "$GLOBAL_USER_CONFIG_FOLDER/$VM" ]; then + echo "$BASENAME: config not found: $GLOBAL_USER_CONFIG_FOLDER/$VM" + exit 1 + else + source $GLOBAL_USER_CONFIG_FOLDER/$VM + fi + + if [ -z "$image" ]; then + image="/var/cache/qemu/$VM/box.img" + fi + + # Box and folder config + KVMXFILE="`readlink $GLOBAL_USER_CONFIG_FOLDER/$VM`" + KVMX_PROJECT_FOLDER="`dirname $KVMXFILE`" + STORAGE="`dirname $image`" + STATE_DIR="$STORAGE/state/$VM" + PIDFILE="$STATE_DIR/pid" + PORTFILE="$STATE_DIR/port" + SSHFILE="$STATE_DIR/ssh" + LOGFILE="$STATE_DIR/log" + SPICEFILE="$STATE_DIR/spice" + mkdir -p $STATE_DIR + + if [ ! -e "$image" ] && [ "$ACTION" != "up" ] && [ "$ACTION" != "purge" ] && [ "$ACTION" != "destroy" ]; then + echo "$BASENAME: file not found: $image" + exit 1 + fi + fi +} + # Run spice client function kvmx_spice { if ! kvmx_running; then @@ -330,57 +381,6 @@ function kvmx_upgrade { echo "sudo apt-get update && sudo apt-get dist-upgrade -y && sudo apt-get autoremove -y" | kvmx_ssh } -# Initialize -function kvmx_initialize { - if [ "$ACTION" == "init" ] || [ "$ACTION" == "list" ]; then - return - fi - - if [ -z "$VM" ]; then - VM="$(basename `pwd`)" - fi - - # 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_LOGIN="user" - - # Initalize - mkdir -p $GLOBAL_USER_CONFIG_FOLDER - - # Load and check guest config - if [ "$ACTION" != "init" ] && [ "$ACTION" != "list" ] && [ "$ACTION" != "edit" ] && [ "$ACTION" != "usage" ]; then - if [ ! -e "$GLOBAL_USER_CONFIG_FOLDER/$VM" ]; then - echo "$BASENAME: config not found: $GLOBAL_USER_CONFIG_FOLDER/$VM" - exit 1 - else - source $GLOBAL_USER_CONFIG_FOLDER/$VM - fi - - if [ -z "$image" ]; then - image="/var/cache/qemu/$VM/box.img" - fi - - # Box and folder config - KVMXFILE="`readlink $GLOBAL_USER_CONFIG_FOLDER/$VM`" - KVMX_PROJECT_FOLDER="`dirname $KVMXFILE`" - STORAGE="`dirname $image`" - STATE_DIR="$STORAGE/state/$VM" - PIDFILE="$STATE_DIR/pid" - PORTFILE="$STATE_DIR/port" - SSHFILE="$STATE_DIR/ssh" - LOGFILE="$STATE_DIR/log" - SPICEFILE="$STATE_DIR/spice" - mkdir -p $STATE_DIR - - if [ ! -e "$image" ] && [ "$ACTION" != "up" ] && [ "$ACTION" != "purge" ] && [ "$ACTION" != "destroy" ]; then - echo "$BASENAME: file not found: $image" - exit 1 - fi - fi -} - # Initializes a new guest function kvmx_init { FOLDER="$3" @@ -579,7 +579,7 @@ function kvmx_log { # Dispatch if type kvmx_$ACTION 2> /dev/null | grep -q 'function'; then - kvmx_initialize + __kvmx_initialize kvmx_$ACTION $* else kvmx_usage |