2010年6月14日 星期一

Debian Package (3) - 製作一個簡單但是有點用處的 Debian Package

以 Taiwan Radio Tuner 為例
現在要製作一個利用 Google Chrome 的 App Mode 來收聽網路廣播的程式
另外還要利用 Alltray 讓這個網頁應用程式可以隱藏在系統狀態列裡面
所以只要製作一個 taiwan-radio-tuner.desktop 安裝到 /usr/share/applications/ 底下就可以了
[Desktop Entry]
Name=Taiwan Radio Tuner
Exec=alltray google-chrome --app=http://fd.idv.tw/radio/
Icon=google-chrome
Type=Application
Categories=GTK;Application;AudioVideo;Audio;Player;
不過因為這個廣播程式會需要安裝一些額外的 codecs 才能夠正常地播放音樂
所以要額外安裝 gstreamer0.10-plugins-bad gstreamer0.10-plugins-ugly gstreamer0.10-ffmpeg 這幾個套件

但是這些步驟也許對一般的使用者來說太過複雜了,所以製作一個 Debian Package
首先準備好 taiwan-radio-tuner 的目錄
$ mkdir taiwan-radio-tuner-0.1
把上面的 taiwan-radio-tuner.desktop 放進去
$ mv taiwan-radio-tuner.desktop taiwan-radio-tuner-0.1
然後在 taiwan-radio-tuner-0.1 底下產生 debian 這個目錄
$ cd taiwan-radio-tuner-0.1
$ mkdir debian
接下來開始準備 debian/control
Source: taiwan-radio-tuner
Maintainer: Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
Section: contrib/web
Priority: extra
Standards-Version: 3.8.4
Homepage: https://chrome.google.com/extensions/detail/hacebidkncpkfenhpapdbkcefalehepa

Package: taiwan-radio-tuner
Architecture: all
Depends: google-chrome, alltray, gstreamer0.10-plugins-bad, gstreamer0.10-plugins-ugly, gstreamer0.10-ffmpeg
Description: Listen to the radio of Taiwan.
 The easiest way to listen to Internet Radio of Taiwan.
這邊要注意到 Section 這欄寫的是 contrib/web 寫成 contrib 是因為這個套件相依到 google-chrome 這個 non-free 的套件

規則如下:
  • 如果本身是 free 的套件卻相依到 non-free 的套件就應該放在 contrib 底下。
  • 如果本身是 non-free 的套件當然就是直接放在 non-free 底下,這種情況會是 non-free/web
  • 如果本身是 free 的套件也沒有相依到 non-free 的套件,那麼寫成 web 就可以了。
這是參考 Debian Policy Manual - 2.4 Sections 來分類的,如果在 Ubuntu 上可能會有另外的分類方式。

還有準備 debian/compat
$ echo 7 > debian/compat
準備 debian/rules
$ cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
最後使用 dch --create 來產生一個 debian/changelog
taiwan-radio-tuner (0.1) experimental; urgency=low                                            

  * Initial release.

 -- Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>  Mon, 14 Jun 2010 12:47:29 +0800
不過還有一個很重要的檔案要準備 debian/install 內容如下
taiwan-radio-tuner.desktop /usr/share/applications/
也就是要把 taiwan-radio-tuner.desktop 安裝到 /usr/share/applications/ 底下的意思
如果沒有這個 debian/install 來指定安裝的地方,dpkg 就不會知道這個 taiwan-radio-tuner.desktop 要安裝到哪裡
所以也就不會把 taiwan-radio-tuner.desktop 包裝在 Debian Package 裡面

以上都準備好,最後就可以執行 dpkg-buildpackage -rfakeroot -uc -us -tc 來產生 Debian Package 了~

把產生出來的 Debian Package 安裝進系統後就應該可以在 GNOME 系統選單裡面看到一個 Taiwan Radio Tuner 的 Icon 可以點選了~

Debian Package (2) - 從基本開始製作一個簡單的 Debian Package (續)

延續前一篇文章 Debian Package (1) - 從基本開始製作一個簡單的 Debian Package

在使用 dpkg-buildpackage -rfakeroot -uc -us 來產生 Debian Package 的時候其會有一些警告訊息
dpkg-source: warning: missing information for output field Standards-Version
dpkg-genchanges: warning: missing Section for binary package foo; using '-'
dpkg-genchanges: warning: missing Priority for binary package foo; using '-'
dpkg-genchanges: warning: missing Section for source files
dpkg-genchanges: warning: missing Priority for source files
我們只要把 debian/control 修改成
Source: foo
Maintainer: foo <foo@bar.com>
Section: misc
Priority: extra             
Standards-Version: 3.8.4

