An ebuild file is a text file, used by Gentoo package managers, that identifies a specific software package, and how the Gentoo package manager should deal with it. It uses a bash syntax style and is standardized through the EAPI version .
Gentoo Linux uses ebuilds as the package management format for individual software titles. These ebuilds contain metadata about the software (the name and version of the software, which the software uses and the home page), dependency information (both at creation time and at run time) and instructions on how to deal with the software ( configure, build, install, test …).
When you set up Gentoo, you probably remember that you had to download and decompress a snapshot Gentoo repository. This snapshot (which you upgrade when you run emerge --sync
) is full of ebuilds, it’s Gentoo’s repository and once it’s uncompressed it’s usually located at /usr/portage.
If you decide to create an ebuild inside
/usr/portage
, eg/usr/portage/hello-world.ebuild
, runningemerge --sync
will automatically delete it, there are rules for it is accepted in the Portage directory tree.
You must have sudo or root privileges.
mkdir -p /usr/local/portage/app-misc/hello-world
Notice that we need to create in /usr/local/ and not in ~/usr/portage/~
Then use cd $_
to enter the created directory, variable $_ saves the last argument executed.
vim ./hello-world-1.0.ebuild
Note that the ebuild header and header has already been autocompleted. The same (header only) could also be created copying from the Portage directory with the following command:
cp /usr/portage/header.txt ./hello-world-1.0.ebuild
# Copyright 2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=7
DESCRIPTION=""
HOMEPAGE=""
SRC_URI=""
LICENSE=""
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE=""
DEPEND=""
RDEPEND="${DEPEND}"
BDEPEND=""
SLOT ="0"
;~alpha ~arm ~hppa ~ia64 ~ppc64 ~s390 ~sh ~sparc
;make.conf
file;Remember that this is a basic example, there are other variables that can be consulted at: https://devmanual.gentoo.org/ebuild-writing/variables/. For more information about schema, see the file:
/usr/portage/skel.ebuild
.
Our ebuild got its final version as follows:
# Copyright 2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=7
DESCRIPTION="Print Hello world in Shell Script"
HOMEPAGE="http://terminalroot.com.br/"
SRC_URI="http://terminalroot.com.br/downs/hello-world.tar.gz"
LICENSE="MIT"
SLOT="0"
KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86"
Note that variables that have not been declared in our ebuild are not essential to its operation.
Content of our hello-world
(notice that it is without the .sh extension):
#!/usr/bin/env bash
# Simple examples for ebuild
# terminalroot.com.br
hello_world(){
printf "%s\n" "Hello world!"
}
hello_world
Create a directory named: hello-world-1.0
, and add the shell script inside it. Then just compress and upload to a web address:
tar zcvf hello-world-1.0.tar.gz hello-world-1.0 /
Now run the following command: ebuild hello-world-1.0.ebuild manifest clean merge
. Note that you first try to download your file from a mirror, but since it is not in the Gentoo mirrors, it will be downloaded from the specified * SRC_URI * value and saved in the /usr/portage/distfiles/hello-world-1.0.tar.gz
. So when it has the file, it can create a manifest (a Manifest
name file inside the directory where ebuild is), this contains a hash of our ebuild and that file downloaded to ensure integrity, so that the corruption produces errors.
Then the process emerges, integrity is checked first. So we can see that the file we download is automatically decompressed, which is very useful since we do not need to implement it any more. We can change this behavior by replacing its src_unpack
function by defining some variables using eclass that define such behavior; but we do not have to do this in this case.
But the installation does not occur, as we need to tell ebuild where to install our file.
For ebuild to install the final file, we need to assign an Ebuild Function that defines where it should be installed, for this we will use the src_install
function together with another function dobin that installs a binary in /usr/bin
, and sets the file mode to * 0755 * and sets the property to superuser or its equivalent in the system or installation at hand ie src_install
is required for our shell script hello-world to be later placed in /usr/bin
and made executable:
src_install () {
dobin hello-world
}
The final content of our ebuild was:
# Copyright 2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI = 7
DESCRIPTION = "Print Hello world in Shell Script"
HOMEPAGE="http://terminalroot.com.br/"
SRC_URI="http://terminalroot.com.br/downs/hello-world.tar.gz"
LICENSE="MIT"
SLOT="0"
KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86"
src_install(){
dobin hello-world
}
After adding the above function to ebuild, let’s run the command again:
ebuild hello-world-1.0.ebuild manifest clean merge
If all goes well, just run the terminal: hello-world
and you will see the output: Hello world!.
If you want to uninstall, use emerge: emerge -C hello-world
and if you also want to clean the distfiles: rm /usr/portage/hello-world
.
You do not need to remove the Manifest
file unless you want to.
Learn more: https://wiki.gentoo.org/wiki/Basic_guide_to_write_Gentoo_Ebuilds