Command Not Found Magic

試著在剛裝好的 Ubuntu 上亂打一些指令時,發現在 CLI 介面,Ubuntu 會聰明的提醒你忘了裝甚麼軟體套件。

user@user-laptop:~$ proxychains
The program 'proxychains' is currently not installed.
You can install it by typing:
sudo apt-get install proxychains
-bash: proxychains: command not found

稍微玩了一下,發現是 command-not-found 這個神奇法術。軟體套件包含 /usr/lib/command-not-found 、是一個用 Python 刻的指令稿,此軟體會查詢預先建成的指令/軟體名稱資料庫,只要餵給它指令名稱,他可以迅速的提示如何安裝含有該指令的軟體套件。由於資料庫是 gdbm,且大小只有 2.3M (command-not-found-data 0.2.17ubuntu1),因此查詢的速度相當快,使用者不太感覺到差異。

要使用此功能,尚必須在 bash 中定義一個 command_not_found_handle 函式,在查無指令時自動執行 command-not-found. Ubuntu 已經將這段程式建於 /etc/bash.bashrc.

不過目前使用的套件資料庫是預建的,因此不會依照你所使用的 apt sources 自動更新資料庫。若是可以整合 apt-file 與 dlocate 兩個的功能,應該可以提供較有彈性的功能吧。

July 10th, 2008 at 5:38 pm | Comments & Trackbacks (0) | Permalink


Adobe AIR for Linux

今年三月底時,Adobe 在 Adobe Lab 發行Adobe AIR for Linux alpha 版本。Adobe AIR 是一種執行環境,提供一個可使用 Adobe Flash, Adobe Flex, HTMLAjax 開發桌面 RIA 應用程式的平台。

試玩了一下,可以安裝 twhirl (Running Twhirl on Ubuntu 7.10) 等軟體沒有問題。可惜的是,目前 Linux 版本還不能支援 XIM,以至於無法輸入中文。

另外一個惱人問題是 Adobe AIR 將 zip 格式檔案都以 xdg-mime (xdg-mime of Portland project) 註冊成使用 Adobe AIR 開啟,以至於你的 zip 檔、OpenOffice 文件檔 (也是 zip 壓縮格式) 都變成以 Adobe AIR 開啟了!

解決辦法是

先移除原本的 xdg-mime 設定

# xdg-mime uninstall --novendor "/opt/Adobe AIR/Versions/1.0/support/AdobeAIR.xml"

以編輯器開啟 "/opt/Adobe AIR/Versions/1.0/support/AdobeAIR.xml",並移除檔案中以下文字

<magic priority="100">
<match type="string" value="PK\003\004" offset="0" />
</magic> 

重新安裝 xgd-mime 設定

# xdg-mime install --novendor "/opt/Adobe AIR/Versions/1.0/support/AdobeAIR.xml"

上述 # 開頭指令,指使用 root 執行。

June 25th, 2008 at 5:25 pm | Comments & Trackbacks (1) | Permalink


Over the Air

哇,連續 48 小時針對行動裝置的 BarComp,議程主題含括了所有的開放平台,同一段時間居然同時有 6 個議程同時進行!真是太酷了。Over the AirMobile Monday London 所辦的活動,贊助的有 Nokia, Google, Yahoo, Sun, Adobe 等。活動就在明天開始。

Over the air

看了看台灣的 Mobile Monday Taipei 調性偏向高調的商務聚會性質,缺乏了玩家、開發者那樣的氛圍。相較之下,Nokia Taiwan 為 Mobile01 社群辦的 S60 玩家聚會還更吸引我去湊熱鬧呢。

April 3rd, 2008 at 12:33 pm | Comments & Trackbacks (0) | Permalink


Debian 無人值守安裝程式

上一篇提到可以透過 debconf 的無交互介面的軟體安裝,其實你尚可以用 debconf 來做 preseeding (sarge 的中文手冊也提到 preseeding)的設定檔。Preseeding 是一種製作「無人值守」安裝光碟的方法,基本上就是以預先設定回答所有安裝過程中會詢問的問題,因此你可以先做好一片預定安裝的軟體與設定的安裝光碟/設定檔,然後使用該設定自動安裝機器。透過 debconf 的幫忙,你可以先架設一台 Debian 主機作為「種子」,然後以該種子的設定複製到其它的新安裝機器上。作法相當容易,你可以使用 debconf-get-selections 取得種子機器的所有設定,透過參數程式會吐出一段樣本,再依據需求校改即可。

