星期四, 8月 07, 2014

Lock on suspend & Systemd

Ever since I switched to systemd, I found that the acpi-support LOCK_SCREEN(in /etc/default/acpi-support) setting doesn't work anymore. While acpi_listen still shows that the lid closing event is detected, my screenlock program(i3lock) wasn't getting executed whatsoever.

With a little bit of tracing I found that the lid event and relevant scripts are indeed executed but after invoking the 'CheckPolicy' function in the /etc/acpi/lid.sh the script halted. This is because the script checks the system to see if there are other program being in charge of power management and if there is acpi gets aborted.

So, to enforce screen locking after resume (or before sleep), we'll need to setup a service in systemd that gets executed at the appropriate time. After a bit of searching and playing with the options, I found this ready-to-use unit file by Karsten Gebbert:

to use this, download the .service file to /etc/systemd/system and enable the service with the following command:
(sudo) systemctl enable i3lock@[user].service
Where [user] should be replaced by the username whose password would be used to unlock.

To check if the service is enabled correctly you can either just try to suspend and see if the i3lock is fired up or check the list of currently enabled services:
 systemctl list-unit-files | grep i3lock
if you have successfully enabled it, there should be message like this:
i3lock@.service                            enabled

Note on the file name:
With an @ in the file name means this file is a template and can be enabled with specified instance name if provided. In this case the instance name will be [user] and it will replace the %i variable in the file.

星期五, 5月 17, 2013

installing Paragon NTFS & HFS driver

