Page 1 of 1

Scripts for rpm building in pure chroot environment

PostPosted: Nov 14th, '14, 18:24
by xxblx
I wrote it for myself. But may be it will be useful for someone else.

Mageia-chroot scripts is a set of bash-scripts for using Mageia on chroot.
  • mageia-chroot.tarball - Generate tarball (tar.gz archive) with Mageia (in-chroot installed packages: basesystem-minimal, urpmi and rpm-build).
  • mageia-chroot.rpmbuild - Rebuild src.rpm(s) to rpm(s). (must be used only with tarballs generated by mageia-chroot.tarball)
  • mageia-chroot.install - Install Mageia to chroot, but not make tarball.
  • mageia-chroot.unpack - Unpack a tarball (tar.gz) with Mageia for using in chroot.
  • mageia-chroot.run - Run chroot.
Git-repository on bitbucket.org: https://bitbucket.org/xxblx/mageia-chroot

Help & Usage available in git-repos's wiki: https://bitbucket.org/xxblx/mageia-chroot/wiki/Home

Few examples
* tarball generation
Spoiler:
Code: Select all
# ./mageia-chroot.tarball -d http://ftp.belnet.be/mageia/distrib/4/i586 -p /mnt/mageia-chroot/ -m /home/user/.rpmmacros

At this example will be created tarball with next properties:
  • chroot's dir: /mnt/mageia-chroot
  • Mageia release: 4
  • Mageia arch: i586
  • Mageia official repo's mirror: ftp.belnet.be by http
  • /home/user/.rpmmacros will be placed to chroot's dir as /root/.rpmmacros and will be used in packages building
Result: Mageia4_i586.tar.gz will be created in $PWD.

Details see in wiki: https://bitbucket.org/xxblx/mageia-chro ... ot.tarball

* src.rpm rebuild to rpm
Spoiler:
Attention: All keys (-t, -o, -d, -m) must be placed before src.rpm(s) in command!

Code: Select all
# ./mageia-chroot.rpmbuild -t Mageia4_i586.tar.gz pkg.src.rpm

  • At this example will be used Mageia4_i586.tar.gz as tarball
  • pkg.src.rpm will be rebuild to pkg.rpm
  • Result (compiled rpm) will be placed in $PWD
Code: Select all
# ./mageia-chroot.rpmbuild -t Mageia4_i586.tar.gz -o /tmp pkg.src.rpm

Same as previous, but result (compiled rpm) will be placed to /tmp
Code: Select all
# ./mageia-chroot.rpmbuild -t Mageia4_i586.tar.gz -m /home/user/.rpmmacros pkg.src.rpm

/home/user/.rpmmacros will be used as /root/.rpmmacros at package building stage
Code: Select all
# ./mageia-chroot.rpmbuild -t Mageia4_i586.tar.gz -d http://packages.mageialinux.ru/mageia4/i586/ pkg.src.rpm

Mageia Russian Community (MRC) repository for Mageia 4, i586 will be added to system and used together with official repo's mirror added at tarball generation stage.
--
And, of course, you can rebuild few packages in one command
Code: Select all
# ./mageia-chroot.rpmbuild -t Mageia4_i586.tar.gz pkg[1].src.rpm pkg[2].src.rpm pkg[3].src.rpm ... pkg[n].src.rpm


Details see in wiki: https://bitbucket.org/xxblx/mageia-chro ... t.rpmbuild


If you have any questions, feel free to ask me.

Re: Scripts for rpm building in pure chroot environment

PostPosted: Nov 14th, '14, 22:16
by doktor5000
Dumb question: Where's the difference compared to iurt? Or compared to aum++

Re: Scripts for rpm building in pure chroot environment

PostPosted: Nov 14th, '14, 23:09
by xxblx
1.) Mageia-chroot scripts is not focused on rpms building only. In TODO list are scripts for one-command setup ssh, launching GUI applications from chroot, etc. Tarball and rpmbuild were just first scripts.
2). iurt == perl ; aum++ == c++ ; mageia-chroot scripts == bash. Bash script can by easy supported and modified by any advanced linux user or sysadmin. It's easily for read and edit.
3). I was need to get some practice is bash-scripting. So, mageia-chroot scripts is a result of my training :)

