OpenSource in action

    Very often on the network you can find lengthy discussions about the undoubted benefits of open source software, about the motivation of programmers involved in such projects and so on. In addition, the fact that any user of such software with certain technical skills will be able to “sharpen" all this good for themselves is especially noted. Say, it’s not for nothing that the source code is open.

    However, personally I know very few people (to be honest, only two) who at least to a small extent took advantage of the open source code of the programs they use. Key arguments: I do not know where to get this code; I don’t know how to collect all this later; I'm afraid to make garbage out of my distribution kit by building my own modules.

    In this short article, I will try to give a simple example of how you can modify something, while maintaining a slender package and repository distribution structure.

    To illustrate all the techniques and mechanisms, I set myself a fairly simple, but no practical value goal: I have a frequently used wget utility and I have nosebleed, as I want it to greet me every time I start. Here I want and that's it. We will strive for this.


    Since I performed all the manipulations described below on my home distribution (Fedora), then we will consider the utilities and commands related to this particular assembly. There will be differences on other systems (deb instead of rpm, aptitude instead of yum), but we are mostly interested in the methodology, not the details.

    To work, we need the installed packages yum-utils and rpm-build.

    So, for starters, we need to decide which package our executable belongs to: Aha, our package is called “wget”. Now we need its source codes. In addition to binary packages, packages with source codes are usually stored in repositories, so we do not need to look for anything anywhere. It is enough to use the built-in tools: After executing this command, an rpm package will appear in the current directory containing the source codes of the current version of interest to us. It must be installed:

    [root@phantomazz ~]$ rpm –qf `which wget`
    wget-1.11.4-3.fc11.x86_64




    [root@phantomazz ~]$ yumdownloader --source wget




    [root@phantomazz ~]$ rpm –ivh wget-1.11.4-3.fc11.src.rpm


    All further actions will occur in the folder '/ root / rpmbuild', which will be automatically created when installing the package with source codes. It is there, in the subfolder 'SOURCES' we will find directly the archive with the source codes 'wget-1.11.4.tar.bz2'. Further, a technical matter: unzip the archive, find the file 'main.c', in the main function make the changes we are interested in (add the desired printf), and, attention, pack everything back into the archive with the same name. We will not build a separate module - we are interested in the whole package, because this is correct. There are no 'make && make install', after which you will not find the ends, only packages, especially since all the infrastructure necessary for this is already prepared. The thing is small - go to the directory '/ root / rpmbuild / SPECS' and execute:

    [root@phantomazz ~]$ rpmbuild -bb wget.spec


    The rpmbuild utility will itself build the binary modules and pack everything into a single package. It acts in accordance with the .spec file, so at this stage there is also the opportunity to make your own changes: add or remove any files from the package, modify installation scripts, and so on. The mechanism has a certain flexibility.

    In total, at the output in the '/ root / rpmbuild / RPMS' folder, we will receive a package that is ready either for immediate installation on our system or for further distribution to similar owners of megalomania who like their utilities to greet them.

    As a continuation of the topic, it is possible to write a patch (by the way, examples of patches can be found in the source code directory) that automates the assembly of the package with the functionality we need in future versions, and it is also possible to prohibit further updating of this package in general if it suits us. The master's business.

    Also popular now: