制作Deb包

从无到有制作Deb包的一个实例

从无到有制作Deb包的一个实例20080126

我希望从零开始制作出一个自己的Deb包,意思是连软件的源码都是自己写的,类似于deb from scratch吧,那么这样的一个制作过程大致由三部分构成:
1 源码的编写和测试
2 使用autotools工具生成符合Gnu编程标准的相关文件,如configure,makefile等。
3 按照Debian的方式制作Deb包文件

现在我编写了一个小软件hb-0.01,意思是hyperbolic,是自己写的一个双曲函数和反双曲函数的小软件,总共只有三个文件,在/home/wen1/hb-0.01/目录下,整个制作hb软件的deb包的过程为:

第一步:源码编写
这个步骤由用户自己编写,我的小软件总共只有三个文件,一个是头文件,一个是函数实现的C文件,还有一个主程序C文件,系统显示为:

wen1@lenny:~/hb-0.01$ ls -l
total 12
-rw-r--r-- 1 wen1 wen1 140 2008-01-26 15:17 bolic.h
-rw-r--r-- 1 wen1 wen1 369 2008-01-26 15:17 boliclib.c
-rw-r--r-- 1 wen1 wen1 300 2008-01-26 15:17 hb.c

第二步:使用Autotools工具生成所有符合Gnu编程标准的配置文件等。
这个过程的步骤比较多,具体来说,包括有:
1 使用autoscan命令来生成一个configure的模板文件。系统操作为:

wen1@lenny:~/hb-0.01$ autoscan
wen1@lenny:~/hb-0.01$ ls -l
total 16
-rw-r--r-- 1 wen1 wen1 0 2008-01-26 15:25 autoscan.log
-rw-r--r-- 1 wen1 wen1 140 2008-01-26 15:17 bolic.h
-rw-r--r-- 1 wen1 wen1 369 2008-01-26 15:17 boliclib.c
-rw-r--r-- 1 wen1 wen1 484 2008-01-26 15:25 configure.scan
-rw-r--r-- 1 wen1 wen1 300 2008-01-26 15:17 hb.c

可以看到现在生成了一个configure.scan文件。

2 将configure.scan文件改名为configure.in,并进行相应的修改,我的是:

AC_PREREQ(2.61)
AC_INIT(hb, 0.01, wenheping@tom.com)
AM_INIT_AUTOMAKE(hb,0.01)
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CHECK_FUNCS([sqrt])
AC_OUTPUT(Makefile)

一般来说,这里只有AC_INIT、AC_OUTPUT、AM_INIT_AUTOMAKE三个参数需要根据自己的情况修改一下,其他自动生成的东西不动。

3执行命令aclocal和autoconf,生成configure文件:

wen1@lenny:~/hb-0.01$ aclocal
wen1@lenny:~/hb-0.01$ autoconf
wen1@lenny:~/hb-0.01$ ls -l
total 184
-rw-r--r-- 1 wen1 wen1 31848 2008-01-26 15:36 aclocal.m4
drwxr-xr-x 2 wen1 wen1 4096 2008-01-26 15:36 autom4te.cache
-rw-r--r-- 1 wen1 wen1 0 2008-01-26 15:25 autoscan.log
-rw-r--r-- 1 wen1 wen1 140 2008-01-26 15:17 bolic.h
-rw-r--r-- 1 wen1 wen1 369 2008-01-26 15:17 boliclib.c
-rwxr-xr-x 1 wen1 wen1 130126 2008-01-26 15:36 configure
-rw-r--r-- 1 wen1 wen1 434 2008-01-26 15:35 configure.in
-rw-r--r-- 1 wen1 wen1 300 2008-01-26 15:17 hb.c

可以看到现在生成了configure文件。

4新建Makefile.am文件,再由automake工具根据所写的Makefile.am文件来自动生成Makefile.in文件。
Makefile.am文件一般定义自己的软件最后生成的可执行程序名字、需要连接的库等,我的该文件内容为:

AUTOMAKE_OPTIONS=foreign #
bin_PROGRAMS=hb # 最后生成的可执行文件的名字
hb_SOURCES=hb.c bolic.h boliclib.c # 所有的源码文件
LIBS = -lm # 需要连接math库

然后用automake生成Makefile.in文件,为了符合规范,先:

wen1@lenny:~/hb-0.01$ touch NEWS README AUTHORS ChangeLog

然后的系统显示为:

