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:

https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=vivaldi

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:


source=("http://ftp.us.debian.org/debian/pool/main/${pkgname:0:1}/${pkgname%-bin}/${pkgname%-bin}_${pkgver}_amd64.deb")

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:

 _pkgarch=arm64
pkgname=example-bin
_pkgname=example
_pkgname1=example-othername
_githuborg=SomeGithubOrg
pkgdesc="Lorem ipsum dolor sit amet"
_pkgver1='0.2.3'
_tag_ver='v0.2.3'
pkgver=${_pkgver1//-/.}
_pkggopath="github.com/${_githuborg}/${_pkgname1}"
pkgrel=2
arch=('any')
url="https://${_pkggopath}"
license=()
makedepends=(git dpkg)
depends=()
_debdeps="reprepro"
provides=(example)
_release_url=("${url}/releases/download/${_tag_ver}/${_pkgname}-${_tag_ver}")
source=("${_release_url}-linux-${_pkgarch}.tar.gz"
"postinst.sh"
'example.service'
'example2.service'
'otherfile.go')
sha256sums=('9a41a13604dab1971e0c4a8200fbaa6d0bb77d8c19d6d6e5702bbd02e661078d'
            'a09bef654583c2b3d1fbfdb0647e713dc5ede6bb5675293b51b7b3164ef863b8'
            '99a01866a21a02b7c972262cb054da718419d4e8d37dcd36cefbb5b17d877867'
            '7c7e7713c14a949f44faac18c3badee87e3c99987aaaa28a6ebef5022dd13f86'
            'a44f65d1d3b218512556d8a4a44fbe9c65f4d64cc699859157aa9568cee5422e')

[[ $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
_debpkgdir=${_pkgname}-${pkgver}-${pkgrel}-${_pkgarch}
_pkgdir=${pkgdir}/${_debpkgdir}

#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}/postinst.sh ${_pkgdir}/DEBIAN/postinst

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

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: