From mboxrd@z Thu Jan 1 00:00:00 1970 From: Uri Lublin Subject: Re: [PATCH] added unattended.sh script Date: Sun, 28 Jun 2009 14:15:14 +0300 Message-ID: <4A4750C2.3040705@redhat.com> References: <1245361860-26726-1-git-send-email-dhuff@redhat.com> <1245361860-26726-4-git-send-email-dhuff@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org To: David Huff Return-path: Received: from mx2.redhat.com ([66.187.237.31]:59150 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751406AbZF1LPV (ORCPT ); Sun, 28 Jun 2009 07:15:21 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n5SBFOZx028843 for ; Sun, 28 Jun 2009 07:15:24 -0400 In-Reply-To: <1245361860-26726-4-git-send-email-dhuff@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 06/19/2009 12:50 AM, David Huff wrote: > this script gets run by the preprocesser and setup a floppy disk image > containing the answers file > > will also setup a pxe envrionment if tftp parameter is supplied. Hi David, Most of my comments would probably be "automatically" fixed when you port it to Python (e.g. whitespace issues). > --- > client/tests/kvm/scripts/unattended.sh | 157 ++++++++++++++++++++++++++++++++ > 1 files changed, 157 insertions(+), 0 deletions(-) > create mode 100755 client/tests/kvm/scripts/unattended.sh > > diff --git a/client/tests/kvm/scripts/unattended.sh b/client/tests/kvm/scripts/unattended.sh > new file mode 100755 > index 0000000..9624887 > --- /dev/null > +++ b/client/tests/kvm/scripts/unattended.sh > @@ -0,0 +1,157 @@ > +#!/bin/bash > +# > +# unattended.sh - sets up environment for an unattended install for kvm_autotest > +# > +# Copyright (C) 2009 Red Hat, Inc. > +# Written by: > +# David Huff > +# Darryl L. Pierce > +# > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; version 2 of the License. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program; if not, write to the Free Software > +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, > +# MA 02110-1301, USA. A copy of the GNU General Public License is > +# also available at http://www.gnu.org/copyleft/gpl.html. > + > +ME=$(basename "$0") > +log() { printf '%s: %s\n' "$*">&2; } > +die() { log "Aborting: $*"; exit 1; } > +debug() { if $debugging; then log "[DEBUG] $*"; fi } > + > +debugging=true > + > +set -e > + > +# creates a floppy disk image and adds unattended config file > +# this is prefered over vvfat b/c of know issues with fat16 > +# uses loop back mout b/c -i wasent available unitil mtools> 4.0 > +# $CONFIG file to put on floppy disk image > +create_floppy_disk () { > + local size="144" > + local filename="images/$KVM_TEST_floppy" mixture of tabs and spaces (all over) > + > + #create floppy disk image > + debug "Creating floppy disk: filename=${filename} size=${size}" > + qemu-img create -f raw $filename "${size}M"> /dev/null 2>&1 qemu-img might not be in found. use ./qemu-img > + if [ $? != 0 ]; then die "Unable to create disk image: $filename"; fi > + > + mkfs.msdos $filename > + if [ $? != 0 ]; then die "Unable to format disk image: $filename"; fi > + > + #mount floppy disk image > + mp=$(mktemp -d floppytmp.XXXXXX) > + mount -t vfat -v -o loop $filename $mp > + if [ $? != 0 ]; then die "Unable to mount disk image: $filename to: $mp"; fi > + > + #copy config file to disk > + if [[ "$CONFIG" =~ \.ks\$ ]] || [[ "$CONFIG" =~ \.cfg\$ ]]; then > + cp $CONFIG $mp/ks.cfg > + elif [[ "$CONFIG" =~ \.sif\$ ]]; then > + cp $CONFIG $mp/winnt.sif > + else > + cp $CONFIG $mp > + fi > + > + #unmount floppy > + df | grep $mp> /dev/null 2>&1&& umount -v $mp > + rmdir $mp > +} > + > + > +# setup pxeboot evironment > +# $PXE - iso image > +# $ARGS - kernel arguments > +setup_pxeboot () { > + local workdir="images/$KVM_TEST_tftp" > + local iso=$PXE > + local pxedefault=$workdir/pxelinux.cfg/default > + local pxelinux="/usr/lib/syslinux/pxelinux.0" > + local cdlocation="images/pxeboot/" > + > + # Check pxelinux.0 exists. > + if [ ! -f /usr/share/syslinux/pxelinux.0 -a ! -f /usr/lib/syslinux/pxelinux.0 ]; then > + die "Warning: pxelinux.0 not found, Make sure syslinux or pxelinux is installed on this system." > + fi > + > + #create clean tftpboot dir > + if [ -d $workdir ]; then > + log "$ME: subdirectory $workdir exists already. overwriting" > + rm -rf $workdir > + fi > + > + mkdir -p $workdir/pxelinux.cfg > + > + # pxelinux bootloader. > + if [ -f /usr/share/syslinux/pxelinux.0 ]; then > + cp /usr/share/syslinux/pxelinux.0 $workdir > + elif [ -f /usr/lib/syslinux/pxelinux.0 ]; then > + cp /usr/lib/syslinux/pxelinux.0 $workdir > + else > + die "Warning: pxelinux.0 not found, Make sure syslinux or pxelinux is installed on this system." > + fi > + > + # get vmlinz and initrd form image > + mp=$(mktemp -d cdtmp.XXXXXX) > + mount -t iso9660 -v -o ro,loop "$iso" $mp > + if [ $? != 0 ]; then die "Unable to mount cd image: $iso to: $mp"; fi > + > + > + # Does it look like an ISO? > + if [ ! -d $mp/$cdlocation ]; then > + die "The ISO image does not look like a ISO image to me." > + fi > + > + cp $mp/$cdlocation/initrd.img $mp/$cdlocation/vmlinuz $workdir > + df | grep $mp> /dev/null 2>&1&& umount -v $mp > + rmdir $mp > + > + # set default kernel arguments if none were provided > + if [ -z "$ARGS" ]; then > + local $ARGS="" Should be ARGS="" > + fi > + > + local definition="DEFAULT pxeboot" > + definition="${definition}\nTIMEOUT 20" > + definition="${definition}\nPROMPT 0" > + definition="${definition}\nLABEL pxeboot" > + definition="${definition}\n KERNEL vmlinuz" > + definition="${definition}\n APPEND initrd=initrd.img $ARGS" > + > + debug "pxeboot definition=\n${definition}" > + printf "${definition}\n"> $pxedefault > +} > + > +CONFIG=$KVM_TEST_unattended_file > +NAME=$KVM_TEST_image > +PXE=isos/$KVM_TEST_cdrom > +ARGS=$KVM_TEST_kernel_args I think it would be nice to get all KVM_TEST_ params here and pass them as arguments to local (this file) functions. > + > + > +# check to see we are root > +if [ $( id -u ) -ne 0 ]; then > + die "Must run as root" > +fi > + > +# Require "CONFIG_FILE" > +if [[ ! -e $CONFIG ]]; then > + die "no unattended config file found: "$CONFIG"" > +fi > + > +log "using unattended config file: $CONFIG" > + > +# create teh floppy image typo: the. Regards, Uri.