Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virt builder images example #3

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions auto_create_vm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

# example: ./auto_create_vm.sh cockpit ~/build

prog=`basename $0`

function printh() {
echo -e "Usage: $prog "
echo " <postfix> [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 <<EOF >> $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
32 changes: 26 additions & 6 deletions create-guest-qcow2.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -54,7 +55,7 @@ create_ks_file()
cat << EOF > $fkstart
install
text
reboot
shutdown
lang en_US.UTF-8
keyboard us
network --bootproto dhcp
Expand Down Expand Up @@ -112,17 +113,19 @@ create_guest()
--hvm \
--location=$locn \
--nographics \
--serial=pty
--serial=pty\
--noreboot

rm $fkst
return 0
}

usage ()
{
echo -e "Usage: $prog [OPTIONS] <vm-name> <distro> <arch>\n"
echo " distro: f20 f21"
echo -e "Usage: $prog [OPTIONS] <vm-name> <distro> <arch> [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 ()
Expand Down Expand Up @@ -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
Expand All @@ -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=""
Expand All @@ -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"
Expand Down