]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Hostfwd and misc fixes
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 10 Mar 2017 01:20:41 +0000 (22:20 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 10 Mar 2017 01:20:41 +0000 (22:20 -0300)
kvmx
kvmx-create
kvmxfile

diff --git a/kvmx b/kvmx
index ccf39ade2ef2bf2f4721b6c7128e0d96bc78eaf7..38ddfbac6fc2a7ff2eaa46f5a1270719857fa11e 100755 (executable)
--- a/kvmx
+++ b/kvmx
@@ -35,10 +35,14 @@ function kvmx_up {
     exit 1
   fi
 
-  if [ "$shared_folder" ]; then
+  if [ ! -z "$shared_folder" ]; then
     local shared="-fsdev local,id=shared,path=$shared_folder,security_model=none -device virtio-9p-pci,fsdev=shared,mount_tag=shared"
   fi
 
+  if [ ! -z "$port_mapping" ]; then
+    local hostfwd=",$port_mapping"
+  fi
+
   # Check if image exists, create otherwise
   if [ ! -e "$image" ]; then
     if [ ! -z "$basebox" ]; then
@@ -66,7 +70,7 @@ function kvmx_up {
       -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:$SSH-:22 &> $LOGFILE &
+      -net user,hostfwd=tcp:127.0.0.1:$SSH-:22$hostfwd &> $LOGFILE &
 
   PID="$!"
 
@@ -138,7 +142,14 @@ function kvmx_resume {
 
 # Poweroff the guest
 function kvmx_poweroff {
+  if ! kvmx_running; then
+    echo "$BASENAME: guest $VM is not running"
+    exit 1
+  fi
+
   echo /usr/bin/sudo poweroff | kvmx_ssh &> /dev/null
+  sleep 3
+  kvmx_status
 }
 
 # Rsync files to the guest
@@ -318,6 +329,7 @@ function kvmx_destroy {
   rm -f $PIDFILE
   rm -f $SSHFILE
   rm -f $PORTFILE
+  rm -f $LOGFILE
 
   echo "$BASENAME: please inspect and remove `dirname $image` manually."
 }
index b460705a83f135763e50ded0bede11c37028a233..f2709f66644dd8c2ecf0c6615113514e69efb1c6 100755 (executable)
@@ -185,7 +185,6 @@ function kvmx_create_custom {
   kvmx_sudo_run mount none -t proc  $WORK/proc
   kvmx_sudo_run mount none -t sysfs $WORK/sys
   kvmx_sudo_run mount -o bind /dev/ $WORK/dev
-  echo LANG=C | $SUDO tee $WORK/etc/default/locale > /dev/null
 
   # Hostname configuration.
   echo $hostname.$domain     | $SUDO tee    $WORK/etc/hostname > /dev/null
@@ -201,6 +200,12 @@ function kvmx_create_custom {
   # Fstab
   echo "/dev/vda2 / ext4 errors=remount-ro 0 1" | $SUDO tee $WORK/etc/fstab > /dev/null
 
+  # Locale
+  $APT_INSTALL locales
+  echo "LANG=$LANG"  | $SUDO tee    $WORK/etc/default/locale > /dev/null
+  echo "$LANG UTF-8" | $SUDO tee -a $WORK/etc/locale.gen     > /dev/null
+  kvmx_sudo_run chroot $WORK/ locale-gen
+
   # Initial upgrade
   echo "Applying initial upgrades..."
   kvmx_sudo_run chroot $WORK/ apt-get update
@@ -213,7 +218,6 @@ function kvmx_create_custom {
   fi
 
   # Basic packages
-  $APT_INSTALL locales
   $APT_INSTALL screen cron lsb-release openssl -y
   $APT_INSTALL spice-vdagent qemu-guest-agent
 
@@ -249,9 +253,9 @@ function kvmx_create_custom {
 /usr/sbin/service spice-vdagent start
 
 # Ensure file sharing between host and guest
-if [ ! -z "$shared_mountpoint" ]; then
-  /bin/mkdir -p $shared_mountpoint
-  /bin/mount -t 9p -o trans=virtio shared $shared_mountpoint -oversion=9p2000.L,posixacl,cache=loose
+if [ ! -z "$shared_folder_mountpoint" ]; then
+  /bin/mkdir -p $shared_folder_mountpoint
+  /bin/mount -t 9p -o trans=virtio shared $shared_folder_mountpoint -oversion=9p2000.L,posixacl,cache=loose
 fi
 
 exit 0
index f3b04988d513de50e8b7a5d89286194077960baa..32d26002a4d14325854c6becf388c82c1d1a0a47 100644 (file)
--- a/kvmxfile
+++ b/kvmxfile
@@ -16,8 +16,8 @@ shared_folder_mountpoint="/media/shared"
 # boots.
 run_spice_client="1"
 
-# Set host_port-:guest_port mapping pairs.
-#port_mapping="8080-:80,8443-:443"
+# Set additional hostfwd mappings
+#port_mapping="hostfwd=tcp:127.0.0.1:8080-:80,hostfwd=tcp:127.0.0.1:8443-:443"
 
 # Where the guest image is stored
 image="$HOME/.local/share/kvmx/$VM/box.img"