wen1@lenny:~/hb-0.01$ automake --add-missing
wen1@lenny:~/hb-0.01$ ls
aclocal.m4 bolic.h configure.in INSTALL missing
AUTHORS boliclib.c COPYING install-sh NEWS
autom4te.cache ChangeLog depcomp Makefile.am README
autoscan.log configure hb.c Makefile.in

5执行configure生成Makefile
这一步很简单,生成Makefile之后,还可以使用一些其他的make命令,如make clean,make install,make dist,看看它们会给你什么样的效果。

以上的例子很简单,更为复杂的Autotools的运用和Makefile的编写等内容请参照:
http://www.gnu.org/software/autoconf/ (最权威的了)
http://sourceware.org/autobook/ (很详细的一本书)
http://www.lrde.epita.fr/~adl/autotools.html (这个演示文稿做得相当不错)

第三步:生成Deb包。
生成deb包,有两种方法,一种很简单,直接在软件源码目录内运行checkinstall再回答几个简单的问题就可以了,但一般不推荐使用该办法;二是按照Debian的New Maintainer Guide一步一步制作deb包,详细的过程请参照:
http://www.debian.org/doc/maint-guide/

我的制作过程大致为:
1 下载安装必须的软件:
#apt-get install build-essential dpkg-dev dh-make debhelper fakeroot gnupg lintian Linda pbuilder

2 生成tar.gz文件并把该文件移动到源码的父目录:
wen1@lenny:~/hb-0.01$ make dist
wen1@lenny:~/hb-0.01$ mv hb*.gz ../

3运行dh_make命令。

wen1@lenny:~/hb-0.01$ dh_make -e wenheping@tom.com -f ../hb-0.01.tar.gz

运行该命令之后,原来的软件包将会被打包为hb-0.01.orig.tar.gz并放在父目录中,注意文件名中包名称和版本是以_分割的而且tar.gz之前有orig.。

4 修改Makefile、control等文件。
Debian要求可执行文件不能安装在/usr/local目录下,所以然后要检查Makefile文件的相应的安装位置,我的这个小软件本来就是安装在/usr/bin下,所以不用修改Makefile文件。
至于control copyright等文件,如果只是自己做一个自己用的deb包文件,不改也可以,但是如果是为Debian做的准备上传到Debian apt源中的话,就要按照规范认真地填写。

5 生成deb包文件,我是这样的:
wen1@lenny:~/hb-0.01$ ./configure
wen1@lenny:~/hb-0.01$ make
wen1@lenny:~/hb-0.01$ dpkg-buildpackage –rfakeroot

这样,我的hb软件的deb包文件及其他相关文件就生成了---但是生成于源码目录的父目录中。

第 6 章 构建软件包

现在我们已经为构建软件包做好了准备。

6.1. 完整的(重)构建

In order to perform a complete (re)build of a package properly, you need tomake sure you have installed

然后在源代码目录中执行以下命令:

$ dpkg-buildpackage

这样会自动完成所有从源代码包构建二进制包的工作,包括:

  • 清理源代码树(debian/rules clean)

  • 构建源代码包(dpkg-source -b)

  • 构建程序(debian/rules build)

  • 构建二进制包(fakeroot debian/rules binary)

  • 使用 gpg 签署 .dsc 文件

  • 使用 dpkg-genchanges gpg 创建并签署上传用的.changes 文件

The only input that will be required of you is your GPG secret pass phrase,twice. [64] If you are building Debianpackages only for your own local use, you can skip promptings for the GPGsignatures on the .dsc file and the.changes file like this:

$ dpkg-buildpackage -us -uc

