首页 > 系统相关 >linux程序打包成deb

linux程序打包成deb

时间:2022-10-27 13:35:23浏览次数:55  
标签:1.0 dh data helloworld linux 508b9712a279 deb root 打包

前言

最近在研究如何将自己的程序打包称deb格式,用dpkg或者apt管理起来,最终我们可以使用"dpkg-buildpackage -us -uc"来生成我们的deb文档。以下为我的学习心得,将每一个步骤记录下来。

准备工作

  一.创建一个文件夹,里面放自己的程序,或者源码,文件夹命名<packagename>-<version>。

packagename即deb软件包名称,只能含有 小写字母 (a-z), 数字 (0-9), 加号 (+) 和 减号 (-) , 以及 点号 (.)。 软件包名最短长度两个字符;它必须以字母开头;它不能与仓库软件包名发生冲突。还有,把软件包名的长度控制在 30 字符以内是明智之举。

version即deb软件包版本号,只包含字母和数字 (0-9A-Za-z), 以及加号 (+), 波浪号 (~), 还有 点号(.)。它必须以数字开头 (0-9)。如果可能的话,最好把它的长度控制在8字符以内。 

范例:我要建立一个helloworld-1.0.0的deb软件包

  1.创建一个文件夹:helloworld-1.0.0

  2.将自己的程序放进去(这里我写了一个简单的脚本)

 

1 root@508b9712a279:/data# tree
2 .
3 └── helloworld-1.0.0
4     └── sbin
5         └── helloworld
6 
7 2 directories, 1 file
8 root@508b9712a279:/data#

 

   3.打包:将helloworld-1.0.0打包成tar.gz

1 root@508b9712a279:/data# tar -zcvf helloworld-1.0.0.tar.gz helloworld-1.0.0/
2 helloworld-1.0.0/
3 helloworld-1.0.0/sbin/
4 helloworld-1.0.0/sbin/helloworld
5 root@508b9712a279:/data# ls -l
6 total 8
7 drwxrwxr-x 3 moxa moxa 4096 Oct 27 11:29 helloworld-1.0.0
8 -rw-rw-r-- 1 moxa moxa  226 Oct 27 11:35 helloworld-1.0.0.tar.gz
9 root@508b9712a279:/data#

 

  二.使用dh_make初始化软件包

1.安装dh_make:apt install -y dh-make

2.设置dh_make默认环境变量:$DEBEMAIL 和 $DEBFULLNAME,这样大多数 Debian 维护工具就能够正确识别你用于维护软件包的姓名和电子邮件地址。我的做法是将其加在.bashrc的最后,然后再source ~/.bashrc生效。

1 root@508b9712a279:/data/helloworld-1.0.0# tail -n 4 ~/.bashrc
2 DEBEMAIL="[email protected]"
3 DEBFULLNAME="ethan wang"
4 export DEBEMAIL DEBFULLNAME
5 
6 root@508b9712a279:/data/helloworld-1.0.0# source ~/.bashrc

3.检验环境变量已生效

1 root@508b9712a279:/data/helloworld-1.0.0# export | grep DEB
2 declare -x DEBEMAIL="[email protected]"
3 declare -x DEBFULLNAME="ethan wang"

4.初始化软件包

 1 root@508b9712a279:/data# ls
 2 helloworld-1.0.0  helloworld-1.0.0.tar.gz
 3 root@508b9712a279:/data# ls
 4 helloworld-1.0.0  helloworld-1.0.0.tar.gz
 5 root@508b9712a279:/data# cd helloworld-1.0.0
 6 root@508b9712a279:/data/helloworld-1.0.0# dh_make -f ../helloworld-1.0.0.tar.gz -n -s -y
 7 Maintainer Name     : ethan wang
 8 Email-Address       : [email protected]
 9 Date                : Thu, 27 Oct 2022 03:56:40 +0000
10 Package Name        : helloworld
11 Version             : 1.0.0
12 License             : gpl3
13 Package Type        : single
14 Currently there is not top level Makefile. This may require additional tuning
15 Done. Please edit the files in the debian/ subdirectory now.
16 
17 root@508b9712a279:/data/helloworld-1.0.0# 


