PBuilder and Cowdancer

8月 22nd, 2006 Comments Off

零、前言
之前我介紹過在 Fedora 底下使用 mock 來 Chroot Build 套件
那麼,在 Ubuntu 底下有什麼好用的工具呢?
我找到了 PBuilder and Cowdancer
底下是我最近在使用 Pbuilder and Cowdancer 的一些心得

一、簡介
1.pbuilder 即 Personal Builder,是一個在私人環境下自動化打包套件的系統,會建立一
個 Chroot System,然後在 Chroot 環境裡 Build Package

2.pdebuild is a wrapper for Debian Developers, to allow running pbuilder just like “debuild”, as a normal user.

3.cowdancer is a Copy-on-write directory tree utility.

4.cow-shell command invokes a shell session. Within that session, under the directory cow-shell was invoke, cowdancer will create a new file when existing i-nodes are opened for
write.

5.cowbuilder command is a wrapper for pbuilder which allows using pbuilder-like interface over cowdancer environment.

二、安裝

sudo apt-get install pbuilder cowdancer

不過 Ubuntu Dapper 裡的 pbuilder 及 cowdancer 都太舊了,很多新的功能都不能用
所以我只好去 Edgy 裡 ‘借’ 比較新版的 pbuilder cowdancer debootstrap 來用
在我的 APT Repository 裡有放我包好給 dapper 用的新版本

三、設定
編輯設定檔 /etc/pbuilderrc 或 ~/.pbuilderrc
我有修改的部份如下:

MIRRORSITE=http://tw.archive.ubuntu.com/ubuntu
OTHERMIRROR="deb http://cle.linux.org.tw/candyz/Ubuntu i386/|deb http://tw.archive.ubuntu.com/ubuntu dapper-updates main restricted universe multiverse|deb http://tw.archive.ubuntu.com/ubuntu dapper-security main restricted universe multiverse"
BUILDRESULT=~/TMP/
COMPONENTS="main restricted universe multiverse"
DISTRIBUTION=dapper
DEBEMAIL="Chung-Yen Chang "
DEBBUILDOPTS="-k0x476A8659"
BUILDUSERID=1000
BUILDUSERNAME=candyz
PDEBUILD_PBUILDER=cowbuilder

四、使用
在使用之前,請先編輯好設定檔,看是要哪一個版本,相關路徑指定好

1.建立 Chroot 的環境

pbuilder create

或是

cowbuilder --create

建議使用 “cowbuilder –create” 來取代 “pbuilder create”,速度比較快一點

2.更新 Chroot 環境

pbuilder update

或是

cowbuilder --update

3.進入 Chroot 的環境

pbuilder login

或是

cowbuilder --login

4.進入 Chroot 的環境並執行指令

pbuilder execute

或是

cowbuilder --execute

5.開始打包套件

pbuilder --build pcmanfm_0.3.0.2-0candyz1.dsc
 or
cd pcmanfm-0.3.0.2
pdebuild --auto-debsign --debsign-k 0x476A8659

或是

cowbuilder --build pcmanfm_0.3.0-0candyz1.dsc
 or
cd pcmanfm-0.3.0.2
pdebuild --auto-debsign --debsign-k 0x476A8659

大致上就是這樣

五、結語
pbuilder 使用起來,沒有 Fedora 上的 mock 方便,我想同時打包 dapper and edgy 的套件時,也有點麻煩
為了方便在 dapper 及 edgy 的 Chroot 環境下切換,於是我寫了一支小小的 shell script 來用:

$ cat mock

