BASENAME="`basename $0`"
DIRNAME="`dirname $0`"
ACTION="$1"
-VM="$2"
GLOBAL_USER_CONFIG_FOLDER="$HOME/.config/kvmx"
GLOBAL_USER_CONFIG_FILE="$HOME/.config/kvmxconfig"
return
fi
- if [ -z "$VM" ]; then
+ # Check if second argument is a VM name or option
+ if [ -z "$2" ]; then
VM="$(basename `pwd`)"
+ SHIFTARGS="1"
+ elif [ -e 'kvmxfile' ] && [ ! -e "$GLOBAL_USER_CONFIG_FOLDER/$2" ] && [ "$2" != "$(basename `pwd`)" ]; then
+ VM="$(basename `pwd`)"
+ SHIFTARGS="1"
+ else
+ VM="$2"
+ SHIFTARGS="2"
fi
# Default parameters
exit 1
fi
+ if [ "$spice" == "0" ]; then
+ echo "$BASENAME: spice is disabled for guest $VM"
+ exit 1
+ fi
+
# Ensure we have the right port configuration: we can also be
# running directly from command line.
PORT="`cat $PORTFILE`"
if [ -z "$PORT" ]; then
- echo "$BASENAME: cannot get spice port for $VM."
+ echo "$BASENAME: cannot get spice port for $VM"
exit 1
fi
-S "kvmx-$VM" -t "kvmx-$VM" socat STDIO,raw,echo=0 "UNIX:${CONSOLEFILE},retry=30" &
if [ "$run_spice_client" == "1" ]; then
- sleep 1
- kvmx_spice
+ if [ "$spice" == "0" ]; then
+ echo "$BASENAME: spice is disabled for guest $VM"
+ else
+ sleep 1
+ kvmx_spice
+ fi
fi
if [ "$ssh_support" == "y" ]; then
exit 1
fi
+ if [ "$ssh_support" != "y" ]; then
+ echo "$BASENAME: ssh_support is disabled for guest $VM"
+ exit 1
+ fi
+
echo "Setting hostname..."
$SSH_COMMAND -o ConnectTimeout=2 -p $SSH 127.0.0.1 <<EOF
##### BEGIN REMOTE SCRIPT #####
function kvmx_usage {
echo "$BASENAME $VERSION - virtual machine manager"
echo ""
- echo "usage: $BASENAME <action> <vm> [options]"
+ echo "usage: $BASENAME <action> [vm] [options]"
echo ""
echo "available actions:"
echo ""
# Shift params according to how the program was called:
# either "kvmx ssh" or "kvmx ssh guest".
- if [ "$ACTION" == "ssh" ]; then
- if [ ! -z "$2" ]; then
- shift 2
- else
- shift 1
- fi
- fi
+ #if [ "$ACTION" == "ssh" ]; then
+ # if [ ! -z "$2" ]; then
+ # shift 2
+ # else
+ # shift 1
+ # fi
+ #fi
SSH="`cat $SSHFILE`"
#TERM=xterm $SSH_COMMAND -p $SSH 127.0.0.1 $*
exit 1
fi
- ORIG="$3"
- DEST="$4"
+ if [ "$ssh_support" != "y" ]; then
+ echo "$BASENAME: ssh_support is disabled for guest $VM"
+ exit 1
+ fi
+
+ ORIG="$1"
+ DEST="$2"
if [ -z "$DEST" ]; then
# Error
exit 1
fi
- ORIG="$3"
- DEST="$4"
+ if [ "$ssh_support" != "y" ]; then
+ echo "$BASENAME: ssh_support is disabled for guest $VM"
+ exit 1
+ fi
+
+ ORIG="$1"
+ DEST="$2"
if [ -z "$DEST" ]; then
# Error
exit 1
fi
- ORIG="$3"
- DEST="$4"
+ if [ "$ssh_support" != "y" ]; then
+ echo "$BASENAME: ssh_support is disabled for guest $VM"
+ exit 1
+ fi
+
+ ORIG="$1"
+ DEST="$2"
if [ -z "$DEST" ]; then
# Error
exit 1
fi
- ORIG="$3"
- DEST="$4"
+ if [ "$ssh_support" != "y" ]; then
+ echo "$BASENAME: ssh_support is disabled for guest $VM"
+ exit 1
+ fi
+
+ ORIG="$1"
+ DEST="$2"
if [ -z "$DEST" ]; then
# Error
# Initializes a new guest
function kvmx_init {
- FOLDER="$3"
+ FOLDER="$1"
if [ -z "$FOLDER" ]; then
if [ -z "$VM" ]; then
exit 1
fi
- FOLDER="$3"
+ FOLDER="$1"
DEST="`basename $FOLDER`"
if [ -z "$FOLDER" ]; then
#exit 1
fi
+ if [ "$ssh_support" != "y" ]; then
+ echo "$BASENAME: ssh_support is disabled for guest $VM"
+ exit 1
+ fi
+
if [ -z "$provision_command" ]; then
echo "$BASENAME: error: parameter provision_command is not configured for $VM."
exit 1
exit 1
fi
- local action="$3"
- shift 3
+ local action="$1"
+ shift
SSH="`cat $SSHFILE`"
exit 1
fi
- ORIG="$3"
+ ORIG="$1"
if [ -z "$ORIG" ]; then
echo "$BASENAME: missing file argument."
exit 1
fi
- FOLDER="$3"
+ FOLDER="$1"
DEST="`basename $FOLDER`"
if [ -z "$FOLDER" ]; then
exit 1
fi
- local media="$3"
+ local media="$1"
if [ -z "$media" ]; then
echo "usage: $BASENAME install $VM <installation-media>"
# Dispatch
if type kvmx_$ACTION 2> /dev/null | grep -q "kvmx_$ACTION ()"; then
- __kvmx_initialize
+ __kvmx_initialize $*
+
+ if [ "$ACTION" != "app_base" ]; then
+ shift $SHIFTARGS
+ fi
+
kvmx_$ACTION $*
else
kvmx_usage
net="user"
# Set this is you want to be able to share a single folder between host and guest.
+# Needs ssh_support set to "y" and a workable SSH connection to the guest.
shared_folder="."
shared_folder_mountpoint="/home/$user/code/$VM"
#shared_folder_mountpoint="/srv/shared"
#shared_folder_mountpoint="/vagrant"
# Set this is you want to be able to share multiple folders between host and guest.
+# Needs ssh_support set to "y" and a workable SSH connection to the guest.
# Format: <id1>:<host-folder1>:<guest-mountpoint1>,<id2>:<host-folder2>:<guest-mountpoint2>[,...]
#shared_folders="shared1:.:/home/$user/code/$VM,shared2:$HOME/.local/share/app:/home/$user/.local/share/app"
#shared_folders_cache="none"
# Folder to sync during provisioning in the format "/host/folder1 /guest/folder1,/host/folder2 /guest/folder2[,...]".
+# Needs ssh_support set to "y" and a workable SSH connection to the guest.
#provision_rsync="$KVMX_BASE/share/provision/ /usr/local/share/kvmx/provision/"
#provision_rsync="puppet/ /etc/puppet/"
#provision_rsync_opts="--exclude=somefolder"
# Absolute path for a provision script located inside the guest.
+# Needs ssh_support set to "y" and a workable SSH connection to the guest.
#provision_command="/usr/local/share/kvmx/provision/development && /etc/puppet/bin/provision && /etc/puppet/bin/deploy"
#provision_command="/usr/local/share/kvmx/provision/development && /etc/puppet/bin/deploy"
#provision_command="/usr/local/share/kvmx/provision/development && /home/$user/code/$VM/bin/custom-provisioner"