For a non-native Debian package, e.g., gentoo, you will see the following files in theparent directory (~/gentoo) after building packages:

  • gentoo_0.9.12.orig.tar.gz

    This is the original upstream source code tarball, merely renamed to theabove so that it adheres to the Debian standard. Note that this was createdinitially by the dh_make -f ../gentoo-0.9.12.tar.gz.

  • gentoo_0.9.12-1.dsc

    这是一个从 control 文件生成的源代码概要,可用于 dpkg-source(1) 程序。这个文件是使用 GPG 签署过的,以便别人可以确信它确实是你所提供的。

  • gentoo_0.9.12-1.debian.tar.gz

    This compressed tarball contains your debian directorycontents. Each and every addition you made to the original source code isstored as a quilt patch indebian/patches.

    如果其他人想要重新构建你的软件包,他们可以使用以上三个文件很容易地完成。只需复制三个文件,再运行 dpkg-source -xgentoo_0.9.12-1.dsc[65]

  • gentoo_0.9.12-1_i386.deb

    这是你的二进制包,可以使用 dpkg 程序安装或卸载它,就像其他软件包一样。

  • gentoo_0.9.12-1_i386.changes

    This file describes all the changes made in the current package revision; itis used by the Debian FTP archive maintenance programs to install the binaryand source packages. It is partly generated from thechangelog file and the .dsc file.This file is GPG signed, so that people can be sure that it's really yours.

    As you keep working on the package, its behavior will change and newfeatures will be added. People downloading your package can look at thisfile and quickly see what has changed. Debian archive maintenance programswill also post the contents of this file to the debian-devel-announce@lists.debian.orgmailing list.

The long strings of numbers in the .dsc and.changes files are SHA1/SHA256 checksums for the filesmentioned. Anyone downloading your files can test them with sha1sum(1) or sha256sum(1) and if the numbers don't match,they'll know the file is corrupt or has been tampered with.

For a native Debian package, e.g., mypackage, you will see the following files inthe parent directory after building packages:

  • mypackage_1.0.tar.gz

    This is the source code tarball created from themypackage-1.0 directory by thedpkg-source command. (Its suffix is notorig.tar.gz.)

  • mypackage_1.0.dsc

    This is a summary of the contents of the source code as in the non-nativeDebian package. (There is no Debian revision.)

  • mypackage_1.0_i386.deb

    This is your completed binary package as in the non-native Debian package.(There is no Debian revision.)

  • mypackage_1.0_i386.changes

    This file describes all the changes made in the current package version asin the non-native Debian package. (There is no Debian revision.)

6.2. 自动编译系统

Debian supports many ports with the autobuilder network running buildddaemons on computers of many different architectures. Although you do notneed to do this yourself, you should be aware of what will happen to yourpackages. Let's look into roughly how they rebuild your packages formultiple architectures. [66]

For Architecture: any packages, the autobuilder systemperforms a rebuild. It ensures the installation of

然后在源代码目录中执行以下命令:

$ dpkg-buildpackage -B

这样会自动完成从源代码包构建平台依赖二进制包的工作,包括:

  • 清理源代码树(debian/rules clean)

  • 构建程序(debian/rules build)

  • 构建平台依赖二进制包(fakeroot debian/rules binary-arch)

  • 使用 gpg 签署 .dsc 文件

  • 使用 dpkg-genchanges gpg 创建并签署上传用的.changes 文件

这就是你看到你的软件包在其他平台上可用的原因。

Although packages listed in the Build-Depends-Indep fieldare required to be installed for our normal packaging work (see 第 6.1 节 “完整的(重)构建”), they are not required to be installed for theautobuilder system since it builds only architecture dependent binarypackages. [67] This distinction betweennormal packaging and autobuilding procedures is what dictates whether youshould record such required packages in the Build-Dependsor Build-Depends-Indep fields of thedebian/control file (see 第 4.1 节 “control).

6.3. debuild 命令

You can automate the dpkg-buildpackage command's packagebuild process further with the debuild command. Seedebuild(1).

Customization of the debuild command can be done through/etc/devscripts.conf or~/.devscripts. I would suggest at least the followingitems:

DEBSIGN_KEYID=Your_GPG_keyID
DEBUILD_LINTIAN_OPTS=-i -I --show-overrides

With these, packages are signed by your specified GPG key ID (good forsponsoring packages) and checked in detail by the lintiancommand.

Cleaning the source and rebuilding the package from your user account is assimple as:

$ debuild

Here, if you are building Debian packages only for your own local use, youcan skip promptings for the GPG signatures on the .dscfile and the .changes file like this:

$ debuild -us -uc

You can clean the source tree as simply as:

$ debuild clean

6.4. pbuilder 软件包

For a clean room (chroot) build environment to verify thebuild dependencies, the pbuilderpackage is very useful. [68] This ensuresa clean build from the source under the sid auto-builderfor different architectures and avoids a severity serious FTBFS (Fails ToBuild From Source) bug which is always in the RC (release critical)category. [69]