Package: foo
Architecture: all
Description: blah
這樣就不會又那些警告訊息了~
Section 這個欄位標示套件的分類 詳細可以參考 http://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections
Priority 這個欄位標示套件的重要性 詳細可以參考 http://www.debian.org/doc/debian-policy/ch-archive.html#s-priorities
Standards-Version 這個欄位則是標示打包 Debian Package 時所參考 Debian Policy 文件的版本號碼
目前最新是 3.8.4.0 在 http://www.debian.org/doc/debian-policy/ 最下面可以看到

不過到目前為止都只是一個無用的 Debian Package 罷了~ :P

但是這個無用的 Debian Package 可以看到一個 Debian Package 最基本的組成要件到底是什麼,說穿了就只是以下的四個檔案
debian/changelog #套件的變更紀錄
debian/compat #套件相容 debhelper 版本
debian/control #套件所有的描述跟分類
debian/rules #製作 Debian Package 時的 Makefile (背後會使用到 debhelper)
那麼接下來開始製作一個有點用處的 Debian Package 吧~ :)

2010年6月11日 星期五

Debian Package (1) - 從基本開始製作一個簡單的 Debian Package

首先要安裝需要的工具組
$ sudo aptitude install debhelper devscripts
然後產生一個目錄
$ mkdir foo-0.1
在裡面準備 debian/control
Source: foo
Maintainer: foo <foo@bar.com>

Package: foo
Architecture: all
Description: blah
然後準備 debian/rules
$ cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
有興趣可以看一下內容
#!/usr/bin/make -f
%:
    dh $@
