Mailinglist Archive: opensuse-buildservice (239 mails)

< Previous Next >
[opensuse-buildservice] [PATCH] Add --build-abuild-id to osc and build
  • From: David Greaves <david@xxxxxxxxxxxx>
  • Date: Fri, 08 May 2009 22:19:08 +0100
  • Message-id: <4A04A1CC.6040405@xxxxxxxxxxxx>
When building locally in a qemu/chroot and debugging I find I want to edit the
files in the chroot from my desktop gui editor but they're all owned by 399:399.

This pair of patches allows me to set the uid:gid to match my local user and
eases this process.

usage is:
build --build-abuild-id uid:gid

or more usually:
osc build --build-abuild-id 500:500

osc also accepts (and extends the default) .oscrc settings:
build-abuild-id = 500:500

It only supports numeric ids.

David


--
"Don't worry, you'll be fine; I saw it work in a cartoon once..."
Binary files osc-0.117/osc/babysitter.pyc and osc-0.117lbt/osc/babysitter.pyc
differ
diff -uNr osc-0.117/osc/build.py osc-0.117lbt/osc/build.py
--- osc-0.117/osc/build.py 2009-04-22 12:16:00.000000000 +0100
+++ osc-0.117lbt/osc/build.py 2009-05-08 21:57:40.396766503 +0100
@@ -278,6 +278,18 @@
buildargs.append('--with %s' % opts._with)
if opts.without:
buildargs.append('--without %s' % opts.without)
+ if opts.build_abuild_id or config['build-abuild-id']:
+ buildidre = re.compile('^[0-9]{1,5}:[0-9]{1,5}$')
+ if opts.build_abuild_id:
+ if not buildidre.match(opts.build_abuild_id):
+ print >>sys.stderr, 'Error: build-abuild-id arg must be 2
colon separated numerics: "uid:gid"'
+ return 1
+ buildargs.append('--build-abuild-id %s' % opts.build_abuild_id)
+ elif config['build-abuild-id']:
+ if not buildidre.match(config['build-abuild-id']):
+ print >>sys.stderr, 'Error: build-abuild-id config must be 2
colon separated numerics: "uid:gid"'
+ return 1
+ buildargs.append('--build-abuild-id %s' %
config['build-abuild-id'])
# FIXME: quoting
# if opts.define:
# buildargs.append('--define "%s"' % opts.define)
Binary files osc-0.117/osc/cmdln.pyc and osc-0.117lbt/osc/cmdln.pyc differ
diff -uNr osc-0.117/osc/commandline.py osc-0.117lbt/osc/commandline.py
--- osc-0.117/osc/commandline.py 2009-04-23 10:25:38.000000000 +0100
+++ osc-0.117lbt/osc/commandline.py 2009-04-29 22:16:12.198461134 +0100
@@ -1979,6 +1979,9 @@
help='Run build as root. The default is to build as '
'unprivileged user. Note that a line "# norootforbuild" '
'in the spec file will invalidate this option.')
+ @cmdln.option('--build-abuild-id', metavar='uid:gid',
+ help='specify the numeric uid:gid pair to assign to the '
+ 'unprivileged "abuild" user')
@cmdln.option('--local-package', action='store_true',
help='build a package which does not exist on the server')
@cmdln.option('--alternative-project', metavar='PROJECT',
@@ -1999,9 +2002,9 @@
of the 'osc repos' output. BUILD_DESCR is either a RPM spec file, or a
Debian dsc file.

- The command honours packagecachedir and build-root settings in .oscrc,
- if present. You may want to set su-wrapper = 'sudo' in .oscrc, and
- configure sudo with option NOPASSWD for /usr/bin/build.
+ The command honours packagecachedir, build-root and build-abuild-id
+ settings in .oscrc, if present. You may want to set su-wrapper = 'sudo'
+ in .oscrc, and configure sudo with option NOPASSWD for /usr/bin/build.

If neither --clean nor --noinit is given, build will reuse an existing
build-root again, removing unneeded packages and add missing ones. This
Binary files osc-0.117/osc/commandline.pyc and osc-0.117lbt/osc/commandline.pyc
differ
diff -uNr osc-0.117/osc/conf.py osc-0.117lbt/osc/conf.py
--- osc-0.117/osc/conf.py 2009-04-22 12:16:00.000000000 +0100
+++ osc-0.117lbt/osc/conf.py 2009-05-08 20:30:51.758699798 +0100
@@ -48,6 +48,7 @@
'build-cmd': '/usr/bin/build',
'build-type' : '', # may be empty for chroot, kvm or xen
'build-root': '/var/tmp/build-root',
+ 'build-abuild-id': '399:399',
'build-device': '', # required for VM builds
'build-memory' : '',# required for VM builds
'build-swap' : '', # optional for VM builds
@@ -85,6 +86,12 @@
# /srv/oscbuild/%%(repo)s-%%(arch)s-%%(project)s-%%(package)s
#build-root = %(build-root)s

+# Numeric uid:gid to assign to the "abuild" user in the build-root
+# This is convenient when sharing the buildroot with ordinary userids
+# on the host.
+# This should not be 0
+build-abuild-id = 399:399
+
# extra packages to install when building packages locally (osc build)
# this corresponds to osc build's -x option and can be overridden with that
# -x '' can also be given on the command line to override this setting, or

diff -uNr build-2009.04.23/build build-2009.04.23lbt/build
--- build-2009.04.23/build 2009-04-22 09:15:50.000000000 +0100
+++ build-2009.04.23lbt/build 2009-05-08 20:35:51.166699320 +0100
@@ -36,6 +36,9 @@
# whether we have virtio support
kvm_virtio=

+# Default uid:gid for the build user
+ABUILD_UID=399
+ABUILD_GID=399
DO_INIT=true
DO_LINT=
DO_CHECKS=true
@@ -160,6 +163,11 @@
--debug
enable creation of a debuginfo package

+ --build-abuild-id uid:gid
+ Specify the uid and gid to use for abuild
+ This is useful if you are hacking in the buildroot.
+ This must be set to the same value if the buildroot is re-used.
+
Remember to have fun!

[*] Maximum RPM: http://www.rpm.org/max-rpm/
@@ -682,6 +690,16 @@
*-changelog)
CHANGELOG=true
;;
+ --build-abuild-id)
+ ABUILD_ID="$ARG"
+ if [[ ${BASH_VERSINFO[0]} -ge 3 && ! $ABUILD_ID =~
^[0-9]{1,5}:[0-9]{1,5}$ ]] ; then
+ echo "abuild argument must be uid:gid"
+ cleanup_and_exit
+ fi
+ ABUILD_UID=${ABUILD_ID%:*}
+ ABUILD_GID=${ABUILD_ID#*:}
+ shift
+ ;;
-*)
echo Unknown Option "$PARAM". Exit.
cleanup_and_exit 1
@@ -1170,12 +1188,12 @@

