2010年8月16日 星期一

COSCUP 2010 投影片

首先是第一天晚上的 Ubuntu BoF
第二天上午的 Introducing GStreamer
第二天下午的 Debian Policy 中的 5.6.12 小節的 Version

2010年6月26日 星期六

BetaRadio v1.0 網路廣播點播器 正式釋出

BetaRadio 因為 hichannel 網頁不斷地改版,最後碰到了 libmms 這個函式庫的一個 bug 所以專案就一直呈現死掉的狀態;不過最近終於有時間能夠找出 libmms 的 bug 並且修正,所以才能夠再次地讓這個純 C 語言寫出來的網路廣播點播器復活。

Source code tarball 可以在 http://code.google.com/p/betaradio/downloads/list 下載
相依一個特別的函式庫 json-cat 可以在 http://github.com/fourdollars/json-cat/downloads 下載 Source code tarball

另外就是特別為 Ubuntu 10.04 使用者準備好一個 PPA 可以馬上裝起來就可以使用了。

GUI 安裝方式 [系統]->[管理]->[軟體來源] 裡面的 [其它軟體] 點擊 [加入] 後輸入
ppa:fourdollars/lucid
然後關閉 [軟體來源] 選擇 [重新載入] 
再打開 [系統]->[管理]->[Synaptic套件管理程式] 搜尋 betaradio 就可以找到來安裝了

或是可以使用命令列輸入來安裝
$ sudo apt-add-repository ppa:fourdollars/lucid
$ sudo apt-get update
$ sudo apt-get install betaradio
安裝完就可以在 [應用程式]->[影音] 裡面看到 "BetaRadio 點播器" 點一下就可以使用了~ :)

2010年6月17日 星期四

Debian Package (5) - 版本號碼

關於 Debian Package 的版本號碼規則全都寫在 Debian Policy Manual 上面的 5.6.12 Version
基本格式就只有一段
[epoch:]upstream_version[-debian_revision]
其中的 epoch 就是紀元,epoch 為大於或等於零的整數,如果不特別指定 epoch 就是零,這讓我想到以前有學過:前寒武紀/寒武紀/奧陶紀/志留紀/泥盆紀/石碳紀/二疊紀/三疊紀/侏儸紀/白堊紀/第三紀/第四紀,前寒武紀一定是最古老的,所以無論後面的 upstream_version 跟 debian_version 寫的是什麼,侏儸紀的版號一定大於前寒武紀,例如:
0:9527 < 1:7
一看就知道 9527 一定比 7 還要大的啊!不過因為 9527 在比較舊的紀元,所以多大都沒有用的!


接著是 upstream_version 照字面上翻譯就是上游軟體的版本號碼,例如 PCManX GTK+ 目前最新的正式釋出版本號碼為 0.3.9,不過如果接下來的 PCManX GTK+ 0.3.10 有一些測試 alpha/beta/rc 的版號就可能會長得像是 0.3.10-alpha1 / 0.3.10-beta2 / 0.3.10-rc3 之類的。


最後就是 debian_version 例如 Ubuntu 10.04 所提供的 PCManX GTK+ 套件版號為 0.3.9-2ubuntu2
$ apt-cache policy pcmanx-gtk2
...
0.3.9-2ubuntu2 0
500 http://tw.archive.ubuntu.com/ubuntu/ lucid/universe Packages
這邊的 debian_version 就是 2ubuntu2


知道版本號碼的組成元素之後就是要開始比較大小,軟體套件能不能夠升級就是要靠版號比大小。


指令 dpkg 有提供一個參數可以用來比對版號的大小
dpkg --compare-versions
例如:
$ dpkg --compare-versions 0:9527-2ubuntu2 '<' 1:7-2ubuntu2; echo $?
0
$ dpkg --compare-versions 0:9527-2ubuntu2 '<' 0:9527-2ubuntu2~3small; echo $?
1
不知道看倌有沒有注意到 0:9527-2ubuntu2 '<' 0:9527-2ubuntu2~3small 比較的結果是失敗的
0:9527-2ubuntu2~3small
---------------^------
Debian Package Version 有一個特別的地方,就是 '~' 開頭的版號比空字串還要小,什麼!'~' 比什麼都沒寫的虛無還要小!
所以可以做個有趣的實驗
$ dpkg --compare-versions 1-1~ '<' 1-1; echo $?
0
$ dpkg --compare-versions 1-1~~ '<' 1-1~; echo $?
0
看到沒有~ 尾巴長的越長的版號反而是越小的~ >w<


最後再聊一些約定俗成的慣例。


慣例一:
debian_version 可以省略不寫,如果要寫的話,結尾一定要是數字,而且這個數字不可為零。


慣例二:
除了該 Debian Package 的 Maintainer 之外,其他人不可以使用 debian_version 全為數字的版號,例如:假設今天有 PCManX GTK+ 0.3.10 的正式釋出版本,我們自己私下在打包 Debian Package 時就不可以使用 0.3.10-1 這樣的版號,不過根據慣例一,我們可以使用 0.3.10-0ubuntu1 這樣的版號,不過 0ubuntu1 這樣的 debian_version 只有上傳 Package 到 Ubuntu 的 Maintainer 才可以這樣使用,如果把 Debian 跟 Ubuntu 都當上游的話,那麼就應該使用 0ubuntu0ppa1 這樣的版號,當然 ppa 也可以換成其它自己偏好的字串。


