deb包制作

简介

deb编包的本质是:将编译过程自动化,并生成可执行程序,使得可以通过apt-get中安装。

源码,编译器编译成指定架构版本的二进制,
不同架构的二进制组织形式不同,如大小端对齐。

DEB源码介绍

DEB 包的源码是由:程序源码+debian 目录构成,其中 debian 目录中存放着打包成 DEB 文件所需的全部文件。
通过 debian 目录中的文件可以定制软件包的行为。其中最为重要的,对于所有的软件包都必需的基本文件是:

  • control :包的一些基本信息(名字、依赖等)
    • 软件包在构建和运行时的依赖
    • 软件包其他主要信息
  • rules :构建包时的规则
    • 是用来指定如何构建软件包的,是包的编译规则文件;
    • 默认可以调用软件源码的 make 等编译程序及规则进行;
    • 也可对默认的构建编译流程进行覆写,以满足 DEB 打包的特殊需求。
  • changelog : Debian 包的修改记录
    • 记录当前 DEB 包的变更历史;
    • 同时 DEB 包的版本号也是在此文件中指定;
  • install:安装指定文件到系统目录
    • 文件拷贝列表,声明 DEB 安装时所需拷贝的文件及目标位置
  • copyright :包的版权信息
    • 包含软件包的版权和授权信息;

准备

安装依赖

sudo apt install dh-make devscripts build-essential dput gedit

配置用户名和邮箱

vim ~/.bashrc

DEBEMAIL="chendeqiang@kylinos.cn"
DEBFULLNAME="chendeqiang"
export DEBEMAIL DEBFULLNAME
. ~/.bashrc

新建源码文件

# 新建文件夹并进入,这里需要注意的是文件夹构成:包名-版本号
mkdir ~/hello-1.0/
cd ~/hello-1.0/
# 新建源码文件
gedit hello.bash

hello.bash的文件内容:

#!/bin/bash
echo "Hello World!!!"

加执行权限:

sudo chmod +x hello.bash

制作压缩包

# 制作压缩包
tar -zcvf ../hello-1.0.tar.gz ../hello-1.0/

生成debian文件夹

使用dh_make命令生成debian文件夹。

dh_make -n -f ../hello-1.0.tar.gz #-n native
s
y

修改debian文件夹

修改control

gedit debian/control
Source: hello # 源码包名
Section: shells # 其他分类为x11
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,all
Depends: ${shlibs:Depends}, ${misc:Depends}  # 与其他包的关系控制,这里是运行依赖
Description: <insert up to 60 chars description>
 <insert long description, indented with spaces>

修改changelog

dch
hello (1.0-1) v101; urgency=medium

  * Initial release (Closes: #nnnn)  <nnnn is the bug number of your ITP>

 -- chendeqiang <chendeqiang@kylinos.cn>  Thu, 28 Jan 2021 21:05:06 +0800

添加install

如果makefile没有指定一些文件的安装目录,则可以在install文件中进行指定。

gedit debian/install
hello.bash /usr/bin/

install 文件格式,目标文件 空格 目标位置

生成gpg密钥

GPG入门知识

查看gpg密钥

gpg --list-key

生成gpg密钥

如果没有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]

其中,rsa1234将作为加密的密钥。

配置默认签名

echo 'DEBSIGN_KEYID="9B91BDA0F08C1C82F322B25B660EAA39DB4FF519"' >> ~/.devscripts

生成deb包

debuild

本地安装deb包

cd ~
sudo dpkg -i hello_1.0-1_amd64.deb

# 卸载deb包
# sduo dpkg -r -i hello_1.0-1_amd64.deb

运行可执行文件

hello.bash
#Hello World!!!

上传公钥到PPA

上传gpg公钥

# 查看秘钥
gpg --fingerprint

# 上传公钥到服务器,可以通过 `nslookup launchpad.dev`查看ip 
gpg --keyserver 172.0.0.0 --send-key  rsa1234

打开 https://launchpad.dev/~chendeqiang ,修改 OpenPGP keys,
之后launchpad将发送一封用GPG加密的邮件到用户的邮箱,
然后使用 gpg --decrypt 解密,并点击链接完成认证

上传ssh公钥

# 生成秘钥
ssh-keygen  –t  rsa
# 一直回车

# 复制公钥
vim ~/.ssh/id_rsa.pub

打开 https://launchpad.dev/~chendeqiang ,修改 SSH keys,
粘贴刚刚复制的秘钥

可以使用 seahorse 查看和管理gpg和ssh秘钥。
更多gpg信息参考:https://www.cnblogs.com/chendeqiang/p/14233944.html

其他

添加域名/etc/hosts 和 ~/.dput.cf可参考《launchpad平台用户使用手册》

生成deb源码包,上传到PPA进行编译

#生成源码包,patch需要添加-sa
debuild -S
cd ~/
dput devppa:chendeqiang/kylinos-desktop/ppatest hello1_1.0-1_source.changes 

添加PPA的apt源

访问应用主页 https://launchpad.dev/~chendeqiang/+archive/kylinos-desktop/ppatest
添加Technical details about this PPA下的两个链接到source.list

sudo vim /etc/apt/source.list
sudo apt-get update

安装应用

重新打开一个终端

sudo apt-get install cdqtest

# 运行应用
demo

恢复源码包

下载以下三个包:

xxx.dsc 
xxx.origin.tar.gz 
xxx.debian.tar.xz

然后:

dpkg-source -x xxx.dsc 

makefile方式构建源码

hello.c

#include<stdio.h>
int main()
{
        printf("helloworld!\n");
        return 0;
}

Makefile

hello : hello.o
        gcc -o hello hello.o

hello.o : hello.c
        gcc -c hello.c

#clean :
#      rm hello hello.o
#install:
#      install hello /usr/bin/

cmake方式构建源码

hello.c

#include<stdio.h>
int main()
{
        printf("helloworld!\n");
        return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(hellocdq)
add_executable(hellocdq hello.cpp)

debin/control

Build-Depends: debhelper (>=9) , cmake

debian/rules

#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1


# see FEATURE AREAS in dpkg-buildflags(1)
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# package maintainers to append LDFLAGS
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

%:
	dh $@ 

# dh_make generated override targets
# This is example for Cmake (See https://bugs.debian.org/641051 )
override_dh_auto_configure:
	dh_auto_configure -- #	-DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)

备注

查询dns
nslookup launchpad.dev

Control和chagelog的包名是除了版本号的包名

参考链接:
https://blog.csdn.net/kyle__shaw/article/details/8938787?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-3.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-3.control
https://blog.csdn.net/kyle__shaw/article/details/8938787

其他参考资料:

posted @ 2021-01-04 20:30  多弗朗强哥  阅读(2146)  评论(0编辑  收藏  举报