Let's customize the pbuilder packageas follows:

  • setting the /var/cache/pbuilder/result directorywritable by for your user account.

  • creating a directory, e.g./var/cache/pbuilder/hooks,writable by the user, to place hook scripts in.

  • configuring ~/.pbuilderrc or/etc/pbuilderrc to include the followsing.

    AUTO_DEBSIGN=${AUTO_DEBSIGN:-yes}
    HOOKDIR=/var/cache/pbuilder/hooks
    

这使你可以使用 ~/.gnupg/ 目录中的 GPG 私钥签署生成的软件包。

First let's initialize the local pbuilder chroot system asfollows.

$ sudo pbuilder create

If you already have a completed source package, issue the following commandsin the directory where thefoo.orig.tar.gz,foo.debian.tar.gz, andfoo.dsc files exist toupdate the local pbuilderchroot system and to build binary packages in it.

$ sudo pbuilder --update
$ sudo pbuilder --build foo_version.dsc

The newly built packages without the GPG signatures will be located in/var/cache/pbuilder/result/ with non-root ownership.

The GPG signatures on the .dsc file and the.changes file can be generated as:

$ cd /var/cache/pbuilder/result/
$ debsign foo_version.dsc
$ debsign foo_version_arch.changes

If you have an updated source tree but have not generated the matchingsource package, issue the following commands in the source directory wherethe debian directory exists, instead.

$ sudo pbuilder --update
$ pdebuild

Here, if you are building Debian packages only for your local use, you canskip promptings for the GPG signatures on the .dsc fileand the .changes file as:

$ AUTO_DEBSIGN=no pdebuild

你可以使用 pbuilder --login --save-after-login 命令登录到这个chroot 环境中并按照需要对其进行配置。通过 ^D(Control-D)离开这个 shell 时环境会被保存。

最新版的 lintian 命令可以通过设置钩子脚本/var/cache/pbuilder/hooks/B90lintianchroot 环境中运行。脚本内容如下:[70]

#!/bin/sh
set -e
install_packages() {
    apt-get -y --force-yes install "$@"
    }
install_packages lintian
echo "+++ lintian output +++"
su -c "lintian -i -I --show-overrides /tmp/buildd/*.changes" - pbuilder
# use this version if you don't want lintian to fail the build
#su -c "lintian -i -I --show-overrides /tmp/buildd/*.changes; :" - pbuilder
echo "+++ end of lintian output +++"

You need to have access to the latest sid environment tobuild packages properly for sid. In practice,sid may be experiencing issues which makes it undesirablefor you to migrate your whole system. The pbuilder package can help you to cope with thiskind of situation.

You may need to update your stable packages after theirrelease for stable-proposed-updates,stable/updates, etc. [71] For such occasions, the fact you may be running asid system is not a good enough excuse for failing toupdate them promptly. The pbuilderpackage can help you to access environments of almost any Debian derivativedistribution of the same architecture.

See http://www.netfort.gr.jp/~dancer/software/pbuilder.html, pdebuild(1), pbuilderrc(5), and pbuilder(8).

6.5. git-buildpackage 和相似命令

If your upstream uses a source code management system (VCS) [72] to maintain their code, you should consider usingit as well. This makes merging and cherry-picking upstream patches mucheasier. There are several specialized wrapper script packages for Debianpackage building for each VCS.

  • git-buildpackage: a suite to helpwith Debian packages in Git repositories.

  • svn-buildpackage:帮助维护 Subversion仓库中软件包的程序。

  • cvs-buildpackage: a set of Debianpackage scripts for CVS source trees.

For advanced audiences, there are packages whichautomate the building of packages under a VCS-managedsource tree. I will not explain them in this tutorial. [73]

6.6. 快速重构建

With a large package, you may not want to rebuild from scratch every timewhile you're tuning details in debian/rules. Fortesting purposes, you can make a .deb file withoutrebuilding the upstream sources like this[74]:

$ fakeroot debian/rules binary

Or simply do the following to see if it builds or not:

$ fakeroot debian/rules build

一旦完成了调试,记住要按照前面所的正常过程重构建你的软件包。你可能无法正常上传用此种方法构建的 .deb文件。



[64] This GPG key must be signed by a Debian developer to get connected to theweb of trust and must be registered to the Debiankeyring. This enables your uploaded packages to be accepted to theDebian archives. See Creating a new GPGkey and Debian Wiki onKeysigning.

[65] You can avoid applying quilt patches in the 3.0(quilt) source format at the end of the extraction with the--skip-patches option. Alternatively, you can rundquilt pop -a after normal operation.