P.S. For example, yesterday I rebuild widelands b18 from cauldron to Mageia 4 i586. With aum++ building process was broken at ~95% of compilation progress with error ""No space left on device", but free space was over 90+ Gb at /home, 50+ at /, free inodes were too. With mageia-chroot.rpmbuild widelands rpms were successfully build from the first time. Look like aum++ sometimes has problems with /tmp and tmpfs using.

Re: Scripts for rpm building in pure chroot environment

PostPosted: Nov 20th, '14, 02:40
by xxblx
New scripts:
  • mageia-chroot.install - Install Mageia to chroot, but not make tarball.
  • mageia-chroot.unpack - Unpack a tarball (tar.gz) with Mageia for using in chroot.
  • mageia-chroot.run - Run chroot.

Re: Scripts for rpm building in pure chroot environment

PostPosted: Jan 14th, '15, 21:12
by paiiou
Good evening,
I discovered this page these last days.
These scripts are very interesting. Thank you very much.
I allowed to adapt some to my way of working.
You can find them at the following address:
http://paiiou.free.fr/Tuto/Install/mga5 ... ot.tarball
http://paiiou.free.fr/Tuto/Install/mga5 ... ot.deploie
http://paiiou.free.fr/Tuto/Install/mga5 ... oot.delete

Please note: t will maybe be necessary to adjust the encoding of your browser to UTF-8.

Re: Scripts for rpm building in pure chroot environment

PostPosted: Jan 14th, '15, 23:27
by xxblx
paiiou wrote:Good evening,
I discovered this page these last days.
These scripts are very interesting. Thank you very much.
I allowed to adapt some to my way of working.
You can find them at the following address:
http://paiiou.free.fr/Tuto/Install/mga5 ... ot.tarball
http://paiiou.free.fr/Tuto/Install/mga5 ... ot.deploie
http://paiiou.free.fr/Tuto/Install/mga5 ... oot.delete

Please note: t will maybe be necessary to adjust the encoding of your browser to UTF-8.

Thanks for sharing. Very interesting.

Re: Scripts for rpm building in pure chroot environment

PostPosted: Jan 22nd, '15, 00:30
by paiiou
Hello,
I had a problem of building a package. It is an error when I builds under root.
I am modifying my scripts to build with my paiiou pen name.

I execute now my script with my normal user.
In my script, I use sudo for the commands which require.
Sudo is configured correctly.
It works very well for:
sudo urpmi.addmedia --distrib --urpmi-root "${CHPATH}" "${MIRROR}"
and for
sudo urpmi --auto --urpmi-root "${CHPATH}" basesystem-minimal urpmi locales-fr mc

On the other hand, I have an error with sudo cp file "${CHPATH}"
or with sudo echo "bla bla bla" > "${CHPATH}"/file
=> Permission non accordée

If I execute the command outside the script, directly in a terminal of Xfce, I do not have error.

You have an idea why it does not work in the script? How to by-pass?

Re: Scripts for rpm building in pure chroot environment

PostPosted: Jan 22nd, '15, 00:58
by xxblx
Hello.

On the other hand, I have an error with sudo cp file "${CHPATH}"
or with sudo echo "bla bla bla" > "${CHPATH}"/file
=> Permission non accordée

When you work with sudo, you work from user. Check premissions of your user on ${CHPATH}. May be you need to set yours user as an owner of ${CHPATH} or add to user write premission.

Re: Scripts for rpm building in pure chroot environment

PostPosted: Jan 22nd, '15, 11:23
by paiiou
Thank you for the answer.
I verified the owner of the directory. It is good root.
In fact, cp work correctly.
It is echo which does not work, I think because of the contents: sudo echo "useradd -m $pseudo"
I by-passed the problem by copying a file which contains the command.

I continuous the modification of my scripts with sudo.

Re: Scripts for rpm building in pure chroot environment

PostPosted: Jan 22nd, '15, 23:36
by paiiou
Good evening,
I thought of having ended my modifications.
My scripts seemed good to work.
I created a user 'paiiou' in the chroot, with ' useradd m u on 1100-p " " paiiou ' .
(This user does not exist in the normal installation).

