Skip to content

Instantly share code, notes, and snippets.

@akesterson
Created March 14, 2014 20:38
Show Gist options
  • Save akesterson/9556321 to your computer and use it in GitHub Desktop.
Save akesterson/9556321 to your computer and use it in GitHub Desktop.
Per-user mock build chroot
# Add this code to your /etc/mock/site-defaults.cfg file, and then
# all of your mock builds will take place in ${HOME}/.mockbuild/CONFIG.
# This will allow many users to build the same package config (-r)
# at any given time; so john, tom, dick and harry can build epel-5-noarch
# at the same time, and john can build epel-5-noarch, epel-6-x86_64,
# and fedora-13-x86_64 at the same time, because they all have their own
# build basedir.
# Note that this is very linux specific, YMMV on other platforms.
import pwd
import os
sudouser=os.environ.get('SUDO_USER', '')
if sudouser:
homedir=pwd.getpwnam(sudouser).pw_dir
else:
homedir=pwd.getpwuid(os.getuid()).pw_dir
mockdir=os.path.join(homedir, ".mockbuild")
config_opts['basedir']=os.path.abspath(mockdir)
@akesterson
Copy link
Author

Also, the sudo checking is because mock performs privilege escalation, so by the time this code is being executed, python already thinks we're root, so we have to backtrack and find who we really are.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment