SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2015-02-25 18:28:12

twoion
Emerald Caffeine
From: 星界
Registered: 2012-05-11
Posts: 1,648

[Script] How to build a .deb package from a BunsenLabs git repository

For people who do not know how to build or do not have (yet) experience in building Debian packages the right way or are lost in the variety of tools that exist for building Debian packages from sources hosted in git repos, and for whacky developers, I have written a quick-and-dirty Bash script that automates the build process. Well, partially.

This script makes assumptions about how the repository is laid out and probably does not handle edge cases and special cases very well, or at all. The script has been tested only with the developer scripts on a sid/unstable system. Who knows if it works on stable/waldorf/wheezy. It should work on testing though. Or could. Whatever.

Don't use this.

Getting the script

You can just download the script directly.

You may also clone my repo and execute the script from there:

git clone https://github.com/2ion/git2deb.git
Synopsis
Usage:
  git2deb [-h] git-url [git-branch]
Where:
  -h          Print this message and exit
  git-url     Git clone URL, see git-clone(1)
  git-branch  Git branch the package sources are located on
Minimal dependencies:
  devscripts, equivs, dh-make, sudo, debhelper
Prerequisites

Install all of the packages listed above:

sudo apt-get install devscripts equivs dh-make sudo debhelper
Limitations

The script will only build packages which are in the package source format version 3.0. These packages have a lowercase 'debian' directory in their tree. Lots of the bunsen packages have not yet been converted (the have an uppercase DEBIAN directory). The script performs a superficial check and aborts if it fails.

I also forcibly set the package class argument of dh_make to -s = single binary, even when the package does build e.g. an architecture-independent package. Hitherto, it seems that regardless of the package class, packages are being built correctly. When leaving of the package class, the user is shown a selection prompt for the package class. Since noops don't know about this, I just went ahead with setting the flag. In the case of problems, I'll just remove it and enable the prompt again (you can do this, too).

The script will also refuse to run as root.

Example usage

Find a git-hosted Debian package you want to build, for example the deb8-theme package from Bunsen: https://github.com/BunsenLabs/deb8-theme. Find the 'git clone url' of that package; on Github it is being shown on the right:

https://github.com/BunsenLabs/deb8-theme.git

Note the git branch the debian package sources are located on. In our case, it is 'master'.

Go to the directory you want to find the built package in later, for example:

$ mkdir ~/deb8-theme-builds
$ cd ~/deb8-theme-builds

Run the script (supposing it is in your $PATH) like so:

git2deb https://github.com/BunsenLabs/deb8-theme.git master

The last argument 'master' is optional, it defaults to 'master' when omitted.

Text scrolls by, and you will be prompted for your sudo password twice: once for installing build dependencies using a helper package built on the fly, and once for removing that helper package again.

You should find the built package in your current working directory:

$ ls ~/deb8-theme-builds
deb8-theme_1.1-1_all.deb
deb8-theme_1.1-1_amd64.changes
deb8-theme_1.1-1.dsc

--
Edit: Moved git2deb to its own repo.

Last edited by twoion (2015-02-28 17:02:47)


Tannhäuser ~ {www,pkg,ddl}.bunsenlabs.org/{gitlog,repoidx}

Offline

Be excellent to each other!

#2 2015-02-25 21:39:06

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: [Script] How to build a .deb package from a BunsenLabs git repository

/subscribed

I have a few .deb packages I have to "unarchive" and change a dependency

This is 100% new territory for me - and then re-create the .deb package again 100% new territory.

All because python-central doesn't exist in Jessie/SID  --  mad  mad  mad  mad  mad

I'm in no big rush, I'm still running Waldorf and not sure if this will help me at all but ... I'm subscribed anyway.


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#3 2015-02-25 22:20:34

damo
#! gimpbanger
From: N51.5 W002.8 (mostly)
Registered: 2011-11-24
Posts: 5,434

Re: [Script] How to build a .deb package from a BunsenLabs git repository

@S11

If you want to just re-package a deb, to change dependencies or whatever, then @johnraff made a script to do just that.

There is also a handy HowTo over on the VSIDO forums:  Using dpkg-deb to remake a package

There are only 3 dpkg-deb commands you need to use wink


BunsenLabs Group on deviantArt
damo's gallery on deviantArt
Openbox themes
Forum Moderator smile

Offline

#4 2015-02-25 22:26:24

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: [Script] How to build a .deb package from a BunsenLabs git repository

OK, will check out johnraffs script of your work  smile

Thank you.


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#5 2015-02-26 02:03:59

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: [Script] How to build a .deb package from a BunsenLabs git repository

twoion thank you so much!!

Of course I intend to read up on all this, but there's work to do right now and this will speed things up a lot.  cool

twoion wrote:

The script will only build packages which are in the package source format version 3.0. These packages have a lowercase 'debian' directory in their tree. Lots of the bunsen packages have not yet been converted (they have an uppercase DEBIAN directory). The script performs a superficial check and aborts if it fails.

This conversion is a high priority right now. I'm not asking you to write me another script to do it, but I wonder if you can point out a quick-and-dirty guide to converting those repos to format 3, if such a guide exists? Or just list out the best tools and commands to use?


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
#! forum moderator    BunsenLabs

Offline

#6 2015-02-26 08:33:45

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: [Script] How to build a .deb package from a BunsenLabs git repository

So far, I've found this tutorial:
https://wiki.debian.org/IntroDebianPackaging
and with this
https://www.debian.org/doc/manuals/main … er.en.html
and with the files in Philip's original source package, I managed to hack bunsen-configs into what looks like some sort of shape.

Of course, much more work to be done, and most of it has been walking in the dark so far...


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
#! forum moderator    BunsenLabs

Offline

#7 2015-02-26 11:11:35

twoion
Emerald Caffeine
From: 星界
Registered: 2012-05-11
Posts: 1,648

Re: [Script] How to build a .deb package from a BunsenLabs git repository

johnraff wrote:

twoion thank you so much!!

Of course I intend to read up on all this, but there's work to do right now and this will speed things up a lot.  cool

twoion wrote:

The script will only build packages which are in the package source format version 3.0. These packages have a lowercase 'debian' directory in their tree. Lots of the bunsen packages have not yet been converted (they have an uppercase DEBIAN directory). The script performs a superficial check and aborts if it fails.

This conversion is a high priority right now. I'm not asking you to write me another script to do it, but I wonder if you can point out a quick-and-dirty guide to converting those repos to format 3, if such a guide exists? Or just list out the best tools and commands to use?

You can go along the commands in the script actually.

1. Get the old package sources
2. dh_make -p $packagename_$packageversion --createorig --addmissing # $packageversion: use from changelog or make new
3. debian has been created, populated with templates. Fill in, modify and re-use what has been available in the old package if possible
4. create stuff for the debhelpers, for example $package-name.install for installing files, 'docs' for listing docs. You may google the
template/example files that are in the directory if you're curious what they do. See man 7 debhelper for a long list of stuff you can do. debian/rules controls the build process and the invocation of all the debhelper tools. It's a makefile. You can use overrides like override_dh_install (override_$debhelper) and modify every aspect.
5. Useful too: http://debathena.mit.edu/config-package-dev/
6. dh_make -p $packagename_$packageversion --createorig # again, --createorig regenerates the pristine tarball after you've modified the package source!
7. dpkg-buildpackage -us -uc # unsigned package

You'll have questions: Is it ok to install files into users' homedirs (no it's not). How do I register a config file? How to I take over an existing config file from another package? How to handle dotfiles? What do the sections in debian/control mean? Etc. This stuff is written in the Debian Maintainers' Manual or the Debian Policy Manual.
--
I have kind of begun writing a packaging tutorial but it's not done yet. Actually, it won't be finsihed anytime soon. You can look here for whatever's there at the moment. There's a bunch of interesting links in there, too.


Tannhäuser ~ {www,pkg,ddl}.bunsenlabs.org/{gitlog,repoidx}

Offline

#8 2015-02-26 11:43:25

edps
Member
From: Rio de Janeiro, Brazil
Registered: 2012-05-19
Posts: 30
Website

Re: [Script] How to build a .deb package from a BunsenLabs git repository

this is amazing! big_smile

It would be a good idea to add the option -tc in the command  dpkg-buildpackage -us -uc?, like this:

dpkg-buildpackage -us -uc -b -tc

* after conclusion clean the source tree.

in the case of bunsen-pipemenus a error on the copy of the file README.md led me to packaging it in the traditional way:

[9145:9132 0:1942] 08:01:53 Qui Fev 26 [edps@debian: +1] ~/build/git/BunsenLabs/bunsen-pipemenus 
(1:1942)$ git2deb https://github.com/BunsenLabs/bunsen-pipemenus masterCloning into 'bunsen-pipemenus'...
remote: Counting objects: 81, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 81 (delta 1), reused 0 (delta 0), pack-reused 76
Unpacking objects: 100% (81/81), done.
Checking connectivity... done.
Already on 'master'
Your branch is up-to-date with 'origin/master'.
Maintainer name  : root
Email-Address    : root@localhost 
Date             : Thu, 26 Feb 2015 08:02:17 -0300
Package Name     : bunsen-pipemenus
Version          : 0.14
License          : blank
Type of Package  : Single
Currently there is no top level Makefile. This may require additional tuning.
You already have a debian/ subdirectory in the source tree.
dh_make will not try to overwrite anything.
dh_testdir
...
dh_builddeb
dpkg-deb: construindo pacote 'bunsen-pipemenus-build-deps' em '../bunsen-pipemenus-build-deps_0.14-4_all.deb'.

The package has been created.
Attention, the package has been created in the current directory,
not in ".." as indicated by the message above!
A seleccionar pacote anteriormente não seleccionado bunsen-pipemenus-build-deps.
(Lendo banco de dados ... 412224 ficheiros e directórios actualmente instalados.)
Desempacotando bunsen-pipemenus-build-deps (de bunsen-pipemenus-build-deps_0.14-4_all.deb) ...
Lendo listas de pacotes... Pronto
Construindo árvore de dependências       
Lendo informação de estado... Pronto
0 pacotes atualizados, 0 pacotes novos instalados, 0 a serem removidos e 1 não atualizados.
1 pacotes não totalmente instalados ou removidos.
Depois desta operação, 0 B adicionais de espaço em disco serão usados.
Configurando bunsen-pipemenus-build-deps (0.14-4) ...
(Lendo banco de dados ... 412227 ficheiros e directórios actualmente instalados.)
Removendo bunsen-pipemenus-build-deps ...
dpkg-buildpackage: source package bunsen-pipemenus
dpkg-buildpackage: source version 0.14-4
dpkg-buildpackage: source changed by Jens Oliver John <dev@2ion.de>
dpkg-buildpackage: host architecture i386
 dpkg-source --before-build bunsen-pipemenus
 fakeroot debian/rules clean
dh clean 
   dh_testdir
   dh_auto_clean
   dh_clean
 dpkg-source -b bunsen-pipemenus
dpkg-source: info: using source format `3.0 (quilt)'
dpkg-source: info: building bunsen-pipemenus using existing ./bunsen-pipemenus_0.14.orig.tar.gz
dpkg-source: info: building bunsen-pipemenus in bunsen-pipemenus_0.14-4.debian.tar.gz
dpkg-source: info: building bunsen-pipemenus in bunsen-pipemenus_0.14-4.dsc
 debian/rules build
dh build 
   dh_testdir
...
   dh_auto_test
 fakeroot debian/rules binary
dh binary 
   dh_testroot
...
   dh_installdocs
cp: cannot stat ‘README.md’: Arquivo ou diretório não encontrado
dh_installdocs: cp -a README.md debian/bunsen-pipemenus/usr/share/doc/bunsen-pipemenus returned exit code 1
make: ** [binary] Erro 2
dpkg-buildpackage: error: fakeroot debian/rules binary gave error exit status 2

manually:

[9145:9132 0:1947] 08:14:02 Qui Fev 26 [edps@debian: +1] ~/build/git/BunsenLabs/bunsen-pipemenus 
(1:1947)$ mv -v README README.md
‘README’ -> ‘README.md’

[9145:9132 0:1948] 08:14:22 Qui Fev 26 [edps@debian: +1] ~/build/git/BunsenLabs/bunsen-pipemenus 
(1:1948)$ mk-build-deps 
dh_testdir
...
...
dh_builddeb
dpkg-deb: construindo pacote 'bunsen-pipemenus-build-deps' em '../bunsen-pipemenus-build-deps_0.14-4_all.deb'.

The package has been created.
Attention, the package has been created in the current directory,
not in ".." as indicated by the message above!

[9145:9132 0:1923] 08:14:49 Qui Fev 26 [edps@debian: +1] ~/build/git/BunsenLabs/bunsen-pipemenus 
(1:1923)$ sudo dpkg -i bunsen-pipemenus-build-deps_0.14-4_all.deb 
A seleccionar pacote anteriormente não seleccionado bunsen-pipemenus-build-deps.
(Lendo banco de dados ... 412240 ficheiros e directórios actualmente instalados.)
Desempacotando bunsen-pipemenus-build-deps (de bunsen-pipemenus-build-deps_0.14-4_all.deb) ...
Configurando bunsen-pipemenus-build-deps (0.14-4) ...

[9145:9132 0:1927] 08:18:40 Qui Fev 26 [edps@debian: +1] ~/build/git/BunsenLabs/bunsen-pipemenus 
(1:1927)$ dpkg-buildpackage -us -uc -b -D -tc
dpkg-buildpackage: source package bunsen-pipemenus
dpkg-buildpackage: source version 0.14-4
dpkg-buildpackage: source changed by Jens Oliver John <dev@2ion.de>
dpkg-buildpackage: host architecture i386
 dpkg-source --before-build bunsen-pipemenus
 fakeroot debian/rules clean
dh clean 
   dh_testdir
   dh_auto_clean
   dh_clean
 debian/rules build
dh build 
   dh_testdir
...
   dh_auto_test
 fakeroot debian/rules binary
dh binary 
   dh_testroot
....
   dh_builddeb
dpkg-deb: construindo pacote 'bunsen-pipemenus' em '../bunsen-pipemenus_0.14-4_all.deb'.
 dpkg-genchanges -b >../bunsen-pipemenus_0.14-4_i386.changes
dpkg-genchanges: binary-only upload - not including any source code
 fakeroot debian/rules clean
dh clean 
   dh_testdir
   dh_auto_clean
   dh_clean
 dpkg-source --after-build bunsen-pipemenus
dpkg-buildpackage: binary only upload (no source included)

[9145:9132 0:1929] 08:23:47 Qui Fev 26 [edps@debian: +1] ~/build/git/BunsenLabs/bunsen-pipemenus 
(1:1929)$ sudo dpkg -i ../bunsen-pipemenus_0.14-4_all.deb 
A seleccionar pacote anteriormente não seleccionado bunsen-pipemenus.
(Lendo banco de dados ... 412228 ficheiros e directórios actualmente instalados.)
Desempacotando bunsen-pipemenus (de .../bunsen-pipemenus_0.14-4_all.deb) ...
Configurando bunsen-pipemenus (0.14-4) ...

[9145:9132 0:1929] 08:24:05 Qui Fev 26 [edps@debian: +1] ~/build/git/BunsenLabs/bunsen-pipemenus 
(1:1929)$ dpkg --get-selections | grep bunsen
bunsen-pipemenus				install
bunsen-pipemenus-build-deps			install

Offline

#9 2015-02-26 12:48:30

twoion
Emerald Caffeine
From: 星界
Registered: 2012-05-11
Posts: 1,648

Re: [Script] How to build a .deb package from a BunsenLabs git repository

edps wrote:

this is amazing! big_smile

It would be a good idea to add the option -tc in the command  dpkg-buildpackage -us -uc?, like this:

dpkg-buildpackage -us -uc -b -tc

* after conclusion clean the source tree.

This is not necessary, since all the cloning and building happens in a temporary directory which will be removed when the scripts exits anyway.

in the case of bunsen-pipemenus a error on the copy of the file README.md led me to packaging it in the traditional way

Thanks for the bug report. This happened because we forgot to reflect a change in the source in the package configuration. The problem is fixed in bunsen-pipemnus_0.14-5. The package should now build without user intervention.


Tannhäuser ~ {www,pkg,ddl}.bunsenlabs.org/{gitlog,repoidx}

Offline

#10 2015-02-26 13:37:30

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 13,970

Re: [Script] How to build a .deb package from a BunsenLabs git repository

johnraff wrote:

So far, I've found this tutorial:
https://wiki.debian.org/IntroDebianPackaging
and with this
https://www.debian.org/doc/manuals/main … er.en.html
and with the files in Philip's original source package, I managed to hack bunsen-configs into what looks like some sort of shape.

Of course, much more work to be done, and most of it has been walking in the dark so far...

Looks like you guys are getting a good start on this. cool  I've barely started doing my research, but I did find a kind of "master page" for Debian developers' manuals:
https://www.debian.org/doc/devel-manuals

Offline

#11 2015-03-01 03:14:15

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: [Script] How to build a .deb package from a BunsenLabs git repository

twoion, as a relative beginner here I hesitate to bring this up, but your line 73:

readonly pkgversion=$(head -n1 -- debian/changelog | cut -d' ' -f2 | tr -d '()' | cut -d- -f1)

Is cutting off everything after the first hyphen in the version number, right?
According to this, the upstream_version is allowed to contain hyphens, so shouldn't we be cutting off only the debian_revision, ie the part after the last hyphen? Like this, perhaps:

readonly pkgversion=$(sed -rn "s/^.*\(([^)]+)\).*$/\1/;s/-[^-]+$//p;q"  debian/changelog)

Or am I misunderstanding something as usual?   roll


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
#! forum moderator    BunsenLabs

Offline

#12 2015-03-02 08:34:55

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: [Script] How to build a .deb package from a BunsenLabs git repository

btw I've discovered that you can use a local path to a git repository instead of a url to github and the script works fine. You can make a .deb from your local git repo without pushing the changes up to github if you want to test something.  cool


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
#! forum moderator    BunsenLabs

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: acrobat

Debian Logo