aboutsummaryrefslogtreecommitdiff
path: root/kvmx
blob: 6b620a27cffca88f33ca5af5e92ae23152e42e39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
#
# KVM and SPICE client wrapper
#

# Parameters
BASENAME="`basename $0`"
STORAGE="/var/cache/qemu"
SHARED="/var/data/load"
PORT="$(($RANDOM + 1024))"
ACTION="$1"
VM="$2"

# Check
if [ -z "$VM" ] && [ "$ACTION" != "clip" ]; then
  echo "usage: $BASENAME <action> <vm>"
  exit 1
elif [ ! -e "$STORAGE/$VM.img" ] && [ "$ACTION" != "clip" ]; then
  echo "file not found: $STORAGE/$VM.img"
  exit 1
fi

# Dispatch
if [ "$ACTION" == "up" ]; then
  # Run virtual machine
  kvm -m 2048 -name $VM -drive file=$STORAGE/$VM.img,if=virtio -vga qxl \
      -spice port=$PORT,addr=127.0.0.1,disable-ticketing,streaming-video=off,jpeg-wan-compression=never,playback-compression=off,zlib-glz-wan-compression=never,image-compression=off \
      -device virtio-serial-pci \
      -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \
      -chardev spicevmc,id=spicechannel0,name=vdagent \
      -smp 2 -soundhw ac97 -cpu host -balloon virtio \
      #-net nic,model=virtio \
      #-net user,hostfwd=tcp:127.0.0.1:5555-:22 \
      -fsdev local,id=shared,path=$SHARED,security_model=none -device virtio-9p-pci,fsdev=shared,mount_tag=shared &

  # Run spice client
  # https://lists.freedesktop.org/archives/spice-devel/2013-September/014643.html
  SPICE_NOGRAB=1 spicec --host localhost --port $PORT &
  #spicy -h localhost -p $PORT
  #remote-viewer spice://localhost:$PORT

  # Give time to boot
  sleep 5

  # Fix window titles
  xdotool search --name "SPICEc:0" set_window --name $VM
elif [ "$ACTION" == "clip" ]; then
  instances="`ps -o pid,command -e | grep "spice-vdagent$" | cut -d ' ' -f 2 | xargs`"

  # Kill old instances
  for pid in $instances; do
    kill -9 $pid &> /dev/null
  done

  # Just to make sure we're inside a virtual machine
  if which spice-vdagent &> /dev/null ; then
    spice-vdagent
  fi
fi