deb包制作

摘要:
简介deb编包的本质是:将编译过程自动化,并生成可执行程序,使得可以通过apt-get中安装。DEB源码介绍DEB包的源码是由:程序源码+debian目录构成,其中debian目录中存放着打包成DEB文件所需的全部文件。通过debian目录中的文件可以定制软件包的行为。修改rules如果要安装二进制等文件,则需要覆写rules-˃dh_installvimdebian/rules#seeENVIRONMENTindpkg-buildflags#packagemaintainerstoappendCFLAGS#exportDEB_CFLAGS_MAINT_APPEND=-Wall-pedantic#packagemaintainerstoappendLDFLAGS#exportDEB_LDFLAGS_MAINT_APPEND=-Wl,--as-needed%:dh$@override_dh_install:cphellobash.sh/usr/bin#dh_makegeneratedoverridetargets#ThisisexampleforCmake#override_dh_auto_configure:#dh_auto_configure--#-DCMAKE_LIBRARY_PATH=$需要注意的是,如果覆写了二进制被安装在/usr/bin,则debuild需要加sudo权限,且安装后的二进制文件不具备执行权限,需要手动加上可执行权限。
简介

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

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

DEB源码介绍

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

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

新建文件 ~/hello-1.0/hello.bash

#!/bin/bash

echo "Hellocdq!!!"
制作压缩包
tar -zcvf ~/hello-1.0.tar.gz ~/hello-1.0/
生成debian文件夹
cd ~/hello-1.0
debian ../hello-1.0.tar.gz
#此时生成 ~/hello-1.0/debian/
修改debian文件夹

修改control

vim debian/control
Source: hello
Section: shells
Priority: optional
Maintainer: chendeqiang <chendeqiang@kylinos.cn>
Build-Depends: debhelper-compat (= 12) #添加编译依赖
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: hello1
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, abc  #添加依赖包
Description: <insert up to 60 chars description>
 <insert long description, indented with spaces>

Package: hello2 #一份源码生成两个包
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: <insert up to 60 chars description>
 <insert long description, indented with spaces>

修改changelog

vim debian/changelog
hello (1.0-1) v100; 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

修改format

vim debian/source/format
3.0 (native)

3.0 (native) 指base是自建包,3.0 (quilt) 指base是上游包。

修改rules

如果要安装二进制等文件,则需要覆写rules->dh_install

vim debian/rules
# 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 $@

override_dh_install:
    cp hellobash.sh /usr/bin

# 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)

需要注意的是,如果覆写了二进制被安装在/usr/bin ,则debuild需要加sudo权限,且安装后的二进制文件不具备执行权限,需要手动加上可执行权限。

修改install

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

vim debian/install
hello /usr/bin/
生成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将作为加密的密钥。

构建deb包
#如果没有 debuild 命令,则:
#sudo apt install devscripts
debuild -us -uc -nc -krsa1234

#此时将生成 ~/hello1_1.0-1_amd64.deb 和 ~/hello2_1.0-1_amd64.deb

如果报错:dpkg-checkbuilddeps: 错误: Unmet build dependencies: build-essential:native
则:sudo apt install build-essential

配置debuild所使用的默认签名

echo 'DEBSIGN_KEYID="rsa1234"' >> ~/.devscripts

#如果简写的不行,就全写:
echo 'DEBSIGN_KEYID="9B91BDA0F08C1C82F322B25B660EAA39DB4FF519"' >> ~/.devscripts

运行 debuild -sa -S (注意:V10.1 debuild -sa -S -nc)生成源码包时就会自动用选择的key来对.dsc和.changes文件进行签名了
注意:配置默认签名只对debuild命令有效,dpkg-buildpackage -S 依然是根据changelog里的署名来查找key,如果找不到就不会签名。
本地编包命令:dpkg-buildpackage -b

本地安装deb包
sudo dpkg -i eee_1.1-1_arm64.deb

# 卸载deb包
# sduo dpkg -r -i eee_1.1-1_arm64.deb

运行可执行文件

demo
#helloworld!
上传公钥到PPA

上传gpg公钥

# 查看秘钥
gpg --fingerprint

# 上传公钥到服务器
gpg --keyserver 172.0.0.0 --send-key  rsa1234

关联ppa账号和gpg秘钥

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

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

上传ssh公钥

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

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

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

其他

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

上传deb包到PPA进行编译
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!
");
        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!
");
        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)

参考链接:
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

其他参考资料:

免责声明:文章转载自《deb包制作》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇其他查询nginx 获取请求头,URL参数下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

android的多次点击事件的实现(有源码)

三次点击事件的原理图:数组的复制(android源码的调用): 下面就是第一步: 创建long数组,里面的数字代表点击的次数。 下面是主要代码实现: system.arraycopy();里面的参数描述:   最后就是在if里面实现你想要的按钮的点击逻辑,不过最后一点很重要,当按钮还有触摸的点击事件的时候,有一点: 一定记得返回false; 下...

Frida从入门到入狱

一、Frida简单介绍 Frida是个轻量级so级别的hook框架,使用frida可以获取进程的信息(模块列表,线程列表,库导出函数),可以拦截指定函数和调用指定函数,可以注入代码,Frida的主要工作方式是将脚本注入到目标重新的进程中,而且在执行过程中可以实时看到其中的变化。 二、Frida安装使用 python安装:pip install frida ...

手写Redux-Saga源码

上一篇文章我们分析了Redux-Thunk的源码,可以看到他的代码非常简单,只是让dispatch可以处理函数类型的action,其作者也承认对于复杂场景,Redux-Thunk并不适用,还推荐了Redux-Saga来处理复杂副作用。本文要讲的就是Redux-Saga,这个也是我在实际工作中使用最多的Redux异步解决方案。Redux-Saga比Redux...

码云客户端Gitee使用2 下载项目

码云上面有许多优秀的开源项目,非常感谢这些组织、公司、团队以及个人的开源精神以及为开源项目长期付出的的艰辛。举手之劳,Star一下! NetModular是一个非常优秀的开源项目,她是基于.Net Core和 Vue.js 的业务模块化以及前后端分离的快速开发框架。码云地址为:https://gitee.com/laoli/NetModular 选择一个好...

【嵌入式开发】 Linux Kernel 下载 配置 编译 安装 及 驱动简介

作者 : 韩曙亮 转载请出名出处 : http://blog.csdn.net/shulianghan/article/details/38636827 一. Linux 内核简介  1. 内核功能简介 (1) 操作系统 和 内核 简介 操作系统 :  -- 功能 : 完成基本功能 和 系统管理; -- 组成 : 内核(kernel), 设备...

Debian下自动备份文件并上传到远程FTP服务器且删除指定日期前的备份Shell脚本

      说明:  1、备份目录/home/osyunwei下面所有的文件到/home/osyunweibak里面,并且保存为osyunwei20120701.tar.gz的压缩文件格式(2012_07_01是指备份执行时当天的日期),最后只保留最近7天的备份 2、上传/home/osyunweibak里面的备份文件到远程FTP服务器上,并且只保留最近7...