4. Empacotando um novo software¶
Mesmo que haja milhares de pacotes no arquivo do Ubuntu, ainda há os que ninguém pegou ainda. Se houver um programa que você acha que deva ganhar uma exposição maior, talvez você queira colocar a mão na massa e criar um pacote para o Ubuntu ou um PPA. Este guia irá mostrar passo-a-passo o processo de empacotamento e um novo programa.
Você deverá ler o artigo Preparando para preparar o seu ambiente de desenvolvimento.
4.1. Verificando o programa¶
O primeiro estágio no empacotamento é obter o tar da versão a partir do upstream (nós chamamos os autores dos aplicativos de “upstream”) e verificar se ele compila e executa.
Este guia irá mostrar como empacotar um aplicativo simples chamado GNU Hello que foi postado em GNU.org.
Download GNU Hello:
$ wget -O hello-2.10.tar.gz "http://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz"
Now uncompress it:
$ tar xf hello-2.10.tar.gz
$ cd hello-2.10
Este aplicativo utiliza um sistema de compilação de autoconfiguração, então nós devemos executar “./configure” para preparar para a compilação.
This will check for the required build dependencies. As hello
is a simple
example, build-essential
should provide everything we need. For more
complex programs, the command will fail if you do not have the needed libraries
and development files. Install the needed packages and repeat until the command
runs successfully.:
$ ./configure
Agora você pode compilar o fonte:
$ make
Se a compilação concluir com sucesso você poderá instalar e executar o programa:
$ sudo make install
$ hello
4.2. Iniciando um pacote¶
bzr-builddeb
includes a plugin to create a new package from a template. The
plugin is a wrapper around the dh_make
command. Run the command providing
the package name, version number, and path to the upstream tarball:
$ sudo apt-get install dh-make bzr-builddeb
$ cd ..
$ bzr dh-make hello 2.10 hello-2.10.tar.gz
Quando for perguntado o tipo de pacote, digite “s” para um único binário. Isto irá importar o código para um ramo e adicionar o diretório de empacotamento “debian/”. Dê uma olhada no conteúdo. A maioria dos arquivos adicionados são necessários somente para pacotes especializados (como módulos Emacs), então você pode começar removendo os arquivos de exemplo opcionais:
$ cd hello/debian
$ rm *ex *EX
Agora você deve customizar cada um dos arquivos.
In debian/changelog
change the
version number to an Ubuntu version: 2.10-0ubuntu1
(upstream version 2.10,
Debian version 0, Ubuntu version 1). Also change unstable
to the current
development Ubuntu release such as trusty
.
Much of the package building work is done by a series of scripts
called debhelper
. The exact behaviour of debhelper
changes
with new major versions, the compat file instructs debhelper
which
version to act as. You will generally want to set this to the most
recent version which is 9
.
control
contains all the metadata of the package. The first paragraph
describes the source package. The second and following paragraphs describe
the binary packages to be built. We will need to add the packages needed to
compile the application to Build-Depends:
. For hello
, make sure that it
includes at least:
Build-Depends: debhelper (>= 9)
Você também precisará preencher a descrição do programa no campo “Description:”.
“copyright” deve ser preenchido de acordo com a licença do código upstream. De acordo com o arquivo hello/COPYING, ela é GNU GPL 3 ou mais recente.
“docs” contém todos os arquivos de documentação do upstream que você acha que devam ser incluídos no pacote final.
“README.source” e “README.Debian” são necessários somente se o seu pacote tiver quaisquer características fora do padrão. Nós não temos, você pode excluí-los.
“source/format” pode ser deixado como está, ele descreve o formato da versão do pacote fonte e deve ser “3.0 (quilt)”.
O “rules” é o arquivo mais complexo. É um makefile que compila o código e o transforma em um pacote binário. Felizmente, a maior parte do trabalho hoje em dia é feita automaticamente pelo “debhelper 7” para que o alvo makefile universal “%” apenas execute o script “dh”, que irá executar tudo que for necessário.
Todos estes arquivos são explicados mais detalhadamente no artigo resumo do diretório debian.
Finalmente submeta o código para seu ramo de empacotamento:
$ bzr add debian/source/format
$ bzr commit -m "Initial commit of Debian packaging."
4.3. Construindo o pacote¶
Agora precisamos verificar se nosso empacotamento compila o pacote com sucesso e constrói o pacote binário .deb:
$ bzr builddeb -- -us -uc
$ cd ../../
“bzr builddeb” é um comando para construir o pacote no local atual. As opções “-us -uc” dizem que não é preciso que o GPG assine o pacote. O resultado será colocado em “..”.
Você pode visualizar o conteúdo do pacote com:
$ lesspipe hello_2.10-0ubuntu1_amd64.deb
Install the package and check it works (later you will be able to uninstall it
using sudo apt-get remove hello
if you want):
$ sudo dpkg --install hello_2.10-0ubuntu1_amd64.deb
You can also install all packages at once using:
$ sudo debi
4.4. Próximos passos¶
Even if it builds the .deb binary package, your packaging may have
bugs. Many errors can be automatically detected by our tool
lintian
which can be run on the source .dsc metadata file, .deb
binary packages or .changes file:
$ lintian hello_2.10-0ubuntu1.dsc
$ lintian hello_2.10-0ubuntu1_amd64.deb
To see verbose description of the problems use --info
lintian flag
or lintian-info
command.
For Python packages, there is also a lintian4python
tool that provides
some additional lintian checks.
Depois de efetuar uma correção no empacotamento, você pode reconstruí-lo usando “-nc” (no clean) não precisando construir tudo novamente:
$ bzr builddeb -- -nc -us -uc
Having checked that the package builds locally you should ensure it builds on a
clean system using pbuilder
. Since we are going to upload to a PPA
(Personal Package Archive) shortly, this upload will need to be signed to
allow Launchpad to verify that the upload comes from you (you can tell the
upload will be signed because the -us
and -uc
flags are not passed to
bzr builddeb
like they were before). For signing to work you need to have
set up GPG. If you haven’t set up pbuilder-dist
or GPG yet, do so
now:
$ bzr builddeb -S
$ cd ../build-area
$ pbuilder-dist trusty build hello_2.10-0ubuntu1.dsc
Quando você estiver feliz com seu pacote você irá querer que outros revisem-o. Você pode enviar para o ramo no Launchpad para revisão:
$ bzr push lp:~<lp-username>/+junk/hello-package
Enviá-lo ao PPA irá assegurar que ele pode ser construído e irá fornecer uma maneira fácil para você e os outros testarem os pacotes binários. Você deverá configurá um PPA no Launchpad e então enviar o pacote com “dput”:
$ dput ppa:<lp-username>/<ppa-name> hello_2.10-0ubuntu1.changes
You can ask for reviews in #ubuntu-motu
IRC channel, or on the
MOTU mailing list. There might also be a more specific
team you could ask such as the GNU team for more specific questions.
4.5. Submetendo para inclusão¶
Há várias maneira pelas quais um pacote pode entrar no Ubuntu. Na maioria dos casos, ir através do Debian primeiro pode ser a melhor maneira. Isto assegurará que o seu pacote alcançará o maior número de usuários, porque estará disponível não somente no Debian e no Ubuntu, mas também em todas as distribuições derivadas. Aqui estão alguns links úteis para enviar novos pacotes para o Debian:
Debian Mentors FAQ - debian-mentors is for the mentoring of new and prospective Debian Developers. It is where you can find a sponsor to upload your package to the archive.
Work-Needing and Prospective Packages - Information on how to file “Intent to Package” and “Request for Package” bugs as well as list of open ITPs and RFPs.
Debian Developer’s Reference, 5.1. New packages - The entire document is invaluable for both Ubuntu and Debian packagers. This section documents processes for submitting new packages.
In some cases, it might make sense to go directly into Ubuntu first. For instance, Debian might be in a freeze making it unlikely that your package will make it into Ubuntu in time for the next release. This process is documented on the “New Packages” section of the Ubuntu wiki.
4.6. Screenshots¶
Once you have uploaded a package to debian, you should add screenshots to allow propective users to see what the program is like. These should be uploaded to http://screenshots.debian.net/upload .