Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

New QEMU/KDialog script

14 views
Skip to first unread message

Hans Bezemer

unread,
Jan 4, 2012, 6:26:25 AM1/4/12
to
Hi!

This might be a better solution when the number of snapshots exceeds 9.

Hans

---8<---
# Script to start Coherent on QEMU
# Copyright, J.L. Bezemer 2012

#
# Coherent disk configuration, change as required
# This configuration assumes a single harddisk and a floppy
# Both in QCOW2 format
#

COHAT0A=/opt/qemu/coherent.dsk
COHFD0=/opt/qemu/null.dsk

function installed {
which "$1" 2> /dev/null | wc -l
}

#
# Check for all QEMU components
#

if [ `installed kdialog` -gt 0 ]; then
KDIALOG=`which kdialog`
else
echo "Can't find: 'kdialog'"
exit 1
fi

if [ `installed qemu-img` -gt 0 ]; then
QEMUIMG=`which qemu-img`
else
$KDIALOG --error "Can't find: 'qemu-img'"
exit 1
fi

if [ `installed qemu-system-i386` -gt 0 ]; then
QEMU386=`which qemu-system-i386`
else
$KDIALOG --error "Can't find: 'qemu-system-i386'"
exit 1
fi

#
# If all disks are available, select the snapshot and start Coherent
#

if [ -f $COHAT0A ]; then
if [ -f $COHFD0 ]; then
SNAPSHOT=`$QEMUIMG snapshot -l $COHAT0A | grep -e "^[0-9]" | cut -c
11-33`
SNAPSHOT=`$KDIALOG --combobox "Select Coherent snapshot:" $SNAPSHOT`;
CANCEL=$?

if [ $CANCEL -eq 0 ]; then
$QEMU386 -hda $COHAT0A -fda $COHFD0 -m 16 -loadvm $SNAPSHOT
else
$KDIALOG --title "Cancel" --sorry "Coherent start cancelled"
fi
exit 0
fi
fi

#
# This is trapped when the disks are not found
#

$KDIALOG --error "Coherent disks not found"
exit 1
---8<---

Hans Bezemer

unread,
Jan 4, 2012, 11:44:22 AM1/4/12
to
Hans Bezemer wrote:

The following changes have been applied to the script:
- Automatic enabling of the TELNET serial port;
- Support for 10+ snapshots (probably);
- Support for Zenity (GNOME, also Windows);
- Put it explicitly under the GPL license

This script requires Zenity, BGStart and MSYS for Windows.

See also:
http://thebeezspeaks.blogspot.com/2011/02/running-shellscripts-under-windows.html
http://thebeezspeaks.blogspot.com/2011/01/installing-wwf-toolkit-under-windows.html

Hans Bezemer


---8<---
#! /bin/sh

# Script to start Coherent on QEMU - Copyright 2012 J.L. Bezemer
# You can redistribute this file and/or modify it under
# the terms of the GNU General Public License

#
# Coherent disk configuration, change as required
# This configuration assumes a single harddisk and a floppy
# Both in QCOW2 format
#

COHAT0A=/opt/qemu/coherent.dsk
COHFD0=/opt/qemu/null.dsk

#
# Returns non-zero when program found in $PATH, otherwise zero.
#

function installed {
which "$1" 2> /dev/null | wc -l
}

#
# Generalized functions to let the GUI utility show a text or combo box
#

function error_box {
case `basename "$GUI"` in
kdialog) $GUI --error "$1"
;;
zenity) $GUI --error --text="$1"
;;
esac
exit 1
}

function warning_box {
case `basename "$GUI"` in
kdialog) $GUI --sorry "$1"
;;
zenity) $GUI --warning --text="$1"
;;
esac
}

function combo_box {
case `basename "$GUI"` in
kdialog) $GUI --combobox "Select Coherent snapshot:" "$@"
;;
zenity) $GUI --title "Select Coherent
snapshot" --list --column="Available snapshots" "$@"
;;
esac
}

#
# Try to find a GUI utility.
#

if [ `installed kdialog` -gt 0 ]; then
GUI=`which kdialog`
elif [ `installed zenity` -gt 0 ]; then
GUI=`which zenity`
else
echo "(ERROR): Can't find: 'Zenity' or 'KDialog'"
exit 1
fi

#
# Check for all QEMU components
#

if [ `installed qemu-img` -gt 0 ]; then
QEMUIMG=`which qemu-img`
else
error_box "Can't find: 'qemu-img'"
fi

if [ `installed qemu-system-i386` -gt 0 ]; then
QEMU386=`which qemu-system-i386`
else
error_box "Can't find: 'qemu-system-i386'"
fi

#
# If all disks are available, select the snapshot and start Coherent
#

if [ -f $COHAT0A ]; then
if [ -f $COHFD0 ]; then
SNAPSHOT=`$QEMUIMG snapshot -l $COHAT0A | grep -e "^[0-9]" | cut -c
11-33`
SNAPSHOT=`combo_box $SNAPSHOT`; CANCEL=$?

if [ $CANCEL -eq 0 ]; then
$QEMU386 -hda $COHAT0A -fda $COHFD0 -m 16 -serial
telnet:localhost:4444,server,nowait -loadvm $SNAPSHOT
else
warning_box "Coherent start cancelled"
fi
exit 0
fi
fi

#
# This is trapped when the disks are not found
#

error_box "Can't find: $COHAT0A or $COHFD0"
---8<---

0 new messages