慣例三:
如果是使用 apt-get source pcmanx-gtk2 抓下來改的 Debian Package,在改完後要直接在原本的版號後面加上自己的版號,像是原本是 0.3.9-2ubuntu2 就會變成 0.3.9-2ubuntu2fourdollars1

2010年6月14日 星期一

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

前一篇文章只能完成了 Debian Package 的打包但是並沒有上傳至 Debian 官方的套件庫
如果想要上傳到 Debian 官方的套件庫就必需尋求 Debian Developer (以下簡稱 DD) 的協助了
另外就是還要準備一把已經被 DD 簽過的金鑰才行 (可能要數個 DD 簽過才行)
如果沒有熟識的 DD 幫忙,其實還可以到 http://lists.debian.org/debian-mentors 上面尋求 DD 的協助
不過建議先看過 The debian-mentors FAQ 這份文件後再去尋求 DD 的協助

另外一種方式是自己維護 Debian Packages Archives 不過這真的很麻煩~ ^^b
如果是在 Ubuntu 上面的話可以考慮使用 Launchpad 上的 PPA 服務
以下將以 Launchpad PPA 為例

首先要建立自己的 Launchpad PPA 才行
會有一些申請的動作要自己去完成
可以參考 https://help.launchpad.net/Packaging/PPA 上面的說明

以下會假設已經完成 Launchpad PPA 的設定並且也準備好 SSH 金鑰跟 GPG 金鑰,只剩下要上傳 Debian Source Package 的動作要做。

因為 Launchpad PPA 只支援 Debian Source Package 的上傳,Launchpad 會再從 Debian Source Package 把 Debian Binary Package 給編譯產生出來,而之前的指令 dpkg-buildpackage -rfakeroot -uc -us -tc 其實會同時把 Debian Binary/Source Package 給產生出來,不過因為 -uc -us 這兩個參數就是指定不要使用 GPG 簽章,所以產生出來的 Debian Package 應該也無法上傳到 PPA 上使用。

如果要建立有簽章的 Debian Source Package 就要使用下面的指令
$ export DEBFULLNAME="First-Name Family-Name (Nickname)"
$ export DEBEMAIL="username@foo.bar"
$ dpkg-buildpackage -rfakeroot -S
這樣就可以在目錄上層建立牽過的 Debian Source Package 由以下三個檔案組成
taiwan-radio-tuner_0.1.dsc
taiwan-radio-tuner_0.1_source.changes
taiwan-radio-tuner_0.1.tar.gz
不過目前這樣的 Debian Source Package 就算上傳到 PPA 也會是失敗收場。

因為 Ubuntu 有一些規則要依循才行,首先修改 debian/changelog
taiwan-radio-tuner (0.1) lucid; urgency=low                                            

  * Initial release.

 -- First-Name Family-Name (Nickname) <username@foo.bar>  Mon, 14 Jun 2010 12:47:29 +0800
原本的 experimental 要改成 lucid 因為要給 Ubuntu 10.04 使用

另外就是如果要嚴格一點通過 lintian - Debian package checker 的測試,這是上傳到 Debian 官方套件庫必定要通過的測試,雖然在 Launchpad PPA 並沒有要求要通過 lintian 的測試,執行 debuild -S 後會發現有一些錯誤跟警告訊息出現。
W: taiwan-radio-tuner source: debhelper-but-no-misc-depends taiwan-radio-tuner
E: taiwan-radio-tuner source: package-uses-debhelper-but-lacks-build-depends
W: taiwan-radio-tuner source: package-lacks-versioned-build-depends-on-debhelper 7
W: taiwan-radio-tuner source: missing-debian-source-format
這些訊息其實只要 Google 一下就可以輕易地找到解決方法。
  • 首先是 debhelper-but-no-misc-depends 只要在 Depends 這個欄位多加上 ${misc:Depends} 就可以解決
  • 再來是 package-uses-debhelper-but-lacks-build-depends 跟 package-lacks-versioned-build-depends-on-debhelper 要多加上一個欄位 Build-Depends: debhelper (>= 7)
  • 剩下的 missing-debian-source-format 要多一個檔案在 debian/source/format 內容為 3.0 (native),因為這是一個原生的 Debian Package,如果是從上游的 tarball 而來的話就應該要使用 3.0 (quilt) 才行。
修改過後的 debian/control 如下:
Source: taiwan-radio-tuner
Maintainer: First-Name Family-Name (nickname) <username@foo.bar>
Section: contrib/web
Priority: extra
Build-Depends: debhelper (>= 7)
Standards-Version: 3.8.4
Homepage: https://chrome.google.com/extensions/detail/hacebidkncpkfenhpapdbkcefalehepa

Package: taiwan-radio-tuner
Architecture: all
Depends: ${misc: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.
修改成這樣再去執行 debuild -S 應該就不會再有任何的錯誤訊息或是警告訊息的出現了。

最後就可以用 dput 上傳到 PPA 裡面啦~ :)
$ dput ppa:username/lucid taiwan-radio-tuner_0.1_source.changes
現在在 https://launchpad.net/~fourdollars/+archive/lucid
上面應該可以看到已經上傳到 Launchpad PPA 上的 Debian Package 了~
如果想要使用的朋友可以在 Ubuntu 10.04 上面執行 sudo add-apt-repository ppa:fourdollars/lucid
然後再執行 sudo apt-get update && sudo apt-get install taiwan-radio-tuner 應該就可以安裝好了~ :)

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