From 4e211122234db3972056d1f9cc91b70ca47cbb7c Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Fri, 7 Dec 2007 12:31:14 +0000 Subject: [PATCH] cleaning up the root creation functions and build.common - untested --- Makefile | 15 +- build.common | 638 +++++++++---------- config.planetlab/bootstrapfs-production.pkgs | 16 +- getrpmmacros.sh | 5 + 4 files changed, 329 insertions(+), 345 deletions(-) create mode 100755 getrpmmacros.sh diff --git a/Makefile b/Makefile index 3e8f6eae..00431172 100644 --- a/Makefile +++ b/Makefile @@ -204,6 +204,8 @@ myplc-release: (echo "Build trelease: $(RELEASE)") >> $@ echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx modules versions info" >> $@ $(MAKE) --no-print-directory versions >> $@ + echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx rpms list" >> $@ + $(MAKE) --no-print-directory version-rpms >> $@ ### yumgroups.xml # the source @@ -296,9 +298,7 @@ endif rm -f $@ echo "%_topdir $(HOME)" >> $@ echo "%_tmppath $(HOME)/tmp" >> $@ - echo "%_netsharedpath /proc:/dev/pts" >> $@ - echo "%_install_langs C:de:en:es:fr" >> $@ - echo "%_excludedocs yes" >> $@ + getrpmmacros.sh >> $@ ### this utility allows to extract various info from a spec file ### and to define them in makefiles @@ -601,6 +601,15 @@ $(foreach module,$(ALL-MODULES), $(eval $(call print_version,$(module)))) versions: $(foreach module, $(ALL-MODULES), $(module)-version) +RFORMAT="%20s :: %s\n" +define print_rpms +$(1)-version-rpms: + @$(foreach rpm,$($(1).rpms),printf $(RFORMAT) $(1) $(notdir $(rpm));) +version-rpms: $(1)-version-rpms +endef + +$(foreach package,$(sort $(ALL)), $(eval $(call print_rpms,$(package)))) + #################### include install Makefile # the default is to use the distro-dependent install file # however the main distro file can redefine PLDISTROINSTALL diff --git a/build.common b/build.common index 6c5b199b..97193b26 100644 --- a/build.common +++ b/build.common @@ -125,7 +125,16 @@ function pl_process_fedora_options () { } ######################################## handling a root image -function pl_makedevs() { +function pl_root_rpm_macros () { + cat < $(pl_locateDistroFile ../build/ $OPTARG.mirrors))) + mirrors=(file://$OPTARG) + fi + ;; + r) + releasever=$OPTARG + ;; + a) + basearch=$OPTARG + ;; + g) + groups[${#groups[*]}]="$OPTARG" + ;; + p) + packages[${#packages[*]}]="$OPTARG" + ;; + x) + exclude[${#exclude[*]}]="$OPTARG" + ;; + f) + pkgsfile=$OPTARG + ;; + k) + exclude_kernel="exclude=kernel* ulogd iptables" + ;; + v) + verbose=1 + set -x + ;; + h|*) + mkfedora_usage + ;; + esac + done -shift $(($OPTIND - 1)) -if [ ! -d "$1" ] ; then - mkfedora_usage -fi + shift $(($OPTIND - 1)) + if [ ! -d "$1" ] ; then + mkfedora_usage + fi -vroot=$(cd $1 && pwd -P) + vroot=$(cd $1 && pwd -P) -if [ $UID -ne 0 ] ; then - echo "Error: You must run this script as root." - exit 1 -fi + if [ $UID -ne 0 ] ; then + echo "Error: You must run this script as root." + exit 1 + fi -function mkfedora_fetch () -{ - curl --fail --silent --max-time 60 "$1" -} + function mkfedora_fetch () + { + curl --fail --silent --max-time 60 "$1" + } -# hard to find two mirrors with a similar layout -# set list of attempted locations according to releasever -if [ $releasever -ge 7 ] ; then - attempts=" + # set list of attempted locations according to releasever + if [ $releasever -ge 7 ] ; then + attempts=" linux/releases/$releasever/Everything/$basearch/os $releasever/Everything/$basearch/os core/$releasever/Everything/$basearch/os linux/core/$releasever/$basearch/os " -else - attempts=" -linux/core/$releasever/$basearch/os -core/$releasever/$basearch/os -$releasever/$basearch/os -" -fi + else + attempts=" + linux/core/$releasever/$basearch/os + core/$releasever/$basearch/os + $releasever/$basearch/os + " + fi -echo "$0: candidate mirrors" -for mirror in "${mirrors[@]}" ; do - echo "* candidate mirror $mirror" -done -baseurl="" -for mirror in "${mirrors[@]}" ; do - for attempt in $attempts; do - attempturl=$mirror/$attempt - if mkfedora_fetch $attempturl/repodata/repomd.xml >/dev/null ; then - baseurl=$attempturl - break 2 - fi + echo "$0: candidate mirrors" + for mirror in "${mirrors[@]}" ; do + echo "* candidate mirror $mirror" done -done - -if [ -z "$baseurl" ] ; then - echo "Error: $releasever/$basearch/os/repodata/repomd.xml" - echo " could not be found in any of the following locations:" - echo - for mirror in ${mirrors[@]} ; do - for attempt in $attempts ; do - echo $mirror/$attempt + baseurl="" + for mirror in "${mirrors[@]}" ; do + for attempt in $attempts; do + attempturl=$mirror/$attempt + if mkfedora_fetch $attempturl/repodata/repomd.xml >/dev/null ; then + baseurl=$attempturl + break 2 + fi done done - echo - mkfedora_usage -fi -# this used to be for when mkfedora was called within myplc -# that is, when the bootcd was recomputed from scratch -### exec 3>&1 -### exec 4>&2 -### if [ $verbose -eq 0 ] ; then -### exec 1>/dev/null -### exec 2>/dev/null -### fi - -# Do not tolerate errors -set -e - -## make rpms ignore installing stuff to special fs entries like /proc -# Because of https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=52725 -# you have to use at least one language beside 'C' -# Prevent all locales from being installed in reference image -mkdir -p $vroot/etc/rpm -cat > $vroot/etc/rpm/macros <$vroot/etc/fstab < $vroot/etc/rpm/macros + + # Trick rpm and yum, who read the real root /etc/rpm/macros file + # rather than the one installed in the reference image, despite what + # you might expect the --root and --installroot options to mean. Both + # programs always read $HOME/.rpmmacros. + export HOME=$vroot/tmp + mkdir -p $vroot/tmp + pl_root_rpm_macros > $vroot/tmp/.rpmmacros + + function mkfedora_cleanup () { + umount -l $vroot/proc + umount -l $vroot/dev/shm + umount -l $vroot/dev/pts + } + + # Clean up before exiting if anything goes wrong + trap "mkfedora_cleanup" ERR INT + + # Mount in reference image + mount -t devpts none $vroot/dev/pts + mount -t tmpfs none $vroot/dev/shm + mkdir -p $vroot/proc + mount -t proc none $vroot/proc + + # Create a /var/lib dirs for yum & rpm + mkdir -p $vroot/var/lib/yum + mkdir -p $vroot/var/lib/rpm + mkdir -p $vroot/usr/share/info + + # Create a dummy /etc/fstab in reference image + mkdir -p $vroot/etc + cat >$vroot/etc/fstab < $vroot/etc/sysconfig/network + # Necessary for some scripts + mkdir -p $vroot/etc/sysconfig + echo "NETWORKING=yes" > $vroot/etc/sysconfig/network -# Initialize RPM database in reference image -mkdir -p $vroot/var/lib/rpm -rpm --root $vroot --initdb -rpm --root $vroot --import $baseurl/RPM-GPG-KEY-fedora + # Initialize RPM database in reference image + mkdir -p $vroot/var/lib/rpm + rpm --root $vroot --initdb + rpm --root $vroot --import $baseurl/RPM-GPG-KEY-fedora -# Initialize yum in reference image -mkdir -p $vroot/var/cache/yum $vroot/var/log -if [ $releasever -lt 7 ] ; then + # Initialize yum in reference image + mkdir -p $vroot/var/cache/yum $vroot/var/log + if [ $releasever -lt 7 ] ; then corename="Core " -else + else corename="" -fi + fi -cat >$vroot/etc/yum.conf <$vroot/etc/yum.conf <>$vroot/etc/yum.conf <>$vroot/etc/yum.conf <>$vroot/etc/yum.conf <>$vroot/etc/yum.conf </dev/null ; then - echo "* Warning: Missing packages" - rpm --root $vroot -q "${packages[@]}" | grep "not installed" - fi -fi - -if [ ${#groups[*]} -gt 0 ] ; then - ## call yum sequentially to get finer-grained info on dependencies - for grp in "${groups[@]}" ; do - echo "* Installing optional group $grp" - yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \ - groupinstall "$grp" - done -fi + # pkgs file + if [ -n "$pkgsfile" ] ; then + # parse pkgsfile and add to local vars + fcdistro=$(pl_getReleaseName "Fedora" $releasever) + for i in $(pl_parsePkgs package $fcdistro $pkgsfile) ; do + packages[${#packages[*]}]="$i" + done + for i in $(pl_parsePkgs group $fcdistro $pkgsfile) ; do + groups[${#groups[*]}]="$i" + done + for i in $(pl_parsePkgs exclude $fcdistro $pkgsfile) ; do + exclude[${#exclude[*]}]="$i" + done + junk=$(pl_parsePkgs junk $fcdistro $pkgsfile) + precious=$(pl_parsePkgs precious $fcdistro $pkgsfile) + fi -# FC2 dev %preinstall checks /proc/mounts to make sure that /dev is -# not currently mounted as devfs. If it thinks it is, it will refuse -# to install the package. On a modern system running udev that mounts -# /dev as tmpfs, this check fails. Since we are installing into a -# chroot, whether /dev is mounted on the host system or not doesn't -# matter. If dev was explicitly mentioned in the packages list, force -# its installation. -if [ "$releasever" = "2" ] ; then - for package in "${packages[@]}" ; do - if [ "$package" = "dev" ] && ! rpm --root $vroot -q dev >/dev/null 2>&1 ; then - rpm --root $vroot -Uvh --noscripts $baseurl/Fedora/RPMS/dev-3.3.13-1.i386.rpm - break - fi + excludes= + for package in "${exclude[@]}" ; do + excludes="$excludes --exclude=$package" done -fi - -# Clean yum cache -echo "* Cleaning up" -yum -c $vroot/etc/yum.conf --installroot=$vroot -y clean all - -# Clean RPM state -rm -f $vroot/var/lib/rpm/__db* - -# Set time zone to UTC -if [ -f $vroot/usr/share/zoneinfo/UTC -a -f $vroot/etc/localtime ] ; then - rm -f $vroot/etc/localtime - ln -s /usr/share/zoneinfo/UTC $vroot/etc/localtime -fi - -# formerly in bootcd/prep.sh : to optimize footprint -echo "* Removing unnecessary junk" -pushd $vroot - -# Save precious files -[ -n "$precious" ] && tar --ignore-failed-read -cpf precious.tar $precious - -# Remove unnecessary junk -[ -n "$junk" ] && rm -rf $junk - -# Restore precious files -[ -n "$precious" ] && tar -xpf precious.tar && rm -f precious.tar - -popd - -# remove trap handler, as we are about to call it directly. -trap - ERR INT + # glibc must be specified explicitly for the correct arch to be + # chosen. + echo "* Installing glibc" + yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes install glibc + + # Go, baby, go + if [ ${#packages[*]} -gt 0 ] ; then + echo "* Installing optional packages" "${packages[@]}" + yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \ + install "${packages[@]}" + if ! rpm --root $vroot -q "${packages[@]}" >/dev/null ; then + echo "* Warning: Missing packages" + rpm --root $vroot -q "${packages[@]}" | grep "not installed" + fi + fi -# Clean up -mkfedora_cleanup + if [ ${#groups[*]} -gt 0 ] ; then + ## call yum sequentially to get finer-grained info on dependencies + for grp in "${groups[@]}" ; do + echo "* Installing optional group $grp" + yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \ + groupinstall "$grp" + done + fi -return 0 -} + # formerly in bootcd/prep.sh : to optimize footprint + echo "* Removing unnecessary junk" + + pushd $vroot + + # Save precious files + [ -n "$precious" ] && tar --ignore-failed-read -cpf precious.tar $precious + + # Remove unnecessary junk + [ -n "$junk" ] && rm -rf $junk + + # Restore precious files + [ -n "$precious" ] && tar -xpf precious.tar && rm -f precious.tar + + popd + +### # FC2 dev %preinstall checks /proc/mounts to make sure that /dev is +### # not currently mounted as devfs. If it thinks it is, it will refuse +### # to install the package. On a modern system running udev that mounts +### # /dev as tmpfs, this check fails. Since we are installing into a +### # chroot, whether /dev is mounted on the host system or not doesn't +### # matter. If dev was explicitly mentioned in the packages list, force +### # its installation. +### if [ "$releasever" = "2" ] ; then +### for package in "${packages[@]}" ; do +### if [ "$package" = "dev" ] && ! rpm --root $vroot -q dev >/dev/null 2>&1 ; then +### rpm --root $vroot -Uvh --noscripts $baseurl/Fedora/RPMS/dev-3.3.13-1.i386.rpm +### break +### fi +### done +### fi + + # Clean yum cache + echo "* Cleaning up" + yum -c $vroot/etc/yum.conf --installroot=$vroot -y clean all + + # Clean RPM state + rm -f $vroot/var/lib/rpm/__db* + + # Set time zone to UTC + if [ -f $vroot/usr/share/zoneinfo/UTC -a -f $vroot/etc/localtime ] ; then + rm -f $vroot/etc/localtime + ln -s /usr/share/zoneinfo/UTC $vroot/etc/localtime + fi -function pl_mkfedora() { - root=$1 - shift - options=$@ + # remove trap handler, as we are about to call it directly. + trap - ERR INT - pl_makedevs $root + # Clean up + mkfedora_cleanup - [ -n "$pl_DISTRO_URL" ] && options="$options -l $pl_DISTRO_URL" - [ -n "$pl_DISTRO_ARCH" ] && options="$options -a $pl_DISTRO_ARCH" - [ -n "$pl_DISTRO_RELEASE" ] && options="$options -r $pl_DISTRO_RELEASE" - # echo "mkfedora -v $options $root" - mkfedora -v $options $root + return 0 } -function pl_setup_chroot() { +function pl_root_setup_chroot() { root=$1; shift options="$@" - pl_mkfedora $root $options + pl_root_makedevs $root + pl_root_mkfedora $root $options # Disable all services in reference image chroot $root sh -c "/sbin/chkconfig --list | awk '{ print \$1 }' | xargs -i /sbin/chkconfig {} off" diff --git a/config.planetlab/bootstrapfs-production.pkgs b/config.planetlab/bootstrapfs-production.pkgs index 114d87bf..df0ed887 100644 --- a/config.planetlab/bootstrapfs-production.pkgs +++ b/config.planetlab/bootstrapfs-production.pkgs @@ -1,13 +1,13 @@ -# Install the "PlanetLab" group. This requires that the PlanetLab -# build system install the appropriate yumgroups.xml file (currently -# build/groups/v4_yumgroups.xml) in $RPM_BUILD_DIR/../RPMS/ and that -# mkfedora runs either yum-arch or createrepo on that directory. dev -# is specified explicitly because of a stupid bug in its %post script -# that causes its installation to fail; see the mkfedora script for a +# Install the "PlanetLab" group. This requires that the +# build system install the appropriate yumgroups.xml file +# -- currently build/groups/.xml -- +# /RPMS/ and that the build runs createrepo on that directory. +# dev is specified explicitly because of a stupid bug in its %post script +# that causes its installation to fail; see pl_root_mkfedora for a # full explanation. coreutils and python are specified explicitly # because groupinstall does not honor Requires(pre) dependencies # properly, most %pre scripts require coreutils to be installed first, # and some of our %post scripts require python. -package: python -group: PlanetLab \ No newline at end of file +package: python dev coreutils +group: PlanetLab diff --git a/getrpmmacros.sh b/getrpmmacros.sh new file mode 100755 index 00000000..e5f0fa73 --- /dev/null +++ b/getrpmmacros.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +. build.common + +pl_root_rpm_macros -- 2.47.0