From 02526baaf979783e3f1ed661f8f16a256b3b9f5a Mon Sep 17 00:00:00 2001
From: Nico Schottelius <nico@nico-notebook.schottelius.org>
Date: Sun, 12 Jan 2020 14:43:06 +0100
Subject: [PATCH] add ifdown support

---
 uncloud/hack/hackcloud/ifdown.sh |  3 +++
 uncloud/hack/hackcloud/vm.sh     | 11 +++++------
 2 files changed, 8 insertions(+), 6 deletions(-)
 create mode 100644 uncloud/hack/hackcloud/ifdown.sh

diff --git a/uncloud/hack/hackcloud/ifdown.sh b/uncloud/hack/hackcloud/ifdown.sh
new file mode 100644
index 0000000..70fe1db
--- /dev/null
+++ b/uncloud/hack/hackcloud/ifdown.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+echo $@!
diff --git a/uncloud/hack/hackcloud/vm.sh b/uncloud/hack/hackcloud/vm.sh
index dfef8cc..56956ea 100755
--- a/uncloud/hack/hackcloud/vm.sh
+++ b/uncloud/hack/hackcloud/vm.sh
@@ -1,7 +1,5 @@
 #!/bin/sh
 
-vmid=$1; shift
-
 qemu=/usr/bin/qemu-system-x86_64
 
 accel=kvm
@@ -9,15 +7,16 @@ accel=kvm
 
 memory=1024
 cores=2
-uuid=732e08c7-84f8-4d43-9571-263db4f80080
+uuid=$(uuidgen)
+mac=$(./mac-gen.py)
 
 export bridge=br100
 
-$qemu -name uc${vmid} \
+$qemu -name "uncloud-!${uuid}" \
       -machine pc,accel=${accel} \
       -m ${memory} \
       -smp ${cores} \
       -uuid ${uuid} \
       -drive file=alpine-virt-3.11.2-x86_64.iso,media=cdrom \
-      -netdev tap,id=netmain,script=./ifup.sh \
-      -device virtio-net-pci,netdev=netmain,id=net0,mac=02:00:f0:a9:c4:4e
+      -netdev tap,id=netmain,script=./ifup.sh,downscript=./ifdown.sh \
+      -device virtio-net-pci,netdev=netmain,id=net0,mac=${mac}