-s:Automatically set the package class to Single binary, skipping the question.

-n:Create a native Debian packages

-y:Automatic yes to prompts and run non-interactively. The package class needs to be set for dh_make to run fully automatically.

 在helloworld-1.0.0内就会生成一个debian的文件夹

5. debian目录中的必需文件

 1 -rw-r--r-- 1 root root  176 Oct 27 10:36 debian/changelog
 2 -rw-r--r-- 1 root root    3 Oct 27 10:36 debian/compat
 3 -rw-r--r-- 1 root root  279 Oct 27 10:36 debian/control
 4 -rw-r--r-- 1 root root 1675 Oct 27 10:36 debian/copyright
 5 -rw-r--r-- 1 root root  143 Oct 27 10:36 debian/install
 6 -rwxr-xr-x 1 root root  678 Oct 27 10:36 debian/rules
 7 
 8 debian/source:
 9 total 4
10 -rwxr-xr-x 1 root root 13 Oct 27 10:36 format

debian/install : 如果你的软件包需要那些标准的 make install 没有安装的文件,你可以把文件名和目标路径写入 install 文件,它们将被 dh_install(1) 安装。 

1 root@508b9712a279:/data/helloworld-1.0.0# cat debian/install
2 sbin/* sbin/
3 root@508b9712a279:/data/helloworld-1.0.0#

更多详细资料可以参考官方文档:https://www.debian.org/doc/manuals/maint-guide/dreq.zh-cn.html

创建软件包

 1 root@508b9712a279:/data/helloworld-1.0.0# dpkg-buildpackage -us -uc
 2 dpkg-buildpackage: info: source package helloworld
 3 dpkg-buildpackage: info: source version 1.0.0
 4 dpkg-buildpackage: info: source distribution unstable
 5 dpkg-buildpackage: info: source changed by ethan wang <[email protected]>
 6 dpkg-buildpackage: info: host architecture amd64
 7  dpkg-source --before-build .
 8  debian/rules clean
 9 dh clean
10    dh_clean
11  dpkg-source -b .
12 dpkg-source: info: using source format '3.0 (native)'
13 dpkg-source: info: building helloworld in helloworld_1.0.0.tar.xz
14 dpkg-source: info: building helloworld in helloworld_1.0.0.dsc
15  debian/rules binary
16 dh binary
17    dh_update_autotools_config
18    dh_autoreconf
19    create-stamp debian/debhelper-build-stamp
20    dh_prep
21    dh_install
22    dh_installdocs
23    dh_installchangelogs
24    dh_perl
25    dh_link
26    dh_strip_nondeterminism
27    dh_compress
28    dh_fixperms
29    dh_missing
30    dh_dwz -a
31    dh_strip -a
32    dh_makeshlibs -a
33    dh_shlibdeps -a
34    dh_installdeb
35    dh_gencontrol
36 dpkg-gencontrol: warning: Depends field of package helloworld: substitution variable ${shlibs:Depends} used, but is not defined
37    dh_md5sums
38    dh_builddeb
39 dpkg-deb: building package 'helloworld' in '../helloworld_1.0.0_amd64.deb'.
40  dpkg-genbuildinfo
41  dpkg-genchanges  >../helloworld_1.0.0_amd64.changes
42 dpkg-genchanges: info: including full source code in upload
43  dpkg-source --after-build .
44 dpkg-buildpackage: info: full upload; Debian-native package (full source is included)
45 root@508b9712a279:/data/helloworld-1.0.0#
46 root@508b9712a279:/data/helloworld-1.0.0#
47 root@508b9712a279:/data/helloworld-1.0.0#
48 root@508b9712a279:/data/helloworld-1.0.0# dpkg -c ../helloworld_1.0.0_amd64.deb
49 drwxr-xr-x root/root         0 2022-10-27 03:56 ./
50 drwxr-xr-x root/root         0 2022-10-27 03:56 ./sbin/
51 -rwxr-xr-x root/root        53 2022-10-27 03:30 ./sbin/helloworld
52 drwxr-xr-x root/root         0 2022-10-27 03:56 ./usr/
53 drwxr-xr-x root/root         0 2022-10-27 03:56 ./usr/share/
54 drwxr-xr-x root/root         0 2022-10-27 03:56 ./usr/share/doc/
55 drwxr-xr-x root/root         0 2022-10-27 03:56 ./usr/share/doc/helloworld/
56 -rw-r--r-- root/root       185 2022-10-27 03:56 ./usr/share/doc/helloworld/README.Debian
57 -rw-r--r-- root/root       141 2022-10-27 03:56 ./usr/share/doc/helloworld/changelog.gz
58 -rw-r--r-- root/root      1640 2022-10-27 03:56 ./usr/share/doc/helloworld/copyright
59 root@508b9712a279:/data/helloworld-1.0.0#

安装&运行&卸载

 1 root@508b9712a279:/data/helloworld-1.0.0# dpkg -i ../helloworld_1.0.0_amd64.deb
 2 Selecting previously unselected package helloworld.
 3 (Reading database ... 20973 files and directories currently installed.)
 4 Preparing to unpack ../helloworld_1.0.0_amd64.deb ...
 5 Unpacking helloworld (1.0.0) ...
 6 Setting up helloworld (1.0.0) ...
 7 root@508b9712a279:/data/helloworld-1.0.0# helloworld
 8 hello,world, i am a deb package.
 9 root@508b9712a279:/data/helloworld-1.0.0# dpkg --purge helloworld
10 (Reading database ... 20978 files and directories currently installed.)
11 Removing helloworld (1.0.0) ...
12 root@508b9712a279:/data/helloworld-1.0.0#

 

 

 

 

  

 

  

 

标签:1.0,dh,data,helloworld,linux,508b9712a279,deb,root,打包
From: https://www.cnblogs.com/ethandlwang/p/16831774.html

相关文章

  • Linux 进程
    引入进程的原因进程是为了刻画并发程序的执行过程而引入的概念,进程管理就是对并发程序的运行过程的管理,也就是对CPU的管理。进程管理的目标是最大限度地发挥CPU的处理能......
  • Linux系统安全及应用
    Linux系统安全及应用......
  • linux命令备忘
    chown[-cfhvR][--help][--version]user[:group]file...参数:user:新的文件拥有者的使用者IDgroup:新的文件拥有者的使用者组(group)-c:显示更改的部分......
  • Node.JS 安装(Windows 和 Linux )
    1、Linux版采用YUM方式安装。1.1、卸载旧版本查看旧版本:rpm-qa|grepnodejs卸载:卸载过程中输入y确认yumremovenodejs1.2、安装1.2.1、Hint官......
  • Linux 文件
    Linux中一切皆为文件文件文件是具有名字的一组相关信息的有序集合,存放在外部存储器中。文件系统文件系统是操作系统的一个重要组成部分,它负责管理系统中的文件,为用户提......
  • 【服务器数据恢复】linux ext3文件系统执行FSCK后无法挂载的数据恢复案例
    服务器数据恢复环境:POWEREDGE系列某型号服务器;LINUX系统+RAID5。​服务器故障:管理员执行FSCK操作后LINUX系统无法MOUNT。服务器数据恢复过程:1、经过北亚数据恢复工程......
  • Linux Shell 函数
    Shell函数#!/bin/bash定义在被使用之前,函数必须已经被定义如果函数名重复,后一个函数会覆盖前一个函数functionfoo{ echo"foo"}#也可以不写function关键字ba......
  • Linux系统分区(硬盘GPT分区与MBR分区的转换)
        4.分区方法[root@rhel7~]#fdisk/dev/sdbWelcometofdisk(util-linux2.23.2).Changeswillremaininmemoryonly,untilyoudecidetowritethem.......
  • Linux Supervisor使用
     一、supervisor简介​Supervisor是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动重启。它是通过fork/......
  • nginx安装配置 linux
    编译安装nginx的配置文件的路径在哪这个版本不同,位置还是不同的。我的是nginx-1.9.9版本源码安装,配置文件在conf这个目录里面:/usr/local/nginx/conf/nginx.conf如果你找不见......