O que o dh_usrlocal realmente faz

3

A página do manual dh_usrlocal me parece um pouco enigmática:

It finds subdirectories of usr/local in the package build directory, and removes them, replacing them with maintainer script snippets (unless -n is used) to create the directories at install time, and remove them when the package is removed, in a manner compliant with Debian policy. These snippets are inserted into the maintainer scripts by dh_installdeb. See dh_installdeb(1) for an explanation of debhelper maintainer script snippets.

Scripts do Mainainer, snippets, -n ... OK, mas qual é o propósito ? Realmente cria diretórios (vazios?)?

Pode uma alma gentil explicar-me de uma maneira mais prática? Qual parte da política devo ler? Devo me importar se meu aplicativo é instalado com PREFIX=/usr ?

    
por Alois Mahdal 18.08.2017 / 03:09

1 resposta

5

O objetivo é ajudar na conformidade com as políticas por esse pacote. De acordo com a política do Debian (e, IIRC, o Filesystem Hierarchy Standard ou FHS ), os pacotes Debian oficiais não são permitidos para possuir arquivos ou diretórios em /usr/local - essa árvore de diretórios pertence ao administrador do sistema local.

De link :

(ênfase em negrito adicionada por mim)

9.1.2. Site-specific programs

As mandated by the FHS, packages must not place any files in /usr/local, either by putting them in the file system archive to be unpacked by dpkg or by manipulating them in their maintainer scripts.

However, the package may create empty directories below /usr/local so that the system administrator knows where to place site-specific files. These are not directories in /usr/local, but are children of directories in /usr/local. These directories (/usr/local/*/dir/) should be removed on package removal if they are empty.

Note that this applies only to directories below /usr/local, not in /usr/local. Packages must not create sub-directories in the directory /usr/local itself, except those listed in FHS, section 4.5. However, you may create directories below them as you wish. You must not remove any of the directories listed in 4.5, even if you created them.

Since /usr/local can be mounted read-only from a remote server, these directories must be created and removed by the postinst and prerm maintainer scripts and not be included in the .deb archive. These scripts must not fail if either of these operations fail.

For example, the emacsen-common package could contain something like

if [ ! -e /usr/local/share/emacs ]; then
    if mkdir /usr/local/share/emacs 2>/dev/null; then
        if chown root:staff /usr/local/share/emacs; then
            chmod 2775 /usr/local/share/emacs || true
        fi
    fi
fi

in its postinst script, and

rmdir /usr/local/share/emacs/site-lisp 2>/dev/null || true
rmdir /usr/local/share/emacs 2>/dev/null || true

in the prerm script. (Note that this form is used to ensure that if the script is interrupted, the directory /usr/local/share/emacs will still be removed.)

If you do create a directory in /usr/local for local additions to a package, you should ensure that settings in /usr/local take precedence over the equivalents in /usr.

However, because /usr/local and its contents are for exclusive use of the local administrator, a package must not rely on the presence or absence of files or directories in /usr/local for normal operation.

The /usr/local directory itself and all the subdirectories created by the package should (by default) have permissions 2775 (group-writable and set-group-id) and be owned by root:staff.

Veja também o link

dh_usrlocal remove esses diretórios do pacote e os substitui pelo código nos scripts de pacote (os scripts .postinst e .prerm ) para criar / excluí-los no momento da instalação / desinstalação, seguindo o exemplo dado no política.

Isto pode parecer fazer pouca diferença prática porque os diretórios ainda são criados na instalação e excluídos na desinstalação, mas o Debian considera a falha de um pacote em obedecer à política ser um erro tão sério quanto qualquer outro - adesão consistente e escrupulosa a política é um fator importante na garantia de qualidade para pacotes Debian.

    
por 18.08.2017 / 04:51