在 debian/compat 指定一下這是 Debhelper 7 的 Debian Package
$ echo 7 > debian/compat
最後執行一下
$ dch --create --package foo -v 0.1 -D experimental
產生 debian/changelog 內容會像是
foo (0.1) experimental; urgency=low

  * Initial release. (Closes: #XXXXXX)                                   

 -- foo <foo@bar.com>  Fri, 11 Jun 2010 12:01:20 +0800
然後就可以開始打包了
$ dpkg-buildpackage -rfakeroot -uc -us
之後就會在 foo-0.1 這個目錄的上層目錄看到產生出來的 Debian Package 了
foo_0.1_all.deb
foo_0.1_amd64.changes
foo_0.1.dsc
foo_0.1.tar.gz
可以用指令看一下 foo_0.1_all.deb 的內容物
$ dpkg -c foo_0.1_all.deb
drwxr-xr-x root/root         0 2010-06-11 12:07 ./
drwxr-xr-x root/root         0 2010-06-11 12:07 ./usr/
drwxr-xr-x root/root         0 2010-06-11 12:07 ./usr/share/
drwxr-xr-x root/root         0 2010-06-11 12:07 ./usr/share/doc/
drwxr-xr-x root/root         0 2010-06-11 12:07 ./usr/share/doc/foo/
-rw-r--r-- root/root       161 2010-06-11 12:04 ./usr/share/doc/foo/changelog.gz
可以看到裡面只有一個之前寫的檔案 changelog.gz
也可以使用指令看一下這個 Debian Package 的資訊
$ dpkg -I foo_0.1_all.deb
 新式 debian 套件,版本 2.0。
 大小為 982 bytes:control 套件檔=371 bytes。
     218 bytes,    6 行         control
      79 bytes,    1 行         md5sums
 Package: foo
 Version: 0.1
 Architecture: all
 Maintainer: foo <foo@bar.com>
 Installed-Size: 28
 Description: blah
參考資料:http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-sourcecontrolfiles

2010年5月5日 星期三

自製 Ubuntu 10.04 Desktop/Server/Alternate/DVD ISO i386/amd64 安裝用 USB 隨身碟

首先要準備安裝用的 ISO 檔案
ubuntu-10.04-alternate-amd64.iso
ubuntu-10.04-alternate-i386.iso
ubuntu-10.04-desktop-amd64.iso
ubuntu-10.04-desktop-i386.iso
ubuntu-10.04-dvd-amd64.iso
ubuntu-10.04-dvd-i386.iso
ubuntu-10.04-server-amd64.iso
ubuntu-10.04-server-i386.iso
然後準備一隻容量至少 1GB 的 USB 隨身碟;如果要使用 DVD ISO 來製作的話,USB 隨身碟要準備容量至少 8GB 以上;如果想要製作多重開機的話,就準備容量越大越好的 USB 隨身碟,大到足夠塞進所有想要放進去的 ISO 檔案。

Ubuntu 10.04 Alternate/Server 安裝用 USB 隨身碟製作方法
$ wget http://archive.ubuntu.com/ubuntu/dists/lucid/main/installer-i386/current/images/hd-media/boot.img.gz
$ sudo dd if=/dev/zero of=/dev/sdc count=512
$ sudo su -c "zcat boot.img.gz > /dev/sdc"
等待約五分鐘完成後,再執行以下步驟就完成了。

$ sudo mount /dev/sdc /mnt
$ sudo cp -av ubuntu-10.04-alternate-i386.iso /mnt
$ sudo umount /mnt
以上粗體字的部份需要根據需求調整,例如 sdc -> sdb 或 alternate -> server 或 i386 -> amd64

Ubuntu 10.04 Desktop/DVD 安裝用 USB 隨身碟製作方法

先使用 fdisk 或是 gparted 將隨身碟分割好再進行以下步驟

$ sudo mkfs.vfat /dev/sdc1
$ sudo mount /dev/sdc1 /mnt
$ sudo grub-install --no-floppy --root-directory=/mnt /dev/sdc
然後再新增一個檔案 /mnt/boot/grub/grub.cfg 內容如下

menuentry "Ubuntu 10.04 Desktop i386" {
  loopback loop /iso/ubuntu-10.04-desktop-i386.iso
  linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/iso/ubuntu-10.04-desktop-i386.iso noeject noprompt --
  initrd (loop)/casper/initrd.lz
}
記得要把 ISO 檔案複製進 USB 隨身碟

$ sudo mkdir /mnt/iso
$ sudo cp -av ubuntu-10.04-desktop-i386.iso /mnt/iso
$ sudo umount /mnt
以上粗體字的部份需要根據需求調整,例如 sdc -> sdb 或 desktop -> dvd 或 i386 -> amd64

Desktop/DVD 的製作比較有彈性,只要在 grub.cfg 裡面增加 menuentry 就可以了,所以可以輕易地製作出多重 ISO 開機的 USB 隨身碟。

P.S. DVD 的部份因為筆者本身沒有 8GB 以上的 USB 隨身碟,所以沒有驗證過,不過應該是可以可行的。

2010年5月2日 星期日

Ubuntu 10.04 的 flash 中文方塊又出現啦~

筆者的修正方法是將系統的預設字型都換成 AR PL UMing TW
在家目錄底下增加一個檔案 .fonts.conf 內容為
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- ~/.fonts.conf for per-user font configuration -->
<fontconfig>
  <alias binding="strong">
    <family>serif</family>
    <prefer>
      <family>AR PL UMing TW</family>
      <family>Droid Serif</family>
    </prefer>
  </alias>
  <alias binding="strong">
    <family>sans-serif</family>
    <prefer>
      <family>AR PL UMing TW</family>
      <family>Droid Sans</family>
    </prefer>
  </alias>
  <alias binding="strong">
    <family>monospace</family>
    <prefer>
      <family>AR PL UMing TW</family>
      <family>Droid Sans Mono</family>
     </prefer>
  </alias>
  <alias binding="strong">
    <family>Terminus</family>
    <prefer>
      <family>Terminus</family>                      
      <family>AR PL UMing TW</family>
    </prefer>
  </alias>
  <alias binding="strong">
    <family>Droid Serif</family>
    <prefer>
      <family>Droid Serif</family>
      <family>Droid Sans Fallback</family>
    </prefer>
  </alias>
  <alias binding="strong">
    <family>Droid Sans</family>
    <prefer>
      <family>Droid Sans</family>
      <family>Droid Sans Fallback</family>
    </prefer>
  </alias>
  <alias binding="strong">
    <family>Droid Sans Mono</family>
    <prefer>
      <family>Droid Sans Mono</family>
      <family>Droid Sans Fallback</family>
    </prefer>
  </alias>
</fontconfig>
然後再執行
fc-cache -f -v
這樣就可以了~ :)

2010年4月28日 星期三

使用 perlbrew 來安裝 perl-5.12.3 跟 cpanm 的筆記

perlbrew 的好處就是可以使用一般使用者的權限來安裝 perl 跟其模組,不用擔心會破壞到原本系統的穩定性。
首先去抓 gugod 在 GitHub 上的 perlbrew 接者開始安裝 perl-5.12.3
git clone git://github.com/gugod/App-perlbrew.git
cd App-perlbrew
./perlbrew install
./perlbrew init
source ~/perl5/perlbrew/etc/bashrc
perlbrew install perl-5.12.3
perlbrew switch perl-5.12.3
然後去抓 miyagawa 在 GitHub 上的 cpanm 回來安裝
git clone http://github.com/miyagawa/cpanminus.git
cd cpanminus
./cpanm .
再回去用 cpanm 重新安裝一遍 perlbrew (因為第一次安裝時會少裝一些文件檔案)
cd App-perlbrew
cpanm Module::Install
cpanm .
以上步驟做完就可以有一個最簡單的 perl-5.12.3 的執行環境
之後使用前可以手動執行 source ~/perl5/perlbrew/etc/bashrc
或是直接把 source ~/perl5/perlbrew/etc/bashrc 加在 ~/.bashrc 裡面

