顯示具有 Linux 標籤的文章。 顯示所有文章
顯示具有 Linux 標籤的文章。 顯示所有文章

Resolve "PHP not found" of PHP/Java Bridge on Gentoo Linux

Environment:
  • Gentoo Linux
  • dev-lang/php-5.3.8 +cgi
  • www-apache/mod_fastcgi-2.4.7_pre0910052141
  • www-servers/tomcat-6.0.32-r1

PHP/Java Bridge: 6.2.1, installed in /var/lib/tomcat-6/webapps/JavaBridge

Problem Description:
Follow the installation guide on the PHP/Java Bridge website.  The test by the following command does not report any error.
java -classpath JavaBridge.war TestInstallation
However, when visiting the URL http://localhost:8080/JavaBridge, an error message is returned:
java.io.IOException: PHP not found. Please install php-cgi.
PHP test command was: [/usr/bin/php-cgi, -v]

Resolution:
  1. Edit /var/lib/tomcat-6/webapps/JavaBridge/WEB-INF/web.xml.  Uncomment the following line:
    <context-param><param-name>php_exec</param-name><param-value>php-cgi</param-value></context-param>
  2. Rename the pre-compiled php-cgi brought by JavaBridge.war.
    $ cd /var/lib/tomcat-6/webapps/JavaBridge/WEB_INF/cgi/i386-linux
    $ mv php.cgi php.cgi.pjb
  3. Create a symbolic link to /usr/bin/php-cgi. Assume the working directory is /var/lib/tomcat-6/webapps/JavaBridge/WEB_INF/cgi/i386-linux.
    $ ln -s /usr/bin/php-cgi .

It is also working to use the pre-compiled php-cgi from PHP/Java Bridge. Instead of steps 2 and 3, simply make the php-cgi executable.
$ chmod +x /var/lib/tomcat-6/webapps/JavaBridge/WEB_INF/cgi/i386-linux/php-cgi
Note that the pre-compiled php-cgi from PHP/Java Bridge is not recommended.

Release of JCBR 0.8.1

Please find this version in the earlier post JCBR: Java Chinese Book Reader. In this version, the following changes are made.
  • Fix a bug in the preference dialog that does not display the gestures correctly.
  • Fix a bug in determining the change of background color and foreground color.

Release of JCBR 0.8.0

Please find this version in the earlier post JCBR: Java Chinese Book Reader. In this version, the following changes are made.
  • Add support of Windows and Linux.
  • Display the selected book name at the bottom of the bookshelves dialog.
  • Make the font of the bookshelves dialog and the TOC dialog customizable.
  • Allow language switching on Windows and Linux.

Failed to Install camlp5 in Gentoo Linux - "make inconsistent assumptions over implementation Pretty"

When I use emerge to install camlp5-5.14 with ocaml-3.11.2 (or camlp5-5.12 with ocaml-3.10.2) and with ocamlopt enabled in Gentoo Linux, I get the following error message:
File "_none_", line 1, characters 0-1:
Error: Files prtools.cmx and ../lib/pretty.cmx
       make inconsistent assumptions over implementation Pretty
To solve this problem, I temporarily move /usr/lib/ocaml/pretty.cmx to some other place (or rename it). Don't forget to move the file back after camlp5 is installed successfully.

Added on 2010/11/29: I found the reason. The error message occurs because I installed the libraries of CIL in /usr/lib/ocaml by a self-written ebuild file. To prevent this error every time upgrading camlp5, I should install the CIL libraries in a separate folder.

L2TP IPSec VPN + NAT on Gentoo Linux with Single Network Adapter

This article describes how I setup an NAT server and an L2TP IPSec VPN server on Gentoo Linux with only one network adapter. Assume

  • 12.34.56.78 is the public IP of the server,
  • 12.34.56.1 is the gateway of the server,
  • 192.168.0.1 is the private IP of the server, and
  • 192.168.0.0/24 is the internal network.


Ubuntu Diary : Segmentation Fault while Removing capplets-data