[66] The actual autobuilder system involves much more complicated schemes thanthe one documented here. Such details are beyond the scope of thisdocument.

[67] Unlike under the pbuilder package,the chroot environment under the sbuild package used by the autobuilder systemdoes not enforce the use of a minimal system and may have many leftoverpackages installed.

[68] Since the pbuilder package is stillevolving, you should check the actual configuration situation by consultingthe latest official documentation.

[69] See http://buildd.debian.org/ for more on Debian package auto-building.

[70] This assumes HOOKDIR=/var/cache/pbuilder/hooks. You canfind many examples of hook scripts in the/usr/share/doc/pbuilder/examples directory.

[71] 升级你的 stable 软件包有规定限制。

[72] See Version control systems for more.

[73] Here are some web resources available for advanced audiences.

[74] 常规情形下被配置好的环境变量在此时不会被自动设置。永远不要将使用这个 快速方法构建的软件包上传到任何地方。

如何制作deb包
2010年03月01日 星期一 16:18

The GNU Privacy Guard

Private和public的钥匙是gpg加密和解密过程的主要部分,所以第一步就是创建为自己创建一对密匙.

  1. 生成私钥

    $gpg --gen-key

    你需要回答一些这个命令提出的问题

    1. 私钥的种类和size,这里缺省的答案已经足够好了

    2. 私钥的有效期,我通常选择不会过期,呵呵

    3. 你的真实的姓名和e-mail地址,这些是用来从一大堆钥匙中找到你的钥匙的

    4. 关于你的钥匙的comment,可以为空,我一般填一个昵称

    5. 钥匙的密码. 千万别忘了,否则所有你加密过的文件都没用了

  2. 为你的私钥生成一个公钥(文本文件),这是我的:aubrey.asc.zip

    $ gpg --armor --output public.key --export <your email>

    你可以分发这个文件了,给你的朋友,或者贴到你的个人网站上, or whatever.

  3. 为自己加密一个文件. 这里--recipient可以是你的全名,也可以是你的邮件地址
    #gpg --encrypt --recipient 'Your Name' foo.txt
  4. 密这个文件. 这里不加--output选项的话,解密的内容将被送到屏幕上
    #gpg --output foo.txt --decrypt foo.txt.gpg
  5. 别人加密一个文件. 这里首先要import别人的公钥,然后加密。注意这里变化的只是--recipient选项
    #gpg --import key.asc
    #gpg --list-keys
    #gpg --encrypt --recipient 'myfriend@his.isp.net' foo.txt
  6. 解密一个从别人那里发来的文件. 这个和本机加密的文件解密没什么区别.
    #gpg --output foo.txt --decrypt foo.txt.gpg

如何制作deb包

下面用一个简单的程序例子,来讲解如何制作deb包。首先你需要一个deb包管理的系统,debian, ubuntu等。
  这里我用的是nexenta. 这些系统默认装好了deb包制作需要的工具,如dpkg-dev, devscripts等。如果没有,你也可以在制作过程中用apt-get install来手动安装。

1. 创建一个简单的源码包

aubrey@aubrey-nexenta:~/deb$ ls -l hellodeb/
total 2
-rw-r--r-- 1 aubrey staff 203 Feb 16 12:50 Makefile
-rw-r--r-- 1 aubrey staff 73 Feb 16 12:46 hellodeb.c
  C code与制作deb包关系不大,也不需要修改,我们主要看一下Makefile文件,我们在制作deb包的时候,这个文件是需要修改的。
PROG=hellodeb
CC=gcc
BINDIR=/usr/bin
INSTALL=cp

$(PROG): hellodeb.c
$(CC) -o $(PROG) hellodeb.c

clean:
rm -rf $(PROG)

install:
$(INSTALL) $(PROG) $(BINDIR)

uninstall:
rm -rf $(BINDIR)/$(PROG)
2. 创建GPG key。GPG key在build包的时候需要用到,创建的方法参见 GPG使用指南 。创建完后,检查一下:
aubrey@aubrey-nexenta:~/deb/hellodeb$ gpg --list-keys
/export/home/aubrey/.gnupg/pubring.gpg
--------------------------------------
pub 1024D/7F8F1E57 2008-01-29
uid Aubrey Li
sub 2048g/6AF6581E 2008-01-29