P.S. 可以先將家目錄底下的 .cpan .cpanm .cpanplus 目錄都刪除掉 (或是更名就可以了) 再開始執行上面的步驟比較不會發生一些奇怪的問題

2010年4月23日 星期五

使用 GnuPG 驗證 Ubuntu 10.04 LTS RC 安裝光碟 ISO 檔

首先到台灣的 Mirror Site 上面下載相關的檔案回來
$ wget http://tw.releases.ubuntu.com/10.04/SHA1SUMS
$ wget http://tw.releases.ubuntu.com/10.04/SHA1SUMS.gpg
$ wget http://tw.releases.ubuntu.com/10.04/ubuntu-10.04-rc-desktop-i386.iso
利用 SHA1SUMS.gpg 來檢查 SHA1SUMS 是否為 Ubuntu 官方釋出的檔案 (有可能是經過偽造的)
$ gpg --verify SHA1SUMS.gpg SHA1SUMS
gpg: 由 2010年04月22日 (週四) 21時22分58秒 CST 建立的簽章, 使用 DSA 金鑰 ID FBB75451
gpg: 無法檢查簽章: 找不到公鑰
在 Ubuntu 系統上一開始檢查一定會找不到,不過可以透過 apt-key list 找到公鑰
$ sudo apt-key list
/etc/apt/trusted.gpg
--------------------
pub   1024D/437D05B5 2004-09-12
uid                  Ubuntu Archive Automatic Signing Key <ftpmaster@ubuntu.com>
sub   2048g/79164387 2004-09-12

pub   1024D/FBB75451 2004-12-30
uid                  Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com>
那麼就可以使用 apt-key export 取出公鑰
$ sudo apt-key export FBB75451 > cdimage.gpg
接下來在匯入 GnuPG 的金鑰鑰匙圈裡
$ gpg --import cdimage.gpg
gpg: 金鑰 FBB75451: 公鑰 "Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com>" 已匯入
gpg: 處理總量: 1
gpg:               已匯入: 1
gpg: 3 個勉強信任以及 1 個完全信任是 classic 信任模型的最小需求
gpg: 深度: 0  有效:   3  已簽署:  18  信任: 0-, 0q, 0n, 0m, 0f, 3u
gpg: 深度: 1  有效:  18  已簽署:  12  信任: 5-, 0q, 0n, 13m, 0f, 0u
gpg: 深度: 2  有效:   2  已簽署:   2  信任: 2-, 0q, 0n, 0m, 0f, 0u
gpg: 下次信任資料庫檢查將於 2012-07-13 進行
這時候再重新執行前面第一行指令
$ gpg --verify SHA1SUMS.gpg SHA1SUMS
gpg: 由 2010年04月22日 (週四) 21時22分58秒 CST 建立的簽章, 使用 DSA 金鑰 ID FBB75451
gpg: 完好的簽章來自於 "Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com>"
gpg: 警告: 這把金鑰並非以受信任的簽章所認證!
gpg:          沒有證據指出這個簽章屬於這個持有者.
主鑰指紋: C598 6B4F 1257 FFA8 6632  CBA7 4618 1433 FBB7 5451
出現這個警告的原因是因為還沒有將 FBB75451 這把公鑰加進自己的信任小圈圈裡面
不過不要緊,假設我們能夠信任 Ubuntu 系統裡面本來就有的公鑰 (如果不能信任的話,那就不應該繼續使用你的 Ubuntu 系統了 :P)
所以現在可以相信 SHA1SUMS 這個檔案真的是 Ubuntu 官方釋放出來的
於是就可以使用指令 sha1sum 來檢查 ubuntu-10.04-rc-desktop-i386.iso 這個檔案的完整性了
$ grep ubuntu-10.04-rc-desktop-i386.iso SHA1SUMS
66227f4fb31a25a22614666cd4ab538cc8f60956 *ubuntu-10.04-rc-desktop-i386.iso
$ sha1sum ubuntu-10.04-rc-desktop-i386.iso
66227f4fb31a25a22614666cd4ab538cc8f60956  ubuntu-10.04-rc-desktop-i386.iso
嗯~ 沒錯我下載的 ISO 真的是 Ubuntu 官方釋出的版本~ :D

參考資料:http://wiki.debian.org.tw/index.php/GnuPG