My linux world » Mock

Mock


Mock creates chroots and builds packages in them. Its only task is to reliably populate a chroot and attempt to build a package in that chroot.

Fedora projects

Contents

Objectives

Prerequiste

I assume that you have a Centos installation.

Installation

You can copy/paste this script and use it to configure automatically your server.

  1. #!/bin/bash
  2.  
  3. echo "install mock"
  4. dnf -y install mock
  5.  
  6. echo "only user who belongs to the group 'mock' can use mock. We add the user 'builder' to the mock group"
  7. echo " 1. create user builder"
  8. useradd builder
  9. echo " 2. unlock builder account (that will create /home/builder directory)."
  10. echo "set login/passwd : builder/builder"
  11. echo builder | passwd builder --stdin
  12. echo " 3. Add builder to the group 'mock'"
  13. usermod -G mock -a builder
  14.  
  15. echo "Now create mock for epel 6 (64 bits)"
  16. runuser -l builder -c 'mock -r epel-6-x86_64 --init'
  17. runuser -l builder -c 'mock -r epel-6-x86_64 chroot "cat /etc/issue"'
  18.  

How to use it?

First have a look to /etc/mock/. You will see all version you can use.
Important! You must login as ‘builder’ (or any user that belongs to ‘mock’ group).
Then type:

/usr/bin/mock -r my-version --init

Environment is here : /var/lib/mock/my-version

You can open a shell for the environment:

/usr/bin/mock -r my-version --shell

If you want to install package:

/usr/bin/mock -r my-version install yum

If you want to execute a command:

/usr/bin/mock -r my-version chroot "commands"

Copyright © 2024 My linux world - by Marc RABAHI
Design by Marc RABAHI and encelades.