3. 要开始对这个包进行deb化了。首先确保源代码目录绝对干净,为了让软件包能够正确地制作,必须把源代码目录的名字改成小写,并且符合-的形式。
aubrey@aubrey-nexenta:~/deb$ ls
hellodeb
aubrey@aubrey-nexenta:~/deb$ mv hellodeb/ hellodeb-1.0
aubrey@aubrey-nexenta:~/deb$ ls
hellodeb-1.0
4. 在正式deb化之前,我们先要export两个环境变量:
aubrey@aubrey-nexenta:~/deb$ export DEBEMAIL="aubreylee@gmail.com"
aubrey@aubrey-nexenta:~/deb$ export DEBFULLNAME="Aubrey Li"
  注意, 这里的name和email必须和你生成GPG钥匙的时候完全一样。这两个变量值也会在deb包的changelog等多个文件里被用到。
5. 现在可以对源码包进行deb化了。
aubrey@aubrey-nexenta:~/deb/hellodeb-1.0$ dh_make

Type of package: single binary, multiple binary, library, kernel module or cdbs?
[s/m/l/k/b] s

Maintainer name : Aubrey Li
Email-Address : aubreylee@gmail.com
Date : Sat, 16 Feb 2008 13:19:46 +0800
Package Name : hellodeb
Version : 1.0
License : blank
Type of Package : Single
Hit to confirm:
Done. Please edit the files in the debian/ subdirectory now. You should also
check that the hellodeb Makefiles install into $DESTDIR and not in / .
aubrey@aubrey-nexenta:~/deb/hellodeb-1.0$
  这里询问包的类型,这里我们是单个可执行文件,所以我选了s。
  还有两个重要的提示:
Please edit the files in the debian/ subdirectory now.

  • You should also check that the hellodeb Makefiles install into $DESTDIR and not in / .

6. 我们先关注一下第二个提示,修改Makefile。这里主要是安装路径,修改如下:

PROG=hellodeb
CC=gcc
BINDIR=$(DESTDIR)/usr/bin
INSTALL=cp

$(PROG): hellodeb.c
$(CC) -o $(PROG) hellodeb.c

clean:
rm -rf $(PROG)

install:
mkdir -p $(BINDIR)
$(INSTALL) $(PROG) $(BINDIR)

uninstall:
rm -rf $(BINDIR)/$(PROG)
  第一个修改是为了在build包的时候能够把需要的文件安装到正确的目录,从而正确的包含在生成的deb包中。
  第二个修改是因为修改后的BINDIR变量的目录并不存在,所以需要手动创建。

7. 然后我们要看一下debian这个生成的目录了
aubrey@aubrey-nexenta:~/deb/hellodeb-1.0/debian$ ls
README.Debian control docs hellodeb-default.ex manpage.sgml.ex postrm.ex watch.ex
changelog copyright emacsen-install.ex hellodeb.doc-base.EX manpage.xml.ex preinst.ex
compat cron.d.ex emacsen-remove.ex init.d.ex menu.ex prerm.ex
conffiles.ex dirs emacsen-startup.ex manpage.1.ex postinst.ex rules
  这个目录下面的文件很多,不能一一解释。这里列举几个重要的,也是绝大部分软件必须的:
  • control文件: 声明很多重要的变量,dpkg通过这些变量来管理软件包
  • copyright文件: 不用说,版权信息,相当重要
  • changelog文件: 这是一个必需文件,包含软件版本号,修订号,发行版和优先级。
  • rules文件: 这实际上是另外一个Makefile脚本,用来给dpkg-buildpackage用的.
  • compat文件: 这个文件留着是有用的
  • dirs文件:这个文件指出我们需要的但是在缺省情况下不会自动创建的目录

  我删除掉其他文件,debian目录现在如下:

aubrey@aubrey-nexenta:~/deb/hellodeb-1.0/debian$ ls
changelog compat control copyright dirs rules
  注意,除了compat文件,其他文件都是需要修改的,根据你自己的软件包的情况。

8. 好了,所有的准备工作都就绪了。我们可以build软件包。dpkg-buildpackage有一项dh_testroot的检查,你必须用root来运行这个命令,或者用fakeroot(需要安装fakeroot包)
aubrey@aubrey-nexenta:~/deb/hellodeb-1.0$ dpkg-buildpackage -rfakeroot -sa
  或者切换到root,注意,你要确保你保持切换后仍旧保持当前用户的路径,否则在build包的时候会找不到GPG key。