前天使用 GUI 介面更新 Ubuntu 時不知道為什麼,跳出一個視窗跟我說更新失敗,因為要睡覺了,就沒有仔細查看。結果昨天發現 Gnome 進不去了,今天早上開始嘗試解決這個問題,發現使用 apt-get upgrade 的時候,會出現類似下面的訊息:

dpkg: error processing capplets-data (--configure):
subprocess post-installation script returned error exit status 139

如果用 apt-get remove capplets-data 的話,則會出現 Segmentation fault ,訊息大致上是說執行 postrm 的時候出錯。於是就完全不能更新,也不能移除有問題的套件,連重新 config 也不行。

後來仔細看一下 /var/lib/dpkg/info/capplets-data.postrm ,發現原來是在執行

scrollkeeper-update -q

的時候會發生 Segmentation fault ,只要執行

scrollkeeper-rebuilddb

就可以解決這個問題了。

Ubuntu Diary : OXIM and im-switch

Intro

Linux 上的輸入模組也蠻多種的,像是 scim 、 gcin 等等,一開始我裝的是 scim ,不過有時候叫不出來。如果我在用 MSN 跟笨笨聊天的時候叫不出來,那可真是令人生氣。後來棄 scim 改投 gcin ,雖然沒什麼大問題,不過就是用不習慣。因為以往在 Windows 上用的輸入法是新酷音,而最近剛好發現還有另一個輸入模組 oxim 的存在, oxim 加上 libchewing 的長相真是像極了 Windows 上的新酷音,所以決定裝 oxim 來試試看。

在 Ubuntu 上裝 oxim 也不是那麼簡單,因為官方的 Repository 沒有 oxim 套件,雖然網路上有人有做好,但是不想加入來源不明的 Repository ,只好從原始碼編譯。只是從編譯到安裝使用出了一些小狀況,還好網路上找的到資料解決。以下就說明一下安裝 oxim 的步驟。

Install OXIM

  1. 首先到 OXIM 首頁下載原始碼,我自己是抓 cvs 版本的。
  2. cvs 版本沒有 configure 跟 Makefile.in ,而自動產生 configure 與 Makefile.in 是利用 autotools 來完成,所以要先有 autotools 。 Ubuntu 的話裝個 autobook 就會自動安裝 autoconf 跟 automake 等等套件。(其實我沒有裝 autobook ,我是看缺甚麼就裝甚麼,所以不確定只裝 autobook 夠不夠。)
    $ sudo apt-get install autobook

    oxim 作者很貼心地把產生的步驟寫成一個 script ,執行他一下 configure 跟 Makefile.in 就出來了。

    $ ./autogen.sh
  3. 接下來就跟一般編譯原始碼的動作一樣了,只是有些必要套件要安裝,像是 libqt3-headers 、 qt3-dev-tools 、 libchewing3-dev 等等族繁不及備載(其實是我裝好忘了)。而 configure 會找不到 qt3 ,得自己加上參數指定。
    $ ./configure --with-qt-dir=/usr/share/qt3

    如果跑出來的結果像這樣

    Build options:
    Version 1.1.3.90
    Install prefix /usr
    IM Module directory ${exec_prefix}/lib/oxim/immodules
    Module directory ${exec_prefix}/lib/oxim/modules
    Table directory ${exec_prefix}/lib/oxim/tables

    Input Method modules:
    Chewing yes
    Unicode yes

    Optional:
    GTK+ IM module yes
    QT IM module yes

    GUI Setup Tool yes

    恭喜你成功了,如果跑到一半跟你說找不到某個東西,或是有些功能你要但是 configure 的結果跟你說 no ,那就是缺了東西,看看缺了甚麼套件裝起來吧。

  4. configure 完之後就編譯跟安裝吧。
    $ make
    $ sudo make install

Config with im-switch

電腦上安裝了很多輸入模組,想切換時怎麼辦?用 im-switch 吧。首先把 im-switch 套件裝起來。

$ sudo apt-get install im-switch

使用 im-switch -s 可以設定要使用哪一個輸入模組,用 root 身份執行的話還可以改變整個系統的預設值。所以要用 oxim 的話,就執行下面指令。

$ im-switch -s oxim

如果要指定在哪個語系環境下使用哪一種輸入模組,可以加上 -z 參數,例如:

$ im-switch -z zh_TW -s oxim

這樣一來就會在使用者的 ~/.xinput.d 下建立 en_US 或 zh_TW 的連結指向 /etc/X11/xinit/xinput.d/oxim 設定檔。在 /etc/X11/xinit/xinput.d 目錄下會有各輸入模組的設定檔,連結到哪個檔案的話就會用該輸入模組。

不幸的是,光這樣是不足的,重新登入 Gnome 之後可能會發現 oxim 沒跑出來,雖然 XMODIFIERS 等環境變數設定都有。上網找了一下沒找到相關資料,最後發現原來是 /etc/X11/xinit/xinput.d/oxim 設定檔的問題。看看 scim 與 gcin 的設定檔,發現他們的 XIM_PROGRAM 都是完整路徑,只有 oxim 不是,把這部份改成完整路徑 /usr/bin/oxim 就 OK 了。底下是我的 /etc/X11/xinit/xinput.d/oxim 設定檔,注意一下 XIM_PROGRAM 那一行吧:

#!/bin/sh
#
# Open X Input Method startup script.
#
# By Firefly.
#

OXIM_IM_MODULE_DIR="/usr/lib/oxim/immodules"
XIM=oxim
XMODIFIERS="@im=${XIM}"
XIM_PROGRAM=/usr/bin/oxim
XIM_ARGS="-x oxim"

USR_DIR="$HOME/.oxim"
GTK_IM_MODULE_FILE="${USR_DIR}/gtk.immodules"

# 找出 gtk-query-immodules 指令的完整路徑與真正名稱
for cmd in gtk-query-immodules-2.0-64 \
gtk-query-immodules-2.0-32 \
gtk-query-immodules-2.0 \
gtk-query-immodules
do
TEST_CMD=`which ${cmd} 2>/dev/null`
if [ ! -z ${TEST_CMD} ]
then
GTK_QRY_CMD=${TEST_CMD}
break
fi
done

# 檢查 OXIM 的 GTK2 輸入模組是否安裝
if [ -f ${OXIM_IM_MODULE_DIR}/gtk-im-oxim.so ] ; then
# 檢查使用者家目錄之下是否有下列目錄
if [ ! -d ${USR_DIR} ] ; then
mkdir -p ${USR_DIR}
fi

# 建一個 gtk im modules 的紀錄檔
if [ ! -z ${GTK_QRY_CMD} ] ; then
${GTK_QRY_CMD} > ${GTK_IM_MODULE_FILE}
else
# 否則只建立自己的 immodule 紀錄
echo "\"${OXIM_IM_MODULE_DIR}/gtk-im-oxim.so\"" > ${GTK_IM_MODULE_FILE}
echo "\"oxim\" \"Open X Input Method\" \"gtk20\" \"/usr/share/locale\" \"*\"" >> ${GTK_IM_MODULE_FILE}
fi
GTK_IM_MODULE=oxim
export GTK_IM_MODULE_FILE
else
GTK_IM_MODULE=xim
fi

# 檢查 OXIM 的 QT 輸入模組是否安裝
if [ -f ${OXIM_IM_MODULE_DIR}/qt-im-oxim.so ] ; then
export QT_IM_MODULE=oxim
fi

改成這樣之後重新登出再登入應該就可以看到 oxim 了。

Troubleshooting

Q: 你騙人!我執行 im-switch -s oxim 的時候明明就出現下面這個錯誤訊息。

