diff --git a/auto_create_vm.sh b/auto_create_vm.sh new file mode 100755 index 0000000..9ecd977 --- /dev/null +++ b/auto_create_vm.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +# example: ./auto_create_vm.sh cockpit ~/build + +prog=`basename $0` + +function printh() { + echo -e "Usage: $prog " + echo " [dir] [customization_script]" + echo " postfix: it create output name in format like fedora21-suffix" + echo " dir: where to create/store images [optional]" + echo " customization_script: do customization script on guests [optional]" + +} +if [ "$#" -lt 1 ]; then + printh; + exit 255 +fi + +POSTFIX=$1 +test "$2" && DIR=$2 || DIR=/var/lib/libvirt/images +test "$3" && CUSTOMIZATION="--script '$3'" +ARCH=x86_64 +TYPE=qcow2 +mkdir -p $DIR + + +function create_parametrized(){ +set -x + DIST=$1 + REALDIST=$2 + REVISION=$3 + test "$4" && DISTOVERWRITE=$4 || DISTOVERWRITE=$DIST + DOMAIN=$DIST-$POSTFIX + ./create-guest-qcow2.bash $DOMAIN $REALDIST $ARCH $DIR + sleep 5 + sudo virt-sysprep --connect qemu:///system -d $DOMAIN $CUSTOMIZATION + DISCNAME="$DOMAIN.$TYPE" + CDISCNAME="$DISCNAME.xz" + UNSIZE=`stat $DIR/$DISCNAME -c "%s"` + xz --best --block-size=16777216 $DIR/$DISCNAME + COMSIZE=`stat $DIR/$CDISCNAME -c "%s"` + SHASUM=`sha512sum $DIR/$CDISCNAME | cut -d ' ' -f 1` + cat <> $DIR/index +[$DOMAIN] +name=$DOMAIN +osinfo=$DISTOVERWRITE +arch=$ARCH +file=$CDISCNAME +revision=$REVISION +checksum=$SHASUM +format=$TYPE +size=$UNSIZE +compressed_size=$COMSIZE + +EOF +set +x +} + +create_parametrized fedora21 f21 1 fedora21 +create_parametrized fedora22 f22 1 fedora21 + +if [ `gpg --list-keys | wc -l` -lt 4 ]; then + echo "!!! your probably does not have generated gpg key, running command: gpg --gen-key" + gpg --gen-key +fi +echo "Signing $DIR/index file" +gpg --clearsign --armor $DIR/index diff --git a/create-guest-qcow2.bash b/create-guest-qcow2.bash index 239d993..f3f2dff 100755 --- a/create-guest-qcow2.bash +++ b/create-guest-qcow2.bash @@ -41,7 +41,8 @@ IMAGE_HOME="/var/lib/libvirt/images" burl="http://dl.fedoraproject.org/pub" location1="$burl/fedora/linux/releases/20/Fedora/ARCH/os" location2="$burl/fedora/linux/releases/21/Server/ARCH/os" - +location3="$burl/fedora/linux/development/22/ARCH/os" +location4="$burl/fedora/linux/development/rawhide/ARCH/os" # Create a minimal kickstart file and return the temporary file name. # Do remember to delete this temporary file when it is no longer required. @@ -54,7 +55,7 @@ create_ks_file() cat << EOF > $fkstart install text -reboot +shutdown lang en_US.UTF-8 keyboard us network --bootproto dhcp @@ -112,7 +113,8 @@ create_guest() --hvm \ --location=$locn \ --nographics \ - --serial=pty + --serial=pty\ + --noreboot rm $fkst return 0 @@ -120,9 +122,10 @@ create_guest() usage () { - echo -e "Usage: $prog [OPTIONS] \n" - echo " distro: f20 f21" + echo -e "Usage: $prog [OPTIONS] [destination directory]\n" + echo " distro: f20 f21 f22 fraw or http os source like: http://.../pub/fedora/linux/development/latest-22/x86_64/os/" echo " arch: i386, x86_64" + echo " destination directory: directory, where to store image instead of default one" } printh () @@ -177,7 +180,7 @@ check_options () # check if min no. of arguments are 3 # - if [ "$#" != 3 ]; then + if [ "$#" -lt 3 ]; then printh; exit 255 fi @@ -194,6 +197,8 @@ check_options () name=$1 dist=$2 arch=$3 + destdir=$4 + test -n "$destdir" && IMAGE_HOME="$destdir" dimg="$IMAGE_HOME/$name.qcow2" locn="" @@ -207,7 +212,22 @@ check_options () dist="fedora21" locn=${location2/ARCH/$arch} ;; + + f22) + dist="fedora21" + locn=${location3/ARCH/$arch} + ;; + + fraw) + dist="fedora21" + locn=${location4/ARCH/$arch} + ;; + http*) + locn=${dist/ARCH/$arch} + echo "RAW version: $locn" + dist="fedora21" + ;; *) echo "$0: invalid distribution name"