aubrey@aubrey-nexenta:~/deb/hellodeb-1.0$ sudo -s
Password:
root@aubrey-nexenta:~/deb/hellodeb-1.0# dpkg-buildpackage -sa
  build过程中需要输入GPG密匙的密码,两次,其他就没什么事情可做了。

9. 创建完成后,在该目录的上级目录应该得到如下几个文件:
  • hellodeb_1.0-1.tar.gz: 源码包
  • hellodeb_1.0-1.dsc: 源代码总结,根据control文件创建,包含GPG签名
  • hellodeb_1.0-1_solaris-i386.deb: 完整的二进制包,可用dpkg管理
  • hellodeb_1.0-1_solaris-i386.changes: 供dput使用

10. 最后作一下检查和安装工作.

root@aubrey-nexenta:~/deb# dpkg-deb -c hellodeb_1.0-1_solaris-i386.deb
drwxr-xr-x root/root 0 2008-02-16 13:56:12 ./
drwxr-xr-x root/root 0 2008-02-16 13:56:10 ./usr/
drwxr-xr-x root/root 0 2008-02-16 13:56:10 ./usr/share/
drwxr-xr-x root/root 0 2008-02-16 13:56:10 ./usr/share/doc/
drwxr-xr-x root/root 0 2008-02-16 13:56:12 ./usr/share/doc/hellodeb/
-rw-r--r-- root/root 246 2008-02-16 13:19:48 ./usr/share/doc/hellodeb/copyright
-rw-r--r-- root/root 191 2008-02-16 13:19:48 ./usr/share/doc/hellodeb/changelog.Debian.gz
drwxr-xr-x root/root 0 2008-02-16 13:56:11 ./usr/bin/
-rwxr-xr-x root/root 3436 2008-02-16 13:56:11 ./usr/bin/hellodeb
root@aubrey-nexenta:~/deb# dpkg -i hellodeb_1.0-1_solaris-i386.deb
Selecting previously deselected package hellodeb.
(Reading database ... 31630 files and directories currently installed.)
Unpacking hellodeb (from hellodeb_1.0-1_solaris-i386.deb) ...
Setting up hellodeb (1.0-1) ...
root@aubrey-nexenta:~/deb# which hellodeb
/usr/bin/hellodeb
root@aubrey-nexenta:~/deb# hellodeb
hello deb
root@aubrey-nexenta:~/deb# dpkg -r hellodeb
(Reading database ... 31632 files and directories currently installed.)
Removing hellodeb ...
root@aubrey-nexenta:~/deb# which hellodeb
root@aubrey-nexenta:~/deb#

http://blog.chinaunix.net/u1/41699/showart_472258.html



dpkg是Debian系统中用于安装、卸载和管理软件的工具。制作deb就是将软件成.deb文件,方便在Debian系统中进行安装和管理。下面是一个dpkg制作deb的例子。 首先,我们需要将软件成一个目录结构,括必要的文件和文件夹。例如,我们要制作一个名为example的软件,我们可以创建一个example文件夹,并将软件的文件复制到该文件夹中。 在example文件夹中,我们需要创建一个DEBIAN文件夹,用于存放软件的控制文件。在DEBIAN文件夹中,我们需要创建一个control文件,该文件用于描述软件的基本信息,例如软件名称、版本、适用的操作系统等。可以使用一个文本编辑器打开control文件,并按照一定的格式填写信息。 控制文件中的一个示例内容如下: Package: example Version: 1.0 Architecture: amd64 Maintainer: Your Name <your@email.com> Description: This is an example package. 除了control文件,如果软件还依赖其他软件,我们还需要创建一个文件来描述这些依赖。我们可以创建一个名为package_name.dependencies的文件,并在其中列出软件的依赖关系。 在完成上述步骤后,我们可以使用dpkg-deb命令将example文件夹打成一个.deb文件。打开终端,切换到example文件夹所在的目录,然后执行以下命令: dpkg-deb -b example 执行完毕后,会生成一个名为example.deb的文件,即制作完成的deb。我们可以通过dpkg命令进行安装、卸载或管理该软件。例如,要安装example.deb,可以执行以下命令: sudo dpkg -i example.deb 通过上述步骤,我们就完成了一个简单的dpkg制作deb的例子。当然,实际制作deb时可能还涉及其他要求和步骤,例如设置文件权限、预/后安装脚本等,这取决于具体的软件需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值