With ' sudo chroot CHPATH ', I reach well the chroot.
But when I make su paiiou, it answers me that the user paiiou does not exist.
Nevertheless it appears well in files /etc/group, etc/passwd ... in the chroot.

I think that there must also exist (or only?) In the basic system.
I will try tomorrow

Georges (alias Paiiou)

Re: Scripts for rpm building in pure chroot environment

PostPosted: Jan 23rd, '15, 00:07
by xxblx
paiiou wrote:I think that there must also exist (or only?) In the basic system.

If you want to access to system inside chroot as some specific user (for example, paiiou), you can just setup openssh-server in chrooted system for it. Once you will need on opensssh-server configure - to set not-default (!= 22) port in ${CPATH}/etc/ssh/sshd_config, for example. set 2212.
In this way you can access to chroot by ssh as long as /proc mounted to ${CPATH}/proc.
Code: Select all
ssh paiiou@localhost -p 2212


If will troubles with shell after login
add to /etc/fstab
Code: Select all
none /dev/pts devpts defaults 0 0

and exec mount, of course
Code: Select all
mount /dev/pts

Re: Scripts for rpm building in pure chroot environment

PostPosted: Jan 27th, '15, 10:48
by paiiou
Hello,
I was not able to connect in chroot with ssh.
It is not because of the firewall: I have it for a moment deactivate.

I then took back the tries with the scripts derived of your:
- launched as root
- acces with chroot command
- and then only user's change with su - paiiou

It works perfectly now.

Here are the scripts:
http://paiiou.free.fr/Tuto/Install/mga5/build : Preparation of the system
http://paiiou.free.fr/Tuto/Install/mga5 ... ot.install
http://paiiou.free.fr/Tuto/Install/mga5 ... ot.tarball
http://paiiou.free.fr/Tuto/Install/mga5 ... oot.delete
http://paiiou.free.fr/Tuto/Install/mga5 ... ot.extract
http://paiiou.free.fr/Tuto/Install/mga5 ... hroot.goto

Thank you again for your help

Re: Scripts for rpm building in pure chroot environment

PostPosted: Mar 19th, '15, 17:25
by xxblx
I added new options to mageia-chroot.run
-x app_name # launch X11-apllication inside chroot
-f # (use with -x) install application if that not installed inside chroot yet.

That feature is not useful for packaging, but can be used for applications isolation (for security task or for testing for example).

[paranoid_mode]
For example, it's possible to isolate skype inside chroot and easy run it inside chroot.

I installed new clean system to /mnt/skype-chroot (via mageia-chroot.install) and installed skype inside this system.

I added to ~/.bashrc
Code: Select all
alias skype="pkexec /home/xxblx/Development/SOURCES/Bash/mageia-chroot/mageia-chroot.run -p /mnt/skype-chroot -x skype"


And now can easy run skype inside isolated chroot environment in one command
Code: Select all
skype


Also I created desktop-file ~/.local/share/applications/skype.desktop
Code: Select all
[Desktop Entry]
Name=Skype (isolated)
Comment=Skype Internet Telephony
Exec=/home/xxblx/Development/SOURCES/Bash/run_skype
Icon=skype
Terminal=false
Type=Application
Categories=Network;

And easy can run isolated skype from applications menu.

Content of /home/xxblx/Development/SOURCES/Bash/run_skype same to skype alias
Code: Select all
[xxblx@localhost ~]$ cat /home/xxblx/Development/SOURCES/Bash/run_skype
#!/bin/bash

pkexec /home/xxblx/Development/SOURCES/Bash/mageia-chroot/mageia-chroot.run -p /mnt/skype-chroot -x skype

[/paranoid_mode]

Re: Scripts for rpm building in pure chroot environment

PostPosted: Jan 3rd, '16, 14:32
by xxblx
New option in mageia-chroot.tarball:
-l - put directory with installed system into tarball with relative path (see --one-file-system in tar --help)

example: system installed into /mnt/chroot
by default in tarball first level will be - mnt
with -l first level will be right chroot

Re: Scripts for rpm building in pure chroot environment

PostPosted: Aug 16th, '16, 14:23
by plspls
is there same script for apt package chroot environment?