#!/bin/bash
clear
if [ $# -lt 1 ]; then
  echo
  echo "Usage: $0 [Distribution] [Operation] [Options]"
  echo
  ls -1d /var/cache/pbuilder/base.cow*
  echo
  exit 0
fi

DIST="$1"
OPER="$2"
shift
shift
OPTS="$@"

cd && ln -sf .pbuilderrc-$DIST .pbuilderrc

if [ "$DIST" = "dapper" ]; then
  echo
  echo "Checking dapper..."
  if [ -d /var/cache/pbuilder/base.cow-dapper ]; then
    mv /var/cache/pbuilder/base.cow /var/cache/pbuilder/base.cow-edgy
    mv /var/cache/pbuilder/base.cow-dapper /var/cache/pbuilder/base.cow
  fi
fi

if [ "$DIST" = "edgy" ]; then
  echo
  echo "Checking edgy..."
  if [ -d /var/cache/pbuilder/base.cow-edgy ]; then
    mv /var/cache/pbuilder/base.cow /var/cache/pbuilder/base.cow-dapper
    mv /var/cache/pbuilder/base.cow-edgy /var/cache/pbuilder/base.cow
  fi
fi

if [ "$OPER" = "" ]; then
   echo
   echo "Switch to $DIST OK."
   echo "Now you can type 'pdebuild' to build."
   echo
else
  /usr/sbin/cowbuilder $OPER $OPTS
fi

我的設定檔分別是 ~/.pbuilderrc-dapper (for Dapper) 及 ~/.pbuilderrc-edgy (for Edgy)
然後用 link 的方式來決定要用哪一個

而 Chroot 的環境分別是 /var/cache/pbuilder/ 下的 base.cow-dapper (for Dapper) 及 base.cow-edgy (for Edgy)

mock 的用法:
$ mock

Usage: /root/bin/mock [Distribution] [Operation] [Options]

/var/cache/pbuilder/base.cow
/var/cache/pbuilder/base.cow-edgy

切換到 dapper or edgy 的環境
$ mock dapper

Checking dapper...

Switch to dapper OK.
Now you can type 'pdebuild' to build.

或是
$ mock edgy

Checking edgy...

Switch to edgy OK.
Now you can type 'pdebuild' to build.

然後再直接下 ‘pdebuild’ 指令來打包即可

mock 預設是呼叫 cowbuilder 指令
所以,也可以直接使用:
$ mock dapper –create
$ mock dapper –update
$ mock edgy –login
等指令

附錄、pbuilder and cowdancer 的指令語法
1.pbuilder

pbuilder - a personal builder
Copyright 2001-2006 Junichi Uekawa
Distributed under GNU Public License version 2 or later

pbuilder [operation] [pbuilder-options]
pdebuild [pdebuild-options] -- [pbuilder-options]

command lines:
pbuilder create [--basetgz base.tgz-path] [--distribution sarge|etch|sid|experimental]
  Creates a base.tgz

pbuilder update [--basetgz base.tgz-path] [--distribution sarge|etch|sid|experimental]
  Updates a base.tgz

pbuilder build [--basetgz base.tgz-path] pbuilder_2.2.0-1.dsc
  Builds using the base.tgz. Requires a .dsc filename

pbuilder clean
  Cleans the temporal build directory.

pbuilder login
pbuilder execute -- [command] [command-options]
  Logs in to the build environment and execute command.

pbuilder dumpconfig
  Dumps configuration information to stdout for debugging.

pbuilder-options:
 --basetgz [base.tgz location]
 --buildplace [location of build]
 --mirror [mirror location]
 --othermirror [other mirror location in apt deb-line format, delimited with | signs]
 --http-proxy [proxy]
 --distribution [distribution(sarge|sid|etch|experimental)]
 --buildresult [location-to-copy-build-result]
 --aptcache [location of retrieved package files]
 --removepackages [packages-to-remove on pbuilder create]
 --extrapackages [packages-to-add on pbuilder create]
 --configfile [configuration file to load]
 --hookdir [hook directory]
 --debemail [mail address]
 --debbuildopts [dpkg-buildpackage options]
 --logfile [filename to output log]
 --pkgname-logfile
 --aptconfdir [overriding apt config dir]
 --timeout [timeout time]
 --override-config
 --binary-arch
 --preserve-buildplace
 --bindmounts [bind-mount-point]
 --debug
 --autocleanaptcache
 --debootstrapopts [debootstrap options]
 --save-after-login/--save-after-exec
 --debootstrap [debootstrap|cdebootstrap]

pdebuild-specific pbuilder-options:
 --pbuilderroot [command to obtain root privilege for pbuilder]
 --buildsourceroot [command to obtain root privilege for dpkg-buildpackage]
 --use-pdebuild-internal
 --auto-debsign
 --debsign-k [keyid]

2.cowbuilder

cowbuilder [operation] [options]
operation:
 --build
 --create
 --update
 --login
 --execute
 --help
options:
 --basepath:
 --buildplace:
 --distribution:
FireStats icon Powered by FireStats