update-alternatives: Cannot find alternative `/etc/X11/xinit/xinput.d/oxim'.

A: 這是因為你用 root 身份執行的關係,當你用一般使用者身份執行的話, im-switch 會在 ~/.xinput.d 建立設定檔連結,不會有甚麼大問題,除非你執行的指令是 im-switch -s zechs 之類的。當你用 root 身份執行的時候,連結會建立在 /etc/alternatives ,這時候問題就出現了,因為系統不認為 oxim 屬於一個 alternative 。

怎麼知道 oxim 是不是一個 alternative ?先執行下面這個指令:

$ im-switch -l

他會列出所有可以用的輸入模組,如果沒有看到

oxim - priority 0

這一行的話( priority 後面的數字不見得是 0 ),就表示 oxim 還沒被加到 alternatives 裡面(雖然說有的話也不見得每個語系都有,目前我也不知道該怎麼查)。

要解決這個問題也很簡單,加進去就好了。例如我使用的語系是 en_US ,就下這個指令:

$ sudo update-alternatives --install /etc/X11/xinit/xinput.d/all_ALL xinput-all_ALL /etc/X11/xinit/xinput.d/oxim 0

繁體中文語系的話改成 zh_TW 就可以了。

$ sudo update-alternatives --install /etc/X11/xinit/xinput.d/zh_TW xinput-zh_TW /etc/X11/xinit/xinput.d/oxim 0

想知道參數的意義? man 一下吧。

$ man update-alternatives

加進去之後再用 root 身份執行 im-switch -s oxim ,這時應該就不會再跟你抱怨了。

想從 alternatives 中移除 oxim 的話就用下面指令:

$ sudo update-alternatives --remove xinput-all_ALL /etc/X11/xinit/xinput.d/oxim

References

Ubuntu Diary : Suspend and Hibernate with µswsusp

Intro

The original suspension and hibernation functions in Ubuntu 7.04 does not work well on my laptop (IBM Thinkpad T42). After searching WWW, I found a better package, µswsusp, for supporting these functions. However, several problems occurred when I tried to use it. I could find solutions of some problems in Ubuntu forum. For those problems that I couldn’t find solutions, I had to solve them by myself. Finally I succeeded after a lot of try and error. Hope I don’t miss any step in the following.

Suspension

The following method works on my laptop.

  1. Install uswsusp.
    $ sudo apt-get install uswsusp
  2. Edit /usr/lib/hal/scripts/linux/hal-system-power-suspend-linux. Replace the whole content with the following two lines.
    #!/bin/sh
    /sbin/s2ram
  3. Try it.

Some users in the Ubuntu forum suggest the following way to use µswsusp.

  1. Install uswsusp.
    $ sudo apt-get install uswsusp
  2. Remove all packages that appear before s2ram in /usr/lib/hal/scripts/linux/hal-system-power-suspend-linux. Otherwise, s2ram will not be the first choice when suspending. Here we don’t really uninstall those packages but use dpkg-divert to rename necessary files. For example, I have /etc/acpi/sleep.sh before s2ram. So I execute the following command.
    $ sudo dpkg-divert --rename --divert /etc/acpi/sleep.sh.disabled /etc/acpi/sleep.sh
  3. In /usr/lib/hal/scripts/linux/hal-system-power-suspend-linux, it assumes s2ram is in /usr/sbin. However, Ubuntu installs it in /sbin. Thus we have to make a symbolic link.
    $ sudo ln -s /sbin/s2ram /usr/sbin/s2ram

However, this method does not work on my laptop. Every time it resumes from a suspension state, the Gnome desktop restarts and I lose the previous session.

Hibernation

  1. Install uswsusp.
    $ sudo apt-get install uswsusp
  2. It seems that the package in Ubuntu’s repository is too old. In this step, we want to use some scripts from Ubuntu’s repository to generate initrd with the latest uswsusp.
    1. Download the source code suspend-0.7.tar.gz of uswsusp.
    2. Extract suspend-0.7.tar.gz.
    3. Modify config_parser.h and Makefile. Replace “suspend.conf” with “uswsusp.conf. For example, in config_parser.h, we have the following line.
      #define CONFIG_FILE     "/etc/uswsusp.conf"

      In Makefile, we have the following line.

      CONFIGFILE=uswsusp.conf

      I have to change this such that the command resume can find configuration file after resuming.

    4. Compile the source code.
      $ make
    5. Install the executables.
      $ sudo cp s2both /sbin/s2both
      $ sudo cp s2ram /sbin/s2ram
      $ sudo cp s2disk /sbin/s2disk
      $ sudo cp resume /usr/lib/uswsusp/resume
    6. Copy the configuration in conf/suspend.conf to /etc/uswsusp.conf and modify it. Below is my /etc/uswsusp.conf.
      # /etc/uswsusp.conf(8) -- Configuration file for s2disk/s2both
      snapshot device = /dev/snapshot
      resume device = /dev/sda3
      #compress = y
      early writeout = y
      image size = 365106872
      #RSA key file = /etc/uswsusp.key
      shutdown method = platform
      splash = y

      In this configuration file, you have to specify your resume device. For example, my swap partition is /dev/sda3. Some lines are commented out because they are not recognized by uswsusp-0.7.

  3. Like suspend, we want s2disk to be the first choice when hibernating. Thus replace /usr/lib/hal/scripts/linux/hal-system-power-hibernate-linux with the following.
    #!/bin/sh
    /sbin/s2disk

    Another way is to rename all files that appear before s2disk in /usr/lib/hal/scripts/linux/hal-system-power-hibernate-linux. for example,

    $ sudo dpkg-divert --rename --divert /etc/acpi/hibernate.sh.disabled /etc/acpi/hibernate.sh

    and create a symbolic link because hal-system-power-hibernate-linux assumes s2disk is in /usr/sbin.

    $ sudo ln -s /sbin/s2disk /usr/sbin/s2disk

    Although /etc/acpi/hibernate.sh supports s2disk, it passes wrong arguments to s2disk. However, after I fix it, there is still other problem with /etc/acpi/hibernate.sh, for example, Gnome desktop restarts and previous session is lost. That’s why I want to disable hibernate.sh.

  4. Update /etc/initramfs-tools/conf.d/resume. Again you have to set the resume device to your real swap partition. For example,
    RESUME=/dev/sda3
  5. Update initrd.
    $ sudo update-initramfs -u
  6. Try it now.

Troubleshooting

Q: s2disk complains that it could not use the resume device.
A: Execute the following command first.

$ free

If your output looks like:

             total       used       free     shared    buffers     cached
Mem: 775100 422044 353056 0 448 227016
-/+ buffers/cache: 194580 580520
Swap: 0 0 0

This is because the swap partition has new UUID, but it does not update /etc/fstab. If this happens,
you can mount the swap partition by

$ sudo swapon /dev/sda3

Then change the UUID of the swap parition by the real path in /etc/fstab, for example

/dev/sda3        swap    sw              0       0

Q: After resuming, Gnome desktop restarts.
A: Be sure to use s2disk directly without /etc/acpi/hibernate.sh.

Q: When resuming, it stops in the boot logo.
A: This may be caused by setting wrong resume device or wrong configuration file such that the resuming procedure could not find where to load previous state. Press Ctrl+F1 to see if it asks you to enter the resume device, enter the path to your swap partition, for example /dev/sda3, and then press Enter. It should continue to resume. Make sure that the name of configuration file in config_parser.h and Makefile is set correctly. Also make sure to set correct resume device in /etc/uswsusp.conf and /etc/initramfs-tools/conf.d/resume. You may need to update initrd by

$ sudo update-initramfs -u

Reference

Since everyone could have different problems, I list some references below.

BASH: Read a file line by line

假設 $file 的變數值是一個檔案名稱,該檔案內容為:

a 1
b 2
c 3
d 4
e 5

則以下方式可以將該檔案一行一行讀入,並將讀入的每一行存在 $line 變數裡面:

Method 1

Code:

number=0
while read -r line
do
number=$(($number + 1))
done < <(cat $file)
echo "# of lines = $number"

Output:

# of lines = 5

Note:
除了 cat $file 以外,也可以使用其他指令,不一定要從檔案讀入。

Method 2

Code:

number=0
while read -r line
do
number=$(($number + 1))
done < $file
echo "# of lines = $number"

Output:

# of lines = 5

Method 3

Code:

number=0
exec 9< $file
while read -u 9 -r line
do
number=$(($number + 1))
done
echo "# of lines = $number"

Output:

# of lines = 5

Note:
exec 後面的數字是 descriptor 代號,和 read -u 用一樣的就可以了。

Method 4

Code:

number=0
cat $file | while read -r line
do
number=$(($number + 1))
done
echo "# of lines = $number"

Output:

# of lines = 0

Note:
最後得出來的結果會是 0 。