Debian本地源的搭建方法

一些自己开发或者修改的debian程序,如果想使用apt-get工具进行安装的话,需要自己搭建debian软件源,本文简要介绍一下搭建方法。

  • 目录结构:
buildd@debian:~/debian-dev$ tree -d -L 4
.
├── dists
│   ├── jessie
│   │   ├── contrib
│   │   │   ├── binary-all
│   │   │   ├── binary-amd64
│   │   │   ├── binary-armel
│   │   │   ├── binary-armhf
│   │   │   └── source
│   │   ├── main
│   │   │   ├── binary-all
│   │   │   ├── binary-amd64
│   │   │   ├── binary-armel
│   │   │   ├── binary-armhf
│   │   │   └── source
│   │   └── non-free
│   │       ├── binary-all
│   │       ├── binary-amd64
│   │       ├── binary-armel
│   │       ├── binary-armhf
│   │       └── source
│   ├── jessie-dev -> jessie/
│   └── stable -> jessie
└── pool
    ├── contrib
    ├── main
    │   ├── a
    │   │   └── audit
    │   └── libs
    │       ├── libselinux
    │       └── libsepol
    └── non-free

31 directories

dists目录用于存储repo信息,pool目录用于存储软件代码和编译好的deb包。

  • 修改Release配置文件,便于使用工具管理:
buildd@debian:~/debian-dev$ cat apt-release.cnf 
APT::FTPArchive::Release::Codename "jessie-dev";
APT::FTPArchive::Release::Origin "ZWB";
APT::FTPArchive::Release::Components "main contrib non-free";
APT::FTPArchive::Release::Label "Debian ZWB";
APT::FTPArchive::Release::Architectures "amd64 armel armhf";
APT::FTPArchive::Release::Suite "stable";
  • 生成gpg密钥,用于对Release文件和deb包签名:
buildd@debian:~/debian-dev$ gpg --gen-key
gpg (GnuPG) 1.4.18; Copyright (C) 2014 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

请选择您要使用的密钥种类:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (仅用于签名)
   (4) RSA (仅用于签名)
您的选择? 4
RSA 密钥长度应在 1024 位与 4096 位之间。
您想要用多大的密钥尺寸?(2048)2048
您所要求的密钥尺寸是 2048 位
请设定这把密钥的有效期限。
         0 = 密钥永不过期
      <n>  = 密钥在 n 天后过期
      <n>w = 密钥在 n 周后过期
      <n>m = 密钥在 n 月后过期
      <n>y = 密钥在 n 年后过期
密钥的有效期限是?(0) 10y
密钥于 20260322日 星期日 151327秒 CST 过期
以上正确吗?(y/n)y

您需要一个用户标识来辨识您的密钥;本软件会用真实姓名、注释和电子邮件地址组合
成用户标识,如下所示:
    “Heinrich Heine (Der Dichter) <[email protected]>”

真实姓名:your name
电子邮件地址:[email protected]
注释:comm
您选定了这个用户标识:
    “your name (comm) <[email protected]>”

更改姓名(N)、注释(C)、电子邮件地址(E)或确定(O)/退出(Q)?o
您需要一个密码来保护您的私钥。

我们需要生成大量的随机字节。这个时候您可以多做些琐事(像是敲打键盘、移动
鼠标、读写硬盘之类的),这会让随机数字发生器有更好的机会获得足够的熵数。

随机字节不够多。请再做一些其他的琐事,以使操作系统能搜集到更多的熵!
(还需要190字节)
......+++++
..+++++
gpg: 密钥 A9A6BBB3 被标记为绝对信任
公钥和私钥已经生成并经签名。

gpg: 正在检查信任度数据库
gpg: 需要 3 份勉强信任和 1 份完全信任,PGP 信任模型
gpg: 深度:0 有效性:  2 已签名:  0 信任度:0-,0q,0n,0m,0f,2u
gpg: 下次信任度数据库检查将于 2026-03-22 进行
pub   2048R/A9A6BBB3 2016-03-24 [有效至:2026-03-22]
密钥指纹 = 5BBC 569F A8D9 F81F 6F11  BC0C E3CF 8397 A9A6 BBB3
uid                  your name (comm) <[email protected]>

请注意这把密钥还不能用来加密,您必须先用“--edit-key”指令
生成用于加密的子钥。
#可以使用 gpg --list-keys 进行密钥对的查询
#可以使用 gpg --export A9A6BBB3 > Release.gpg 导出公钥,用于使用者添加信任密钥
  • 编写软件源自动化管理脚本:
buildd@debian:~/debian-dev$ cat auto.sh 
#!/bin/sh

ARCH="amd64 armhf armel"
COMP="contrib main non-free"

for arch in $ARCH
do
        for cc in $COMP 
        do
                dpkg-scanpackages -a $arch pool/$cc > dists/jessie/$cc/binary-$arch/Packages
                gzip -9c dists/jessie/$cc/binary-$arch/Packages > dists/jessie/$cc/binary-$arch/Packages.gz
        done
done

for cc in $COMP
do
        dpkg-scansources pool/$cc > dists/jessie/$cc/source/Sources
        gzip -9c dists/jessie/$cc/source/Sources > dists/jessie/$cc/source/Sources.gz
done

rm -f dists/jessie/Release
rm -f dists/jessie/InRelease
rm -f dists/jessie/Release.gpg
apt-ftparchive -c /home/buildd/debian-dev/apt-release.cnf  release dists/jessie > .Release
mv .Release dists/jessie/Release
gpg --clearsign -o dists/jessie/InRelease dists/jessie/Release
gpg -o dists/jessie/Release.gpg -abs dists/jessie/Release

#以上脚本用于生成Packages文件和Sources文件,并生成.gz压缩包;
#apt-ftparchive release时用到了上一步的apt-release.cnf配置文件,用于Release文件头部分信息的生成;
  • 软件源的使用:
    本地软件源可以使用file::///形式进行配置,也可使用Apache服务器进行网络发布,具体参照/etc/apt/source.list文件进行配置。需要注意的是:使用之初需要添加自己的公钥为信任密钥,可使用apt-key add进行导入。
buildd@debian:~/debian-dev$ cat /etc/apt/sources.list

deb http://192.168.1.2/debian-dev jessie-dev contrib main
deb-src http://192.168.1.2/debian-dev jessie-dev contrib main

deb http://ftp.debian.org/debian jessie contrib main
deb-src http://ftp.debian.org/debian jessie contrib main
  • 其他问题

原件源的优先级问题
如果source.list文件中配置的两个软件源有重复软件,需要使用Pin-Priority进行定义优先级。例如:

buildd@debian:~/debian-dev$ cat /etc/apt/preferences
Package: *
Pin: release n=jessie-dev
Pin-Priority: 600

Package: *
Pin: release n=jessie
Pin-Priority: 500

#本例中软件源的发行版name设定为jessie-dev,优先级为600,官方源优先级定义为500,所有在使用apt-get的时候如果有重复的软件会根据优先级进行判别从哪个源进行下载安装;

#可使用apt-cache policy package_name进行查看软件现在地址细节

deb包签名:

dpkg-sig --sign builder file1.deb
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章