From 7e178473778b8e448ff4c528abf6253661c552e4 Mon Sep 17 00:00:00 2001 From: Olivier Medoc Date: Fri, 25 Jan 2013 09:03:51 +0100 Subject: [PATCH] template_builder: made make scripts OS independent. An important note is that each OS script need to setup itself its own chroot environment (like creating /proc...). --- .gitignore | 2 + Makefile | 2 +- build_template_rpm | 1 + cleanup_image | 10 ++--- fedorize_image | 40 ++++++------------ qubeize_image | 22 ++++------ .../clean-volatile.img.tar | Bin {clean_images => scripts_fc17}/network | 0 {clean_images => scripts_fc17}/packages.list | 0 {clean_images => scripts_fc17}/part.bin | Bin {clean_images => scripts_fc17}/resolv.conf | 0 templates.spec | 2 +- yum_repo_qubes/.gitignore | 1 + 13 files changed, 31 insertions(+), 49 deletions(-) rename {clean_images => scripts_fc17}/clean-volatile.img.tar (100%) rename {clean_images => scripts_fc17}/network (100%) rename {clean_images => scripts_fc17}/packages.list (100%) rename {clean_images => scripts_fc17}/part.bin (100%) rename {clean_images => scripts_fc17}/resolv.conf (100%) diff --git a/.gitignore b/.gitignore index 1284d5f..7fad1ab 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ base_rpms keys appmenus build_timestamp +*.iso +*.fs diff --git a/Makefile b/Makefile index b373ba6..ffee2c0 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ rpms: @echo $(TIMESTAMP) > build_timestamp @echo "Building template: $(TEMPLATE_NAME)" @createrepo -q -g $$PWD/comps-qubes-template.xml yum_repo_qubes/$(DIST) -o yum_repo_qubes/$(DIST) && \ - sudo -E ./fedorize_image fedorized_images/$(TEMPLATE_NAME).img clean_images/packages.list && \ + sudo -E ./fedorize_image fedorized_images/$(TEMPLATE_NAME).img && \ sudo -E ./qubeize_image fedorized_images/$(TEMPLATE_NAME).img $(TEMPLATE_NAME) && \ ./build_template_rpm $(TEMPLATE_NAME) || exit 1; \ diff --git a/build_template_rpm b/build_template_rpm index c63c8e1..c98a1c9 100755 --- a/build_template_rpm +++ b/build_template_rpm @@ -8,6 +8,7 @@ fi rpmbuild --target noarch \ --define "template_name $NAME" \ + --define "DIST $DIST" \ --define "_topdir $PWD/rpmbuild" \ --define "_tmppath $PWD/rpmbuild/tmp" \ -bb templates.spec diff --git a/cleanup_image b/cleanup_image index cae3612..2673513 100755 --- a/cleanup_image +++ b/cleanup_image @@ -1,6 +1,6 @@ #!/bin/sh -IMG=$1 +export IMG=$1 set -e @@ -16,13 +16,9 @@ if ! [ -f $IMG ]; then fi ls -als $IMG mount -o loop $IMG mnt || exit 1 -INSTALLDIR=`pwd`/mnt/ -rm -f $INSTALLDIR/var/lib/rpm/__db.00* $INSTALLDIR/var/lib/rpm/.rpm.lock -yum -c $PWD/yum.conf $YUM_OPTS clean packages --installroot=$INSTALLDIR +export INSTALLDIR=`pwd`/mnt/ -# Make sure that rpm database has right format (for rpm version in template, not host) -echo "--> Rebuilding rpm database..." -chroot `pwd`/mnt /bin/rpm --rebuilddb 2> /dev/null +scripts_"${DIST}"/09_cleanup.sh echo "--> Compacting image file..." dd if=/dev/zero of=mnt/fillme bs=1M > /dev/null 2>&1 || true diff --git a/fedorize_image b/fedorize_image index 72bc33c..ba8f398 100755 --- a/fedorize_image +++ b/fedorize_image @@ -1,31 +1,28 @@ #!/bin/sh -IMG=$1 -PKGLISTFILE=$2 +export IMG=$1 RETCODE=0 : ${DIST=fc14} -if ! [ $# -eq 2 ]; then -echo "usage $0 " +if ! [ $# -eq 1 ]; then +echo "usage $0 " exit fi if [ "$VERBOSE" == "1" ]; then - YUM_OPTS="$YUM_OPTS -q" + export YUM_OPTS="$YUM_OPTS -q" fi if [ -f $IMG ]; then echo "-> Image file already exists, assuming *update*..." mount -o loop $IMG mnt || exit 1 - INSTALLDIR=`pwd`/mnt/ + export INSTALLDIR=`pwd`/mnt/ else echo "-> Preparing instalation of $DIST template..." - rm -f keys base_rpms - ln -sf keys_$DIST keys - ln -sf base_rpms_$DIST base_rpms + scripts_"${DIST}"/00_prepare.sh echo "-> Initializing empty image..." truncate -s 10G $IMG || exit 1 @@ -36,29 +33,18 @@ else mkdir -p mnt mount -o loop $IMG mnt || exit 1 - INSTALLDIR=`pwd`/mnt/ + export INSTALLDIR=`pwd`/mnt/ - echo "-> Initializing RPM database..." - rpm --initdb --root=$INSTALLDIR - rpm --import --root=$INSTALLDIR keys/* - - echo "-> Installing core RPM packages..." - rpm -i --root=$INSTALLDIR base_rpms/*.rpm || exit 1 - - cp clean_images/network $INSTALLDIR/etc/sysconfig - cp clean_images/resolv.conf $INSTALLDIR/etc - cp -a /dev/null /dev/zero /dev/random /dev/urandom $INSTALLDIR/dev/ + scripts_"${DIST}"/01_install_core.sh fi -mount -t proc proc mnt/proc -PKGGROUPS=$(cat $PKGLISTFILE) -export YUM0=$PWD/yum_repo_qubes +export PKGGROUPS=$(cat scripts_"${DIST}/packages.list") + echo "-> Installing package groups..." -yum clean all -c $PWD/yum.conf $YUM_OPTS -y --installroot=$PWD/mnt -yum install -c $PWD/yum.conf $YUM_OPTS -y --installroot=$INSTALLDIR $PKGGROUPS || RETCODE=1 -yum update -c $PWD/yum.conf $YUM_OPTS -y --installroot=$INSTALLDIR || RETCODE=1 +scripts_"${DIST}"/02_install_groups.sh -umount mnt/proc mnt +echo "-> Unmounting fedorized_image..." +sudo umount $INSTALLDIR exit $RETCODE diff --git a/qubeize_image b/qubeize_image index e7fcc9f..59cb4f8 100755 --- a/qubeize_image +++ b/qubeize_image @@ -1,7 +1,7 @@ #!/bin/sh -CLEANIMG=$1 -NAME=$2 +export CLEANIMG=$1 +export NAME=$2 set -e @@ -39,26 +39,22 @@ function cleanup() { trap cleanup ERR -IMG=qubeized_images/$NAME-root.img +export IMG=qubeized_images/$NAME-root.img echo "--> Copying $CLEANIMG to $IMG..." +echo "--> cp could fail with a sparse file error" cp $CLEANIMG $IMG || exit 1 echo "--> Mouting $IMG" mkdir -p mnt mount -o loop $IMG mnt || exit 1 -mount -t proc proc mnt/proc +export INSTALLDIR=mnt -echo "--> Installing RPMs..." -export YUM0=$PWD/yum_repo_qubes -yum install -c $PWD/yum.conf $YUM_OPTS -y --installroot=$(pwd)/mnt @qubes-vm - -echo "--> Installing 3rd party apps" -./add_3rd_party_software.sh +scripts_"${DIST}"/04_install_qubes.sh echo "--> Copying the Apps Menu shortcuts..." -APPSORIG=qubeized_images/$NAME-apps.orig -APPSTEMPL=qubeized_images/$NAME-apps.templates +export APPSORIG=qubeized_images/$NAME-apps.orig +export APPSTEMPL=qubeized_images/$NAME-apps.templates mkdir -p $APPSORIG cp -r $(pwd)/mnt/usr/share/applications/* $APPSORIG @@ -87,7 +83,7 @@ if ! [ -r mnt/etc/sysconfig/i18n ]; then fi echo "--> Unmounting $IMG" -umount mnt/proc mnt +umount mnt echo "Qubeized image stored at: $IMG" diff --git a/clean_images/clean-volatile.img.tar b/scripts_fc17/clean-volatile.img.tar similarity index 100% rename from clean_images/clean-volatile.img.tar rename to scripts_fc17/clean-volatile.img.tar diff --git a/clean_images/network b/scripts_fc17/network similarity index 100% rename from clean_images/network rename to scripts_fc17/network diff --git a/clean_images/packages.list b/scripts_fc17/packages.list similarity index 100% rename from clean_images/packages.list rename to scripts_fc17/packages.list diff --git a/clean_images/part.bin b/scripts_fc17/part.bin similarity index 100% rename from clean_images/part.bin rename to scripts_fc17/part.bin diff --git a/clean_images/resolv.conf b/scripts_fc17/resolv.conf similarity index 100% rename from clean_images/resolv.conf rename to scripts_fc17/resolv.conf diff --git a/templates.spec b/templates.spec index 98d1dae..9f7dc73 100644 --- a/templates.spec +++ b/templates.spec @@ -44,7 +44,7 @@ touch $RPM_BUILD_ROOT/%{dest_dir}/root.img # we will create the real file in %po touch $RPM_BUILD_ROOT/%{dest_dir}/private.img # we will create the real file in %post touch $RPM_BUILD_ROOT/%{dest_dir}/volatile.img # we will create the real file in %post -cp clean_images/clean-volatile.img.tar $RPM_BUILD_ROOT/%{dest_dir}/clean-volatile.img.tar +cp scripts_%{DIST}/clean-volatile.img.tar $RPM_BUILD_ROOT/%{dest_dir}/clean-volatile.img.tar mkdir -p $RPM_BUILD_ROOT/%{dest_dir}/apps.templates mkdir -p $RPM_BUILD_ROOT/%{dest_dir}/apps diff --git a/yum_repo_qubes/.gitignore b/yum_repo_qubes/.gitignore index 595ccdb..a6b5bba 100644 --- a/yum_repo_qubes/.gitignore +++ b/yum_repo_qubes/.gitignore @@ -1 +1,2 @@ fc* +archlinux*