Setup Apt Repos

自建APT 仓库

生成签名用的 GPG KEY

运行命令: gpg --full-gen-key

按照提示输入姓名、邮箱,确认,有效期,输入密码,~/.gnupg/openpgp-revocs.d/目录下生成.rev的key文件,有效期两年。

随机16位密码: openssl rand -base64 16

生成ASCII格式的Public Key文件

gpg --output [email protected] --armor --export [email protected]

实际测试,--output选项须在前

构建软件包

进入源码仓库文件夹:

dpkg-buildpackage -us -uc

对deb包进行签名

apt-get install dpkg-sig

如果在打包deb之前已经做好了签名key,且软件包的changelog中的姓名、邮箱与生成GPG KEY所用一样,在执行dpkg-buildpackage打包时自动签名。

否则,手动签名:dpkg-sig --sign builder mypackage_0.1.2_amd64.deb

Web服务器

sudo apt install apache2

sudo mkdir -p /var/www/repos/apt/

*/etc/apache2/apache2.conf* 添加 ServerName localhost

sudo vi /etc/apache2/conf.d/repos

# /etc/apache2/conf.d/repos
# Apache HTTP Server 2.4

<Directory /var/www/repos/ >
        # We want the user to be able to browse the directory manually
        Options Indexes FollowSymLinks Multiviews
        Require all granted
</Directory>

# This syntax supports several repositories, e.g. one for Debian, one for Ubuntu.
# Replace * with debian, if you intend to support one distribution only.
<Directory "/var/www/repos/apt/*/db/">
        Require all denied
</Directory>

<Directory "/var/www/repos/apt/*/conf/">
        Require all denied
</Directory>

<Directory "/var/www/repos/apt/*/incoming/">
        Require all denied
</Directory>

sudo vi /etc/apache2/sites-available/000-default.conf

DocumentRoot /var/www/repos/apt

创建APT仓库

Origin: Linux 
Label: debian
Codename: buster
Version: 2019
Update: buster
Architectures: i386 amd64 arm64 mips64el sw_64 source
Components: main
UDebComponents: main
Contents: percomponent nocompatsymlink .bz2
SignWith: yes
Description: debian packages

Origin: Linux 
Label: debian
Codename: buster/sp1
Version: 2019
Update: sp1
Architectures: i386 amd64 arm64 mips64el sw_64 source
Components: main
UDebComponents: main
Contents: percomponent nocompatsymlink .bz2
SignWith: yes
Description: debian packages

reprepro会自动创建仓库所需要的结构。

reprepro --ask-passphrase -Vb . includedeb codename packages.deb
# --aks-passphrase 询问密码,在生成GPG KEY设置的密码
# -V verbose 详细模式,输出详细信息
# -b basedir 
# .  当前目录
# includedeb 添加软件包
# codename 比如eagle, eagle/sp1, eagle/sp2

添加key

wget -O - http://×××/*****.gpg.key | sudo apt-key add -

添加仓库地址到 /etc/apt/sources.list

deb http://192.168.122.1/ buster main

修改仓库优先级

vi /etc/apt/preferences

Package: *
Pin: origin 192.168.122.1
Pin-Priority: 900

参考:

  1. https://wiki.debian.org/DebianRepository/SetupWithReprepro?action=show&redirect=SettingUpSignedAptRepositoryWithReprepro
  2. http://blog.jonliv.es/blog/2011/04/26/creating-your-own-signed-apt-repository-and-debian-packages/