diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2017-05-09 10:51:20 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2017-05-09 10:51:20 -0300 |
commit | e463915f07745ecda9eb0d2d61332fafe17b7f62 (patch) | |
tree | 77616a5ae5a1b89fda9432fad0a4b6a9dabe65cc | |
parent | d90e263b035f50111c58ae597ac2e51edcb3d699 (diff) | |
download | kvmx-e463915f07745ecda9eb0d2d61332fafe17b7f62.tar.gz kvmx-e463915f07745ecda9eb0d2d61332fafe17b7f62.tar.bz2 |
Adds kvmx_open
-rwxr-xr-x | kvmx | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -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 |