Wednesday, March 25, 2009

Gentoo Easy Handling

    First of all a brief explanation of how gentoo works (a simplification of look for a more extensive explanation).

    Gentoo works with two kinds of software trees: the stable tree, and the unstable one; Gentoo's installer portage works with ebuilds which contains all installation data, and everything gentoo needs to install a package. Inside of it there are one thing of interest: the KEYWORD variable which can determine wheter that package is marked as stable or not.

    Before starting to explain how gentoo works, it is interesting to mention how packages are handled, and how versions are handled first. Gentoo has a particular syntax for a package: "category/packagename", but for mentioning a particular version of a package, an operator is strictly needed, for example media-test/test-4.0.0 is incorrect, it should be something like =media-test/test-4.0.0 (you can use <,>,<=,>=,= or ~ operator, the ~ operator will select all revisions for a particular version, for example ~media-test/test-4.0.0 will select 4.0.0-r1, 4.0.0-r2, and so on)

    On the other hand, we have the keywords values:

  • Stable, is the value (substitute arch with yours, like for example x86, amd64...) and is meant to be tested enough by gentoo developers and users which will not break things (hopefully). For installing stable software, nothing else is required, only to execute "emerge ".
  • Unstable means that the package is not tested enough and may harm your system (other packages depending of it don't work anymore, etc), and it is not advised to install. They are keyworded with <~ARCH> value (for example ~x86, ~amd64, etc). To install this kind of packages you have to include the line category/package ~arch to your /etc/portage/package.mask
  • But there are more, sometimes, there are certain situations a bit more special: when a package is listed in package.mask file, or also known as hard masked. This happens when a package is known to cause severe problems to rest of system or only if it's too new to be tested. To install this software, you must unmask it by adding the line "category/package" to your /etc/portage/package.unmask
  • There are cases where you need to manually hard mask a package to prevent it from beeing installed in an update (usefull when you mix between stable and unstable branches and don't want a conflictive package to be updated). In this case, it is enough with adding category/package to /etc/portage/package.mask
    In order to simplify this task, I've created a script to simplify this task. This script is rather simple to be used, and it is autoinstallable, you just need to copy/paste to a file, and run (as root) ./ arch (substitute arch your your architecture).

    After installing, the usage is: gentoo [keyword/mask/unmask] and it will add the correspondent line to the correspondent file inside your /etc/portage directory.

    I hope it could be usefull to someone else than me :) and maybe I could update it adding functions or correcting bugs.


The Script:

#! /bin/bash
if [ -z $1 ]; then
echo "Use ./$0 [ARCH]!"

echo "Gentoo Easy Handling"
echo "By StormByte ("
echo "Execute this as root!"

echo "
echo \"Gentoo Easy Handling\"
echo \"By StormByte (\"
echo \"Remember to execute it as root or as user inside Gentoo group!\"


function usage {
echo \"Use gentoo [keyword/unmask/mask] category/package\"

function display {
echo \"Package \$2 added.\"

if [ -z \$2 ]; then
elif [ \$1 == \"keyword\" ]; then
echo \"\$2 ~\$ARCH\" >> /etc/portage/package.keywords
elif [ \$1 == \"unmask\" ]; then
echo \"\$2\" >> /etc/portage/package.unmask
elif [ \$1 == \"mask\" ]; then
echo \"\$2\" >> /etc/portage/package.mask

" >> /usr/bin/gentoo
chown root:portage /usr/bin/gentoo
chmod 775 /usr/bin/gentoo
echo "Installed under /usr/bin, name of command: gentoo"
echo "For more instructions of how to use it, invoke gentoo without arguments"

No comments: