Using makepkg to create .deb packages & Repackaging .deb for Arch.

I’ve decided to write the article I wish I had read about two years ago

Let’s start with the latter topic. There are actually packages in the AUR which source and repackage packages from other distros. An example of this is the Vivaldi browser:

Note: if you create a package like this and add it to the AUR, according to the rules of submision (#5) you must name it using the -bin suffix (which was not done for vivaldi).

So here are the critical elements of the PKGBUILD:


package() {
    cd "${pkgdir}"
    tar xf "${srcdir}/data.tar.xz"

Note: the extension of that data archive can be different

I do not recommend this for any complex packages, unless you feel up to the task. You will also need to figure out and list the dependencies, which is tedious and time-consuming. You may also need to change certain directory paths, such as those for systemd service files, to their appropriate locations in Arch.

This is really useful if you need older software for some reason. Or pre-bult binaries for other architectures.

Now, the former and perhaps more interesting topic: Creating .deb packages with makepkg.
It really couldn’t be simpler, here’s an example:

pkgdesc="Lorem ipsum dolor sit amet"
makedepends=(git dpkg)

[[ $pkgarch == "amd64" ]] && _buildwith=(env GOOS=linux GOARCH=amd64)
[[ $pkgarch == "arm64" ]] && _buildwith=(env GOOS=linux GOARCH=arm64)
[[ $pkgarch == "armhf" ]] && _buildwith=(env GOOS=linux GOARCH=arm GOARM=6)

build() {
#fix name of binary
mv genericNameBin ${_pkgname}

#create binary
#export GOOS=linux
#export GOARCH=arm64
${_buildwith} go build otherfile.go

#create control file for the debian package
echo "Package: skywire" > ${srcdir}/control
echo "Version: ${pkgver}-${pkgrel}" >> ${srcdir}/control
echo "Priority: optional" >> ${srcdir}/control
echo "Section: web" >> ${srcdir}/control
echo "Architecture: arm64" >> ${srcdir}/control
echo "Depends: ${_debdeps}" >> ${srcdir}/control
echo "Maintainer: Me" >> ${srcdir}/control
echo "Description: ${pkgdesc}" >> ${srcdir}/control

package() {
#set up to create a .deb package

#install binaries
msg2 'installing binaries'
install -Dm755 ${srcdir}/${_pkgname} ${_pkgdir}/usr/bin/${_pkgname}
install -Dm755 ${srcdir}/${_pkgname}-1 ${_pkgdir}/usr/bin/${_pkgname}-1
install -Dm755 ${srcdir}/${_pkgname}-2 ${_pkgdir}/usr/bin/${_pkgname}-2

#install the system.d services TO THEIR PATH ON DEBIAN
install -Dm644 ${srcdir}/${_pkgname}.service ${_pkgdir}/etc/systemd/system/${_pkgname}.service
install -Dm644 ${srcdir}/${_pkgname}2.service ${_pkgdir}/etc/systemd/system/${_pkgname}2.service

#install the other binary
install -Dm755 ${srcdir}/otherbin ${_pkgdir}/usr/bin/otherbin

#install the control file and postinst script for the debian package
install -Dm755 ${srcdir}/control ${_pkgdir}/DEBIAN/control
install -Dm755 ${srcdir}/ ${_pkgdir}/DEBIAN/postinst

#create the debian package
cd $pkgdir
dpkg-deb --build ${_debpkgdir}
mv *.deb ../../
#exit so the arch package doesn't get built

So as you can see, I’m using some envs to make the directory to create the debian package in, inside the pkgdir. In the build, I’m generating the control file. You can have it as a static file but if you generate it, its easier to support other architectures.

You must observe the norms of where Debian expects to find things, that’s the only real challenge with this. You can even add right before the exit to move the built .deb package up to the current directory you are in, where the built arch package normally populates.

Makepkg is a fantastic tool and I have demonstrated the ease with which you can create packages for other distros and from other distro’s packages, in a similar way as you might create any regular package.

So how to do the obviously bad idea you’re probably having right now and get makepkg to run on debian?

It can be done, but it is not for the faint of heart. You would need to port the following to debian:
* pacman
* pacman-static
* pacman-contrib
* pacman-mirrorlist
* yay

You might as well have yay if you are going to have everything else already, right?

I’m definitely not going to detail how to do that any further, but I will leave you with a better idea:

Use EndeavourOS and most of what you need will already be installed.

Follow us:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: