Chapter 3. 工具的配置

Table of Contents

3.1. 電子郵件地址
3.2. mc
3.3. git
3.4. quilt
3.5. devscripts
3.6. sbuild
3.7. git-buildpackage
3.8. HTTP 代理
3.9. 私有 Debian 倉庫
3.10. Virtual machines
3.11. Local network with virtual machines

build-essential 套件必須在構建環境內預先安裝。

devscripts 套件應當安裝在維護者的工作環境中。

Although this is not necessarily an absolute requirement, it is a good idea to install and set up all of the popular set of packages mentioned in this chapter in the maintainer environment. This enables us to share the common baseline working environment. . Please install the tools mentioned in the Overview of Debian Maintainer Tools in the “Debian Developer’s Reference”, as needed, too.

[Caution] Caution

這裡展示的工具配置方式僅作為範例提供,可能與系統上最新的套件相比有所落後。Debian 的開發具有一個移動的目標。請確保閱讀合適的文件並按照需要更新配置內容。

許多 Debian 維護工具識別並使用 shell 環境變數 $DEBEMAIL$DEBFULLNAME 作為作為您的電子郵件地址和名稱。

我們可以通過將下面幾行加入 ~/.bashrc[7] 的方式對這些軟體進行配置。

新增至 ~/.bashrc 檔案. 

DEBEMAIL="your.email.address@example.org"
DEBFULLNAME="Firstname Lastname"
export DEBEMAIL DEBFULLNAME

mc 命令提供了管理檔案的簡單途徑。它可以開啟二進位制 deb 檔案,並僅需對二進位制 deb 檔案按下回車鍵便能檢查其內容。它呼叫了 dpkg-deb 命令作為其後端。我們可以按照下列方式對其配置,以支援簡易 chdir 操作。

新增至 ~/.bashrc 檔案. 

# mc related
if [ -f /usr/lib/mc/mc.sh ]; then
  . /usr/lib/mc/mc.sh
fi

如今 git 命令已成為管理帶歷史的原始碼樹的必要工具。

git 命令的使用者級全域性配置,如您的名字和電子郵件地址,儲存在 ~/.gitconfig 檔案中,且可以使用如下方式配置。

$ git config --global user.name "Name Surname"
$ git config --global user.email yourname@example.com

如果您仍然只習慣 CVS 或者 Subversion 的命令風格,您可以使用如下方式設定幾個命令別名。

$ git config --global alias.ci "commit -a"
$ git config --global alias.co checkout

您可以使用如下命令檢查全域性配置。

$ git config --global --list
[Tip] Tip

有必要使用某些圖形介面 git 工具,例如 gitkgitg 命令來有效地處理 git 倉庫的歷史。

quilt 命令提供了記錄修改的一個基本方式。對 Debian 打包來說,該工具需要進行設定,從而在 debian/patches/ 目錄內記錄修改內容,而非使用預設的 patches/ 目錄。

為了避免改變 quilt 命令自身的行為,我們在這裡建立一個用於 Debian 打包工作的命令別名:dquilt。之後,我們將對應內容寫入 ~/.bashrc 檔案。下面給出的第二行為 dquilt 命令提供與 quilt 命令相同的命令行補全功能。

新增至 ~/.bashrc 檔案. 

alias dquilt="quilt --quiltrc=${HOME}/.quiltrc-dpkg"
. /usr/share/bash-completion/completions/quilt
complete -F _quilt_completion $_quilt_complete_opt dquilt

然後我們來建立具有如下內容的 ~/.quiltrc-dpkg 檔案。

d=.
while [ ! -d $d/debian -a `readlink -e $d` != / ];
    do d=$d/..; done
if [ -d $d/debian ] && [ -z $QUILT_PATCHES ]; then
    # if in Debian packaging tree with unset $QUILT_PATCHES
    QUILT_PATCHES="debian/patches"
    QUILT_PATCH_OPTS="--reject-format=unified"
    QUILT_DIFF_ARGS="-p ab --no-timestamps --no-index --color=auto"
    QUILT_REFRESH_ARGS="-p ab --no-timestamps --no-index"
    QUILT_COLORS="diff_hdr=1;32:diff_add=1;34:diff_rem=1;31:diff_hunk=1;33:"
    QUILT_COLORS="${QUILT_COLORS}diff_ctx=35:diff_cctx=33"
    if ! [ -d $d/debian/patches ]; then mkdir $d/debian/patches; fi
fi

請參考 quilt(1) 和 處理大量補丁的方法暨對 Quilt 的介紹 以瞭解如何使用 quilt 命令。

要取得使用範例,請檢視 Section 4.9, “第三步(備選):修改上游原始碼”

debsign 命令由 devscripts 套件提供,它可以使用使用者的 GPG 私鑰對 Debian 軟體包進行簽名。

debuild 命令同樣由 devscripts 套件提供,它可以構建二進位制套件並使用 lintian 命令對其進行檢查。lintian 命令的詳細輸出通常都很實用。

您可以將下列內容寫入 ~/.devscripts 檔案來進行配置。

DEBUILD_DPKG_BUILDPACKAGE_OPTS="-i -I -us -uc"
DEBUILD_LINTIAN_OPTS="-i -I --show-overrides"
DEBSIGN_KEYID="Your_GPG_keyID"

用於 dpkg-source 命令的 DEBUILD_DPKG_BUILDPACKAGE_OPTS 中可以額外使用 -i-I 選項以幫助構建原始碼中具有外來無關內容的套件(參見 Section 5.17, “構建套件時排除不必要的內容”)。

當前情況下,使用 4096 位的 RSA 金鑰是較好的做法。另見 建立一個新 GPG 金鑰

The sbuild package provides a clean room (chroot) build environment. It offers this efficiently with the help of schroot using the bind-mount feature of the modern Linux kernel.

Since it is the same build environment as the Debian’s buildd infrastructure, it is always up to date and comes with full of useful features.

It can be customized to offer following features:

  • The schroot package to boost the chroot creation speed.
  • lintian 套件能找到所構建套件中的缺陷。
  • The piuparts package to find bugs in the package.
  • The autopkgtest package to find bugs in the package.
  • ccache 套件可以加速 gcc。(可選)
  • libeatmydata1 套件可以加速 dpkg。(可選)
  • 並行執行 make 以提高構建速度。(可選)

Let’s get started by following https://wiki.debian.org/sbuild .

$ sudo apt install sbuild piuparts autopkgtest lintian
$ adduser <your_user_name> sbuild

Logout and login to check you are a member of sbuild group using id command.

$ id
uid=1000(<yourname>) gid=1000(<yourname>) groups=...,132(sbuild)

Let’s create the configuration file ~/.sbuildrc in line with recent Debian practice https://wiki.debian.org/SourceOnlyUpload as:

cat >~/.sbuildrc << 'EOF'
##############################################################################
# PACKAGE BUILD RELATED (source-only-upload as default)
##############################################################################
# -d
$distribution = 'unstable';
# -A
$build_arch_all = 1;
# -s
$build_source = 1;
# --source-only-changes
$source_only_changes = 1;
# -v
$verbose = 1;

##############################################################################
# POST-BUILD RELATED (turn off functionality by setting variables to 0)
##############################################################################
$run_lintian = 1;
$lintian_opts = ['-i', '-I'];
$run_piuparts = 1;
$piuparts_opts = ['--schroot', 'unstable-amd64-sbuild'];
$run_autopkgtest = 1;
$autopkgtest_root_args = '';
$autopkgtest_opts = [ '--', 'schroot', '%r-%a-sbuild' ];

##############################################################################
# PERL MAGIC
##############################################################################
1;
EOF

Following document assumes that sbuild is configured this way.

Edit this to your needs. Post-build tests can be turned on and off by assigning 1 or 0 to the corresponding variables,

[Warning] Warning

可選的設定項可能造成負面影響。如果有疑問,請關閉它們。

[Note] Note

並行的 make 可能在某些已有套件上執行失敗,它同樣會使得構建日誌難以閱讀。

您也可能需要在 ~/.gbp.conf 中設定全域性配置資訊

# Configuration file for "gbp <command>"

[DEFAULT]
# the default build command:
builder = sbuild
# use pristine-tar:
pristine-tar = True
# Use color when on a terminal, alternatives: on/true, off/false or auto
color = auto
[Tip] Tip

這裡的 gbp 命令是 git-buildpackage 命令的一個別名。

您應當在本地設定 HTTP 快取代理以節約查詢 Debian 軟體倉庫的頻寬。可以考慮以下幾種選項:

  • 特化的 HTTP 快取代理,使用 apt-cacher-ng 套件。
  • Generic HTTP caching proxy (squid package) configured by squid-deb-proxy package

In order to use this HTTP proxy without manual configuration adjustment, it’s a good idea to install either auto-apt-proxy or squid-deb-proxy-client package to everywhere.

您可以使用 reprepro 套件搭建私有 Debian 倉庫。

For testing GUI application, it is good idea to have virtual machines. Install virt-manager and qemu-kvm.

Use of chroot and virtual machines allow us not to update the whole host PC to the latest unstable.

In order to access virtual machines easily over the local network, setting up multicast DNS service discovery infrastructure by installing avahi-utils is a good idea.

For all running virtual machines and the host PC, we can use each host name appended with .local for SSH to access each other.



[7] 這裡假設您正在使用 Bash 並以此作為登入預設 shell。如果您設定了其它登入 shell,例如 Z shell,請使用它們對應的配置檔案替換 ~/.bashrc 檔案。