build deb package on archlinux

aur helper 我选择的是 paru,因为 paru 支持在干净的 chroot 中编包

sudo pacman -S --needed base-devel devtools git
git clone https://aur.archlinux.org/paru.git
cd paru
extra-x86_64-build -c
sudo pacman -U paru-*-x86_64.pkg.tar.zst
paru -S --chroot devscripts debian-keyring

使用 dget 下载 dsc 时会将源码包一起拉取

$ dget http://deb.debian.org/debian/pool/main/s/sensible-utils/sensible-utils_0.0.26.dsc
dget: retrieving http://deb.debian.org/debian/pool/main/s/sensible-utils/sensible-utils_0.0.26.dsc
dget: retrieving http://deb.debian.org/debian/pool/main/s/sensible-utils/sensible-utils_0.0.26.tar.xz
sensible-utils_0.0.26.dsc:
      Good signature found
   validating sensible-utils_0.0.26.tar.xz
All files validated successfully.
dpkg-source: info: verifying ./sensible-utils_0.0.26.dsc
dpkg-source: warning: cannot verify inline signature for ./sensible-utils_0.0.26.dsc: missing OpenPGP keyrings
dpkg-source: info: extracting sensible-utils in sensible-utils-0.0.26
dpkg-source: info: unpacking sensible-utils_0.0.26.tar.xz

或者使用 dpkg-source -x 手动解压

$ rm -rf sensible-utils-0.0.26
$ dpkg-source -x --skip-patches ./sensible-utils_0.0.26.dsc 
dpkg-source: warning: --skip-patches is not a valid option for Dpkg::Source::Package::V3::Native
dpkg-source: info: verifying ./sensible-utils_0.0.26.dsc
dpkg-source: warning: cannot verify inline signature for ./sensible-utils_0.0.26.dsc: missing OpenPGP keyrings
dpkg-source: info: extracting sensible-utils in sensible-utils-0.0.26
dpkg-source: info: unpacking sensible-utils_0.0.26.tar.xz

安装 pbuilder-ubuntu

paru -S --chroot pbuilder-ubuntu
--- /usr/share/pbuilder/pbuilderrc	2020-10-13 11:23:36.000000000 +0800
+++ /etc/pbuilderrc	2020-10-13 13:01:06.991275977 +0800
@@ -24,7 +24,7 @@
 # Debian buildds too.  You can set it to $BUILDDIR to get a working HOME, if
 # you need to.
 BUILD_HOME=/nonexistent
-MIRRORSITE=http://archive.ubuntu.com/ubuntu
+MIRRORSITE=https://mirrors.sjtug.sjtu.edu.cn/debian
 #OTHERMIRROR="deb http://www.home.com/updates/ ./"
 #export http_proxy=http://your-proxy:8080/
 USESHM=yes
@@ -118,7 +118,7 @@
 # Set the debootstrap variant to 'buildd' type.
 DEBOOTSTRAPOPTS=(
     '--variant=buildd'
-    '--force-check-gpg'
+    '--no-check-gpg'
     )
 # or unset it to make it not a buildd type.
 # unset DEBOOTSTRAPOPTS
@@ -147,7 +147,7 @@
 AUTOCLEANAPTCACHE=""
 
 #default COMPRESSPROG
-COMPRESSPROG="gzip"
+COMPRESSPROG="pigz"
 
 # pbuilder copies some configuration files (like /etc/hosts or /etc/hostname)
 # from the host system into the chroot.  If the directory specified here
  • MIRRORSITE 指定仓库地址
  • DEBOOTSTRAPOPTS 指定 debootstrap 的参数
  • COMPRESSPROG 使用 pigz 来使用所有核心, 需要预装 pigz 软件包
sudo pbuilder --create --distribution experimental --basetgz exp.tgz

pbuilder 编译软件包有两种方式,通过软件包的dsc 编译,也可以使用pbuilder –login 当作chroot 进入

参考: Pbuilder build package

dsc 可以通过dpkg-source -b .生成

sudo pbuilder --build --basetgz exp.tgz sensible-utils_0.0.26.dsc

编好的 deb 包位于 /var/cache/pbuilder/result

sudo pbuilder --login --basetgz exp.tgz

base环境里做的操作退出时会销毁,如果想保留,可以后边加–save-after-login 参数

sudo pbuilder --login --basetgz exp.tgz --save-after-login