aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2017-04-22 14:22:54 -0300
committerSilvio Rhatto <rhatto@riseup.net>2017-04-22 14:22:54 -0300
commit83edbb621bd1706cbbd1db29a0cf32b62b32b036 (patch)
treef409625e217fd37372dabcdd4ff74668f1a0f379
parentf8e4dba78fb522cf908d33a1638e31b99bc5bbeb (diff)
downloadkvmx-83edbb621bd1706cbbd1db29a0cf32b62b32b036.tar.gz
kvmx-83edbb621bd1706cbbd1db29a0cf32b62b32b036.tar.bz2
Adds scp_from and scp_to
-rwxr-xr-xkvmx50
1 files changed, 49 insertions, 1 deletions
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