From 83edbb621bd1706cbbd1db29a0cf32b62b32b036 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 22 Apr 2017 14:22:54 -0300 Subject: Adds scp_from and scp_to --- kvmx | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/kvmx b/kvmx index 0a0d1c5..7fd6ffe 100755 --- a/kvmx +++ b/kvmx @@ -61,7 +61,9 @@ function kvmx_app_base { # Build a SSH command function __kvmx_ssh_command { # See http://blog.djm.net.au/2013/11/chacha20-and-poly1305-in-openssh.html - SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=FATAL -o ProxyCommand=none -o Ciphers=chacha20-poly1305@openssh.com -i $1" + SSH_OPTS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=FATAL -o ProxyCommand=none -o Ciphers=chacha20-poly1305@openssh.com -i $1" + SSH_COMMAND="ssh $SSH_OPTS" + SCP_COMMAND="scp $SSH_OPTS" } # Create a guest entry at the global user config folder @@ -570,6 +572,52 @@ function kvmx_rsync { rsync -av -e "$SSH_COMMAND -o Port=$SSH" --rsync-path "sudo rsync" $ORIG/ $SSH_LOGIN@127.0.0.1:$DEST/ } +# Copy files from the guest +function kvmx_scp_from { + if ! kvmx_running; then + echo "$BASENAME: guest $VM is not running" + exit 1 + fi + + ORIG="$3" + DEST="$4" + SSH="`cat $SSHFILE`" + + if [ -z "$DEST" ]; then + exit 1 + fi + + # Fix ~/ path + if echo $ORIG | grep -q -e "^$HOME"; then + ORIG="$(echo $ORIG | sed -e "s|^$HOME|/home/$SSH_LOGIN|")" + fi + + $SCP_COMMAND -o Port=$SSH -o User=$SSH_LOGIN 127.0.0.1:$ORIG $DEST +} + +# Copy files to the guest +function kvmx_scp_to { + if ! kvmx_running; then + echo "$BASENAME: guest $VM is not running" + exit 1 + fi + + ORIG="$3" + DEST="$4" + SSH="`cat $SSHFILE`" + + if [ -z "$DEST" ]; then + exit 1 + fi + + # Fix ~/ path + if echo $DEST | grep -q -e "^$HOME"; then + DEST="$(echo $DEST | sed -e "s|^$HOME|/home/$SSH_LOGIN|")" + fi + + $SCP_COMMAND -o Port=$SSH -o User=$SSH_LOGIN $ORIG 127.0.0.1:$DEST +} + # List guests function kvmx_list { if [ -e "$GLOBAL_USER_CONFIG_FOLDER" ]; then -- cgit v1.2.3