pkgsrc (1/6)
Un bel outil présenté par Imil ce samedi, alors j’espère que mes notes seront à la hauteur ! Le thème d’aujourd’hui est le système de gestion de packages pkgsrc, aka “Package source”. Intimement lié à NetBSD, ce système de gestion de paquets est totalement multi-plateformes (Oui oui, même avec Windows ou Mac !)
Pour les néophytes, un package permet de distribuer un logiciel de façon standardisée sur plusieurs machines. En gros, c’est un outil qui va non seulement installer le bout de soft dont on a besoin, mais aussi les autres composants (pages de manuels, fichiers de conf, etc.) et faire les tâches annexes nécessaires (Gestion des droits, Création d’un utilisateur dédié, par exemple …). Bref, les packages, ça sert à ne pas faire des installations artisanales, et donc à gérer toutes ses machines de façon strictement uniforme. Vous en utilisez sûrement un sur votre système : apt, yum ou portage … Ça dépend de vos préférences (Je suis pas raciste, j’ai un ami qui utilise le gestionnaire de packages windows T.T).
Cependant, en 1994, FreeBSD introduit les ports, un système de packages basé sur les sources qui permet à chacun d’installer des applications en les recompilant sur sa plateforme et non pas en récupérant un binaire pré-compilé. L’idée est bonne, les gens de NetBSD la forkent et en font un système universel (C’est à dire Multi-OS) : pkgsrc en naitra !
Premier contact avec pkgsrc
Si pkgsrc est particulièrement associé à l’univers de NetBSD, il fonctionne totalement sur les autres OS. C’est d’ailleurs là son point fort, visiblement. Je vais donc voir en même temps que je tape ces notes comment l’utiliser sous Linux.
Installation (en bootstrap, sous Linux)
Sous NetBSD, l’arborescence associée à pkgsrc se trouve dans le répertoire /usr/pkgsrc. C’est normal, car il s’agit du système propre à cette distribution. Sous Linux, on peut le placer où l’on veut tant que ça n’interfère pas avec le système de packages existant.
Pour me mettre dans un contexte pas trop compliqué, je vais faire une installation de type “bootstrap”, c’est à dire dans mon répertoire home et sans utiliser les droits root.
Au lieu de s’installer dans /usr/pkgsrc, pkgsrc sera dans /home/rancune/pkgsrc :
$cd ~
$env CVS_RSH=ssh cvs -d anoncvs@anoncvs.NetBSD.org:/cvsroot checkout -P pkgsrc
Oui, ça utilise CVS … Si vous ne l’avez pas, il faudra l’installer ou alors passer par git (github.com/NetBSD/pkgsrc)
Les lignes défilent (le temps que CVS fasse son job), et vous vous retrouvez avec un zoli répertoire pkgsrc de 1.2G (Pour un système de packages, ce n’est pas si gros!)
En voici le contenu :
$cd pkgsrc
$ls
total 912
drwxr-xr-x 157 rancune rancune 4096 24 avril 15:34 archivers
drwxr-xr-x 529 rancune rancune 20480 24 avril 15:34 audio
drwxr-xr-x 56 rancune rancune 4096 24 avril 15:34 benchmarks
drwxr-xr-x 76 rancune rancune 4096 24 avril 15:34 biology
drwxr-xr-x 3 rancune rancune 4096 24 avril 15:34 bootstrap
drwxr-xr-x 75 rancune rancune 4096 24 avril 15:34 cad
drwxr-xr-x 156 rancune rancune 12288 24 avril 15:34 chat
drwxr-xr-x 95 rancune rancune 4096 24 avril 15:34 comms
drwxr-xr-x 161 rancune rancune 4096 24 avril 15:34 converters
drwxr-xr-x 83 rancune rancune 4096 24 avril 15:34 cross
drwxr-xr-x 2 rancune rancune 4096 24 avril 15:28 CVS
drwxr-xr-x 534 rancune rancune 36864 24 avril 15:34 databases
drwxr-xr-x 3309 rancune rancune 135168 24 avril 15:34 devel
drwxr-xr-x 3 rancune rancune 4096 24 avril 15:30 distfiles
drwxr-xr-x 4 rancune rancune 4096 24 avril 15:34 doc
drwxr-xr-x 192 rancune rancune 4096 24 avril 15:34 editors
drwxr-xr-x 417 rancune rancune 20480 24 avril 15:34 emulators
drwxr-xr-x 50 rancune rancune 4096 24 avril 15:34 filesystems
drwxr-xr-x 121 rancune rancune 4096 24 avril 15:34 finance
drwxr-xr-x 891 rancune rancune 36864 24 avril 15:34 fonts
drwxr-xr-x 483 rancune rancune 20480 24 avril 15:34 games
drwxr-xr-x 114 rancune rancune 4096 24 avril 15:34 geography
drwxr-xr-x 850 rancune rancune 36864 24 avril 15:34 graphics
drwxr-xr-x 59 rancune rancune 4096 24 avril 15:34 ham
drwxr-xr-x 170 rancune rancune 12288 24 avril 15:34 inputmethod
drwxr-xr-x 334 rancune rancune 20480 24 avril 15:34 lang
drwxr-xr-x 3 rancune rancune 12288 24 avril 15:31 licenses
drwxr-xr-x 410 rancune rancune 20480 24 avril 15:34 mail
-rw-r--r-- 1 rancune rancune 1965 12 févr. 2020 Makefile
drwxr-xr-x 491 rancune rancune 20480 24 avril 15:34 math
drwxr-xr-x 15 rancune rancune 4096 24 avril 15:34 mbone
drwxr-xr-x 104 rancune rancune 12288 24 avril 15:34 meta-pkgs
drwxr-xr-x 405 rancune rancune 20480 24 avril 15:34 misc
drwxr-xr-x 34 rancune rancune 4096 24 avril 15:34 mk
drwxr-xr-x 223 rancune rancune 12288 24 avril 15:34 multimedia
drwxr-xr-x 1041 rancune rancune 36864 24 avril 15:34 net
-rwxr-xr-x 1 rancune rancune 9382 29 déc. 2020 _NetBSD-pkgdb
drwxr-xr-x 30 rancune rancune 4096 24 avril 15:34 news
drwxr-xr-x 3 rancune rancune 4096 24 avril 15:32 packages
drwxr-xr-x 33 rancune rancune 4096 24 avril 15:34 parallel
-rwxr-xr-x 1 rancune rancune 2963 22 août 2018 pkglocate
drwxr-xr-x 79 rancune rancune 4096 24 avril 15:34 pkgtools
drwxr-xr-x 1776 rancune rancune 69632 24 avril 15:34 print
-rw-r--r-- 1 rancune rancune 2893 31 janv. 23:39 README.md
drwxr-xr-x 26 rancune rancune 4096 24 avril 15:34 regress
drwxr-xr-x 661 rancune rancune 36864 24 avril 15:34 security
drwxr-xr-x 46 rancune rancune 4096 24 avril 15:34 shells
drwxr-xr-x 922 rancune rancune 36864 24 avril 15:34 sysutils
drwxr-xr-x 3 rancune rancune 4096 24 avril 15:33 templates
drwxr-xr-x 1386 rancune rancune 53248 24 avril 15:34 textproc
drwxr-xr-x 268 rancune rancune 12288 24 avril 15:34 time
drwxr-xr-x 116 rancune rancune 4096 24 avril 15:34 wm
drwxr-xr-x 1082 rancune rancune 69632 24 avril 15:34 www
drwxr-xr-x 708 rancune rancune 36864 24 avril 15:34 x11
Comme on peut le voir, le “catalogue” des applis disponibles est sous forme de répertoires, correspondant à des catégories. Si par exemple on va visiter la catégorie “biology”, on y retrouve un répertoire par logiciel.
Ceci dit, l’installation n’est pas terminée. Pour préparer pkgsrc, on lance alors le script “bootstrap”, dans notre cas avec l’option unprivileged car nous ne souhaitons pas que les installations se fassent sur le système.
$cd /home/rancune/pkgsrc/bootstrap
$./bootstrap --unprivileged
Cette commande va avoir deux effets :
-
Un répertoire /home/rancune/pkg est créé.
-
bmake, la version BSD de make, est compilée et installée dans ce dernier.
Tout cela se termine sur le message suivant :
[...]
===========================================================================
Please remember to add /home/rancune/pkg/bin to your PATH environment variable
and /home/rancune/pkg/man to your MANPATH environment variable, if necessary.
An example mk.conf file with the settings you provided to "bootstrap"
has been created for you. It can be found in:
/home/rancune/pkg/etc/mk.conf
You can find extensive documentation of the NetBSD Packages Collection
in /home/rancune/pkgsrc/doc/pkgsrc.txt.
Thank you for using pkgsrc!
===========================================================================
Comme je suis un garçon obéissant, je rajoute donc les deux lignes suivantes dans mon bashrc :
export PATH="$PATH:/home/rancune/pkg/bin:/home/rancune/pkg/sbin"
export MANPATH="$MANPATH:/home/rancune/pkg/man"
Après avoir redémarré mon bash, je peux vérifier que cela semble fonctionner avec la commande pkg_info, qui liste les packages installés :
$pkg_info
bootstrap-mk-files-20180901 *.mk files for the bootstrap bmake utility
bmake-20200524nb1 Portable (autoconf) version of NetBSD 'make' utility
cwrappers-20220403 pkgsrc compiler wrappers
pkg_install-20211115 Package management and administration tools for pkgsrc
On notera la présence (installation automatique) de bmake : pkgsrc dépend de bmake et nécessite donc son installation ! Sous Linux, il faudra prendre bien garde à l’utiliser en lieu et place de (gnu)make.
Le répertoire pkg qui s’est créé contient d’ailleurs tous les répertoires habituels : bin, sbin, etc … C’est l’environnement dans lequel seront installés tous les softs fournis par pkgsrc. Pas de mélange avec le système, pas de conflit, pas de risque. J’aime bien ça !
$ls /home/rancune/pkg
total 28
drwxr-xr-x 2 rancune rancune 4096 24 avril 15:44 bin
drwxr-xr-x 2 rancune tty 4096 24 avril 15:45 etc
drwxr-xr-x 3 rancune rancune 4096 24 avril 15:44 libexec
drwxr-xr-x 6 rancune rancune 4096 24 avril 15:45 man
drwxr-xr-x 6 rancune rancune 4096 24 avril 15:45 pkgdb
drwxr-xr-x 2 rancune rancune 4096 24 avril 15:45 sbin
drwxr-xr-x 3 rancune rancune 4096 24 avril 15:44 share
Bon, l’installation de pkgsrc est finie … On joue ?
La configuration de pkgsrc
La configuration de pkgsrc se trouve dans le fichier etc/mk.conf
Comme nous somme sur un système bootstrappé, cela sera donc :
/home/rancune/pkg/etc/mk.conf
$ cat /home/rancune/pkg/etc/mk.conf
# Example /home/rancune/pkg/etc/mk.conf file produced by bootstrap-pkgsrc
# dim. 24 avril 2022 15:43:18 CEST
.ifdef BSD_PKG_MK # begin pkgsrc settings
ABI= 64
UNPRIVILEGED= yes
PKG_DBDIR= /home/rancune/pkg/pkgdb
LOCALBASE= /home/rancune/pkg
SYSCONFBASE= /home/rancune/pkg/etc
VARBASE= /home/rancune/pkg/var
PKG_TOOLS_BIN= /home/rancune/pkg/sbin
PKGINFODIR= info
PKGMANDIR= man
# WARNING: Changing PREFER_* after bootstrap will require rebuilding all
# packages with a dependency that switched between native/pkgsrc.
PREFER_PKGSRC= yes
.endif # end pkgsrc settings
C’est ici que nous pourrons affiner un peu nos réglages en termes de compilations : CFLAGS, LDFLAGS et autres joyeusetés.
Bon, et si on essayait d’installer quelquechose maintenant ?
Un exemple ?
Pour tester pkgsrc, nous allons installer l’utilitaire pkgfind, un outil de recherche parmi les paquets disponibles. On commence par se déplacer vers le bon répertoire :
$cd /home/rancune/pkgsrc/pkgtools/pkgfind
$ls
total 20
drwxr-xr-x 2 rancune rancune 4096 24 avril 15:32 CVS
-rw-r--r-- 1 rancune rancune 109 22 juin 2004 DESCR
drwxr-xr-x 3 rancune rancune 4096 24 avril 15:32 files
-rw-r--r-- 1 rancune rancune 856 4 juil. 2018 Makefile
-rw-r--r-- 1 rancune rancune 90 18 janv. 2005 PLIST
Comme on peut le voir, le contenu du répertoire n’est pas trop complexe. Il contient principalement un Makefile comprenant la recette pour compiler notre logiciel.
Nous allons procéder à ladite compilation avec bmake :
$ bmake
[..]
cc -DHAVE_NBCOMPAT_H=1 -I/home/rancune/pkgsrc/pkgtools/pkgfind/work/libnbcompat -I. -I. -O2 -D_FORTIFY_SOURCE=2 -DHAVE_CONFIG_H -c setmode.c
cc -DHAVE_NBCOMPAT_H=1 -I/home/rancune/pkgsrc/pkgtools/pkgfind/work/libnbcompat -I. -I. -O2 -D_FORTIFY_SOURCE=2 -DHAVE_CONFIG_H -c pwcache.c
ar cr libnbcompat.a glob.o md5c.o md5hl.o rmd160.o rmd160hl.o sha1.o sha1hl.o sha2.o sha2hl.o vis.o unvis.o fgetln.o fparseln.o lchflags.o setgroupent.o setpassent.o setprogname.o shquote.o strlcat.o strlcpy.o strmode.o setmode.o pwcache.o
ranlib libnbcompat.a
=> Adjusting pkgsrc directory.
===> Building for pkgfind-20111022
cc -O2 -D_FORTIFY_SOURCE=2 -DHAVE_NBCOMPAT_H=1 -I/home/rancune/pkgsrc/pkgtools/pkgfind/work/libnbcompat -L/home/rancune/pkgsrc/pkgtools/pkgfind/work/libnbcompat -Wl,-zrelro -Wl,-R/home/rancune/pkg/lib -o /home/rancune/pkgsrc/pkgtools/pkgfind/work/pkgfind-20111022/pkgfind /home/rancune/pkgsrc/pkgtools/pkgfind/work/pkgfind-20111022/pkgfind.c -lnbcompat
$ls
drwxr-xr-x 2 rancune rancune 4096 24 avril 15:32 CVS
-rw-r--r-- 1 rancune rancune 109 22 juin 2004 DESCR
drwxr-xr-x 3 rancune rancune 4096 24 avril 15:32 files
-rw-r--r-- 1 rancune rancune 856 4 juil. 2018 Makefile
-rw-r--r-- 1 rancune rancune 90 18 janv. 2005 PLIST
drwxr-xr-x 16 rancune rancune 4096 24 avril 18:45 work
$ls work/
total 8
drwxr-xr-x 6 rancune rancune 4096 24 avril 18:45 libnbcompat
drwxr-xr-x 3 rancune rancune 4096 24 avril 18:45 pkgfind-20111022
$ls work/pkgfind-20111022/
total 40
drwxr-xr-x 2 rancune rancune 4096 24 avril 18:45 CVS
-rwxr-xr-x 1 rancune rancune 18040 24 avril 18:45 pkgfind
-rw-r--r-- 1 rancune rancune 2620 24 avril 18:45 pkgfind.1
-rw-r--r-- 1 rancune rancune 8461 24 avril 18:45 pkgfind.c
Comme on peut le voir, les différentes étapes de la compilation se font dans le repertoire work/, créé à cet effet.
Il ne reste plus qu’à installer notre soft, encore une fois à l’aide de bmake :
$bmake install
===> Installing for pkgfind-20111022
=> Generating pre-install file lists
=> Creating installation directories
/usr/bin/install -c -s -o rancune -g rancune -m 755 /home/rancune/pkgsrc/pkgtools/pkgfind/work/pkgfind-20111022/pkgfind /home/rancune/pkgsrc/pkgtools/pkgfind/work/.destdir/home/rancune/pkg/bin/pkgfind
/usr/bin/install -c -o rancune -g rancune -m 644 /home/rancune/pkgsrc/pkgtools/pkgfind/work/pkgfind-20111022/pkgfind.1 /home/rancune/pkgsrc/pkgtools/pkgfind/work/.destdir/home/rancune/pkg/man/man1/pkgfind.1
=> Automatic manual page handling
=> Generating post-install file lists
=> Checking file-check results for pkgfind-20111022
=> Creating binary package /home/rancune/pkgsrc/pkgtools/pkgfind/work/.packages/pkgfind-20111022.tgz
===> Building binary package for pkgfind-20111022
=> Creating binary package /home/rancune/pkgsrc/packages/All/pkgfind-20111022.tgz
===> Installing binary package of pkgfind-20111022
===> Cleaning for pkgfind-20111022
Notre programme est maintenant installé dans /home/rancune/pkg.
Si c’est pas la classe ça … \o/
Installer directement des binaires avec pkgin
Si on ne veut pas tout recompiler, on peut également utiliser un outil permettant de télécharger directement des binaires et de les installer : pkgin !
(Preuve de qualité du logiciel, le nom d’un certain Imil apparaît dans les commits du projet … ^^)
Car nous ne sommes pas condamnés à toujours tout recompiler, il existe des build farms, qui vont faire le boulot et fournir des repositories de binaires. Parmis celles-ci, on peut notamment citer la société joyent qui fournit des binaires pour Mac, Linux, SmartOS et NetBSD !
Voici quelques commandes de bases :
- Pour mettre à jour la liste des paquets disponibles:
pkgin up
- Pour installer un package ( ici screen ):
pkgin in screen
- Pour rechercher un package :
pkgin se gnome
pkgin se gnome*.term
- Pour avoir un easter egg (bah quoi ? c’est important!)
pkgin tonic
Un peu comme apt, pkgin se configure au travers du fichier :
/home/rancune/pkg/etc/pkgin/repositories.conf
qui permet de choisir les repos que l’on souhaite utiliser.
Packageons un peu … pkgsrc-wip !
Il est maintenant temps de nous exercer à faire notre propre package, et devenir un peu plus actifs dans cette belle communauté.
Le projet pkgsrc-wip (Work in Progress) est un repo permettant de se “faire la main”. On y obtient l’accès après avoir montré patte blanche (Ca semble assez simple) et ça permet de soumettre ses propres paquets à la communauté. Après 10, 20 … 30 commits, vous serez peut-être remarqués et on vous proposera peut-être de rejoindre le projet officiel, qui sait ?
En tout cas, pour suivre cette voie, il faut commencer par cloner le repo git au bon endroit :
$cd /home/rancune/pkgsrc
$git clone git://wip.pkgsrc.org/pkgsrc-wip.git wip
Pour ça, pas besoin de permission.
Nous allons packager un superbe logiciel, mis au point par Maître Imil himself ! Il est disponible dans le repo gitlab suivant :
https://gitlab.com/iMil/truefalse
(Imil, dans sa grande sagesse, a taggué la version qui nous intéresse du doux nom de “v1.0”. Prenez la bonne version, c’est important !
Ce repo contient trois fichiers :
- truefalse.c
#include <stdlib.h>
int
main(int argc, char *argv[])
{
if (argc < 1)
return EXIT_SUCCESS;
return EXIT_FAILURE;
}
- un fichier Makefile (pour bmake)
PROG= truefalse
MAN=
.include <bsd.prog.mk>
- un README.md
This is a dummy repository to explain pkgsrc's packaging framework.
Les pré-requis
Avant de commencer, il va tout d’abord falloir indiquer à pkgsrc que nous sommes dévelopeur. Oui, c’est ici que le syndrôme de l’imposteur revient frapper à la porte, mais vous allez voir, ca va bien se passer.
Pour ce faire, on édite le fichier etc/mk.conf et on ajoute la ligne suivante :
PKG_DEVELOPER= yes
On installe ensuite le meta-package pkg_developer qui ramène tout ce dont nous allons avoir besoin pour ce nouveau job (Tu les sens arriver les responsabilités ? La pression qui monte ???)
$cd /home/rancune/pkgsrc/meta-pkgs/pkg_developer
$bmake
$bmake install
(Vous pouvez aller prendre un café, ça compile un moment !)
Si vous vous ennuyez pendant la compilation, vous pouvez préparer le répertoire pour notre package en attendant :
$mkdir ~/pkgsrc/wip/truefalse
Playskool présente : mon premier package !
L’outil url2pkg, installé précedemment par pkg_developer, va nous construire un template de package à partir d’une simple url au format tar.gz :
$cd ~/pkgsrc/wip/truefalse
$url2pkg https://gitlab.com/iMil/truefalse/-/archive/v1.0/truefalse-v1.0.tar.gz
===> Cleaning for truefalse-1.0
=> Bootstrap dependency digest>=20211023: found digest-20220214
=> Fetching truefalse-v1.0.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 492 100 492 0 0 1206 0 --:--:-- --:--:-- --:--:-- 1366
=> distinfo: unchanged.
=> Checksum BLAKE2s OK for truefalse-v1.0.tar.gz
=> Checksum SHA512 OK for truefalse-v1.0.tar.gz
===> Installing dependencies for truefalse-1.0
=> Tool dependency cwrappers>=20150314: found cwrappers-20220403
===> Checking for vulnerabilities in truefalse-1.0
===> Overriding tools for truefalse-1.0
===> Extracting for truefalse-1.0
Remember to run pkglint when you're done.
See ../../doc/pkgsrc.txt to get some help.
$ls
total 20
-rw-r--r-- 1 rancune rancune 130 25 avril 10:18 DESCR
-rw-r--r-- 1 rancune rancune 312 25 avril 10:18 distinfo
-rw-r--r-- 1 rancune rancune 425 25 avril 10:18 Makefile
-rw-r--r-- 1 rancune rancune 198 25 avril 10:18 PLIST
drwxr-xr-x 11 rancune rancune 4096 25 avril 10:18 work
Oooooh ! Un Makefile !!!
Nous allons visiter un peu les différents fichiers, en commençant par le Makefile:
# $NetBSD$
DISTNAME= truefalse-v1.0
PKGNAME= ${DISTNAME:S,-v,-,}
CATEGORIES= # TODO: add primary category
MASTER_SITES= https://gitlab.com/iMil/truefalse/-/archive/v1.0/
MAINTAINER= INSERT_YOUR_MAIL_ADDRESS_HERE # or use pkgsrc-users@NetBSD.org
HOMEPAGE= https://gitlab.com/iMil/truefalse/-/archive/v1.0/
COMMENT= TODO: Short description of the package
#LICENSE= # TODO: (see mk/license.mk)
.include "../../mk/bsd.pkg.mk"
Comme on peut le voir, il est relativement simple et comprend quelques blancs que nous allons renseigner.
Le champs PKGNAME, par exemple, contient le nom du package. Il est construit par une regexp à partir du DISTNAME en retirant le numéro de version.
Le champs CATEGORIES, lui, doit contenir la catégorie dans laquelle nous souhaitons ranger notre soft. Pour choisir, il suffit de sélectionner l’un des répertoires de /home/rancune/pkgsrc que nous avons vus plus haut.
Pour LICENSE, nous allons procéder de même. La liste des licences se trouve dans /home/rancune/pkgsrc/licenses, tout simplement. Le fichier mk/licenses.mk permet de voir quelles licences sont valides et comment.
Une fois rempli, notre fichier Makefile ressemble à cela :
# $NetBSD$
DISTNAME= truefalse-v1.0
PKGNAME= ${DISTNAME:S,-v,-,}
CATEGORIES= misc
MASTER_SITES= https://gitlab.com/iMil/truefalse/-/archive/v1.0/
MAINTAINER= truefalse@rancune.org
HOMEPAGE= https://gitlab.com/iMil/truefalse/-/archive/v1.0/
COMMENT= First attempt at making a package
LICENSE= original-bsd
.include "../../mk/bsd.pkg.mk"
Si on veut le compléter, tout un ensemble d’outils est disponible dans le répertoire mk de pkgsrc. Cela vaut le coup d’aller y faire une petite visite !
Le fichier DESCR, quand à lui, contient une description de notre paquet. Il est automatiquement rempli à partir du README.md de notre repo git, il n’y a qu’à adapter un peu !
# truefalse
This is a dummy repository to explain pkgsrc's packaging framework.
Le fichier distinfo contient les hashs BLAKE2s et SHA512 du fichier tar.gz contenant les sources. Il permettra à pkgsrc de les vérifier avant la compilation et l’installation.
$NetBSD$
BLAKE2s (truefalse-v1.0.tar.gz) = 0ebf7a1aaef5f20a6c0df0a0cb38cc9ff7cf1d7d511e18c2ad5a4ec7607265b4
SHA512 (truefalse-v1.0.tar.gz) = 0be26cb93917249540e7d0d37805dcd4540382df91fafc9b9c48a15b71d43059e1a26dbdc752110ac7f26bbeb77aad6c792006059cbea8c2c7976d72ab8bca67
Size (truefalse-v1.0.tar.gz) = 492 bytes
Et pour finir, PLIST contient une liste des fichiers qui seront installés sur le filesystem par notre paquet. Pour le moment, c’est un template vide :
$cat PLIST
@comment $NetBSD$
@comment TODO: to fill this file with the file listing:
@comment TODO: 1. run "/home/rancune/pkg/bin/bmake package"
@comment TODO: 2. run "/home/rancune/pkg/bin/bmake print-PLIST"
Nous allons le remplir bientôt !
On peut maintenant vérifier que nous avons bien fait les choses avec l’outil pkglint, qui permet de valider un package :
$pkglint
Looks fine.
Puisque tout est bon, nous pouvons commencer à voir si notre package compile bien :
$bmake clean
$bmake
=> Bootstrap dependency digest>=20211023: found digest-20220214
=> Checksum BLAKE2s OK for truefalse-v1.0.tar.gz
=> Checksum SHA512 OK for truefalse-v1.0.tar.gz
===> Installing dependencies for truefalse-1.0
=> Tool dependency cwrappers>=20150314: found cwrappers-20220403
===> Checking for vulnerabilities in truefalse-1.0
===> Overriding tools for truefalse-1.0
===> Extracting for truefalse-1.0
===> Patching for truefalse-1.0
===> Creating toolchain wrappers for truefalse-1.0
===> Configuring for truefalse-1.0
===> Building for truefalse-1.0
cc -O2 -D_FORTIFY_SOURCE=2 -c truefalse.c
cc -Wl,-zrelro -Wl,-R/home/rancune/pkg/lib -o truefalse truefalse.o
C’est beau quand ca marche !
Si vous êtes curieux, vous pouvez aller voir dans le répertoire work/ qui vient de se créer. Vous y retrouverez les différentes étapes de construction.
$ls -al work/
total 124
drwxr-xr-x 15 rancune rancune 4096 25 avril 12:16 .
drwxr-xr-x 3 rancune rancune 4096 25 avril 12:16 ..
-rw-r--r-- 1 rancune rancune 14 25 avril 12:16 .barrier_cookie
-rw-r--r-- 1 rancune rancune 14 25 avril 12:16 .build_done
drwxr-xr-x 5 rancune rancune 4096 25 avril 12:16 .buildlink
-rw-r--r-- 1 rancune rancune 561 25 avril 12:16 .build_makevars.mk
drwxr-xr-x 3 rancune rancune 4096 25 avril 12:16 .compiler
-rw-r--r-- 1 rancune rancune 14 25 avril 12:16 .configure_done
-rw-r--r-- 1 rancune rancune 561 25 avril 12:16 .configure_makevars.mk
drwxr-xr-x 4 rancune rancune 4096 25 avril 12:16 .cwrapper
-rw-r--r-- 1 rancune rancune 99 25 avril 12:16 .depends
-rw-r--r-- 1 rancune rancune 0 25 avril 12:16 .depends_done
drwxr-xr-x 2 rancune rancune 4096 25 avril 12:16 .error
drwxr-xr-x 2 rancune rancune 4096 25 avril 12:16 .error-done
-rw-r--r-- 1 rancune rancune 14 25 avril 12:16 .extract_done
-rw-r--r-- 1 rancune rancune 561 25 avril 12:16 .extract_makevars.mk
drwxr-xr-x 3 rancune rancune 4096 25 avril 12:16 .gcc
drwxr-xr-x 2 rancune rancune 4096 25 avril 12:16 .home
-rw-r--r-- 1 rancune rancune 0 25 avril 12:16 .patch_done
-rw-r--r-- 1 rancune rancune 561 25 avril 12:16 .patch_makevars.mk
drwxr-xr-x 2 rancune rancune 4096 25 avril 12:16 .pkgdb
drwxr-xr-x 2 rancune rancune 4096 25 avril 12:16 .pkginstall
-rw-r--r-- 1 rancune rancune 87 25 avril 12:16 .rdepends
-rw-r--r-- 1 rancune rancune 87 25 avril 12:16 .rrdepends
drwxr-xr-x 3 rancune rancune 4096 25 avril 12:16 .tools
-rw-r--r-- 1 rancune rancune 449 25 avril 12:16 .tools_done
-rw-r--r-- 1 rancune rancune 561 25 avril 12:16 .tools_makevars.mk
drwxr-xr-x 2 rancune rancune 4096 25 avril 12:16 truefalse-v1.0
drwxr-xr-x 2 rancune rancune 4096 25 avril 12:16 .warning
drwxr-xr-x 2 rancune rancune 4096 25 avril 12:16 .warning-done
-rw-r--r-- 1 rancune rancune 2915 25 avril 12:16 .work.log
-rw-r--r-- 1 rancune rancune 14 25 avril 12:16 .wrapper_done
-rw-r--r-- 1 rancune rancune 561 25 avril 12:16 .wrapper_makevars.mk
Installation
Avant de lâcher notre package dans la nature, il serait de bon ton de vérifier comment et où il va s’installer :
$bmake stage-install
=> Bootstrap dependency digest>=20211023: found digest-20220214
===> Checking for vulnerabilities in truefalse-1.0
===> Installing for truefalse-1.0
=> Generating pre-install file lists
install -c -s -o rancune -g rancune -m 555 truefalse /home/rancune/pkgsrc/wip/truefalse/work/.destdir/truefalse
=> Automatic manual page handling
=> Generating post-install file lists
=> Checking file-check results for truefalse-1.0
Ici, le prefix d’installation est work/.destdir … et on voit qu’il va nous placer l’executable directement en haut !
Nous allons donc modifier un peu le Makefile pour corriger cela :
# $NetBSD$
DISTNAME= truefalse-v1.0
PKGNAME= ${DISTNAME:S,-v,-,}
CATEGORIES= misc
MASTER_SITES= https://gitlab.com/iMil/truefalse/-/archive/v1.0/
MAINTAINER= truefalse@rancune.org
HOMEPAGE= https://gitlab.com/iMil/truefalse/-/archive/v1.0/
COMMENT= First attempt at making a package
LICENSE= original-bsd
INSTALLATION_DIRS= bin
do-install:
${INSTALL_PROGRAM} ${WRKSRC}/truefalse ${DESTDIR}/${PREFIX}/bin/truefalse
.include "../../mk/bsd.pkg.mk"
L’ajout de la cible do-install que nous faisons dans le Makefile est nécessaire parce que l’auteur du soft que nous packageons n’a pas mis en place de cible d’installation dans son projet (make install ne marche pas). Sinon, Cela marcherait tout seul sans que l’on ait besoin de faire quoi que ce soit !
On met également à jour le fichier PLIST:
bmake print-PLIST > PLIST
Et on reteste …
$bmake clean
===> Cleaning for truefalse-1.0
$bmake stage-install
=> Bootstrap dependency digest>=20211023: found digest-20220214
=> Checksum BLAKE2s OK for truefalse-v1.0.tar.gz
=> Checksum SHA512 OK for truefalse-v1.0.tar.gz
===> Installing dependencies for truefalse-1.0
=> Tool dependency cwrappers>=20150314: found cwrappers-20220403
===> Checking for vulnerabilities in truefalse-1.0
===> Overriding tools for truefalse-1.0
===> Extracting for truefalse-1.0
===> Patching for truefalse-1.0
===> Creating toolchain wrappers for truefalse-1.0
===> Configuring for truefalse-1.0
===> Building for truefalse-1.0
cc -O2 -D_FORTIFY_SOURCE=2 -c truefalse.c
cc -Wl,-zrelro -Wl,-R/home/rancune/pkg/lib -o truefalse truefalse.o
===> Installing for truefalse-1.0
=> Generating pre-install file lists
=> Creating installation directories
/usr/bin/install -c -s -o rancune -g rancune -m 755 /home/rancune/pkgsrc/wip/truefalse/work/truefalse-v1.0/truefalse /home/rancune/pkgsrc/wip/truefalse/work/.destdir//home/rancune/pkg/bin/truefalse
=> Automatic manual page handling
=> Generating post-install file lists
=> Checking file-check results for truefalse-1.0
Nickel :)
Cette fois-ci on y va pour de vrai:
$bmake install
=> Bootstrap dependency digest>=20211023: found digest-20220214
===> Checking for vulnerabilities in truefalse-1.0
=> Creating binary package /home/rancune/pkgsrc/wip/truefalse/work/.packages/truefalse-1.0.tgz
===> Building binary package for truefalse-1.0
=> Creating binary package /home/rancune/pkgsrc/packages/All/truefalse-1.0.tgz
===> Installing binary package of truefalse-1.0
Ça marche !!!!!!!!!!!!!!!!!
Oui, mais le gars qui a écrit ce soft a fait quelques erreurs … Au programme du prochain épisode, nous allons proposer un patch upstream et voir comment on fait !
Le mot de la fin …
Bien que je sois beaucoup plus familier de portage, sous gentoo, le duo pkgsrc/pkgin me semble bien sexy ! De façon générale, les packages installés par ces deux outils sont un univers autonome et distinct du reste du système. Il n’y a donc aucun risque que je fasse une bêtise, comme cela m’est souvent arrivé à mes débuts.
J’avoue, j’ai hâte d’en voir la suite :)
Rancune.
La bibliographie :
-
Une vieille présentation écrite par Imil, pour le FOSDEM 2012:
-
Un article de blog, lui aussi par Imil :
-
Le site web de joyent
-
Les documents de netbsd.org :
-
L’article de Jonathan Perkin, sur pkgsrc dans SmartOS
-
Et bien sûr, la vidéo sur laquelle se basent ces notes !