# debconf-get-selections --installer

相關的語法同手冊描述,修改完成的 preseed.cfg 可於置於網路或磁碟中,再於一般的 Debian 安裝光碟中指定路徑即可。雖說相關的指令不難,但是若要修改到可以順利安裝與調整的程度,還是需要相當多時間調校,相關說明不妨參考 Automating new Debian installations with preseeding

AndrewLee 利用 preseeding 做了一組 Debian for Beginners,內容整合了中文相關的套件與常用的軟體。陸陸續續也校修了不少問題,有興趣使用 Debian 的人不妨試用安裝。至於想偷學技巧人,請往 http://debian.org.tw/d-i/etch/preseed.cfg 挖寶去吧。

March 6th, 2008 at 8:07 pm | Comments & Trackbacks (0) | Permalink


noninteractive dpkg installation on debian system

Once you have many Debian servers, maintenance would be a problem. I just counted that I have more then 30 etch servers running in several vserver machines. Sometimes, I would like to install Debian package in all of these servers. However, it takes too much time to ssh /vserver enter into every hosts, and answer the installation questions one by one.

Thanks for the debconf(1), it’s quite easy to do non-interactive installation, since debconf already provide a noninteractive frontend. All you need to do is set the configuration before you install the package. It can be done by debconf-set-selections.

First, you have to install the package in one hosts. It would be better if you install/test the package on the same distribution version and package version. Here is an example for install localepurge. localepurge is a software for superfluous locale data, that will save you some disk space. As a Chinese, I usually don’t need Spanish, Franch and any other hundreds of different locale data.

Once you install the localepurge, you can use debconf-get-selections to dump the configuration you did.  The debconf-get-selections is part of the debconf-utils. The command would look like

# debconf-get-selections |grep ^localepurge
localepurge	localepurge/quickndirtycalc	boolean	true
localepurge	localepurge/remove_no	note
localepurge	localepurge/mandelete	boolean	true
localepurge	localepurge/showfreedspace	boolean	true
localepurge	localepurge/verbose	boolean	false
localepurge	localepurge/nopurge	multiselect	en, en_US.UTF-8, zh, zh_TW, zh_TW.UTF-8
localepurge	localepurge/dontbothernew	boolean	false
localepurge	localepurge/none_selected	boolean	false

So, these are the questions the debconf will ask you. (Since the questions has different priorities, you might not be asked for all the questions) The localepurge/nopurge line is the locales data we want to keep, so we also want to let the other servers have the same settings. You can use debconf-set-selections to set the values in the other servers.

# echo "localepurge localepurge/nopurge multiselect en, en_US.UTF-8, zh, zh_TW, zh_TW.UTF-8"|debconf-set-selections

Then you can now install the package, it will use the default value you just gave. If you need to install many servser, and do not want to see the question dialogs. You can use noninteractive fronetend to bypas the questions.

# DEBIAN_FRONTEND=noninteractive dpkg-reconfigure localepurge

This is a Tips for Debian system.

March 6th, 2008 at 7:06 pm | Comments & Trackbacks (1) | Permalink


unlock script for svn-mirror

Thanks clkao (高大師) for the great svn-mirror tool. I am using svn-mirror 0.68-3 on Debian Etch for mirror svn repository from the damn far and slow European svn server, so I can enjoy the super faster checkout and show the log messages on local server.

However, since the the svn server is slow and connection is not stable (otherwise I don’t need svn-mirror anyway). The connection might be dropped or the process could be killed by accident in the long mirroring process. The problem is once the program is killed (Ex: by Control+C), then it will run into a dead lock situation. You will keep seeing this messages, and never get the mirror work again.

Waiting for sync lock on /mirror/remote: openwrt:25221.

In order to fix the problem, I wrote a simple script svn-mirror-unlock.pl. It’s for clean the dead lock.

$ svn-mirror-unlock.pl
svn-mirror-unlock.pl: unlock SVMREPOS path
$ perl svn-mirror-unlock.pl unlock /home/svn mirror/remote

This is a tip for Debian.

March 5th, 2008 at 11:58 pm | Comments & Trackbacks (0) | Permalink