Search
SailfishOS Open Build Service
>
Projects
>
home:plfiorini
:
maui:devel
:
x86_64
>
build
> _service:tar_git:0001-Add-support-for-using-Scratchbox2-together-with-OBS-.patch
Log In
Username
Password
Cancel
Overview
Repositories
Revisions
Requests
Users
Advanced
Attributes
Meta
File _service:tar_git:0001-Add-support-for-using-Scratchbox2-together-with-OBS-.patch of Package build
From 8ea7eda705ac081525652448f9868d2919fbb85e Mon Sep 17 00:00:00 2001 From: Carsten Munk <carsten.munk@gmail.com> Date: Thu, 9 Feb 2012 13:37:25 +0100 Subject: [PATCH] Add support for using Scratchbox2 together with OBS as an alternative cross compile approach Signed-off-by: Carsten Munk <carsten.munk@gmail.com> --- Build.pm | 15 ++- Makefile | 2 + build | 224 ++++++++++++++++++++-------------- common_functions | 154 +++++++++++++++++++++++ expanddeps | 1 + getsb2flags | 41 +++++++ init_buildsystem | 355 ++++++++++++++++++++++++++++++------------------------ initscript_sb2 | 22 ++++ 8 files changed, 565 insertions(+), 249 deletions(-) create mode 100644 getsb2flags create mode 100644 initscript_sb2 diff --git a/Build.pm b/Build.pm index 8c35ac6..dd8582e 100644 --- a/Build.pm +++ b/Build.pm @@ -180,6 +180,7 @@ sub read_config { $config->{'vminstall'} = []; $config->{'cbpreinstall'} = []; $config->{'cbinstall'} = []; + $config->{'sb2install'} = []; $config->{'runscripts'} = []; $config->{'required'} = []; $config->{'support'} = []; @@ -190,6 +191,7 @@ sub read_config { $config->{'substitute'} = {}; $config->{'substitute_vers'} = {}; $config->{'optflags'} = {}; + $config->{'sb2flags'} = {}; $config->{'order'} = {}; $config->{'exportfilter'} = {}; $config->{'publishfilter'} = []; @@ -214,7 +216,7 @@ sub read_config { } next; } - if ($l0 eq 'preinstall:' || $l0 eq 'vminstall:' || $l0 eq 'cbpreinstall:' || $l0 eq 'cbinstall:' || $l0 eq 'required:' || $l0 eq 'support:' || $l0 eq 'keep:' || $l0 eq 'prefer:' || $l0 eq 'ignore:' || $l0 eq 'conflict:' || $l0 eq 'runscripts:') { + if ($l0 eq 'preinstall:' || $l0 eq 'vminstall:' || $l0 eq 'cbpreinstall:' || $l0 eq 'cbinstall:' || $l0 eq 'sb2install:' || $l0 eq 'required:' || $l0 eq 'support:' || $l0 eq 'keep:' || $l0 eq 'prefer:' || $l0 eq 'ignore:' || $l0 eq 'conflict:' || $l0 eq 'runscripts:') { my $t = substr($l0, 0, -1); for my $l (@l) { if ($l eq '!*') { @@ -255,6 +257,10 @@ sub read_config { next unless @l; $ll = shift @l; $config->{'optflags'}->{$ll} = join(' ', @l); + } elsif ($l0 eq 'sb2flags:') { + next unless @l; + $ll = shift @l; + $config->{'sb2flags'}->{$ll} = join(' ', @l); } elsif ($l0 eq 'order:') { for my $l (@l) { if ($l eq '!*') { @@ -286,7 +292,7 @@ sub read_config { warn("unknown keyword in config: $l0\n"); } } - for my $l (qw{preinstall vminstall cbpreinstall cbinstall required support keep runscripts repotype patterntype}) { + for my $l (qw{preinstall vminstall cbpreinstall cbinstall sb2install required support keep runscripts repotype patterntype}) { $config->{$l} = [ unify(@{$config->{$l}}) ]; } for my $l (keys %{$config->{'substitute'}}) { @@ -431,6 +437,11 @@ sub get_cbinstalls { return @{$config->{'cbinstall'}}; } +sub get_sb2installs { + my ($config) = @_; + return @{$config->{'sb2install'}}; +} + sub get_runscripts { my ($config) = @_; return @{$config->{'runscripts'}}; diff --git a/Makefile b/Makefile index 4fc8021..862e04e 100644 --- a/Makefile +++ b/Makefile @@ -38,11 +38,13 @@ install: killchroot \ getmacros \ getoptflags \ + getsb2flags \ gettype \ getchangetarget \ common_functions \ init_buildsystem \ initscript_qemu_vm \ + initscript_sb2 \ substitutedeps \ debtransform \ debtransformbz2 \ diff --git a/build b/build index ad81c23..dbaa7eb 100755 --- a/build +++ b/build @@ -11,7 +11,7 @@ test -z "$BUILD_DIR" && BUILD_DIR=/usr/lib/build test -z "$BUILD_ROOT" && BUILD_ROOT=/var/tmp/build-root test -z "$CONFIG_DIR" && CONFIG_DIR="$BUILD_DIR/configs" -export BUILD_ARCH BUILD_HOST_ARCH BUILD_ROOT BUILD_RPMS BUILD_DIR BUILD_DEBUG +export BUILD_ARCH BUILD_HOST_ARCH BUILD_TARGET BUILD_ROOT BUILD_SB2FLAGS BUILD_RPMS BUILD_DIR BUILD_DEBUG VM_TYPE export BUILD_DIST ccache=0 @@ -317,6 +317,7 @@ cleanup_and_exit () { fi if test -n "$RUNNING_IN_VM" ; then test -n "$browner" && chown "$browner" $BUILD_ROOT + cleanup_sb2 cd / if test -n "$VM_SWAP" -a -e "$VM_SWAP" ; then swapoff "$VM_SWAP" 2>/dev/null @@ -324,7 +325,7 @@ cleanup_and_exit () { fi exec >&0 2>&0 # so that the logging tee finishes sleep 1 # wait till tee terminates - if test "$VM_TYPE" != lxc; then + if test "$VM_TYPE" != lxc -a "$VM_TYPE" != sb2; then kill -9 -1 # goodbye cruel world if ! test -x /sbin/halt ; then test -e /proc/sysrq-trigger || mount -n -tproc none /proc @@ -411,7 +412,7 @@ setupicecream() return fi - if ! chroot "$BUILD_ROOT" rpm -q icecream >/dev/null 2>/dev/null; then + if ! enter_target needroot rpm -q icecream >/dev/null 2>/dev/null; then echo "*** icecream package not installed ***" false return @@ -450,7 +451,7 @@ setupicecream() false return fi - chroot $BUILD_ROOT bash -c "cd /var/run/icecream; $createenv" || cleanup_and_exit 1 + enter_target needroot bash -c "cd /var/run/icecream; $createenv" || cleanup_and_exit 1 icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/var/run/icecream/*.tar.{bz2,gz}`) icecc_vers=${icecc_vers//$BUILD_ROOT/} else @@ -501,7 +502,7 @@ create_baselibs() if test -e $BUILD_ROOT$TOPDIR/SOURCES/baselibs.conf ; then BASELIBS_CFG="-c $TOPDIR/SOURCES/baselibs.conf" fi - if test -e $BUILD_ROOT/usr/lib/build/baselibs_global.conf; then + if test -e $BUILD_TARGET/usr/lib/build/baselibs_global.conf; then BASELIBS_GLOBAL="-c /usr/lib/build/baselibs_global.conf" fi pkgs=($RPMS) @@ -516,7 +517,7 @@ create_baselibs() # $BUILD_DIR is set to /.build when using a vm. So we need to # hardcode /usr/lib/build instead of $BUILD_DIR to prefer # mkbaselibs from the distro. - if test -f $BUILD_ROOT$mkbaselibs; then + if test -f $BUILD_TARGET$mkbaselibs; then if test -z "$BASELIBS_CFG" -a -e $BUILD_ROOT/usr/lib/build/baselibs.conf ; then BASELIBS_CFG="-c /usr/lib/build/baselibs.conf" fi @@ -528,28 +529,28 @@ create_baselibs() # use external version whichone=" (external)" mkbaselibs="/.mkbaselibs/mkbaselibs" - rm -rf $BUILD_ROOT/.mkbaselibs - mkdir -p $BUILD_ROOT/.mkbaselibs - cp -f $BUILD_DIR/mkbaselibs $BUILD_ROOT/.mkbaselibs/ + rm -rf $BUILD_TARGET/.mkbaselibs + mkdir -p $BUILD_TARGET/.mkbaselibs + cp -f $BUILD_DIR/mkbaselibs $BUILD_TARGET/.mkbaselibs/ if test "$BUILDTYPE" == "dsc" ; then - cp -f $BUILD_DIR/baselibs_global-deb.conf $BUILD_ROOT/.mkbaselibs/baselibs_g.conf - cp -f $BUILD_ROOT$TOPDIR/SOURCES/baselibs-deb.conf $BUILD_ROOT/.mkbaselibs/baselibs-deb.conf + cp -f $BUILD_DIR/baselibs_global-deb.conf $BUILD_TARGET/.mkbaselibs/baselibs_g.conf + cp -f $BUILD_ROOT$TOPDIR/SOURCES/baselibs-deb.conf $BUILD_TARGET/.mkbaselibs/baselibs-deb.conf BASELIBS_CFG="-c /.mkbaselibs/baselibs-deb.conf" else - cp -f $BUILD_DIR/baselibs_global.conf $BUILD_ROOT/.mkbaselibs/baselibs_g.conf + cp -f $BUILD_DIR/baselibs_global.conf $BUILD_TARGET/.mkbaselibs/baselibs_g.conf if test -z "$BASELIBS_CFG" -a -e $BUILD_DIR/baselibs.conf; then - cp -f $BUILD_DIR/baselibs.conf $BUILD_ROOT/.mkbaselibs/baselibs.conf + cp -f $BUILD_DIR/baselibs.conf $BUILD_TARGET/.mkbaselibs/baselibs.conf BASELIBS_CFG="-c /.mkbaselibs/baselibs.conf" fi fi - if test -e $BUILD_ROOT/.mkbaselibs/baselibs_g.conf; then + if test -e $BUILD_TARGET/.mkbaselibs/baselibs_g.conf; then BASELIBS_GLOBAL="-c /.mkbaselibs/baselibs_g.conf" fi fi echo "... creating baselibs$whichone" while read line do - chroot $BUILD_ROOT su -c "$mkbaselibs $BASELIBS_GLOBAL $BASELIBS_CFG $line" - $BUILD_USER || cleanup_and_exit 1 + enter_target needuser $mkbaselibs $BASELIBS_GLOBAL $BASELIBS_CFG $line || cleanup_and_exit 1 done < <(IFS=$'\n'; echo "${pkgs[*]#$BUILD_ROOT}" | xargs -n 1024) rm -rf $BUILD_ROOT/.mkbaselibs } @@ -561,11 +562,11 @@ copy_oldpackages() local dest [ -z "$RUNNING_IN_VM" ] || return 0 if [ -z "$old_packages" ]; then - rm -rf "$BUILD_ROOT"/.build.oldpackages* + rm -rf "$BUILD_TARGET"/.build.oldpackages* return 0 fi for d in "${old_packages[@]}"; do - dest="$BUILD_ROOT/.build.oldpackages" + dest="$BUILD_TARGET/.build.oldpackages" test "$i" = 0 || dest="$dest$i" if [ -d "$d" -a "$d" != "$dest" ] ; then rm -rf "$dest" @@ -624,7 +625,7 @@ detect_vm_2nd_stage() fi RUNNING_IN_VM=true mount -orw -n -tproc none /proc - if test "$VM_TYPE" != 'lxc'; then + if test "$VM_TYPE" != 'lxc' -a "$VM_TYPE" != 'sb2'; then mount -n ${VMDISK_MOUNT_OPTIONS},remount,rw / fi # qemu inside of xen does not work, check again with kvm later before enabling this @@ -1102,7 +1103,16 @@ done check_for_ppc -if test "$VM_TYPE" = "lxc"; then +set_build_arch + +BUILD_SB2FLAGS=`getsb2flags --dist "$BUILD_DIST" --configdir "$BUILD_DIR/configs" --archpath "$BUILD_ARCH"` + +if [ -n "$BUILD_SB2FLAGS" -a -z "$VM_TYPE" ]; then + echo "Cannot do SB2 with chroot, switching to vm type sb2" + VM_TYPE="sb2" +fi + +if test "$VM_TYPE" = "lxc" -o "$VM_TYPE" = "sb2"; then VM_IMAGE='' VM_SWAP='' fi @@ -1122,7 +1132,9 @@ if test -n "$KILL" ; then echo -n "BUILDSTATUS1" >"$VM_SWAP" fi (set -C; > "$BUILD_ROOT/exit" 2>/dev/null || true) - if test "$VM_TYPE" = 'lxc'; then + if test "$VM_TYPE" = 'sb2'; then + echo "Would kill SB2.." + elif test "$VM_TYPE" = 'lxc'; then LXCID=${BUILD_ROOT##*/} lxc-stop -n "$LXCID" || true lxc-destroy -n "$LXCID" @@ -1253,7 +1265,18 @@ else repos=() fi -set_build_arch + +BUILD_TARGET=$BUILD_ROOT + +if [ -n "$BUILD_SB2FLAGS" ]; then + echo "Will build with SB2, flags: $BUILD_SB2FLAGS" + echo "Switching BUILD_TARGET to $BUILD_ROOT/target" + if test -z "$RUNNING_IN_VM"; then + BUILD_TARGET=$BUILD_ROOT/target + else + BUILD_TARGET=/target + fi +fi if [ -n "$CLEAN_BUILD" ]; then DO_INIT=true @@ -1348,6 +1371,9 @@ fi mkdir_build_root +if [ "x$BUILD_ROOT" != "x$BUILD_TARGET" ]; then + mkdir -p $BUILD_TARGET +fi if [ "$BUILD_ROOT" = / ]; then read dummy dummy browner dummy < <(ls -ld /) fi @@ -1385,6 +1411,7 @@ test -z "$HOST" && HOST=`hostname` if [ -z "$RUNNING_IN_VM" ]; then echo Using BUILD_ROOT=$BUILD_ROOT + echo Using BUILD_TARGET=$BUILD_TARGET test -n "$BUILD_RPMS" && echo Using BUILD_RPMS=$BUILD_RPMS echo Using BUILD_ARCH=$BUILD_ARCH test -n "$VM_TYPE" && echo "Doing $VM_TYPE build${VM_IMAGE:+ in $VM_IMAGE}" @@ -1514,6 +1541,7 @@ for SPECFILE in "${SPECFILES[@]}" ; do # umount later so step aside cd "$SRCDIR" fi + Q="'\''" echo "SPECFILE='${SPECFILE//"'"/$Q}'" > $BUILD_ROOT/.build/build.data echo "BUILD_JOBS='${BUILD_JOBS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data @@ -1543,7 +1571,7 @@ for SPECFILE in "${SPECFILES[@]}" ; do test -n "$VM_SWAP" && echo "VM_SWAP='${VM_SWAPDEV:-/dev/hda2}'" >> $BUILD_ROOT/.build/build.data test -n "$VMDISK_MOUNT_OPTIONS" && echo "VMDISK_MOUNT_OPTIONS='${VMDISK_MOUNT_OPTIONS}'" >> $BUILD_ROOT/.build/build.data PERSONALITY=0 - if test "$VM_TYPE" != 'lxc'; then + if test "$VM_TYPE" != 'lxc' -a "$VM_TYPE" != 'sb2'; then test -n "$PERSONALITY_SYSCALL" && PERSONALITY=`perl -e 'print syscall('$PERSONALITY_SYSCALL', 0)."\n"'` fi if test "$(uname -m)" = 'ppc'; then @@ -1570,9 +1598,10 @@ for SPECFILE in "${SPECFILES[@]}" ; do # needs to work otherwise we have a corrupted file system umount $BUILD_ROOT || cleanup_and_exit 1 fi - if check_use_emulator; then - if [ -x "$BUILD_DIR/initvm" -a -e "$BUILD_DIR/qemu-reg" ]; then + if [ -n "$BUILD_SB2FLAGS" -a -e "$BUILD_DIR/initscript_sb2" ]; then + vm_init_script="/.build/initscript_sb2" + elif [ -x "$BUILD_DIR/initvm" -a -e "$BUILD_DIR/qemu-reg" ]; then vm_init_script="/.build/initvm" elif [ -e $BUILD_DIR/initscript_qemu_vm ]; then vm_init_script="/.build/initscript_qemu_vm" @@ -1683,6 +1712,14 @@ for SPECFILE in "${SPECFILES[@]}" ; do fi echo "$@" "$@" + elif [ "$VM_TYPE" = 'sb2' ]; then + echo "starting sb2 part inside chroot.." + echo "rootfs / rootfs rw 0 0" > $BUILD_ROOT/etc/mtab + touch $BUILD_ROOT/.sb2chroot + chroot $BUILD_ROOT "$vm_init_script" + BUILDSTATUS="$?" + test "$BUILDSTATUS" != 255 || BUILDSTATUS=3 + cleanup_and_exit "$BUILDSTATUS" elif [ "$VM_TYPE" = 'lxc' ]; then echo "booting $VM_TYPE ..." LXCCONF="$BUILD_ROOT/.build.lxc.conf" @@ -1808,8 +1845,8 @@ for SPECFILE in "${SPECFILES[@]}" ; do # check if we want to build with the abuild user # BUILD_USER=abuild - if test -x $BUILD_ROOT/bin/rpm ; then - SUSE_VERSION=`chroot $BUILD_ROOT /bin/rpm --eval '%{?suse_version}' 2>/dev/null` + if test -x $BUILD_TARGET/bin/rpm ; then + SUSE_VERSION=`enter_target needroot /bin/rpm --eval '%{?suse_version}' 2>/dev/null` if test -n "$SUSE_VERSION" && test "$SUSE_VERSION" -le 1020 ; then BUILD_USER=root fi @@ -1822,54 +1859,54 @@ for SPECFILE in "${SPECFILES[@]}" ; do test -n "$NOROOTFORBUILD" && BUILD_USER=abuild if test $BUILD_USER = abuild ; then - if ! egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then - echo "abuild:x:${ABUILD_UID}:${ABUILD_GID}:Autobuild:/home/abuild:/bin/bash" >>$BUILD_ROOT/etc/passwd - echo 'abuild:*:::::::' >>$BUILD_ROOT/etc/shadow # This is needed on Mandriva 2009 - echo 'abuild:*::' >>$BUILD_ROOT/etc/gshadow # This is needed on Ubuntu - echo "abuild:x:${ABUILD_GID}:" >>$BUILD_ROOT/etc/group + if ! egrep '^abuild:' >/dev/null <$BUILD_TARGET/etc/passwd ; then + echo "abuild:x:${ABUILD_UID}:${ABUILD_GID}:Autobuild:/home/abuild:/bin/bash" >>$BUILD_TARGET/etc/passwd + echo 'abuild:*:::::::' >>$BUILD_TARGET/etc/shadow # This is needed on Mandriva 2009 + echo 'abuild:*::' >>$BUILD_TARGET/etc/gshadow # This is needed on Ubuntu + echo "abuild:x:${ABUILD_GID}:" >>$BUILD_TARGET/etc/group mkdir -p $BUILD_ROOT/home/abuild chown "$ABUILD_UID:$ABUILD_GID" $BUILD_ROOT/home/abuild else - if ! egrep "^abuild:x?:${ABUILD_UID}:${ABUILD_GID}" >/dev/null <$BUILD_ROOT/etc/passwd ; then - echo "abuild user present in the buildroot ($BUILD_ROOT) but uid:gid does not match" + if ! egrep "^abuild:x?:${ABUILD_UID}:${ABUILD_GID}" >/dev/null <$BUILD_TARGET/etc/passwd ; then + echo "abuild user present in the build target ($BUILD_TARGET) but uid:gid does not match" echo "buildroot currently using:" - egrep "^abuild:" <$BUILD_ROOT/etc/passwd + egrep "^abuild:" <$BUILD_TARGET/etc/passwd echo "build script attempting to use:" echo "abuild::${ABUILD_UID}:${ABUILD_GID}:..." echo "build aborting" cleanup_and_exit 1 fi fi - if test -f $BUILD_ROOT/etc/shadow ; then - sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/shadow > $BUILD_ROOT/etc/shadow.t && mv $BUILD_ROOT/etc/shadow.t $BUILD_ROOT/etc/shadow + if test -f $BUILD_TARGET/etc/shadow ; then + sed -e "s@^root::@root:*:@" < $BUILD_TARGET/etc/shadow > $BUILD_TARGET/etc/shadow.t && mv $BUILD_TARGET/etc/shadow.t $BUILD_TARGET/etc/shadow fi - if test -f $BUILD_ROOT/etc/gshadow ; then - sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/gshadow > $BUILD_ROOT/etc/gshadow.t && mv $BUILD_ROOT/etc/gshadow.t $BUILD_ROOT/etc/gshadow + if test -f $BUILD_TARGET/etc/gshadow ; then + sed -e "s@^root::@root:*:@" < $BUILD_TARGET/etc/gshadow > $BUILD_TARGET/etc/gshadow.t && mv $BUILD_TARGET/etc/gshadow.t $BUILD_TARGET/etc/gshadow fi BUILD_USER_ABUILD_USED=true else # building as root ABUILD_UID=0 ABUILD_GID=0 - if egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then + if egrep '^abuild:' >/dev/null <$BUILD_TARGET/etc/passwd ; then rm -rf $BUILD_ROOT/home/abuild - egrep -v '^abuild:' <$BUILD_ROOT/etc/passwd >$BUILD_ROOT/etc/passwd.new - mv $BUILD_ROOT/etc/passwd.new $BUILD_ROOT/etc/passwd - egrep -v '^abuild:' <$BUILD_ROOT/etc/group >$BUILD_ROOT/etc/group.new - mv $BUILD_ROOT/etc/group.new $BUILD_ROOT/etc/group - if test -f $BUILD_ROOT/etc/shadow ; then - egrep -v '^abuild:' <$BUILD_ROOT/etc/shadow >$BUILD_ROOT/etc/shadow.new - mv $BUILD_ROOT/etc/shadow.new $BUILD_ROOT/etc/shadow + egrep -v '^abuild:' <$BUILD_TARGET/etc/passwd >$BUILD_TARGET/etc/passwd.new + mv $BUILD_TARGET/etc/passwd.new $BUILD_TARGET/etc/passwd + egrep -v '^abuild:' <$BUILD_TARGET/etc/group >$BUILD_TARGET/etc/group.new + mv $BUILD_TARGET/etc/group.new $BUILD_TARGET/etc/group + if test -f $BUILD_TARGET/etc/shadow ; then + egrep -v '^abuild:' <$BUILD_TARGET/etc/shadow >$BUILD_TARGET/etc/shadow.new + mv $BUILD_TARGET/etc/shadow.new $BUILD_TARGET/etc/shadow fi - if test -f $BUILD_ROOT/etc/gshadow ; then - egrep -v '^abuild:' <$BUILD_ROOT/etc/gshadow >$BUILD_ROOT/etc/gshadow.new - mv $BUILD_ROOT/etc/gshadow.new $BUILD_ROOT/etc/gshadow + if test -f $BUILD_TARGET/etc/gshadow ; then + egrep -v '^abuild:' <$BUILD_TARGET/etc/gshadow >$BUILD_TARGET/etc/gshadow.new + mv $BUILD_TARGET/etc/gshadow.new $BUILD_TARGET/etc/gshadow fi fi fi if test "$BUILDTYPE" = spec ; then - TOPDIR=`chroot $BUILD_ROOT su -c "rpm --eval '%_topdir'" - $BUILD_USER` + TOPDIR=`enter_target needuser rpm --eval '%_topdir'` if test -z "$TOPDIR"; then echo "Error: TOPDIR empty" cleanup_and_exit 1 @@ -1940,9 +1977,9 @@ for SPECFILE in "${SPECFILES[@]}" ; do if test -n "$RELEASE"; then args=(--release "$RELEASE") fi - substitutedeps "${args[@]}" --root "$BUILD_ROOT" --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$CONFIG_DIR" $CHANGELOGARGS "$BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE" "$BUILD_ROOT/.spec.new" || cleanup_and_exit 1 + substitutedeps "${args[@]}" --root "$BUILD_ROOT" --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$CONFIG_DIR" $CHANGELOGARGS "$BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE" "$BUILD_TARGET/.spec.new" || cleanup_and_exit 1 # extract macros from configuration - getmacros --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$CONFIG_DIR" > $BUILD_ROOT/root/.rpmmacros + getmacros --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$CONFIG_DIR" > $BUILD_TARGET/root/.rpmmacros if test -n "$BUILD_DEBUG" ; then echo ' %prep %{?!_suse_insert_debug_package_seen:%?_suse_insert_debug_package}%%prep @@ -1952,35 +1989,35 @@ for SPECFILE in "${SPECFILES[@]}" ; do %%global _suse_insert_debug_package_seen 1 \\\ %%debug_package -' >> $BUILD_ROOT/root/.rpmmacros +' >> $BUILD_TARGET/root/.rpmmacros fi if [ -n "$BUILD_JOBS" ]; then - cat >> $BUILD_ROOT/root/.rpmmacros <<-EOF + cat >> $BUILD_TARGET/root/.rpmmacros <<-EOF %jobs $BUILD_JOBS %_smp_mflags -j$BUILD_JOBS EOF fi - test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmmacros $BUILD_ROOT/home/abuild/.rpmmacros + test $BUILD_USER = abuild && cp -p $BUILD_TARGET/root/.rpmmacros $BUILD_ROOT/home/abuild/.rpmmacros # extract optflags from configuration - getoptflags --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" ${BUILD_DEBUG:+--debug} > $BUILD_ROOT/root/.rpmrc - test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmrc $BUILD_ROOT/home/abuild/.rpmrc + getoptflags --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" ${BUILD_DEBUG:+--debug} > $BUILD_TARGET/root/.rpmrc + test $BUILD_USER = abuild && cp -p $BUILD_TARGET/root/.rpmrc $BUILD_ROOT/home/abuild/.rpmrc if test -z "$ABUILD_TARGET"; then ABUILD_TARGET=$(getchangetarget --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" ) test -z "$ABUILD_TARGET" || echo "build target is $ABUILD_TARGET" fi fi - if test -f $BUILD_ROOT/.spec.new ; then - if ! cmp -s $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT/.spec.new ; then + if test -f $BUILD_TARGET/.spec.new ; then + if ! cmp -s $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_TARGET/.spec.new ; then echo ----------------------------------------------------------------- echo I have the following modifications for $SPECFILE: - sed -e "/^%changelog/q" $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE > $BUILD_ROOT/.spec.t1 - sed -e "/^%changelog/q" $BUILD_ROOT/.spec.new > $BUILD_ROOT/.spec.t2 - diff $BUILD_ROOT/.spec.t1 $BUILD_ROOT/.spec.t2 - rm -f $BUILD_ROOT/.spec.t1 $BUILD_ROOT/.spec.t2 - mv $BUILD_ROOT/.spec.new $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE + sed -e "/^%changelog/q" $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE > $BUILD_TARGET/.spec.t1 + sed -e "/^%changelog/q" $BUILD_TARGET/.spec.new > $BUILD_TARGET/.spec.t2 + diff $BUILD_TARGET/.spec.t1 $BUILD_TARGET/.spec.t2 + rm -f $BUILD_TARGET/.spec.t1 $BUILD_TARGET/.spec.t2 + mv $BUILD_TARGET/.spec.new $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE else - rm -f $BUILD_ROOT/.spec.new + rm -f $BUILD_TARGET/.spec.new fi fi @@ -2004,7 +2041,7 @@ for SPECFILE in "${SPECFILES[@]}" ; do for DEB_DSCFILE in $BUILD_ROOT/$DEB_SOURCEDIR/*.dsc ; do : ; done DEB_DSCFILE="${DEB_DSCFILE##*/}" fi - chroot $BUILD_ROOT su -c "dpkg-source -x $DEB_SOURCEDIR/$DEB_DSCFILE $TOPDIR/BUILD" - $BUILD_USER + enter_target needuser dpkg-source -x $DEB_SOURCEDIR/$DEB_DSCFILE $TOPDIR/BUILD fi if test "$BUILDTYPE" = arch ; then @@ -2024,7 +2061,7 @@ for SPECFILE in "${SPECFILES[@]}" ; do fi echo ----------------------------------------------------------------- echo ----------------------------------------------------------------- - if [ -n "$RUNNING_IN_VM" ]; then + if [ -n "$RUNNING_IN_VM" -a "$VM_TYPE" != "sb2" ]; then if [ -x /sbin/ip ]; then ip addr add 127.0.0.1/8 dev lo ip link set lo up @@ -2041,8 +2078,8 @@ for SPECFILE in "${SPECFILES[@]}" ; do if test -n "$OVERLAY" ; then if test -d "$OVERLAY"; then pushd $OVERLAY - echo "Copying overlay to BUILD_ROOT" - tar -cpf - . | (cd $BUILD_ROOT ; tar -xvf -) + echo "Copying overlay to BUILD_TARGET" + tar -cpf - . | (cd $BUILD_TARGET ; tar -xvf -) popd else echo "OVERLAY ($OVERLAY) is no directory - skipping" @@ -2052,13 +2089,13 @@ for SPECFILE in "${SPECFILES[@]}" ; do if test -n "$RSYNCSRC" ; then if test -n "$RSYNCDEST"; then if test -d "$RSYNCSRC"; then - if ! test -d "$BUILD_ROOT/$RSYNCDEST"; then - echo "ATTENTION! Creating target directory ($BUILD_ROOT/$RSYNCDEST) as its not there." - mkdir -p $BUILD_ROOT/$RSYNCDEST + if ! test -d "$BUILD_TARGET/$RSYNCDEST"; then + echo "ATTENTION! Creating target directory ($BUILD_TARGET/$RSYNCDEST) as its not there." + mkdir -p $BUILD_TARGET/$RSYNCDEST fi echo "Running rsync ..." - rsync -av $RSYNCSRC/* $BUILD_ROOT/$RSYNCDEST/ - chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT/$RSYNCDEST" + rsync -av $RSYNCSRC/* $BUILD_TARGET/$RSYNCDEST/ + chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_TARGET/$RSYNCDEST" RSYNCDONE=true echo "... done" else @@ -2088,7 +2125,7 @@ for SPECFILE in "${SPECFILES[@]}" ; do rpmbopts[${#rpmbopts[@]}]='--define' rpmbopts[${#rpmbopts[@]}]="disturl $DISTURL" fi - if test -s "$BUILD_ROOT/usr/lib/rpm/mandriva/macros" ; then + if test -s "$BUILD_TARGET/usr/lib/rpm/mandriva/macros" ; then rpmbopts[${#rpmbopts[@]}]='--eval' rpmbopts[${#rpmbopts[@]}]="%undefine _enable_debug_packages" fi @@ -2101,19 +2138,22 @@ for SPECFILE in "${SPECFILES[@]}" ; do rpmbopts[${#rpmbopts[@]}]="RSYNCDONE 1" fi + rpmbuild=rpmbuild + + test -x $BUILD_TARGET/usr/bin/rpmbuild || rpmbuild=rpm # su involves a shell which would require even more # complicated quoting to bypass than this toshellscript $rpmbuild \ "${definesnstuff[@]}" \ "${rpmbopts[@]}" \ "$TOPDIR/SOURCES/$SPECFILE" \ - > $BUILD_ROOT/.build.command - chmod 755 $BUILD_ROOT/.build.command + > $BUILD_TARGET/.build.command + chmod 755 $BUILD_TARGET/.build.command check_exit if test -n "$shell"; then - chroot $BUILD_ROOT su - + enter_target needroot bash else - chroot $BUILD_ROOT su -c /.build.command - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true + enter_target needuser /.build.command < /dev/null && BUILD_SUCCEEDED=true fi fi @@ -2133,9 +2173,9 @@ for SPECFILE in "${SPECFILES[@]}" ; do fi if test -n "$shell"; then - chroot $BUILD_ROOT su - + enter_target needroot bash else - chroot $BUILD_ROOT su -c "cd $TOPDIR/BUILD && $DSC_BUILD_CMD" - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true + enter_target needuser "cd $TOPDIR/BUILD && $DSC_BUILD_CMD" < /dev/null && BUILD_SUCCEEDED=true fi mkdir -p $BUILD_ROOT/$TOPDIR/DEBS @@ -2184,13 +2224,13 @@ if test -n "$RPMS" -a -n "$BUILD_USER_ABUILD_USED" ; then fi fi -if test -n "$RPMS" -a -d "$BUILD_ROOT/usr/lib/build/checks" ; then +if test -n "$RPMS" -a -d "$BUILD_TARGET/usr/lib/build/checks" ; then export PNAME="" export DO_RPM_REMOVE=true for SRPM in $BUILD_ROOT/$TOPDIR/SRPMS/*src.rpm ; do test -f "$SRPM" && PNAME=`rpm --nodigest --nosignature -qp --qf "%{NAME}" $SRPM` done - for CHECKSCRIPT in $BUILD_ROOT/usr/lib/build/checks/* ; do + for CHECKSCRIPT in $BUILD_TARGET/usr/lib/build/checks/* ; do echo "... running `basename $CHECKSCRIPT`" $CHECKSCRIPT || cleanup_and_exit 1 done @@ -2199,7 +2239,7 @@ fi RPMS=`find $BUILD_ROOT/$TOPDIR/RPMS -type f -name "*.rpm" 2>/dev/null || true` DEBS=`find $BUILD_ROOT/$TOPDIR/DEBS -type f -name "*.deb" 2>/dev/null || true` -if test -n "$RPMS" -a "$DO_CHECKS" != "false" -a -x "$BUILD_ROOT/opt/testing/bin/rpmlint" ; then +if test -n "$RPMS" -a "$DO_CHECKS" != "false" -a -x "$BUILD_TARGET/opt/testing/bin/rpmlint" ; then LINT_RPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/RPMS \ \( -name "*-debuginfo-*" -o -name "*-debugsource-*" \ -o -name "*-32bit-*" -o -name "*-64bit-*" \ @@ -2212,7 +2252,7 @@ if test -n "$RPMS" -a "$DO_CHECKS" != "false" -a -x "$BUILD_ROOT/opt/testing/bin rpmlint_logfile=$TOPDIR/OTHER/rpmlint.log rm -f "$BUILD_ROOT$rpmlint_logfile" ret=0 - chroot $BUILD_ROOT su -s /opt/testing/bin/rpmlint "$BUILD_USER" -- \ + enter_target needscript /opt/testing/bin/rpmlint \ --info ${LINT_RPM_FILE_LIST[*]#$BUILD_ROOT} \ ${SRPM_FILE_LIST[*]#$BUILD_ROOT} > "$BUILD_ROOT$rpmlint_logfile" || ret=1 cat "$BUILD_ROOT$rpmlint_logfile" @@ -2231,13 +2271,13 @@ exitcode=0 # TODO: don't hardcode. instead run scripts in a directory as it's done for the checks if test -n "$RPMS" \ -a -d "$BUILD_ROOT/$TOPDIR/RPMS" \ - -a -d "$BUILD_ROOT/.build.oldpackages" \ + -a -d "$BUILD_TARGET/.build.oldpackages" \ ; then - if test -x "$BUILD_ROOT/usr/lib/build/same-build-result.sh" ; then + if test -x "$BUILD_TARGET/usr/lib/build/same-build-result.sh" ; then echo "... comparing built packages with the former built" mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null - if chroot $BUILD_ROOT /usr/lib/build/same-build-result.sh /.build.oldpackages "$TOPDIR/RPMS" "$TOPDIR/SRPMS"; then - chroot $BUILD_ROOT touch /.build/.same_result_marker + if enter_target needroot /usr/lib/build/same-build-result.sh /.build.oldpackages "$TOPDIR/RPMS" "$TOPDIR/SRPMS"; then + touch $BUILD_ROOT/.build/.same_result_marker # XXX: dirty build service hack. fix bs_worker. Search for # 'same_result_marker' for traces of a first try to get rid of this if test -n "$REASON" -a -n "$DISTURL"; then @@ -2246,11 +2286,11 @@ if test -n "$RPMS" \ fi fi if test ! -e $BUILD_ROOT/.build/.same_result_marker \ - -a -x "$BUILD_ROOT/usr/bin/makedeltarpm" \ - -a -x $BUILD_ROOT/usr/lib/build/mkdrpms; then + -a -x "$BUILD_TARGET/usr/bin/makedeltarpm" \ + -a -x $BUILD_TARGET/usr/lib/build/mkdrpms; then echo "... creating delta rpms" ds=("$BUILD_ROOT/$TOPDIR"/RPMS/* "$BUILD_ROOT$TOPDIR/SRPMS") - chroot $BUILD_ROOT /usr/lib/build/mkdrpms /.build.oldpackages "${ds[@]#$BUILD_ROOT}" + enter_target needroot /usr/lib/build/mkdrpms /.build.oldpackages "${ds[@]#$BUILD_ROOT}" fi fi diff --git a/common_functions b/common_functions index 9eb437d..dfa1ba2 100755 --- a/common_functions +++ b/common_functions @@ -53,6 +53,158 @@ is_emulator_arch() return 1 } +internal_set_sb2_settings() { + SB2_TOOLCHAIN="/unknown" + SB2_INSTALLMODE="obs-rpm-install" + SB2_DEFAULTMODE="obs-rpm-build" + SB2_SYSROOT="-C --sysroot=/ -L --sysroot=/" + SB2_MAPPING_METHOD="both" + SB2_DEBUG="" + SB2_QEMU="/unknown" + while test -n "$1" ; do + case "$1" in + --toolchain) + shift + SB2_TOOLCHAIN=$1 + shift + ;; + --installmode) + shift + SB2_INSTALLMODE=$1 + shift + ;; + --defaultmode) + shift + SB2_DEFAULTMODE=$1 + shift + ;; + --mappingmethod) + shift + SB2_MAPPING_METHOD=$1 + shift + ;; + --bootstrap) + shift + SB2_SYSROOT="" + ;; + --qemu) + shift + SB2_QEMU=$1 + shift + ;; + --infologs) + shift + SB2_DEBUG="-q -L info" + ;; + --debug) + shift + SB2_DEBUG="-q -d" + ;; + *) + break + ;; + esac + done + if [ "x$SB2_TOOLCHAIN" = "x/unknown" ]; then + echo "Please provide a proper SB2 toolchain in SB2flags. exiting.." + cleanup_and_exit 1 + fi +} + + +cleanup_sb2() { + if [ ! -z "$BUILD_SB2FLAGS" ]; then + if [ -e /home/abuild/sb2-session-needroot ]; then + su -c "cd $PWD; /usr/bin/sb2 -t oscbuild -D /home/abuild/sb2-session-needroot" - abuild + fi + if [ -e /home/abuild/sb2-session-needuser ]; then + su -c "cd $PWD; /usr/bin/sb2 -t oscbuild -D /home/abuild/sb2-session-needuser" - abuild + fi + fi +} + +# chroot-like wrapper, enter_target <mode: needroot|user> $TARGET commands +# needroot - operations that need to be done as root, like unpacking into file system, etc +# needuser - operations that will be done as non-root user + +enter_target() { + if [ -z "$BUILD_SB2FLAGS" ]; then + if [ x$1 == xneeduser ]; then + shift + chroot $BUILD_TARGET su -c "${*}" - $BUILD_USER + elif [ x$1 == xneedscript ]; then + shift + SCRIPT=$1 + shift + chroot $BUILD_TARGET su -s $SCRIPT $BUILD_USER -- ${*} + else + shift + chroot $BUILD_TARGET ${*} + fi + else + if [ -z "$VM_TYPE" ]; then + echo "SB2 currently does not work with chroots.." + cleanup_and_exit 1 + fi + if [ -z "$SB2_TOOLCHAIN" ]; then + internal_set_sb2_settings $BUILD_SB2FLAGS + fi + if [ ! -e $BUILD_TARGET/.sb2inited ]; then + ORIG=$PWD + cd $BUILD_TARGET + su -c "cd $PWD; /usr/bin/sb2-init $SB2_SYSROOT -c $SB2_QEMU -n -N -m $SB2_DEFAULTMODE -t / oscbuild $SB2_TOOLCHAIN" - abuild + su -c "cd $PWD; /usr/bin/sb2-config -t oscbuild setenv SBOX_MAPPING_METHOD $SB2_MAPPING_METHOD" - abuild + + cd $ORIG + touch $BUILD_TARGET/.sb2inited + fi + if [ x$1 = xneedscript ]; then + PARAM=needuser + else + PARAM=$1 + fi + case "$PARAM" in + needroot) + shift + ORIG=$PWD + cd /target + if [ ! -e /home/abuild/sb2-session-needroot ]; then + SESSION="-S /home/abuild/sb2-session-needroot -t oscbuild" + else + SESSION="-J /home/abuild/sb2-session-needroot" + fi + su -c "cd $PWD; /usr/bin/sb2-config -t oscbuild setenv HOME /root" - abuild + su -c "cd $PWD; /usr/bin/sb2-config -t oscbuild setenv USER root" - abuild + su -c "cd $PWD; /usr/bin/sb2 $SESSION $SB2_DEBUG -m $SB2_INSTALLMODE -R ${*}" - abuild + RET=$? + cd $ORIG + return $RET + ;; + needuser) + # Debugging + shift + ORIG=$PWD + cd /target + if [ ! -e /home/abuild/sb2-session-needuser ]; then + SESSION="-S /home/abuild/sb2-session-needuser -t oscbuild" + else + SESSION="-J /home/abuild/sb2-session-needuser" + fi + su -c "cd $PWD; /usr/bin/sb2-config -t oscbuild setenv HOME /home/abuild" - abuild + su -c "cd $PWD; /usr/bin/sb2-config -t oscbuild setenv USER abuild" - abuild + su -c "cd $PWD; /usr/bin/sb2 $SESSION $SB2_DEBUG -m $SB2_DEFAULTMODE ${*}" - abuild + RET=$? + cd $ORIG + return $RET + ;; + *) + echo "Unknown parameter $1" >&2 + ;; + esac + fi +} + + check_use_emulator() { is_emulator_arch || return @@ -72,6 +224,8 @@ check_use_emulator() -a -e /bin/mount-static \ -a -e /usr/sbin/qemu-binfmt-conf.sh; then return 0 # as backup use /usr/sbin/qemu-binfmt.conf.sh + elif [ -n "$BUILD_SB2FLAGS" ]; then + return 0 # Use sb2 else # XXX: error? echo "Warning: cross compile not possible due to missing static binaries" diff --git a/expanddeps b/expanddeps index 7bd51e1..d5f056a 100755 --- a/expanddeps +++ b/expanddeps @@ -203,6 +203,7 @@ sub print_rpmlist print "vminstall: @{$cf->{'vminstall'} || []}\n"; print "cbpreinstall: @{$cf->{'cbpreinstall'} || []}\n"; # preinstall if is_emulator_arch print "cbinstall: @{$cf->{'cbinstall'} || []}\n"; # install if is_emulator_arch + print "sb2install: @{$cf->{'sb2install'} || []}\n"; # install if is_emulator_arch print "runscripts: @{$cf->{'runscripts'} || []}\n"; print "dist: $dist\n" if defined $dist; } diff --git a/getsb2flags b/getsb2flags new file mode 100644 index 0000000..6f038ef --- /dev/null +++ b/getsb2flags @@ -0,0 +1,41 @@ +#!/usr/bin/perl -w + +BEGIN { + unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build'); +} + +use strict; + +use Build; + +my ($dist, $archs, $configdir, $debug); + +while (@ARGV) { + if ($ARGV[0] eq '--dist') { + shift @ARGV; + $dist = shift @ARGV; + next; + } + if ($ARGV[0] eq '--archpath') { + shift @ARGV; + $archs = shift @ARGV; + next; + } + if ($ARGV[0] eq '--configdir') { + shift @ARGV; + $configdir = shift @ARGV; + next; + } + last; +} + +die("Usage: getsb2flags --dist <dist> --archpath <archpath> [--configdir <configdir>]\n") if @ARGV; + +my $cf = Build::read_config_dist($dist, $archs, $configdir); +exit 0 unless $cf->{'optflags'}; +my $all = $cf->{'optflags'}->{'*'}; +$all = defined($all) && $all ne '' ? " $all" : ''; +for (sort keys %{$cf->{'sb2flags'}}) { + next if $_ eq '*'; + print "$_ $cf->{'sb2flags'}->{$_}$all\n"; +} diff --git a/init_buildsystem b/init_buildsystem index 1eca42b..a70ec9a 100755 --- a/init_buildsystem +++ b/init_buildsystem @@ -104,6 +104,9 @@ cleanup_and_exit() { trap EXIT [ "$BUILD_ROOT" != / ] || chown $browner $BUILD_ROOT + if [ -z "$PREPARE_VM" ]; then + cleanup_sb2 + fi # umount so init_buildsystem can be used standalone # XXX: use stat -f /dev/pts/ -c %T to check whether it's mounted and not suppress errors then? umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true @@ -123,7 +126,7 @@ clean_build_root() rm -rf -- $BUILD_ROOT/* rm -rf -- $BUILD_ROOT/.build rm -rf -- $BUILD_ROOT/.root - rm -rf -- $BUILD_ROOT/.init_b_cache + rm -rf -- $BUILD_TARGET/.init_b_cache mkdir -p $BUILD_ROOT/proc mkdir -p $BUILD_ROOT/dev/pts if [ "$UID" = '0' ]; then @@ -136,8 +139,12 @@ clean_build_root() preinstall() { check_exit - echo "preinstalling $1..." - cd $BUILD_ROOT || cleanup_and_exit 1 + echo "preinstalling $1... $2" + if [ -n "$BUILD_SB2FLAGS" -a x$2 = xtools ]; then + cd $BUILD_ROOT || cleanup_and_exit 1 + else + cd $BUILD_TARGET || cleanup_and_exit 1 + fi if test -x /usr/bin/bsdtar ; then CPIO="/usr/bin/bsdtar -P --chroot -o --numeric-owner -x -f-" TAR="/usr/bin/bsdtar -P --chroot -o --numeric-owner -x" @@ -152,9 +159,9 @@ preinstall() CPIO="cpio --extract --unconditional --preserve-modification-time --make-directories --no-absolute-filenames --quiet" TAR="tar -x" fi - if test -e "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" ; then + if test -e "$BUILD_TARGET/.init_b_cache/rpms/$1.rpm" ; then PAYLOADDECOMPRESS=cat - case `rpm -qp --nodigest --nosignature --qf "%{PAYLOADCOMPRESSOR}\n" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm"` in + case `rpm -qp --nodigest --nosignature --qf "%{PAYLOADCOMPRESSOR}\n" "$BUILD_TARGET/.init_b_cache/rpms/$1.rpm"` in lzma) rpm --showrc | grep PayloadIsLzma > /dev/null || PAYLOADDECOMPRESS="lzma -d" ;; xz) rpm --showrc | grep PayloadIsXz > /dev/null || PAYLOADDECOMPRESS="xz -d" ;; esac @@ -169,20 +176,20 @@ preinstall() fi fi if test "$PAYLOADDECOMPRESS" = cat ; then - rpm2cpio "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" | $CPIO + rpm2cpio "$BUILD_TARGET/.init_b_cache/rpms/$1.rpm" | $CPIO else - rpm2cpio "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" | $PAYLOADDECOMPRESS | $CPIO + rpm2cpio "$BUILD_TARGET/.init_b_cache/rpms/$1.rpm" | $PAYLOADDECOMPRESS | $CPIO fi if test -e ".init_b_cache/scripts/$1.run" ; then - rpm -qp --nodigest --nosignature --qf "%{PREIN}" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" > ".init_b_cache/scripts/$1.pre" - rpm -qp --nodigest --nosignature --qf "%{POSTIN}" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" > ".init_b_cache/scripts/$1.post" + rpm -qp --nodigest --nosignature --qf "%{PREIN}" "$BUILD_TARGET/.init_b_cache/rpms/$1.rpm" > ".init_b_cache/scripts/$1.pre" + rpm -qp --nodigest --nosignature --qf "%{POSTIN}" "$BUILD_TARGET/.init_b_cache/rpms/$1.rpm" > ".init_b_cache/scripts/$1.post" echo -n '(none)' > .init_b_cache/scripts/.none cmp -s ".init_b_cache/scripts/$1.pre" .init_b_cache/scripts/.none && rm -f ".init_b_cache/scripts/$1.pre" cmp -s ".init_b_cache/scripts/$1.post" .init_b_cache/scripts/.none && rm -f ".init_b_cache/scripts/$1.post" rm -f .init_b_cache/scripts/.none fi - elif test -e "$BUILD_ROOT/.init_b_cache/rpms/$1.deb" ; then - ar x "$BUILD_ROOT/.init_b_cache/rpms/$1.deb" control.tar.gz data.tar.gz + elif test -e "$BUILD_TARGET/.init_b_cache/rpms/$1.deb" ; then + ar x "$BUILD_TARGET/.init_b_cache/rpms/$1.deb" control.tar.gz data.tar.gz mkdir -p .init_b_cache/scripts/control $TAR -C .init_b_cache/scripts/control -z -f control.tar.gz $TAR -z -f data.tar.gz @@ -205,25 +212,25 @@ preinstall() run_pkg_scripts() { - chroot $BUILD_ROOT /sbin/ldconfig 2>/dev/null + enter_target needroot $BUILD_TARGET /sbin/ldconfig 2>/dev/null for PKG in $PACKAGES_TO_RUNSCRIPTS ; do - if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre" ; then + if test -e "$BUILD_TARGET/.init_b_cache/scripts/$PKG.pre" ; then echo "running $PKG preinstall script" - if test -e "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" ; then - chroot $BUILD_ROOT sh ".init_b_cache/scripts/$PKG.pre" 0 + if test -e "$BUILD_TARGET/.init_b_cache/rpms/$PKG.rpm" ; then + enter_target needroot sh ".init_b_cache/scripts/$PKG.pre" 0 else - chroot $BUILD_ROOT ".init_b_cache/scripts/$PKG.pre" install < /dev/null + enter_target needroot ".init_b_cache/scripts/$PKG.pre" install < /dev/null fi - rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre" + rm -f "$BUILD_TARGET/.init_b_cache/scripts/$PKG.pre" fi - if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post" ; then + if test -e "$BUILD_TARGET/.init_b_cache/scripts/$PKG.post" ; then echo "running $PKG postinstall script" - if test -e "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" ; then - chroot $BUILD_ROOT sh ".init_b_cache/scripts/$PKG.post" 1 + if test -e "$BUILD_TARGET/.init_b_cache/rpms/$PKG.rpm" ; then + enter_target needroot sh ".init_b_cache/scripts/$PKG.post" 1 else - chroot $BUILD_ROOT ".init_b_cache/scripts/$PKG.post" configure '' < /dev/null + enter_target needroot ".init_b_cache/scripts/$PKG.post" configure '' < /dev/null fi - rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post" + rm -f "$BUILD_TARGET/.init_b_cache/scripts/$PKG.post" fi check_exit done @@ -233,38 +240,39 @@ init_db() { if test $PSUF = rpm ; then echo initializing rpm db... - if ! test -e $BUILD_ROOT/usr/lib/rpm/cpuinfo.yaml; then + if ! test -e $BUILD_TARGET/usr/lib/rpm/cpuinfo.yaml; then # rpm v5 does not have initdb - chroot $BUILD_ROOT rpm --initdb || cleanup_and_exit 1 + enter_target needroot rpm --initdb || cleanup_and_exit 1 fi # hack: add nofsync to db config to speed up install - mkdir -p $BUILD_ROOT/root - echo '%__dbi_perms perms=0644 nofsync' > $BUILD_ROOT/.rpmmacros - echo '%__dbi_perms perms=0644 nofsync' > $BUILD_ROOT/root/.rpmmacros + mkdir -p $BUILD_TARGET/root + echo '%__dbi_perms perms=0644 nofsync' > $BUILD_TARGET/.rpmmacros + echo '%__dbi_perms perms=0644 nofsync' > $BUILD_TARGET/root/.rpmmacros elif test $PSUF = deb ; then + enter_target needroot dpkg -i --force all .init_b_cache/dpkg.deb >/dev/null 2>&1 + elif test $PSUF = arch ; then + mkdir -p $BUILD_TARGET/var/lib/pacman/sync + touch $BUILD_TARGET/var/lib/pacman/sync/core.db + touch $BUILD_TARGET/var/lib/pacman/sync/extra.db + touch $BUILD_TARGET/var/lib/pacman/sync/community.db + else # force dpkg into database to make epoch test work - if ! test "$BUILD_ROOT/.init_b_cache/rpms/dpkg.deb" -ef "$BUILD_ROOT/.init_b_cache/dpkg.deb" ; then - rm -f $BUILD_ROOT/.init_b_cache/dpkg.deb - cp $BUILD_ROOT/.init_b_cache/rpms/dpkg.deb $BUILD_ROOT/.init_b_cache/dpkg.deb || cleanup_and_exit 1 + if ! test "$BUILD_TARGET/.init_b_cache/rpms/dpkg.deb" -ef "$BUILD_TARGET/.init_b_cache/dpkg.deb" ; then + rm -f $BUILD_TARGET/.init_b_cache/dpkg.deb + cp $BUILD_TARGET/.init_b_cache/rpms/dpkg.deb $BUILD_TARGET/.init_b_cache/dpkg.deb || cleanup_and_exit 1 fi - chroot $BUILD_ROOT dpkg -i --force all .init_b_cache/dpkg.deb >/dev/null 2>&1 - elif test $PSUF = arch ; then - mkdir -p $BUILD_ROOT/var/lib/pacman/sync - touch $BUILD_ROOT/var/lib/pacman/sync/core.db - touch $BUILD_ROOT/var/lib/pacman/sync/extra.db - touch $BUILD_ROOT/var/lib/pacman/sync/community.db fi } reorder() { test -z "$*" && return - rm -f $BUILD_ROOT/.init_b_cache/order.manifest + rm -f $BUILD_TARGET/.init_b_cache/order.manifest for PKG in "$@" ; do - echo "$PKG" >> $BUILD_ROOT/.init_b_cache/order.manifest + echo "$PKG" >> $BUILD_TARGET/.init_b_cache/order.manifest done - $BUILD_DIR/order --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir $CONFIG_DIR --manifest $BUILD_ROOT/.init_b_cache/order.manifest $BUILD_ROOT/.init_b_cache/rpms - rm -f $BUILD_ROOT/.init_b_cache/order.manifest + $BUILD_DIR/order --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir $CONFIG_DIR --manifest $BUILD_TARGET/.init_b_cache/order.manifest $BUILD_TARGET/.init_b_cache/rpms + rm -f $BUILD_TARGET/.init_b_cache/order.manifest } create_devs() @@ -586,18 +594,18 @@ fi if test -e $BUILD_ROOT/.build/init_buildsystem.data ; then # vm continuation . $BUILD_ROOT/.build/init_buildsystem.data - if ! test -e $BUILD_ROOT/.init_b_cache/preinstall_finished ; then + if ! test -e $BUILD_TARGET/.init_b_cache/preinstall_finished ; then # finish preinstall run_pkg_scripts init_db - touch $BUILD_ROOT/.init_b_cache/preinstall_finished + touch $BUILD_TARGET/.init_b_cache/preinstall_finished fi else # # now make sure that all the packages are installed. # - rm -rf $BUILD_ROOT/.init_b_cache - mkdir -p $BUILD_ROOT/.init_b_cache/scripts + rm -rf $BUILD_TARGET/.init_b_cache + mkdir -p $BUILD_TARGET/.init_b_cache/scripts if test -z "$RPMLIST" ; then # @@ -609,7 +617,7 @@ else # # select and expand packages # - RPMLIST=$BUILD_ROOT/.init_b_cache/rpmlist + RPMLIST=$BUILD_TARGET/.init_b_cache/rpmlist test -z "$LIST_STATE" && echo "expanding package dependencies..." if ! $BUILD_DIR/expanddeps $USEUSEDFORBUILD "${definesnstuff[@]}" --dist "$BUILD_DIST" --depfile "$CACHE_FILE" --archpath "$BUILD_ARCH" --configdir $CONFIG_DIR "${PKGS[@]}" > $RPMLIST ; then rm -f $BUILD_IS_RUNNING @@ -623,12 +631,13 @@ else test "$PKG" = "preinstall:" && continue test "$PKG" = "runscripts:" && continue test "$PKG" = "cbpreinstall:" && continue + test "$PKG" = "sb2install:" && continue test "$PKG" = "vminstall:" && continue test "$PKG" = "dist:" && continue test "$PKG" = "rpmid:" && continue echo "${SRC##*/}" - done < $BUILD_ROOT/.init_b_cache/rpmlist - rm -rf $BUILD_ROOT/.init_b_cache + done < $BUILD_TARGET/.init_b_cache/rpmlist + rm -rf $BUILD_TARGET/.init_b_cache cleanup_and_exit 0 fi @@ -663,10 +672,11 @@ else PACKAGES_TO_RUNSCRIPTS= PACKAGES_TO_VMINSTALL= PACKAGES_TO_CBPREINSTALL= + PACKAGES_TO_SB2INSTALL= PACKAGES_TO_CBINSTALL= RUNSCRIPTS_SEEN= GUESSED_DIST=unknown - mkdir -p $BUILD_ROOT/.init_b_cache/rpms + mkdir -p $BUILD_TARGET/.init_b_cache/rpms while read PKG SRC ; do if test "$PKG" = "preinstall:" ; then PACKAGES_TO_PREINSTALL=$SRC @@ -684,6 +694,12 @@ else fi continue fi + if test "$PKG" = "sb2install:" ; then + if is_emulator_arch ; then + PACKAGES_TO_SB2INSTALL=$SRC + fi + continue + fi if test "$PKG" = "cbinstall:" ; then if is_emulator_arch ; then PACKAGES_TO_CBINSTALL=$SRC @@ -700,7 +716,7 @@ else continue fi if test "$PKG" = "rpmid:" ; then - echo "${SRC#*:}" > $BUILD_ROOT/.init_b_cache/rpms/${SRC%%:*}.id + echo "${SRC#*:}" > $BUILD_TARGET/.init_b_cache/rpms/${SRC%%:*}.id continue fi if test "$PKG" != "${PKG%:}"; then @@ -720,13 +736,27 @@ else esac # downloadpkg modified $SRC, so it has a right name for use fi + # downloadpkg modified $SRC, so it has a right name for use SRCSUF=${SRC/%.pkg.tar.?z/.arch} - ln -s "$SRC" "$BUILD_ROOT/.init_b_cache/rpms/$PKG.${SRCSUF##*.}" + ln -s "$SRC" "$BUILD_TARGET/.init_b_cache/rpms/$PKG.${SRCSUF##*.}" PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL $PKG" done < $RPMLIST - + + # SB2 installs aren't part of the natural order, filter them out + if test -n "$PACKAGES_TO_SB2INSTALL" ; then + for SB2PKG in $PACKAGES_TO_SB2INSTALL ; do + for PKG in $PACKAGES_TO_INSTALL ; do + if [ "x$PKG" != "x$SB2PKG" ]; then + NEWPACKAGES_TO_INSTALL="$NEWPACKAGES_TO_INSTALL $PKG" + fi + done + PACKAGES_TO_INSTALL="$NEWPACKAGES_TO_INSTALL" + done + fi + test -n "$PACKAGES_TO_CBPREINSTALL" && echo "cbpreinstall: $PACKAGES_TO_CBPREINSTALL" test -n "$PACKAGES_TO_CBINSTALL" && echo "cbinstall : $PACKAGES_TO_CBINSTALL" + test -n "$PACKAGES_TO_SB2INSTALL" && echo "sb2install : $PACKAGES_TO_SB2INSTALL" # compatibility... test -z "$RUNSCRIPTS_SEEN" && PACKAGES_TO_RUNSCRIPTS="$PACKAGES_TO_PREINSTALL" @@ -740,8 +770,8 @@ else *) # auto detect from packages PSUF=rpm - test -L $BUILD_ROOT/.init_b_cache/rpms/dpkg.deb && PSUF=deb - test -L $BUILD_ROOT/.init_b_cache/rpms/pacman.arch && PSUF=arch + test -L $BUILD_TARGET/.init_b_cache/rpms/dpkg.deb && PSUF=deb + test -L $BUILD_TARGET/.init_b_cache/rpms/pacman.arch && PSUF=arch ;; esac fi @@ -749,30 +779,38 @@ fi # # now test if there is already a build dir. # -if test ! -f $BUILD_ROOT/var/lib/rpm/packages.rpm -a ! -f $BUILD_ROOT/var/lib/rpm/Packages -a ! -e $BUILD_ROOT/.build/init_buildsystem.data ; then - mkdir -p $BUILD_ROOT/var/lib/rpm || cleanup_and_exit 1 - mkdir -p $BUILD_ROOT/usr/src/packages/SOURCES || cleanup_and_exit 1 - mkdir -p $BUILD_ROOT/etc || cleanup_and_exit 1 - mkdir -p $BUILD_ROOT/proc || cleanup_and_exit 1 - test -f $BUILD_ROOT/etc/HOSTNAME || hostname -f > $BUILD_ROOT/etc/HOSTNAME +if test ! -f $BUILD_TARGET/var/lib/rpm/packages.rpm -a ! -f $BUILD_TARGET/var/lib/rpm/Packages -a ! -e $BUILD_TARGET/.build/init_buildsystem.data ; then + mkdir -p $BUILD_TARGET/var/lib/rpm || cleanup_and_exit 1 + mkdir -p $BUILD_TARGET/usr/src/packages/SOURCES || cleanup_and_exit 1 + mkdir -p $BUILD_TARGET/etc || cleanup_and_exit 1 + mkdir -p $BUILD_TARGET/proc || cleanup_and_exit 1 + test -f $BUILD_TARGET/etc/HOSTNAME || hostname -f > $BUILD_TARGET/etc/HOSTNAME if test $PSUF = deb ; then - mkdir -p $BUILD_ROOT/var/lib/dpkg - mkdir -p $BUILD_ROOT/var/log - mkdir -p $BUILD_ROOT/etc/default - :> $BUILD_ROOT/var/lib/dpkg/status - :> $BUILD_ROOT/var/lib/dpkg/available - :> $BUILD_ROOT/var/log/dpkg.log - :> $BUILD_ROOT/etc/ld.so.conf - :> $BUILD_ROOT/etc/default/rcS + mkdir -p $BUILD_TARGET/var/lib/dpkg + mkdir -p $BUILD_TARGET/var/log + mkdir -p $BUILD_TARGET/etc/default + :> $BUILD_TARGET/var/lib/dpkg/status + :> $BUILD_TARGET/var/lib/dpkg/available + :> $BUILD_TARGET/var/log/dpkg.log + :> $BUILD_TARGET/etc/ld.so.conf + :> $BUILD_TARGET/etc/default/rcS fi for PKG in $PACKAGES_TO_RUNSCRIPTS ; do : > $BUILD_ROOT/.init_b_cache/scripts/$PKG.run done PACKAGES_TO_PREINSTALL=`reorder $PACKAGES_TO_PREINSTALL` + if [ "x$PACKAGES_TO_SB2INSTALL" != x ] ; then + mkdir -p $BUILD_ROOT/target + progress_step PACKAGES_TO_SB2INSTALL + for PKG in $PACKAGES_TO_SB2INSTALL ; do + preinstall ${PKG##*/} tools + done + fi progress_setup PACKAGES_TO_PREINSTALL for PKG in $PACKAGES_TO_PREINSTALL ; do progress_step PACKAGES_TO_PREINSTALL preinstall ${PKG##*/} + cd $BUILD_ROOT done if test -n "$PREPARE_VM" ; then PACKAGES_TO_VMINSTALL=`reorder $PACKAGES_TO_VMINSTALL` @@ -780,6 +818,7 @@ if test ! -f $BUILD_ROOT/var/lib/rpm/packages.rpm -a ! -f $BUILD_ROOT/var/lib/rp for PKG in $PACKAGES_TO_VMINSTALL ; do progress_step PACKAGES_TO_VMINSTALL preinstall ${PKG##*/} + cd $BUILD_ROOT done fi # add cbpreinstall if cross HOST != TARGET @@ -788,25 +827,26 @@ if test ! -f $BUILD_ROOT/var/lib/rpm/packages.rpm -a ! -f $BUILD_ROOT/var/lib/rp for PKG in $PACKAGES_TO_CBPREINSTALL ; do progress_step PACKAGES_TO_CBPREINSTALL preinstall ${PKG##*/} + cd $BUILD_ROOT done if [ -w /root ]; then test -c $BUILD_ROOT/dev/null || create_devs fi - test -e $BUILD_ROOT/etc/fstab || touch $BUILD_ROOT/etc/fstab - test ! -e $BUILD_ROOT/etc/ld.so.conf -a -e $BUILD_ROOT/etc/ld.so.conf.in && cp $BUILD_ROOT/etc/ld.so.conf.in $BUILD_ROOT/etc/ld.so.conf + test -e $BUILD_TARGET/etc/fstab || touch $BUILD_TARGET/etc/fstab + test ! -e $BUILD_TARGET/etc/ld.so.conf -a -e $BUILD_TARGET/etc/ld.so.conf.in && cp $BUILD_TARGET/etc/ld.so.conf.in $BUILD_TARGET/etc/ld.so.conf if test -z "$PREPARE_VM" ; then run_pkg_scripts init_db - touch $BUILD_ROOT/.init_b_cache/preinstall_finished + touch $BUILD_TARGET/.init_b_cache/preinstall_finished fi fi if test -n "$PREPARE_VM" ; then echo "copying packages..." for PKG in $PACKAGES_TO_INSTALL ; do - rm -f $BUILD_ROOT/.init_b_cache/$PKG.$PSUF - cp $BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF $BUILD_ROOT/.init_b_cache/$PKG.$PSUF || cleanup_and_exit 1 - ln -s -f ../$PKG.$PSUF $BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF + rm -f $BUILD_TARGET/.init_b_cache/$PKG.$PSUF + cp $BUILD_TARGET/.init_b_cache/rpms/$PKG.$PSUF $BUILD_TARGET/.init_b_cache/$PKG.$PSUF || cleanup_and_exit 1 + ln -s -f ../$PKG.$PSUF $BUILD_TARGET/.init_b_cache/rpms/$PKG.$PSUF check_exit done # alreadyinstalled check will not work, but we have to live with @@ -838,8 +878,8 @@ if test -n "$CREATE_BUILD_BINARIES" ; then echo "creating .build.binaries directory..." mkdir -p "$BUILD_ROOT/.build.binaries" for PKG in $PACKAGES_TO_INSTALL ; do - test -L "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF" || continue - LPKG=`readlink -f "$BUILD_ROOT/.init_b_cache/rpms/$PKG.$PSUF"` + test -L "$BUILD_TARGET/.init_b_cache/rpms/$PKG.$PSUF" || continue + LPKG=`readlink -f "$BUILD_TARGET/.init_b_cache/rpms/$PKG.$PSUF"` ln "$LPKG" "$BUILD_ROOT/.build.binaries/$PKG.$PSUF" 2>/dev/null test -f "$BUILD_ROOT/.build.binaries/$PKG.$PSUF" && continue cp "$LPKG" "$BUILD_ROOT/.build.binaries/$PKG.$PSUF" @@ -850,11 +890,11 @@ fi # # get list and ids of already installed rpms # -mkdir -p $BUILD_ROOT/.init_b_cache/alreadyinstalled -if test -f $BUILD_ROOT/var/lib/rpm/packages.rpm -o -f $BUILD_ROOT/var/lib/rpm/Packages ; then - chroot $BUILD_ROOT rpm -qa --qf "%{NAME} $RPMIDFMT" | ( +mkdir -p $BUILD_TARGET/.init_b_cache/alreadyinstalled +if test -f $BUILD_TARGET/var/lib/rpm/packages.rpm -o -f $BUILD_TARGET/var/lib/rpm/Packages ; then + enter_target needroot rpm -qa --qf "%{NAME} $RPMIDFMT" | ( while read pp ii; do - echo "$ii" > "$BUILD_ROOT/.init_b_cache/alreadyinstalled/$pp" + echo "$ii" > "$BUILD_TARGET/.init_b_cache/alreadyinstalled/$pp" done ) fi @@ -871,7 +911,7 @@ fi rpm_e() { - chroot $BUILD_ROOT rpm --nodeps -e $PKG 2>&1 | \ + enter_target needroot rpm --nodeps -e $PKG 2>&1 | \ while read line; do case "$line" in @@ -880,7 +920,7 @@ rpm_e() error:\ *scriptlet\ failed*) echo "$line" echo "re-try deleting $PKG using --noscripts" - chroot $BUILD_ROOT rpm --nodeps --noscripts -e $PKG || true + enter_target needroot rpm --nodeps --noscripts -e $PKG || true ;; *) echo "$line" ;; esac @@ -890,28 +930,28 @@ rpm_e() # # delete all packages we don't want # -mkdir -p $BUILD_ROOT/.init_b_cache/todelete -for PKG in $BUILD_ROOT/.init_b_cache/alreadyinstalled/* ; do +mkdir -p $BUILD_TARGET/.init_b_cache/todelete +for PKG in $BUILD_TARGET/.init_b_cache/alreadyinstalled/* ; do PKG=${PKG##*/} test "$PKG" = "*" && continue - ln $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG $BUILD_ROOT/.init_b_cache/todelete/$PKG + ln $BUILD_TARGET/.init_b_cache/alreadyinstalled/$PKG $BUILD_TARGET/.init_b_cache/todelete/$PKG done for PKG in $PACKAGES_TO_INSTALL_FIRST $PACKAGES_TO_INSTALL $PACKAGES_TO_CBINSTALL ; do - rm -f $BUILD_ROOT/.init_b_cache/todelete/$PKG + rm -f $BUILD_TARGET/.init_b_cache/todelete/$PKG done -for PKG in $BUILD_ROOT/.init_b_cache/todelete/* ; do +for PKG in $BUILD_TARGET/.init_b_cache/todelete/* ; do PKG=${PKG##*/} test "$PKG" = "*" && continue echo "deleting $PKG" rpm_e "$PKG" check_exit done -rm -rf $BUILD_ROOT/.init_b_cache/todelete +rm -rf $BUILD_TARGET/.init_b_cache/todelete -rm -rf $BUILD_ROOT/.init_b_cache/preinstalls -mkdir -p $BUILD_ROOT/.init_b_cache/preinstalls +rm -rf $BUILD_TARGET/.init_b_cache/preinstalls +mkdir -p $BUILD_TARGET/.init_b_cache/preinstalls for PKG in $PACKAGES_TO_PREINSTALL $PACKAGES_TO_CBPREINSTALL; do - touch "$BUILD_ROOT/.init_b_cache/preinstalls/$PKG" + touch "$BUILD_TARGET/.init_b_cache/preinstalls/$PKG" done rm -rf $BUILD_ROOT/installed-pkg @@ -927,9 +967,12 @@ test -x /usr/bin/rpmsign && RPMCHECKOPTS_HOST="--nodigest --nosignature" MAIN_LIST="$PACKAGES_TO_INSTALL_FIRST $PACKAGES_TO_INSTALL $PACKAGES_TO_CBINSTALL" progress_setup MAIN_LIST for PKG in $PACKAGES_TO_INSTALL_FIRST RUN_LDCONFIG $PACKAGES_TO_INSTALL $PACKAGES_TO_CBINSTALL; do + + cd $BUILD_TARGET + case $PKG in RUN_LDCONFIG) - test -x $BUILD_ROOT/sbin/ldconfig && chroot $BUILD_ROOT /sbin/ldconfig 2>&1 + test -x $BUILD_TARGET/sbin/ldconfig && enter_target needroot /sbin/ldconfig 2>&1 continue ;; esac @@ -939,16 +982,16 @@ for PKG in $PACKAGES_TO_INSTALL_FIRST RUN_LDCONFIG $PACKAGES_TO_INSTALL $PACKAGE if test $PSUF = deb ; then # debian world, install deb files - test -L $BUILD_ROOT/.init_b_cache/rpms/$PKG.deb || continue - if ! test "$BUILD_ROOT/.init_b_cache/rpms/$PKG.deb" -ef "$BUILD_ROOT/.init_b_cache/$PKG.deb" ; then - rm -f $BUILD_ROOT/.init_b_cache/$PKG.deb - cp $BUILD_ROOT/.init_b_cache/rpms/$PKG.deb $BUILD_ROOT/.init_b_cache/$PKG.deb || cleanup_and_exit 1 + test -L $BUILD_TARGET/.init_b_cache/rpms/$PKG.deb || continue + if ! test "$BUILD_TARGET/.init_b_cache/rpms/$PKG.deb" -ef "$BUILD_TARGET/.init_b_cache/$PKG.deb" ; then + rm -f $BUILD_TARGET/.init_b_cache/$PKG.deb + cp $BUILD_TARGET/.init_b_cache/rpms/$PKG.deb $BUILD_TARGET/.init_b_cache/$PKG.deb || cleanup_and_exit 1 fi - PKGID=`readlink $BUILD_ROOT/.init_b_cache/rpms/$PKG.deb` + PKGID=`readlink $BUILD_TARGET/.init_b_cache/rpms/$PKG.deb` PKGID="${PKGID##*/}" PKGID="${PKGID%.deb}" echo "installing ${PKGID%_*}" - ( chroot $BUILD_ROOT dpkg --install --force all .init_b_cache/$PKG.deb 2>&1 || touch $BUILD_ROOT/exit ) | \ + ( enter_target needroot dpkg --install --force all /.init_b_cache/$PKG.deb 2>&1 || touch $BUILD_ROOT/exit ) | \ perl -ne '$|=1;/^(Configuration file|Installing new config file|Selecting previously deselected|\(Reading database|Unpacking |Setting up|Creating config file|Preparing to replace dpkg)/||/^$/||print' check_exit echo "$PKGID debian" > $BUILD_ROOT/installed-pkg/$PKG @@ -986,11 +1029,11 @@ for PKG in $PACKAGES_TO_INSTALL_FIRST RUN_LDCONFIG $PACKAGES_TO_INSTALL $PACKAGE continue fi - test -L $BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm || continue + test -L $BUILD_TARGET/.init_b_cache/rpms/$PKG.rpm || continue - if test -f $BUILD_ROOT/.init_b_cache/rpms/$PKG.id -a -f $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG ; then - read PKGID < $BUILD_ROOT/.init_b_cache/rpms/$PKG.id - read OLDPKGID < $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG + if test -f $BUILD_TARGET/.init_b_cache/rpms/$PKG.id -a -f $BUILD_TARGET/.init_b_cache/alreadyinstalled/$PKG ; then + read PKGID < $BUILD_TARGET/.init_b_cache/rpms/$PKG.id + read OLDPKGID < $BUILD_TARGET/.init_b_cache/alreadyinstalled/$PKG if test "$PKGID" = "$OLDPKGID" ; then #echo "keeping ${PKGID%% *}" echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG @@ -998,15 +1041,15 @@ for PKG in $PACKAGES_TO_INSTALL_FIRST RUN_LDCONFIG $PACKAGES_TO_INSTALL $PACKAGE fi fi - PKGID=`rpm -qp --qf "$RPMIDFMT" $RPMCHECKOPTS_HOST $BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm` + PKGID=`rpm -qp --qf "$RPMIDFMT" $RPMCHECKOPTS_HOST $BUILD_TARGET/.init_b_cache/rpms/$PKG.rpm` - if test -f $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG ; then - read OLDPKGID < $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG + if test -f $BUILD_TARGET/.init_b_cache/alreadyinstalled/$PKG ; then + read OLDPKGID < $BUILD_TARGET/.init_b_cache/alreadyinstalled/$PKG if test "$PKGID" != "$OLDPKGID" ; then echo deleting unwanted ${OLDPKGID%% *} rpm_e "$PKG" elif test "$VERIFY_BUILD_SYSTEM" = true ; then - chroot $BUILD_ROOT rpm --verify $PKG 2>&1 | tee $TMPFILE + enter_target needroot rpm --verify $PKG 2>&1 | tee $TMPFILE if grep ^missing $TMPFILE > /dev/null ; then echo deleting incomplete ${PKGID%% *} rpm_e "$PKG" @@ -1020,12 +1063,12 @@ for PKG in $PACKAGES_TO_INSTALL_FIRST RUN_LDCONFIG $PACKAGES_TO_INSTALL $PACKAGE echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG continue fi - if test -e "$BUILD_ROOT/.init_b_cache/preinstalls/$PKG" ; then + if test -e "$BUILD_TARGET/.init_b_cache/preinstalls/$PKG" ; then preinstall "$PKG" # call for rpm-4.x and not rpm-devel - test -z "${PKG##rpm-[0-9]*}" && chroot $BUILD_ROOT rpm --rebuilddb + test -z "${PKG##rpm-[0-9]*}" && enter_target needroot rpm --rebuilddb # also exec for exchanged rpm ! naming is rpm-x86-<target>-<ver> - test -z "${PKG##rpm-x86-*[0-9]*}" && chroot $BUILD_ROOT rpm --rebuilddb + test -z "${PKG##rpm-x86-*[0-9]*}" && enter_target needroot rpm --rebuilddb fi fi export ADDITIONAL_PARAMS= @@ -1034,21 +1077,23 @@ for PKG in $PACKAGES_TO_INSTALL_FIRST RUN_LDCONFIG $PACKAGES_TO_INSTALL $PACKAGE fi # work around for cross-build installs, we must not overwrite the running rpm if test "$PKG" = rpm ; then - for i in $BUILD_ROOT/.init_b_cache/preinstalls/rpm-x86-* ; do + for i in $BUILD_TARGET/.init_b_cache/preinstalls/rpm-x86-* ; do test -e "$i" && ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS --justdb" done fi echo "installing ${PKGID%% *}" - if ! test "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" -ef "$BUILD_ROOT/.init_b_cache/$PKG.rpm" ; then - rm -f $BUILD_ROOT/.init_b_cache/$PKG.rpm - cp $BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm $BUILD_ROOT/.init_b_cache/$PKG.rpm || cleanup_and_exit 1 + if ! test "$BUILD_TARGET/.init_b_cache/rpms/$PKG.rpm" -ef "$BUILD_TARGET/.init_b_cache/$PKG.rpm" ; then + rm -f $BUILD_TARGET/.init_b_cache/$PKG.rpm + cp $BUILD_TARGET/.init_b_cache/rpms/$PKG.rpm $BUILD_TARGET/.init_b_cache/$PKG.rpm || cleanup_and_exit 1 fi - ( chroot $BUILD_ROOT rpm --ignorearch --nodeps -U --oldpackage --ignoresize $RPMCHECKOPTS \ - $ADDITIONAL_PARAMS .init_b_cache/$PKG.rpm 2>&1 || \ + ( enter_target needroot rpm --ignorearch --nodeps -U --oldpackage --ignoresize $RPMCHECKOPTS \ + $ADDITIONAL_PARAMS /.init_b_cache/$PKG.rpm 2>&1 || \ touch $BUILD_ROOT/exit ) | \ grep -v "^warning:.*saved as.*rpmorig$" # delete link so package is only installed once - rm -f $BUILD_ROOT/.init_b_cache/$PKG.rpm + if [ ! -e $BUILD_ROOT/exit ]; then + rm -f $BUILD_TARGET/.init_b_cache/$PKG.rpm + fi check_exit echo "$PKGID" > $BUILD_ROOT/installed-pkg/$PKG @@ -1059,9 +1104,9 @@ if test $PSUF = deb ; then # configure all packages after complete installation, not for each package like rpm does # We need to run this twice, because of cyclic dependencies as it does not succeed on most # debian based distros in the first attempt. - if ! chroot $BUILD_ROOT dpkg --configure --pending 2>&1; then + if ! enter_target needroot dpkg --configure --pending 2>&1; then echo "first configure attempt failed, trying again..." - chroot $BUILD_ROOT dpkg --configure --pending 2>&1 || touch $BUILD_ROOT/exit + enter_target needroot dpkg --configure --pending 2>&1 || touch $BUILD_ROOT/exit fi fi @@ -1073,9 +1118,9 @@ cd $BUILD_ROOT || cleanup_and_exit 1 # # setup /etc/mtab # -rm -f $BUILD_ROOT/etc/mtab -cp /proc/mounts $BUILD_ROOT/etc/mtab -chmod 644 $BUILD_ROOT/etc/mtab +rm -f $BUILD_TARGET/etc/mtab +cp /proc/mounts $BUILD_TARGET/etc/mtab +chmod 644 $BUILD_TARGET/etc/mtab # # to be sure, path is set correctly, we have to source /etc/profile before @@ -1130,11 +1175,11 @@ chmod 644 $BUILD_ROOT/etc/mtab # # make sure, that our nis is not present in the chroot system # -test -e $BUILD_ROOT/etc/nsswitch.conf && { - echo removing nis flags from $BUILD_ROOT/etc/nsswitch.conf... - cat $BUILD_ROOT/etc/nsswitch.conf | sed -e"s:nis::g" > \ - $BUILD_ROOT/etc/nsswitch.conf.tmp - mv $BUILD_ROOT/etc/nsswitch.conf.tmp $BUILD_ROOT/etc/nsswitch.conf +test -e $BUILD_TARGET/etc/nsswitch.conf && { + echo removing nis flags from $BUILD_TARGET/etc/nsswitch.conf... + cat $BUILD_TARGET/etc/nsswitch.conf | sed -e"s:nis::g" > \ + $BUILD_TARGET/etc/nsswitch.conf.tmp + mv $BUILD_TARGET/etc/nsswitch.conf.tmp $BUILD_TARGET/etc/nsswitch.conf } # @@ -1142,22 +1187,22 @@ test -e $BUILD_ROOT/etc/nsswitch.conf && { for DIR in /usr/share/doc/packages \ /usr/X11R6/include/X11/pixmaps \ /usr/X11R6/include/X11/bitmaps ; do - mkdir -p $BUILD_ROOT/$DIR + mkdir -p $BUILD_TARGET/$DIR done for FILE in /var/run/utmp /var/log/wtmp /etc/fstab ; do - mkdir -p $BUILD_ROOT/${FILE%/*} - touch $BUILD_ROOT/$FILE + mkdir -p $BUILD_TARGET/${FILE%/*} + touch $BUILD_TARGET/$FILE done echo now finalizing build dir... -if test -x $BUILD_ROOT/sbin/ldconfig ; then - CHROOT_RETURN="`chroot $BUILD_ROOT /sbin/ldconfig 2>&1`" +if test -x $BUILD_TARGET/sbin/ldconfig ; then + CHROOT_RETURN="`enter_target needroot /sbin/ldconfig 2>&1`" case "$CHROOT_RETURN" in *warning:*) - chroot $BUILD_ROOT /sbin/ldconfig + enter_target needroot /sbin/ldconfig echo - echo chroot $BUILD_ROOT /sbin/ldconfig + echo enter_target needroot /sbin/ldconfig echo echo "$CHROOT_RETURN" echo @@ -1167,48 +1212,48 @@ if test -x $BUILD_ROOT/sbin/ldconfig ; then ;; esac fi -test -x $BUILD_ROOT/usr/sbin/Check && chroot $BUILD_ROOT /usr/sbin/Check +test -x $BUILD_TARGET/usr/sbin/Check && enter_target needroot /usr/sbin/Check -mkdir -p $BUILD_ROOT/var/adm/packages -touch $BUILD_ROOT/var/adm/packages -if test -x $BUILD_ROOT/sbin/SuSEconfig ; then - if grep norestarts $BUILD_ROOT/sbin/SuSEconfig > /dev/null ; then - chroot $BUILD_ROOT /sbin/SuSEconfig --norestarts --force +mkdir -p $BUILD_TARGET/var/adm/packages +touch $BUILD_TARGET/var/adm/packages +if test -x $BUILD_TARGET/sbin/SuSEconfig ; then + if grep norestarts $BUILD_TARGET/sbin/SuSEconfig > /dev/null ; then + enter_target needroot /sbin/SuSEconfig --norestarts --force else - chroot $BUILD_ROOT /sbin/SuSEconfig --force + enter_target needroot /sbin/SuSEconfig --force fi fi -if test -x $BUILD_ROOT/usr/X11R6/bin/switch2mesasoft ; then - chroot $BUILD_ROOT /usr/X11R6/bin/switch2mesasoft +if test -x $BUILD_TARGET/usr/X11R6/bin/switch2mesasoft ; then + enter_target needroot /usr/X11R6/bin/switch2mesasoft fi for PROG in /usr/bin/TeX/texhash /usr/bin/texhash ; do - test -x $BUILD_ROOT/$PROG && \ - chroot $BUILD_ROOT bash -c ". /etc/profile ; $PROG" + test -x $BUILD_TARGET/$PROG && \ + enter_target needroot bash -c ". /etc/profile ; $PROG" done -if test -e $BUILD_ROOT/usr/share/zoneinfo/UTC ; then +if test -e $BUILD_TARGET/usr/share/zoneinfo/UTC ; then for PROG in /usr/sbin/zic /usr/bin/zic /bin/zic /sbin/zic ; do - test -x $BUILD_ROOT/$PROG && chroot $BUILD_ROOT $PROG -l UTC + test -x $BUILD_TARGET/$PROG && enter_target needroot $PROG -l UTC done fi test -e $BUILD_ROOT/.build/init_buildsystem.data || HOST=`hostname` -test -e $BUILD_ROOT/etc/hosts || echo "127.0.0.1 localhost" > $BUILD_ROOT/etc/hosts -if ! grep -F "127.0.0.1 $HOST" $BUILD_ROOT/etc/hosts > /dev/null ; then +test -e $BUILD_TARGET/etc/hosts || echo "127.0.0.1 localhost" > $BUILD_TARGET/etc/hosts +if ! grep -F "127.0.0.1 $HOST" $BUILD_TARGET/etc/hosts > /dev/null ; then # this makes a reverse lookup on 127.0.0.1 return the host name, # which is bad, but 127.0.0.2 does not work on all unix systems - echo "127.0.0.1 $HOST" > $BUILD_ROOT/etc/hosts.new - test -f $BUILD_ROOT/etc/hosts && cat $BUILD_ROOT/etc/hosts >> $BUILD_ROOT/etc/hosts.new - mv $BUILD_ROOT/etc/hosts.new $BUILD_ROOT/etc/hosts + echo "127.0.0.1 $HOST" > $BUILD_TARGET/etc/hosts.new + test -f $BUILD_TARGET/etc/hosts && cat $BUILD_TARGET/etc/hosts >> $BUILD_TARGET/etc/hosts.new + mv $BUILD_TARGET/etc/hosts.new $BUILD_TARGET/etc/hosts fi -if test -x $BUILD_ROOT/bin/rpm -a ! -f $BUILD_ROOT/var/lib/rpm/packages.rpm -a ! -f $BUILD_ROOT/var/lib/rpm/Packages ; then +if test -x $BUILD_TARGET/bin/rpm -a ! -f $BUILD_TARGET/var/lib/rpm/packages.rpm -a ! -f $BUILD_TARGET/var/lib/rpm/Packages ; then echo "initializing rpm db..." - chroot $BUILD_ROOT rpm --initdb || cleanup_and_exit 1 + enter_target needroot rpm --initdb || cleanup_and_exit 1 # create provides index - chroot $BUILD_ROOT rpm -q --whatprovides rpm >/dev/null 2>&1 + enter_target needroot rpm -q --whatprovides rpm >/dev/null 2>&1 fi # create modules.dep in kvm/xen @@ -1217,8 +1262,8 @@ fi # /sbin/depmod -a #fi -rm -f $BUILD_ROOT/.rpmmacros $BUILD_ROOT/root/.rpmmacros -rm -rf $BUILD_ROOT/.init_b_cache +rm -f $BUILD_TARGET/.rpmmacros $BUILD_TARGET/root/.rpmmacros +rm -rf $BUILD_TARGET/.init_b_cache rm -f $BUILD_IS_RUNNING rm -f $TMPFILE diff --git a/initscript_sb2 b/initscript_sb2 new file mode 100644 index 0000000..0245f92 --- /dev/null +++ b/initscript_sb2 @@ -0,0 +1,22 @@ +#!/bin/bash +ABUILD_UID=399 +ABUILD_GID=399 + +echo "Setting up abuild user in $BUILD_ROOT for SB2" +echo "abuild::${ABUILD_UID}:${ABUILD_GID}:Autobuild:/home/abuild:/bin/bash" >> /etc/passwd +echo 'abuild:*:::::::' >>/etc/shadow # This is needed on Mandriva 2009 +echo 'abuild:*::' >>/etc/gshadow # This is needed on Ubuntu +echo "abuild::${ABUILD_GID}:" >>/etc/group +mkdir -p /target /home/abuild +chmod 775 /target +chown -R "$ABUILD_UID:$ABUILD_GID" /target /home/abuild +if [ -e /home/abuild/sb2-session-needroot ]; then + rm -rf /home/abuild/sb2-session-needroot +fi +if [ -e /home/abuild/sb2-session-needuser ]; then + rm -rf /home/abuild/sb2-session-needuser +fi +if [ -e /target/.sb2inited ]; then + rm -rf /target/.sb2inited +fi +/bin/bash /.build/build -- 1.7.10.3