aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xkvmx40
1 files changed, 40 insertions, 0 deletions
diff --git a/kvmx b/kvmx
index 340c09f..e96054c 100755
--- a/kvmx
+++ b/kvmx
@@ -991,6 +991,46 @@ function kvmx_xephyr_stop {
fi
}
+# Open a file inside a guest
+function kvmx_open {
+ if ! kvmx_running; then
+ echo "$BASENAME: guest $VM is not running"
+ exit 1
+ fi
+
+ ORIG="$3"
+
+ if [ -z "$ORIG" ]; then
+ echo "$BASENAME: missing file argument."
+ exit 1
+ elif [ ! -e "$ORIG" ]; then
+ echo "$BASENAME: file not found: $ORIG"
+ exit 1
+ fi
+
+ DEST_FOLDER="`kvmx ssh $VM /bin/mktemp -d`"
+ DEST="$DEST_FOLDER/`basename $ORIG`"
+
+ # Copy and open
+ kvmx scp_to $VM $ORIG $DEST
+ kvmx ssh $VM DISPLAY=:0 /usr/bin/xdg-open $DEST
+
+ # Copy back
+ TMP_OPEN_FOLDER="`mktemp -d`"
+ TMP_OPEN="$TMP_OPEN_FOLDER/`basename $ORIG`"
+ kvmx scp_from $VM $DEST $TMP_OPEN
+
+ # Check for changes
+ if ! diff $TMP_OPEN $ORIG 2> /dev/null; then
+ mv $TMP_OPEN $ORIG
+ else
+ rm -rf $TMP_OPEN_FOLDER
+ fi
+
+ # Remove from guest
+ kvmx ssh $VM rm -rf $DEST_FOLDER
+}
+
# Dispatch
if type kvmx_$ACTION 2> /dev/null | grep -q 'function'; then
__kvmx_initialize