Recently, I bought a portable HD, which came NTFS-formatted. At first I considered formatting it to XFS or ext4 but it occurred to me that I might have to mount it with windows from time to time (although I don't have many windows PCs and will not have more than one unless necessary.)

Rather than trying to fix/install anything on the stupid Windows to support xfs/ext4, I prefer messing up with my linux which, in some way, is more intuitive for me than dealing with those mysterious bugs in windows.

There's a ntfs driver called ntfs-3g. It is fine, but somehow too slow. I don't know why it has been staying on FUSE all these years, or if staying on FUSE is the reason that makes it so slow. There's a couple of commercial alternatives that come into play: Tuxera(which I suspect is the reason that ntfs-3g being so slow) and Paragon but only the later one offers a free driver for linux, so I gave it a try and it works pretty well so far.

Here's how I do it:

星期二, 3月 19, 2013

cross-compile node.js (0.10.0) for mipsel (Asus RT-N16 with tomatousb)

最近入手了一台 RT-N16, 馬上是刷了 tomatousb, 還算蠻滿意的, 看了那精美的記憶體, 開完機還剩下 100+ MB, 家裡的裝置也很少使用 p2p, 這些記憶體不用好像有點浪費,於是便想把一些本來跑在桌電的 node server 來跑在 rt-n16 上。
記錄一下 cross-compile 的步驟:
先從 tomatousb 抓他們的 toolchain:

$ git clone git://repo.or.cz/tomato.git tomato
$ cd tomato
$ git checkout tomatousb-K26-1.28.9054 
$ sudo ln -s tools/brcm /opt/brcm
這邊用的是 linux 2.6 的版本, 其他版本可以參考 git tag。
然後再抓 node.js 的 source: 我這邊用的是最新的 node-v0.10.0
$ mkdir $HOME/node-src && cd $HOME/node-src
$ wget http://nodejs.org/dist/v0.10.0/node-v0.10.0.tar.gz
$ tar xf node-v0.10.0.tar.gz
$ cd node-v0.10.0
設定的部分,因為是 cross-compiling, 所以把 snapshot 關掉, 因為 compile 出來的 mksnapshot 也沒辦法在 host 上跑:

$ ./configure --prefix=/opt --dest-cpu=mipsel --dest-os=linux --without-snapshot
編譯過程中會有些錯,主要是 linux 版本的問題跟 pthread 有些函數(pthread_barrier_init|destroy|wait)在 uclibc 不支援,所以我做了個 patch, 這會讓有用到 ub_barrier_init|destroy|wait 的 module 無把編譯但 node 本身似乎是沒有用到這些函數,所以暫時可以這樣做:
$ wget -O - http://moon.cse.yzu.edu.tw/~s961449/node-mipsel.patch | patch -p0
$ PREFIX=/opt/brcm/K26/hndtools-mipsel-uclibc-4.2.4/bin/mipsel-linux-
$ export CC=${PREFIX}gcc
$ export CXX=${PREFIX}g++
$ export AR=${PREFIX}ar
$ export RANLIB=${PREFIX}ranlib
$ export LINK=$CXX
$ make -j4 #4 cores
基本上這樣就可以編出能在 tomato 上跑的 node 了, 編完以後 binary 會在 out/Release/node,但是不知道為什麼 tomato 的 firmware 並沒有把一些必要的 library 包進去,所以還要再附上 librt, libstdc++ 才行(optware 用來編譯的 toolchain 不同,所以也無法使用他們的 librt), 並設定 LD_LIBRARY_PATH 才能跑: node.sh:
LD_LIBRARY_PATH="/lib:/usr/lib:/opt/node/lib" /opt/node/bin/node $@
把檔案傳到 ap 上, 我這邊是用 optware 裝了 sftp, 所以直接用 sftp 上傳:
sftp root@your.ap.address
$ cd /opt
$ mkdir node
$ mkdir node/bin
$ mkdir node/lib
$ put out/Release/node node/bin/
$ put node.sh bin/node
$ put /opt/brcm/K26/hndtools-mipsel-uclibc-4.2.4/lib/librt.so node/lib
$ put /opt/brcm/K26/hndtools-mipsel-uclibc-4.2.4/lib/libstdc++.so node/lib/libstdc++.so.6
或是你要打包好在上傳也可以, 各人喜好啦,(因為當初是先上傳了才發現缺 lib)。 這樣應該就可以在 tomato 上跑 node 了! 但是馬上會用掉 30+% 的記憶體,也許可以再 tune 一下,但可以跑已經大喜大賀了, haha.

星期三, 2月 13, 2013

ibus override xmodmap, use xkb options instead

之前寫過一篇關於把 caps lock 重新 map 到 control 的方法,但昨天更新了 ibus 以後突然發現我的 xmodmap 只要切換輸入法引擎的時候就會被覆寫過去,google 了一下,大家似乎是推薦用 xkb 的設定選項來作調整:

Debian 來講的話,就是修改 /etc/default/keyboard
把 XKBOPTIONS 這行加入 ctrl:nocaps (有其他選項的話以逗號分隔)
重新開 X 以後就可以囉!似乎是比 xmodmap 乾淨一些,但缺點就是這樣改到的是整個系統的設定,如果使用者要改就沒辦法了。 若沒有 root 的權限可以改 /etc/default/keyboard, 也可以在 ~/.xsession 加上:
setxkbmap -option "ctrl:nocaps" &
其他的選項可以參考 man xkeyboard-config, /etc/default/keyboard 相關的資訊: man keyboard

星期六, 2月 09, 2013

pathogen, manage your vim plugins in a clean way

vim 用久了, 裝很多 plugin 很正常, 但有時候只是想試看看某些 plugin 用完要移除的時候卻發現很麻煩, 要自己把檔案刪掉。好加在 vim 發展到現在也有許多人做了套件的工具/套件: pathogenVimana 算是我比較常聽到的管理套件。但 Vimana 需要透過 perl,如果在 windows 下要使用還頗不方便的(雖然我很久沒用windows寫程式了..)。 Pathogen 的運作方式是透過增加 runtime path 的方式,把 plugin 獨自存放在各自,vim 開啟的時候會搜尋所有的 runtime path,把這些設定都讀進來,所以要刪除時只要把該套件的資料夾刪除就可以了。 安裝的方式也很簡單,pathogen 本身就是一個 vim plugin:
$mkdir -p ~/.vim/autoload ~/.vim/bundle; \
$curl -Sso ~/.vim/autoload/pathogen.vim \
基本上就是把 pathogen.vim 下載下來放到 ~/.vim/autoload/,再把套件預設存放的資料夾 ~/.vim/bundle 建立起來。 最後再將
execute pathogen#infect()
加入 vimrc 就可以了,這邊就完成 pathogen 的安裝。 裝好 pathogen 以後,開 vim 時他就會去 ~/.vim/bundle 把下面的資料夾路徑都加入 runtime path,所以安裝套件時只需要在底下開一個資料夾東西丟進去就可以正常使用了,比如說安裝 ctrlp.vim 可以直接 git clone 到 ~/.vim/bundle 下即可:
$ cd ~/.vim/bundle && git clone git://github.com/kien/ctrlp.vim.git