if test $BUILD_USER = abuild ; then
if ! egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
- echo 'abuild::399:399:Autobuild:/home/abuild:/bin/bash'
$BUILD_ROOT/etc/passwd
+ echo
"abuild::${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 8.10
- echo 'abuild::399:' >>$BUILD_ROOT/etc/group
+ echo "abuild::${ABUILD_GID}:" >>$BUILD_ROOT/etc/group
mkdir -p $BUILD_ROOT/home/abuild
- chown 399:399 $BUILD_ROOT/home/abuild
+ chown ${ABUILD_UID}:${ABUILD_GID} $BUILD_ROOT/home/abuild
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
@@ -1231,7 +1249,7 @@
rm -rf $BUILD_ROOT$TOPDIR
for i in BUILD RPMS/`uname -m` RPMS/i386 RPMS/noarch SOURCES SPECS SRPMS
BUILDROOT; do
mkdir -p $BUILD_ROOT$TOPDIR/$i
- test $BUILD_USER = abuild && chown 399:399 $BUILD_ROOT$TOPDIR/$i
+ test $BUILD_USER = abuild && chown ${ABUILD_UID}:${ABUILD_GID}
$BUILD_ROOT$TOPDIR/$i
done
test -e $BUILD_ROOT/exit && cleanup_and_exit

@@ -1289,7 +1307,7 @@

if test "$BUILDTYPE" = dsc ; then
rm -rf $BUILD_ROOT$TOPDIR/BUILD
- test $BUILD_USER = abuild && chown 399:399 $BUILD_ROOT$TOPDIR
+ test $BUILD_USER = abuild && chown ${ABUILD_UID}:${ABUILD_GID}
$BUILD_ROOT$TOPDIR
DEB_TRANSFORM=
DEB_SOURCEDIR=$TOPDIR/SOURCES
DEB_DSCFILE=$SPECFILE
@@ -1311,7 +1329,7 @@
fi

if test $BUILD_USER = abuild ; then
- chown -R 399:399 $BUILD_ROOT$TOPDIR/*
+ chown -R ${ABUILD_UID}:${ABUILD_GID} $BUILD_ROOT$TOPDIR/*
else
chown -R root:root $BUILD_ROOT$TOPDIR/*
fi
@@ -1563,7 +1581,7 @@
echo "... checking for files with abuild user/group"
BADFILE=
while read un gn fn ; do
- if test "$un" = abuild -o "$gn" = abuild -o "$un" = 399 -o "$gn" = 399
; then
+ if test "$un" = abuild -o "$gn" = abuild -o "$un" = "$ABUILD_UID" -o
"$gn" = "$ABUILD_GID" ; then
echo " $un $gn $fn"
BADFILE=true
fi
< Previous Next >
This Thread
  • No further messages