Debian打包教程

环境配置

安装依赖

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

参考链接

Debian 新维护者指
Debian 开发者文档
Debian 政策文档
Ubuntu 打包指南

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

多弗朗强哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值