blob: df2a740476ef303c1c6c538d67ed8031399aaa29 (
plain) (
tree)
|
|
#!/bin/bash
# -----------------------------------------------------------------------------
# Copyright (c) 2007..2009 - RZ Uni FR
# Copyright (c) 2007..2009 - OpenSLX GmbH
#
# This program is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your suggestions, praise, or complaints to feedback@openslx.org
#
# General information about OpenSLX can be found at http://openslx.org/
# -----------------------------------------------------------------------------
# run-virt.sh
# - This is the generic wrapper for the several virtualization solutions.
# The idea is to setup a set of variables used by at least two different
# tools and then include the specific plugin which configures the speci-
# fied virtualization tool.
# -----------------------------------------------------------------------------
# include default directories
. /etc/opt/openslx/openslx.conf
PLUGINCONFROOT=${OPENSLX_DEFAULT_CONFDIR}/plugins
PLUGINCONFDIR=${PLUGINCONFROOT}/vmchooser
# load general virtualization information
[ -f ${PLUGINCONFROOT}/virtualization/virtualization.conf ] && \
. ${PLUGINCONFROOT}/virtualization/virtualization.conf
# Sanity checks
################################################################################
# Theck for running in graphical environment otherwise no much use here
[ -z "$DISPLAY" ] && echo -e "\n\tStart only within a graphical desktop!\n" \
&& exit 1
# Test if the xml path/file is valid (gotten via commandline first parameter)
xml=$1
[ -e "${xml}" ] || { echo -e "\n\tNo XML file given!\n"; exit 1; }
# Read needed variables from XML file
################################################################################
# File name of the image
imgname=$(grep -io "<image_name param=.*\"" ${xml} | \
awk -F "\"" '{ print $2 }')
case ${xml} in
/tmp/*)
# we do not need folder name as it is already included by vmchooser
diskfile=$imgname
imgname=$(basename ${imgname})
;;
*)
# Path to the image
# (readlink produces the absolute path if called relatively)
[ -z $imgpath ] && \
{ imgpath=$(readlink -f $xml); imgpath=${imgpath%/*.xml}; }
# Diskfile is file including absolute path to it
diskfile=$imgpath/$imgname
;;
esac
# TODO: change to new var vmpath, remove diskfile afterwards
vmpath=$diskfile
[ -e $diskfile ] || { echo -e "\n\tImage file $diskfile not found!"; exit 1; }
# Short description of the image (as present in the vmchooser menu line)
vm_name=$(grep -o "short_description param=.*\"" ${xml} | \
sed -e "s/&.*;/; /g" | awk -F "\"" '{print $2}')
# If ${short_description} not defined use ${image_name}
# if ${vm_name} not defined use ${imgname}
vm_name=${vm_name:-"${imgname%.*}"}
# define vm_shortname since vm_name can be very long
vm_shortname=$(echo ${imgname%.*} | sed -e "s, ,-,g")
displayname=${vm_name}
# remove blanks
vm_name=$(echo ${vm_name} | sed -e "s, ,-,g")
# Type of virtual machine to run
virt_mach=$(grep -o "virtualmachine param=.*\"" ${xml} | \
sed -e "s/&.*;/; /g" | awk -F "\"" '{print $2}')
# Make a guess from the filename extension if ${virt_mach} is empty (not set
# within the xml file)
if [ -z ${virt_mach} ] ; then
case "$(echo ${imgname##*.}|tr [A-Z] [a-z])" in
vmdk)
virt_mach="vmware"
;;
img|qcow*)
virt_mach="qemukvm"
;;
vbox)
virt_mach="virtualbox"
;;
*)
echo "Unknown image type, bailing out"
;;
esac
fi
# Definition of the client system
vmostype=$(grep -io '<os param=.*"' ${xml} | awk -F '"' '{ print $2 }')
# Definition of the networking the client system is connected to
network_kind=$(grep -io '<network param=.*"' ${xml} | awk -F '"' '{ print $2 }')
network_card=$(grep -io '<netcard param=.*"' ${xml} | awk -F '"' '{ print $2 }')
# Serial/parallel ports defined (e.g. "ttyS0" or "autodetect")
serial=$(grep -io '<serialport param=.*"' ${xml} | awk -F '"' '{ print $2 }')
parallel=$(grep -io '<parport param=.*"' ${xml} | awk -F '"' '{ print $2 }')
# Declaration of default variables
###############################################################################
# VM-ID static (0D)
VM_ID="00"
# cpu cores
cpu_cores="${cpu_cores}"
# check for CPU virtualization flags
# total amount of memory defined in stage 3
permem=60
# get a result which can be divided through 4
mem=$(expr ${totalmem} / 100 \* ${permem} / 4 \* 4)
[ -n "${mainvirtmem}" ] && forcemem=$(expr ${mainvirtmem} / 4 \* 4)
# configuring ethernet mac address: first 3 bytes are fixed (00:50:56)
# 4th byte is the VM-ID (0D)
# last two bytes are taken from the bridge of the host
# define one MAC per guest
macguestpart="00:50:56:${VM_ID}"
machostpart=$(echo ${hostmacaddr} | awk -F ":" '{print $(NF-1)":"$NF}')
macaddr=$(echo "${macguestpart}:${machostpart}" | tr [a-z] [A-Z])
#TODO: remove when vmware modified
mac=${machostpart}
# virtual fd/cd/dvd and drive devices, floppy b: for configuration
# if $floppy_0 from run-virt.include set then fdtest="TRUE"
fdtest=
fdtest=${floppy_0:+"TRUE"}
# if $fdtest not set floppy0="FALSE", else "TRUE"
floppy0=${fdtest:-"FALSE"}
floppy1="TRUE"
floppy1name="${PLUGINCONFDIR}/loopimg/fd.img"
# if $cdrom_0 from run-virt.include set then cdtest="TRUE"
cdtest=
cdtest=${cdrom_0:+"TRUE"}
# if $cdtest not set cdrom0="FALSE", else "TRUE"
cdrom0=${cdtest:-"FALSE"}
# if $cdrom_1 from run-virt.include set then cdtest="TRUE"
cdtest=
cdtest=${cdrom_1:+"TRUE"}
# if $cdtest not set cdrom1="FALSE", else "TRUE"
cdrom1=${cdtest:-"FALSE"}
# ide is expected default, test for the virtual disk image type should
# be done while creating the runscripts ...
ide="TRUE"
scsi="FALSE"
hddrv="ide"
# add rw share
sharepath="${HOME}"
sharename="home"
# Display resolution within the host system
hostres=$(xvidtune -show 2>/dev/null| grep -ve "^$")
xres=$(echo "${hostres}" | awk '{print $3}')
yres=$(echo "${hostres}" | awk '{print $7}')
# Set hostname: using original hostname and adding string "-vm"
hostname="VM-${HOST}"
# Functions used throughout the script
###############################################################################
# Check for important files used
filecheck ()
{
filecheck=$(LANG=us ls -lh ${diskfile} 2>&1)
writelog "Filecheck:\n${filecheck}\n"
noimage=$(echo ${filecheck} | grep -i "no such file or directory" | wc -l)
rightsfile=${diskfile}
# Check if link
if [ -L "${diskfile}" ]; then
# take link target
rightsfile=$(ls -lh ${diskfile} 2>&1 | awk -F '-> *' '{print $2}')
rightsfile=${vmdir}/${rightsfile}
filecheck=$(LANG=us ls -lh ${rightsfile} 2>&1)
fi
# Does file exist
if [ "${noimage}" -ge "1" ]; then
writelog "Virtual Machine Image Problem:\c "
writelog "\tThe image you've specified doesn't exist."
writelog "Filecheck says:\c "
writelog "\t\t${diskfile}:\n\t\t\tNo such file or directory"
writelog "Hint:\c "
writelog "\t\t\tCompare spelling of the image with your options.\n"
exit 1
fi
# Readable by calling user
if ! [ -r "${diskfile}" >/dev/null 2>&1 \
-o -r "${diskfile}" >/dev/null 2>&1 ]; then
writelog "Vmware Image Problem:\c "
writelog "\tThe image you've specified has wrong rights."
writelog "Filecheck says:\t\t$(echo ${filecheck} \
| awk '{print $1" "$3" "$4}') ${rightsfile}"
writelog "Hint:\t\t\tChange rights with: chmod a+r ${rightsfile}\n"
exit 1
fi
# Writable (for persistent-mode)?
if ! [ -w "${diskfile}" >/dev/null 2>&1 \
-o -w "${diskfile}" >/dev/null 2>&1 ] \
&& [ "${np}" = "independent-persistent" ]; then
writelog "Vmware Image Problem:\c "
writelog "\tThe image you have specified has wrong rights."
writelog "Filecheck says:\t\t$(echo ${filecheck} \
| awk '{print $1" "$3" "$4}') ${rightsfile}"
writelog "Hint:\t\t\tUse nonpersistent-mode or change rights to rw\n"
exit 1
fi
}
# Function to write to stdout and logfile
writelog ()
{
# Write to stdout
echo -e "$1"
# Log into file
echo -e "$1" >> ${OPENSLX_DEFAULT_LOGDIR}/run-virt.${USER}.$$.log
}
# Setup the rest of the environment and run the virtualization tool just confi-
# gured
################################################################################
# Logo for console
cat <<EOL
__ __
.----.--.--.-----.___.--.--.|__|.----.| |_
| _| | | |___| | || || _|| _|
|__| |_____|__|__| \___/ |__||__| |____|
OpenSLX virtual machine environment preparation script ...
EOL
# Adjust sound volume
writelog "Unmuting sound...\c "
amixer -q sset Master 80% unmute 2>/dev/null
amixer -q sset PCM 80% unmute 2>/dev/null
amixer -q sset CD 80% unmute 2>/dev/null
amixer -q sset Headphone 80% unmute 2>/dev/null
amixer -q sset Front 80% umute 2>/dev/null # in SUSE 11.0 it's headphone
amixer -q sset Speaker 0 mute 2>/dev/null # annoying built-in speaker
writelog "finished\n"
# Copy guest configuration (with added information) config.xml to be accessed
# via virtual floppy
# fixme -> to be changed (vmchooser adapts the file content!?)
#TODO: wozu echo?
#echo "Please fix the config.xml generation"
cp ${xml} ${PLUGINCONFDIR}/fd-loop/config.xml
# Check if virtual machine container file exists
#filecheck
# Get all virtual machine specific stuff from the respective include file
if [ -e ${PLUGINCONFROOT}/${virt_mach}/run-virt.include ] ; then
self=${virt_mach}
. ${PLUGINCONFROOT}/${virt_mach}/run-virt.include
# start a windowmanager for easier handling
# (expect problems /w windows opening in background /w vmware without wm)
for dm in xfwm4 metacity openbox blackbox kwin fvwm2 ; do
if which $dm >/dev/null 2>&1 ; then
if [ "$dm" = "fvwm2" ] ; then
echo "EdgeScroll 0 0" > ${redodir}/fvwm
fvwm2 -f ${redodir}/fvwm >/dev/null 2>&1 &
else
$dm >/dev/null 2>&1 &
fi
break
fi
done
${VIRTCMD} ${VIRTCMDOPTS}
writelog "Bye."
exit 0
else
writelog "Failed because of missing ${virt_mach} plugin."
exit 1
fi
|