环境配置
安装依赖
sudo apt install dh-make devscripts build-essential dput gedit
配置用户名和邮箱名
echo '
DEBEMAIL="chendeqiang1024@qq.com"
DEBFULLNAME="Deqiang Chen"
export DEBEMAIL DEBFULLNAME
' >> ~/.bashrc
source ~/.bashrc
配置gpg
gpg涉及非对称加密概念,可参考阮一峰的GPG入门教程
先查看一下是否已经创建了gpg:
gpg --list-key
如果是空,就是没有,需要新建一个gpg密钥。
新建gpg密钥:
gpg --generate-key
真实姓名:chendeqiang
电子邮箱地址:chendeqiang@kylinos.cn
o
输入两次密码
pub rsa1234 2021-01-28 [SC] [有效至:2023-01-28]
9B91BDA0F08C1C82F322B25B660EAA39DB4FF519
uid qiangdechen <chenjjjj@kk.cn>
sub rsa1234 2021-01-28 [E] [有效至:2023-01-28]
pub是公钥,发给别人,别人用公钥加密文件,再发给我们。
配置默认签名:
echo 'DEBSIGN_KEYID="9B91BDA0F08C1C82F322B25B660EAA39DB4FF519"' >> ~/.devscripts
制作deb包
源码包既可以是脚本类型(如shell),也可以是编译类型(如c)。这里为方便演示,使用bash shell编写。
新建源码文件
- 新建一个文件夹 hello,和源码包文件夹 hello-1.0
mkdir -p ~/hello/hello-1.0
cd ~/hello/hello-1.0
这里需要注意的是,源码包文件夹名称必须包含版本号,例如 hello-1.0 ,hello是源码包名,1.0是版本号。
- 新建源码 hello.sh
#!/bin/bash
echo "hello"
加执行权限:
chmod +x hello.sh
创建debian头
dh_make --createorig
s #单文件
y #确认
此时在 ~/hello/hello-1.0/ 下生成 debian 文件夹,这个 debian 文件夹是一个模版,需要我们更改其中的内容才能制作 deb 包。
修改control文件
这里只标注需要修改的地方,其他字段请参考Debian新维护者手册:
vim debian/control
Source: hello
Section: misc # 更改这里的分类,misc是杂项
Priority: optional
Maintainer: chendeqiang <chendeqiang@kylinos.cn> # 更改此处的维护者信息
Build-Depends: debhelper-compat (= 12) ,debhelper (>= 9) # 在这里添加编译依赖
Standards-Version: 4.4.1
#Homepage: <insert the upstream URL, if relevant>
#Vcs-Browser: https://salsa.debian.org/debian/hello
#Vcs-Git: https://salsa.debian.org/debian/hello.git
Package: hello # 生成的二进制包名,一般不用改
Architecture: any # any代表编译类,如c;all代表脚本类,如shell
Depends: ${shlibs:Depends}, ${misc:Depends} # 在这里添加运行依赖
Description: <insert up to 60 chars description>
<insert long description, indented with spaces>
修改changelog
dch
# vim debian/changelog
dch会进入vim编辑器,并在changelog文件上创建新字段
hello (1.0-1) v101; urgency=medium
* Initial release (Closes: #nnnn) <nnnn is the bug number of your ITP>
*
-- Deqiang Chen <chendeqiang1024@qq.com> Mon, 12 Dec 2022 22:54:32 +0800
UNRELEASED
需要修改为发行版的代号,如Ubuntu中,focal,jammy;如kylilnos中,v101。
改完后:wq
保存退出。
修改install
脚本文件没有使用 makefile 来维护,因此安装路径需要手动在install中写一下,同时注意,如果在 makefile 中写了安装路径,那么此处也会覆盖掉 makefile 的行为。
vim debian/install
hello.sh /usr/bin/
创建deb包
debuild
使用deb包
这时就会在上一层文件夹 ~/hello/ 中生成 hello_1.0-1_amd64.deb 安装包。
使用sudo apt install ./hello_1.0-1_amd64.deb
就可以安装deb包了。
安装完成后就可以执行脚本了:
hello.sh
Multiarch
附录 A. 高级打包
Multiarch
Variables for debian/rules