tag:blogger.com,1999:blog-76972445834816437662024-03-13T11:24:14.478+08:00沒什麼好說的...拿來放些筆記或有關程設的東東...lefthahahttp://www.blogger.com/profile/06424653829898666558noreply@blogger.comBlogger92125tag:blogger.com,1999:blog-7697244583481643766.post-9322932473018937262012-05-06T22:06:00.002+08:002012-05-06T22:10:07.129+08:00這兩天 system upgrade 碰到有關 xfce 的問題最近 pacman -Syu 後重開機碰到兩個問題<br />
<br />
<ol>
<li> xfce 的 panel 位置跑掉,所有的 items 擠在左邊</li>
<li>點 panel 上的 Action Buttons 只能 logout 不能關機</li>
</ol>
<div>
幸好搜尋一下就找到解法,但是出這種問題實在很讓人灰心,不知道是 Arch Linux 這邊的打包者還是 xfce 自己的問題?</div>
<div>
<ol>
<li>在 Panel 上新增一個 Separator, 勾選 expand,就可以達到向右靠齊的效果</li>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-dhaX1CTNRy8/T6aEbFBQu2I/AAAAAAAAAIo/MVY74JZo1WU/s1600/expand.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-dhaX1CTNRy8/T6aEbFBQu2I/AAAAAAAAAIo/MVY74JZo1WU/s1600/expand.png" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<li>在 Action Buttons 上點右鍵,進入 Properties,把預設勾選的「Log out」改成勾選「Log out...」,注意是 "...",這樣才可以選擇要 Shtudown 或是 Logout</li>
</ol>
<div>
<br /></div>
<ol>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-L1tmXu-zm3E/T6aFQ9-Xv7I/AAAAAAAAAIw/sAH1nXcM-T0/s1600/xfce_action_button.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="http://3.bp.blogspot.com/-L1tmXu-zm3E/T6aFQ9-Xv7I/AAAAAAAAAIw/sAH1nXcM-T0/s320/xfce_action_button.png" width="214" /></a></div>
</ol>
</div>
<div>
<br /></div>
<div>
Reference:</div>
<div>
<ol>
<li><a href="https://makandracards.com/makandra/4489-right-align-or-center-panel-items-in-xfce">Right-align or center panel items in XFCE</a></li>
<li><a href="https://bbs.archlinux.org/viewtopic.php?pid=1095734">[Solved] XFCE - Suspend, shutdown after update</a></li>
</ol>
</div>lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-23591801110153745042012-02-28T22:10:00.006+08:002012-02-28T22:33:21.130+08:00利用 uWSGI + nginx 搞定 moinmoin 與 bottle.py<div><span>之前用 lighttpd 以 FastCGI 方式架 moinmoin wiki,雖然設定上有點麻煩,</span><span style="font-family: Georgia, serif; ">但還是可以跑,只是最近在同一個 VM 上玩 bottle,雖然試過用 flup 來啟動,</span><span style="font-family: Georgia, serif; ">但一直沒有成功,</span><a href="http://www.saddi.com/software/news/archives/58-flup-1.0-released.html" style="font-family: Georgia, serif; ">連 flup 作者自己都講他討厭 FastCGI</a><span style="font-family: Georgia, serif; "> 。</span></div><div><span><br /></span></div><div><span>於是就來試試 WSGI 看看,但 lighttpd 對 WSGI 似乎還沒有很完善的支援,乾</span>脆就跳槽到 nginx + uWSGI,試了一下才發現這設定真是簡單到不行,跟當初搞<span style="font-family: Georgia, serif; ">moinmoin 搞到火大的情況完全不同。</span></div><div><span><br /></span></div><div><span>不過 Arch Linux 的官方套件庫沒有 uWSGI,必須到 AUR 裡面去找,結果我裝</span><span style="font-family: Georgia, serif; ">不起來,查資料時意外發現 pypi 裡面有 uWSGI,而且用 virtualenv 裝的起</span><span style="font-family: Georgia, serif; ">來!只要有裝 gcc 和libxml2,virtualenv 就可以直接編譯 uWSGI 出來用,</span><span style="font-family: Georgia, serif; ">真是太神奇了!而且 uWSGI 也有支援 virtualenv,只要加上 -H "Venv_dir" </span><span style="font-family: Georgia, serif; ">這個選項就能啟用,而 bottle application 也只要在檔案內加上一行</span></div><br /><pre class="brush: bash "><br />application = bottle.default_app()<br /></pre><br /><div><span><br /></span></div><div><span>就可以跑起來, nginx 設定也很簡單,從官方網站上複製貼上就可以用,</span><span style="font-family: Georgia, serif; ">moinmoin 的設定更是簡單,<a href="https://bitbucket.org/lefthaha/conf/changeset/78322a1a6c91">只需改一行就OK</a>,只是有些選項搞不太懂意思。</span></div><div><span><br /></span></div><div><span>主要由 <a href="http://projects.unbit.it/uwsgi/wiki/RunOnNginx">Running uWSGI behind Nginx</a> 抄來的</span><span style="font-family: Georgia, serif; ">範例:</span></div><div><span><br /></span></div><div><span><div><pre class="brush: bash "># for bottle application<br />location /bottle {<br /> include uwsgi_params;<br /> uwsgi_param SCRIPT_NAME /bottle;<br /> uwsgi_modifier1 30;<br /> uwsgi_pass localhost:9002;<br />}<br /><br /></pre><br /></div><div><span>像 SCRIPT_NAME 只有在 <a href="http://docs.python.org/library/wsgiref.html">wsgiref</a> </span><span style="font-family: Georgia, serif; ">和 </span><a href="http://www.python.org/dev/peps/pep-0333/" style="font-family: Georgia, serif; ">PEP 333</a> <span style="font-family: Georgia, serif; ">看到,bottle 開 debug 模式下去看,傳進去的網址跟瀏覽器要求的一樣,只是後端</span><span style="font-family: Georgia, serif; ">在處理的時候似乎會改變,所以 bottle 會吐錯誤,回報錯誤的網址會改變,不知道能不能設</span><span style="font-family: Georgia, serif; ">成跟 location 不一樣?</span></div><div><span><br /></span></div><div><span>uwsgi_modifier1 就更難找到相關資訊,只知道改另一個數值就跑不起來</span></div><div><span><br /></span></div><div><span>目前遇到比較搞不定的是 bottle 原本的 run(reloader=True) 不知道怎麼讓它</span></div><div><span>重新讀取有修改的檔案,可能要翻一下 bottle 的原始碼看看是怎麼實作的?</span></div><div><span><br /></span></div><div><span><b>Reference:</b></span></div><div><span><a href="http://projects.unbit.it/uwsgi/wiki/Quickstart">uWSGI: Quickstart</a></span></div><div><span style="font-family: Georgia, serif; "><a href="http://projects.unbit.it/uwsgi/wiki/Doc">uWSGI Documentation (list of options for 1.0)</a></span></div><div><span><a href="http://wiki.nginx.org/HttpUwsgiModule">nginx: HttpUwsgiModule</a></span></div><div><span><a href="http://groups.google.com/group/bottlepy/browse_thread/thread/c117e09b8a1b2d79?pli=1">Google Group: Bottle.py + uWSGI</a></span></div><div><span><br /></span></div></span></div>lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-66504232999740572582011-11-17T22:02:00.004+08:002011-11-18T10:32:04.586+08:00系統備份 script<div>紀錄一下半年前的筆記(快沒時間了...Orz)。</div><div><br /></div><div>之前備份策略是每個禮拜將 /home , /etc , /var 備份到另一顆硬碟上,過兩個禮拜再存到外接硬碟,但有時候會忘記整理,就會碰到備份檔把整顆硬碟空間吃光的情形;<a href="https://bitbucket.org/lefthaha/scripts/src/de95262be4a7/backup.py">現在改成先檢查硬碟空間再備份,如果空間不夠會在 terminal 上顯示訊息,等待十分鐘後再次檢查硬碟空間</a>,如果要在 cron job 啟動 GUI 程式,只要在 cmd 前面加上 export DISPLAY=:0 就行了。</div><div><br /></div><div>原本想說用 `wall` 或 `talk` 來送訊息,卻發現 rxvt-unicode 收不到廣播訊息,不信邪想翻翻 `walk` 的原始碼看看到底是怎麼寫的,結果發現原始碼內的輸出訊息不大一樣,才發現 Arch Linux 是用 sysinitv 裡面的 `wall` 而不是 util-linux 內的 `wall`,也因此發現有 pkgtools 這個好用的 package,只要下 pkgfile -s CMD 就可以知道是哪個 package 提供的程式。</div><div><br /></div><div>看了 sysinitv 內的 dowall.c 發現是用 getutent() 來抓目前登入的使用者,但是抓不到 rxvt-unicode 登入的紀錄,還有 xterm +ut 也是抓不到,後來乾脆就直接去掃 /dev/pts/ ,用檔案擁有者來判斷登入者,也很方便, getutent() 測試原始碼如下,編譯完成後只要執行就會列出有抓到登入的使用者。</div><div><br /><pre class="brush: cpp ">#include <sys/types.h><br />#include <stdio.h><br />#include <utmp.h><br />#include <unistd.h><br /><br />int main(){<br /><br />int type ,pid;<br />char *tty,*id, *user, *host;<br />struct utmp *utmp;<br />while ((utmp = getutent()) != NULL) {<br />type = utmp->ut_type;<br />pid = utmp->ut_pid;<br />tty = utmp->ut_line;<br />id = utmp->ut_id;<br />user = utmp->ut_user;<br />host = utmp->ut_host;<br /><br />printf("%d - %d - %s - %s - %s - %s\n",type , pid, tty, id, user, host);<br /> }<br />}<br /><br /><br /></pre></div><div>因為 dcron 有類似 anacron 的功能,所以只要把 script 丟進 /etc/cron.weekly 就會自動執行,這次還用到 logging 這個 module ,非常方便,有了這個 module 就不必自己辛苦刻 log 了 :)</div><div><br /></div><div><br /></div>Reference:<div><br /><div><a href="http://unix.stackexchange.com/questions/14858/in-arch-how-can-i-find-out-what-not-installed-package-contains-file-x">StackExchange - In arch how can I find out what not installed package contains file X?</a></div><div><br /><div><a href="http://ubuntuforums.org/showthread.php?t=185993">ubuntuforums - crontab: How to run GUI programs with cron</a></div><div><br /><a href="https://wiki.archlinux.org/index.php/Pacman_Rosetta">https://wiki.archlinux.org/index.php/Pacman_Rosetta</a></div><div><br /><a href="http://www.gnu.org/s/libc/manual/html_node/Manipulating-the-Database.html">http://www.gnu.org/s/libc/manual/html_node/Manipulating-the-Database.html</a><br /></div></div></div>lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-42816306507975199082011-10-28T10:47:00.002+08:002011-10-28T11:03:25.435+08:00關機時一併將 VirtualBox 正常結束平常開 VirtualBox 都是用<br /><pre class="brush: bash "><br />VBoxHeadless --startvm YOUR_VM_NAME --vrde=off<br /></pre><br /><br />所以有一兩次關機時才想起 VirtualBox 還在背景執行<br />等於直接拔電源,下次重開就就會看到 Guest OS 開始跑硬碟檢查,現在直接把指令寫到 /etc/rc.local.shutdown 內就不必怕忘記了<br />因為 vm name 不是系統共用,而是根據使用者設定來找,所以要使用 su USER -c 來執行<br /><pre class="brush: bash "><br />#!/bin/bash<br />#<br /># /etc/rc.local.shutdown: Local shutdown script.<br />#<br /><br />## stop Virtualbox<br />su YOUR_USER_NAME -c "VBoxManage controlvm YOUR_VM_NAME savestate"<br /></pre>lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-80473639399894629922011-10-04T01:46:00.005+08:002011-10-14T01:21:23.602+08:00Setup sftp for windows users to download BIG files<div>過去都是用 samba 在區網中分享檔案,方便,快速,又不必新增使用者(單純讀取不寫入),傳過 4GB 左右的檔案都沒問題。</div><div><br /></div><div>但是上個月有個大檔 (13GB) 要傳到 Win 7,但是透過 samba 下載不到十分鐘就會跳網路錯誤,接著就從頭開始傳檔,搜尋了一下,似乎是 Windows 的問題,只好在 Linux 上架 sftp , Win 7 使用 WinSCP 來傳,速度至少有 5 MB/s ,偶爾可以衝到 6 MB/s (中間還有經過無線網路),就算斷線還可以續傳,對於傳大型檔案來說是不可或缺的功能,也有 log 可以看,但是有個缺點 — 檔案名稱除了正體中文外,還包含日文或簡體字時,在 WinSCP 上會顯示問號,沒辦法正常顯示。</div><div><br /></div><div>原本要設 chroot sftp ,結果搞了半天,發現 openssh 對 chroot directory 的限制還挺嚴格的,後來還是決定有需要才開啟帳號,平常把 ssh 關掉比較沒有安全上的顧慮,順便紀錄一下設定過程。</div><div><br /></div><div><b>Package:</b></div><div><ul><li><span class="Apple-style-span">openssh 5.9p1-3</span></li><li>WinSCP 4.3.4</li></ul></div><div><br /></div><div>sftp user name: sftptest</div><div>sftp server ip: 192.168.1.2</div><div><a href="https://bitbucket.org/lefthaha/conf/src">config file - /etc/ssh/sshd_config</a></div><div><br /></div><div>------</div><div><br /></div><div># Create user account</div><div>sudo useradd -m sftptest</div><div>sudo passwd sftptest</div><div><br /></div><div># Generate ssh key</div><div># WinSCP only accept "rsa" and "dsa" ,not support for "ecdsa" yet (PuTTYgen)</div><div>su sftptest</div><div>cd /home/sftptest</div><div>ssh-keygen -C "$(id -un)@$(uname -n)-$(date --rfc-3339=date)"</div><div>cp .ssh/id_rsa.pub .ssh/authorized_keys</div><div><br /></div><div><b># copy .ssh/id_rsa to client machine</b></div><div><br /></div><div># Disable sftp user from login into shell</div><div>usermod -s /bin/false sftptest</div><div><br /></div><div># Test if able to establish sftp connection from other machine</div><div># also verify user is unable to login from ssh</div><div>sftp -i id_rsa_from_sftp_server sftptest@192.168.1.2</div><div>ssh sftptest@192.168.1.2 -i id_rsa_from_sftp_server</div><div><br /></div><div># Setup Windows client</div><div><div># WinSCP only accept the ssh-key generated by PuTTYgen</div><div># In PuTTYgen menu, select <b>Conversions</b> -> <b>Import</b> to load id_rsa </div><div># Save private key will create a *.ppk file, use it in WinSCP</div><div># Also set <b>UTF-8 Encoding for Filenames</b> -> <b>On</b> in WinSCP</div><div># for non-ANSCII file names</div><div><br /></div><div><br /></div><div>測試的時候被 sftp 的 chroot directory 搞了很久,錯誤訊息根本不對,最後是跑去看 /var/log/auth.log 才想到問題可能是出在那邊</div></div><div><br /></div><div></div><blockquote><div>Error message for chroot directory ownship problem :</div><div>Write failed: Broken pipe</div><div>Couldn't read packet: Connection reset by peer</div></blockquote><div></div><div><br /></div><div>這錯誤丟 Google ,大部分的解都是說要設定 TimeOut,進 /var/log/auth.log 一看,才發現問題是出在權限設定上</div><div><blockquote>sshd[12399]: fatal: bad ownership or modes for chroot directory component "/path/of/chroot/directory/"</blockquote></div><div>如果要設定 chroot sftp 路徑上所有目錄的擁有者都必須是 root ,而且其他使用者不能寫入,如果用家目錄 (%h) 當 chroot directory,還必須要注意使用者能夠讀取該目錄,不然 ssh 就會因為讀不到 key 跳 " Permission denied (publickey). " 錯誤,權限至少要 750</div><div><br /></div><div>ls -l /home </div><div>drwxr-x--- 3 root sftptest 4.0K Sep 10 19:08 sftptest</div><div><span class="Apple-style-span" style="font-family: Tahoma, 'Trebuchet MS', Trebuchet, Verdana, Arial, 'Lucida Sans', Univers, Helvetica, Helvet, sans-serif; background-color: rgb(255, 255, 255); font-size: medium; "><h1 style="margin-top: 0px; font-size: 21px; background-color: inherit; color: rgb(51, 102, 153); "><br /></h1></span></div><div>Reference:</div><div><a href="https://wiki.archlinux.org/index.php/Using_SSH_Keys">Arch Wiki - Using_SSH_Keys</a></div><div><a href="https://wiki.archlinux.org/index.php/SFTP-chroot">Arch Wiki - SFTP-chroot</a></div><div><a href="http://winscp.net/eng/docs/ui_login_environment">WinSCP docs - Environment Tab</a></div><div><a href="http://www.openbsd.org/cgi-bin/man.cgi?query=sshd_config&sektion=5">sshd_config manual</a></div><div><br /></div>lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-53418426649643867832011-09-09T00:16:00.006+08:002011-09-09T16:58:44.738+08:00設定 chromium 將 ed2k 連結傳給 aMule 下載<b>DE</b>: Xfce 4.8<div><b>chromium</b>:13.0.782.220</div><div><b>aMule</b>:10598-1</div><div><br /></div><div>Firefox 很簡單就可以設定好 ed2k 連結的處理程式,但是 chromium 沒有類似的設定選項,找了好久都沒發現有簡單的解決方案,倒是看到 chromium issue 裡這個問題一直沒修……</div><div><br /></div><div>chromium 預設會把 ed2k 連結傳給 xdg-open,而 xdg-open 針對每個桌面環境都有特殊設定,在 Xfce 裡面是直接傳給 exo-open 去處理,但是用不同參數測了快一個小時,exo-open 還是不能將 ed2k 連結傳給 aMule,正當要放棄的時候,看到 VLC wiki 上介紹可以用mimeinfo.cache 來設定預設程式,測試結果還真的可行,覺得前幾個小時真像個傻瓜 XD</div><div><br /></div><div><a href="https://bitbucket.org/lefthaha/conf/src">設定範例放在 /home/dot.local/share/applications 裡面</a>,如果只是個人設定的話,只要動到 ~/.local/share/applications/ 下的檔案:</div><div><ol><li>先在 defaults.list 內加上一行 x-scheme-handler/ed2k=chromium-ed2k.desktop</li><li>再新增 chromium-ed2k.desktop,因為 chromium 傳的連結有經過 urlencode,所以要另外用程式來解碼後傳給 aMule,比較重要的是 exec 要用<b>絕對路徑</b>,否則會找不到程式</li><li>在 url_unquote.py 內解碼後再傳給 aMule 就搞定了,目前在 python 2.7 下測試過 OK,幾行程式碼就解決</li></ol></div><div><a href="http://contentdb.emule-project.net/download.php?file=13184">測試下載連結(eMule主程式)</a></div><div><br /></div><div>試了兩三個網站都可以正常運作,但是 VeryCD 會有問題,點連結還是會跳開啟錯誤,最奇怪的是將整個網頁下載到電腦內再點連結就可以正常下載,不知道問題是出在那邊?目前暫時還是先用複製連結貼到 aMule 來解決。</div><div><br /></div><div><br /></div><div><br /></div><div># Update 2011-09-09</div><div>一直很好奇 exo-open 是從那個檔案抓設定檔來判斷使用者自訂開啟的程式,翻了 exo-open 的程式碼才發現是利用 exo-helper 傳參數給 exo-open,所以在 ~/.config/xfce4/helpers.rc 跟 ~/.local/share/xfce4/helpers/ 裡面就可以找到相關設定檔,之前看到以為只是說明檔,根本不會想到是藏在這裡面 XD</div><div><br /></div><div>Reference:</div><div><a href="http://wiki.amule.org/index.php/Ed2k_links_handling">aMule wiki - Ed2k links handling</a></div><div><div><a href="http://wiki.videolan.org/How_to_make_VLC_the_default_player">VideoLAN wiki - How to make VLC the default player</a></div><div><a href="http://code.google.com/p/chromium/issues/detail?id=18113">chromium issue 18113</a></div><div><a href="http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s06.html">Desktop Entry Specification</a></div><div><a href="http://www.w3schools.com/TAGS/ref_urlencode.asp">w3schools URL Encoding</a></div><div><br /></div><div><a href="http://git.xfce.org/xfce/exo/tree/exo/exo-execute.c">exo-execute</a></div></div><div><a href="http://git.xfce.org/xfce/exo/tree/exo-helper">exo-helper</a></div>lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-84042207280207767572011-09-02T23:29:00.005+08:002011-09-03T00:11:08.504+08:00目前使用的字型<span class="Apple-style-span">Desktop Environment: Xfce 4.8</span>
<br />used font:ttf-arphic-ukai 、ttf-arphic-uming 、ttf-dejavu 、ttf-droid 、ttf-fireflysung 、ttf-liberation
<br />
<br />Appearance:
<br /><div><ul><li>Icons:Tango</li><li>Fonts:DejaVu Sans Mono Book 13 ( anti-aliasing 、no hinting)</li></ul></div>
<br />Window Manager:<div><ul><li>Title font:Liberation Sans 13</li><li>Theme:Smoothwall</li></ul></div>
<br />Theme 本來想用 Xubuntu 11.04 預設的 greybird ,後來發現 Smoothwall 也不錯,很喜歡右上角視窗放大縮小的按鍵,整個視窗看起來也不會很突兀,有融為一體的感覺,系統字型原本想用 Droid ,可惜在 emesene2 裡面看起來有些字會變得很醜,還是改用 DejaVu,只有把 smplayer 和 VLC 字型改成 Droid ( qtconfig )。<div>
<br /></div><div>qtconfig:</div><div><ul><li>Default Font:Droid Sans Normal 14</li></ul></div>
<br /><a href="http://1.bp.blogspot.com/-nCPjlIMQt9o/TmD6m4HTy4I/AAAAAAAAAFI/ZMpovexTwF4/s1600/all_config.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 320px;" src="http://1.bp.blogspot.com/-nCPjlIMQt9o/TmD6m4HTy4I/AAAAAAAAAFI/ZMpovexTwF4/s400/all_config.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5647789478527617922" /></a>
<br />
<br />Browser:<div>其實看久了還是有點不舒服,忘記之前是怎麼設定的了……</div><div>
<br /><div>Opera:
<br /><div><ul><li>Webpage normal text:DejaVu Sans</li></ul></div>
<br />其他語言好像會自動選擇,像中文是文泉驛正黑,片假名是 AR PL New Kai<div>
<br /></div>
<br />
<br /><a href="http://3.bp.blogspot.com/-rHpJr6I7wDQ/TmD-PpCOmjI/AAAAAAAAAFQ/icGw0yGzskM/s1600/opera_a.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 283px;" src="http://3.bp.blogspot.com/-rHpJr6I7wDQ/TmD-PpCOmjI/AAAAAAAAAFQ/icGw0yGzskM/s400/opera_a.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5647793477389294130" /></a>
<br />
<br /><div>Chromium:</div><div><ul><li>DejaVu Sans</li></ul></div>
<br />
<br /><a href="http://1.bp.blogspot.com/-VgyjESe8kv0/TmD-P9q3xYI/AAAAAAAAAFY/5PC64ggoFLs/s1600/gmail_spam.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 230px;" src="http://1.bp.blogspot.com/-VgyjESe8kv0/TmD-P9q3xYI/AAAAAAAAAFY/5PC64ggoFLs/s400/gmail_spam.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5647793482928473474" /></a>
<br />
<br />Firefox:<div><ul><li>Proportinal:Sans Serif 16</li><li>Serif:文鼎 PL 新宋 Mono</li><li>Sans-serif:sans-serif</li><li>Monospace:文泉驛等寬正黑</li></ul>
<br /><a href="http://3.bp.blogspot.com/-42Czj4X2g3c/TmD-P3a9KxI/AAAAAAAAAFg/gsHft9rLwGc/s1600/firefox.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 363px;" src="http://3.bp.blogspot.com/-42Czj4X2g3c/TmD-P3a9KxI/AAAAAAAAAFg/gsHft9rLwGc/s400/firefox.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5647793481251105554" /></a>
<br />
<br /><div>PcmanX:</div></div><div><ul><li>Font & ASCII Font:Sans</li></ul></div><div>
<br />
<br /><a href="http://3.bp.blogspot.com/-Tf7hTnh6cfo/TmD-QG4UBeI/AAAAAAAAAFo/855r8lylmws/s1600/pcmanx.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 309px;" src="http://3.bp.blogspot.com/-Tf7hTnh6cfo/TmD-QG4UBeI/AAAAAAAAAFo/855r8lylmws/s400/pcmanx.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5647793485400770018" /></a>
<br />
<br />Terimal:</div><div><ul><li>Terminal:DejaVu Sans Mono Book 14 ( anti-aliasing )</li><li>rxvt-unicode:DejaVu Sans Mono:Book:pixelsize=16</li></ul></div>
<br />不知道為什麼 rxvt-unicode 的中文字看起來就是特別醜,如果要編輯有中文的檔案,我還是會用 Terminal。</div></div>
<br /><a href="http://3.bp.blogspot.com/-FLABOr7cLYA/TmD-Qb0TI-I/AAAAAAAAAFw/SDIQtY2lsso/s1600/terminal.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 303px;" src="http://3.bp.blogspot.com/-FLABOr7cLYA/TmD-Qb0TI-I/AAAAAAAAAFw/SDIQtY2lsso/s400/terminal.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5647793491021079522" /></a>lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-30672968661231381702011-09-01T09:54:00.004+08:002011-09-01T10:20:12.572+08:00利用 archiso 和 aif 搭配 chroot 安裝 Arch Linux<p>
<br />因為硬碟出問題,系統碟在 error.log 裡面跳了一堆 UNC error,跑 S.M.A.R.T. 測試也是 read failure,用 Live USB 撐了幾天,把重要資料備 份以後,買了兩個大容量的隨身碟來當外接硬碟使用(7年前的電腦,要更換零件不如換整台,預算有限,就先湊合著用,用久了有感情也是一個原因 ^^),主要系統還是灌在硬碟上,/var 和 /home 及一些暫存的資料就丟到隨身碟上。</p>
<br /><p>因為要重灌,就順便試試之前在 Arch Wiki 上看到用 archiso 配上 chroot 安裝的方法,沒想到 8/19 出了新的 image,wiki 的內容已經不能適用,花了將近一天測試順便寫了個 script,丟在<a href="https://bitbucket.org/lefthaha/arch_live_usb">之前開的 repository 內</a>( utils/unarchfs.sh ),改天有空再更新 Arch Wiki。</p><p>新的 iso 包含了 5 個檔案,mount archiso 後再一一解壓縮或 mount 到 chroot 目錄內,步驟簡單描述如下,因為記憶體有 1.5G,所以就全部都丟到 /tmp/archinstall 下面
<br /></p>
<br /><pre class="brush: bash"># mount archlinux iso
<br />mkdir -pv /tmp/archinstall/image
<br />mount -o loop archlinux-2011.08.19-core-i686.iso /tmp/archinstall/image
<br />
<br /># create directory for chroot
<br />mkdir -pv /tmp/archinstall/archlinux
<br />
<br /># start to extract
<br />cd /tmp/archinstall/image/arch/i686/
<br />
<br /># root-image
<br />unsquashfs -dest /tmp/archinstall/root-image root-image.fs.sfs
<br />mount -t ext4 /tmp/archinstall/root-image/root-image.fs /tmp/archinstall/archlinux
<br />
<br /># create directories in chroot env for other fs to mount
<br />mkdir -pv /tmp/archinstall/archlinux/lib/modules
<br />mkdir -pv /tmp/archinstall/archlinux/usr/share
<br />mkdir -pv /tmp/archinstall/archlinux/repo/core/{i686,any}
<br />
<br /># lib-modules
<br />unsquashfs -dest /tmp/archinstall/lib-modules lib-modules.fs.sfs
<br />mount -t ext4 /tmp/archinstall/lib-modules/lib-modules.fs /tmp/archinstall/archlinux/lib/modules
<br />
<br /># repo-core-i686
<br />mount -o loop -t squashfs repo-core-i686.sfs /tmp/archinstall/archlinux/repo/core/i686
<br />
<br />cd /tmp/archinstall/image/arch/any/
<br />
<br /># usr-share
<br />unsquashfs -dest /tmp/archinstall/usr-share usr-share.fs.sfs
<br />mount -t ext4 /tmp/archinstall/usr-share/usr-share.fs /tmp/archinstall/archlinux/usr/share
<br />
<br /># repo-core-any
<br />mount -o loop -t squashfs repo-core-any.sfs /tmp/archinstall/archlinux/repo/core/any
<br />
<br /></pre>接著 cd /tmp/archinstall/archlinux/ ,再進入 chroot 下 aif -p interactive 就可以開始安裝,比起用 pacman 安裝要方便許多,不必自己準備 /dev 下的檔案, aif 也會幫忙跑 mkinitcpio、locale-gen、設定 Grub ……等,十分輕鬆,不過有一點要注意的是安裝完後要在 chroot 環境內把 aif 自動掛載的磁碟卸載掉,否則離開 chroot 後會發現沒辦法卸載 root-image,可是又找不出有其他程式使用這個檔案。
<br />
<br />目前系統已使用快一個禮拜,/home 掛在 USB 3.0 的隨身碟上插 2.0 的接口,傳大檔可以跑到 15 mb/s,只是瀏覽器的 cache 要設到記憶體下(預設丟在 /home/$USER 內),否則開新分頁會很卡,大概是頻繁寫入小檔案,寫到隨身碟效率變差。
<br />
<br />此外還有遇到 gdm 的小問題:舊系統是用 xfce 4.8 配上 .xinitrc 來設定 gcin ,但是換成 gdm 來登入(沒安裝 gnome)就沒辦法搞定,會把全部的 locale 改成 zh_TW.UTF-8,我只是想用中文輸入法,不想全部介面都變成中文,搞到最後還是換回 xdm。
<br />
<br />另外困擾我兩天的問題是字型,隨身碟系統上是用 Gnome 3,切回 xfce 後預設字型完全不同,讓我眼睛痛了整整一天,平常應該要定期紀錄常用字型,晚點要再寫一篇來紀錄目前使用的字型。
<br />
<br /><p>Reference :
<br /><a href="https://wiki.archlinux.org/index.php/Install_from_Existing_Linux#Another_Method:_Installing_from_Existing_Linux_with_Arch.27s_Image">Arch Wiki - Install_from_Existing_Linux</a>
<br /><a href="http://projects.archlinux.org/archiso.git/tree/README">archiso - README</a>
<br /></p>
<br />lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-11025304088396895552011-08-09T11:04:00.004+08:002011-08-23T00:36:48.924+08:00更改 Gnome 3 的螢幕解析度<div># Update 2011-08-19</div><div># 要安裝 nouveau-dri 才能啟動 gnome-shell,否則只會進入 fallback mode</div><div>
<br /></div>在隨身碟上面裝了 Arch Linux + Gnome 3 來玩,前幾天把顯卡驅動程式由原本的 nvidia 換成 nouveau ,重開機發現沒辦法進入 X ,修改 /etc/X11/xorg.conf <div><div></div><blockquote><div>Section "Device"</div><div> Identifier "Device0"</div><div> Driver "nvidia"</div><div> VendorName "NVIDIA Corporation"</div><div>EndSection</div></blockquote><div></div></div>
<br />將 nvidia 改成 nouveau 就可成功 startx,但是進到 Gnome 跳出警告變成 fallback mode<div>解析度變得很奇怪,比之前設定的 1024x768 還要小,開 System-Settings 想看一下問題出在哪,但是......</div><div>
<br /></div><div>
<br /></div><div>System-Setting 的視窗沒辦法調整大小啊!幹!</div><div>
<br /></div><div>
<br /></div><div>chromium 跟 Terminal 、dconf-editor 都可以調整視窗大小,就是 System-Settings 他媽的不能調整視窗大小,就只能傻傻的看著視窗的上半部顯示目前 Monitor 名稱,下面的選項完全拉不到!</div><div>
<br /></div>
<br /><a href="http://1.bp.blogspot.com/-KFxlWYmyT58/TkCnfREVXPI/AAAAAAAAAFA/1gFcDqwW-SE/s1600/displays.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 206px;" src="http://1.bp.blogspot.com/-KFxlWYmyT58/TkCnfREVXPI/AAAAAAAAAFA/1gFcDqwW-SE/s400/displays.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5638690889067224306" /></a><div>
<br /></div><div>這 screenshot 還是恢復正常解析度後拍的,不然 Gnome 3 的 Take Screenshot 也是沒辦法調整視窗!難怪 Gnome 3 剛釋出的時候就有人在說視窗少了放到最大的功能很不方便,在 fallback mode 把視窗拉到最上層不會自動調整大小到符合螢幕,看著只剩一半的設定畫面,就只能在心裡問候這些開發者的老媽。</div><div>
<br /></div><div>幸好隨身碟上面還有裝 xfce4 ,開進去一看,發現解析度只剩下 640x480,720x400 這兩種,才能找到解法,在原本 nvidia-xconfig 產生的 /etc/X11/xorg.conf 中把 "Monitor" Section 全部 comment ,重新 startx 就可以找到正常的解析度,如果沒有裝 xfce4 ,我就不知道該怎麼辦了......</div><div>
<br /></div><div>後來發現還有 xrandr 可以用,可以參考 <a href="https://wiki.ubuntu.com/X/Config/Resolution">Ubuntu Wiki 上的說明</a>。</div><div>
<br /></div><div>Reference:</div><a href="http://kubuntuforums.net/forums/index.php?topic=3110471.0;wap2">[solved] Setting screen resolution with nouveau/lucid</a>
<br /><a href="http://kubuntuforums.net/forums/index.php?topic=3110165.msg220525#msg220525">[solved] How to get rid of nouveau?</a><div><a href="https://bbs.archlinux.org/viewtopic.php?pid=926377">Gnome 3 - Fallback mode [solved]</a></div>lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-27345701833452811042011-07-28T16:47:00.007+08:002011-08-23T00:36:48.925+08:00Setup moinmoin wiki with lighttpd<div><span class="Apple-style-span" >OS: Arch Linux</span></div><div><span class="Apple-style-span" >Package:</span></div><div><ul><li><span class="Apple-style-span" >python2: 2.7.2-2</span></li><li><span class="Apple-style-span" >moinmoin: 1.9.3-2</span></li><li><span class="Apple-style-span" >lighttpd: 1.4.29-1</span></li></ul></div><div><span class="Apple-style-span" >Install Path: /srv/http/</span></div><br /><br /><a href="http://4.bp.blogspot.com/--PtU02M4j7Y/TjEn4f2HuvI/AAAAAAAAAE4/JIaEPio6g1k/s1600/Screenshot%2B-%2B07282011%2B-%2B05%253A11%253A38%2BPM.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 255px;" src="http://4.bp.blogspot.com/--PtU02M4j7Y/TjEn4f2HuvI/AAAAAAAAAE4/JIaEPio6g1k/s400/Screenshot%2B-%2B07282011%2B-%2B05%253A11%253A38%2BPM.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5634328460391856882" /></a><br /><br /><span class="Apple-style-span" ><br /><a href="https://bitbucket.org/lefthaha/conf/changeset/281893e4312a#chg-etc/lighttpd/lighttpd.conf"># edit /etc/lighttpd/lighttpd.conf to enable fastcgi</a><br /><br />cp -v /usr/share/moin/server/moin.fcgi /srv/http/bin_path/moin.fcgi</span><div><span class="Apple-style-span" ><br /><a href="https://bitbucket.org/lefthaha/conf/changeset/281893e4312a#chg-srv/http/bin_path/moin.fcgi"># edit moin.fcgi</a><br /><br />cp -r /usr/share/moin/{data,underlay} /srv/http/wiki/</span><div><span class="Apple-style-span" ><br /></span><div><span class="Apple-style-span" ># in lighttpd.conf, server.username is "http", change directories owner to http<br />chown -R http /srv/http/wiki/{data,underlay}</span></div><div><span class="Apple-style-span" >cp -v /usr/share/moin/config/wikiconfig.py /srv/http/wiki/<br /><br /></span></div><div><a href="https://bitbucket.org/lefthaha/conf/changeset/281893e4312a#chg-srv/http/wiki/wikiconfig.py"><span class="Apple-style-span" ># edit wikiconfig.py, add superuser account</span></a><div><span class="Apple-style-span" ><br /></span></div><div><span class="Apple-style-span" ># Start wiki, register superuser account</span></div><div><span class="Apple-style-span" >/etc/rc.d/lighttpd start</span></div><div><span class="Apple-style-span" ><br /></span></div><div><span class="Apple-style-span" ># go to http://localhost/wiki/, register superuser account<br /># http://localhost/wiki/LanguageSetup to install page packages<br /><br /># Install theme<br /># Download theme from http://moinmo.in/ThemeMarket<br /># if using the built-in static server<br /># static files are stored in /usr/lib/python2.x/site-packages/MoinMoin/web/statc/htdocs/<br /># I prefer the moniker theme :)</span></div><div><span class="Apple-style-span" ><br />mv theme file to /usr/lib/python2.7/site-packages/MoinMoin/web/static/htdocs/<br />mv theme.py to /srv/http/wiki/data/plugin/theme/<br /><br /># test config<br />/etc/rc.d/lighttpd restart</span></div></div></div></div>lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-42668601472052369132011-06-04T18:23:00.010+08:002011-06-07T09:28:45.620+08:00Ignore tracked file in Mercurial without removing ithgignore only ignore files that have not been tracked before, if you add some files to the repository at previous commits, then you changed your mind, don't want to track those files, list them in .hgignore won't stop Mercurial from tracking them, you need to use `hg rm -Af FILENAME` to remove files from the repository ( files will still exist in the directory ), after commit, Mercurial will really stop tracking those files.<br /><br />Step by step:<br /><ol><li>list files in .hgignore ( eg. echo "glob:FILENAME" >> .hgignore )</li><li>hg rm -Af FILENAME</li><li>hg ci -m "Stop track FILENAME"<br /></li></ol><br />My test:<br /><pre class="brush: text ">[lefthaha@HOST work]$ mkdir test<br />[lefthaha@HOST work]$ cd test/<br />[lefthaha@HOST test]$ hg init<br />[lefthaha@HOST test]$ touch abc.txt<br />[lefthaha@HOST test]$ hg ci -Am 'abc.txt'<br />adding abc.txt<br />abc.txt<br />committed changeset 0:1949cce3893d<br /><br />[lefthaha@HOST test]$ hg st<br />[lefthaha@HOST test]$ hg head<br />changeset: 0:1949cce3893d<br />tag: tip<br />user: left < lefthaha ><br />date: Sat Jun 04 17:18:02 2011 +0800<br />files: abc.txt<br />description: abc.txt<br /><br />[lefthaha@HOST test]$ echo "glob:abc.txt" > .hgignore<br />[lefthaha@HOST test]$ echo ".hgignore" >> .hgignore<br />[lefthaha@HOST test]$ echo "cde" >> abc.txt<br /><br />[lefthaha@HOST test]$ hg st<br />M abc.txt<br />[lefthaha@HOST test]$ hg ci -m "modify abc.txt"<br />abc.txt<br />committed changeset 1:76446b6f8d7f<br />[lefthaha@HOST test]$ ls<br />abc.txt<br />[lefthaha@HOST test]$ hg rm -Af abc.txt<br />removing abc.txt<br />[lefthaha@HOST test]$ hg st<br />R abc.txt<br />[lefthaha@HOST test]$ ls<br />abc.txt<br />[lefthaha@HOST test]$ hg ci -m "hg rm abc.txt"<br />committed changeset 2:b07e13f2dd28<br /><br />[lefthaha@HOST test]$ echo "ijk" >> abc.txt<br />[lefthaha@HOST test]$ hg st<br />[lefthaha@HOST test]$ echo "ijk" >> abc.txt<br />[lefthaha@HOST test]$ hg st<br />[lefthaha@HOST test]$ cat abc.txt<br />cde<br />fgh<br />ijk<br />ijk<br />[lefthaha@HOST test]$ hg ci<br />nothing changed<br /><br />[lefthaha@HOST test]$ cd ..<br /><br /># clone the repository<br />[lefthaha@HOST work]$ hg clone test/ test2<br />updating to branch default<br />resolving manifests<br />0 files updated, 0 files merged, 0 files removed, 0 files unresolved<br />[lefthaha@HOST work]$ cd test2/<br />[lefthaha@HOST test2]$ ls<br />[lefthaha@HOST test2]$ hg st<br />[lefthaha@HOST test2]$ hg head<br />changeset: 2:b07e13f2dd28<br />tag: tip<br />user: left < lefthaha ><br />date: Sat Jun 04 17:20:12 2011 +0800<br />files: abc.txt<br />description:<br />hg rm abc.txt<br /><br />[lefthaha@HOST test2]$ hg log<br />changeset: 2:b07e13f2dd28<br />tag: tip<br />user: left < lefthaha ><br />date: Sat Jun 04 17:20:12 2011 +0800<br />files: abc.txt<br />description:<br />hg rm abc.txt<br /><br />changeset: 1:76446b6f8d7f<br />user: left < lefthaha ><br />date: Sat Jun 04 17:19:34 2011 +0800<br />files: abc.txt<br />description:<br />modify abc.txt<br /><br />changeset: 0:1949cce3893d<br />user: left < lefthaha ><br />date: Sat Jun 04 17:18:02 2011 +0800 1 123<br />files: abc.txt<br />description:<br />abc.txt<br /><br />[lefthaha@HOST test2]$ hg update -r 1<br />resolving manifests<br />getting abc.txt<br />1 files updated, 0 files merged, 0 files removed, 0 files unresolved<br />[lefthaha@HOST test2]$ ls<br />abc.txt<br /><br /></pre><br /><br />There is another trick on Mercurial wiki to ignore multiple files in one line command, not tried yet.<br /><br /><a href="http://mercurial.selenic.com/wiki/TipsAndTricks#Remove_files_that_are_matched_by_.hgignore_but_were_added_in_error">Tips and Tricks - 34. Remove files that are matched by .hgignore but were added in error</a><br /><br /><br />Reference:<br /><a href="http://superuser.com/questions/234307/can-you-remove-a-file-from-mercurial-without-removing-it-from-the-filesystem-like">superuser - Can you remove a file from Mercurial without removing it from the filesystem like Git?</a><br /><a href="http://www.selenic.com/mercurial/hg.1.html">hg(1)</a><br /><a href="http://www.selenic.com/mercurial/hgignore.5.html">hgignore(5)</a>lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-79354528345573870762011-05-26T00:58:00.007+08:002011-05-26T02:05:20.783+08:00sha1 hash encoded in base64到了報稅的季節,幫家人安裝<a href="http://tax.nat.gov.tw/info_IRX_download.html?id=1">報稅軟體</a>的時候發現有提供<a href="http://download.tax.nat.gov.tw/irx/sha1n12.xml"> SHA1 驗證檔</a>,點進去一看,應該是以 base64 編碼,在 Windows 下有安裝 Python 2.7 ,就直接解碼看看( 沒想到 Python 內建的 IDLE 那麼難用,已經習慣 shell 裡按上下鍵叫出之前的指令了... ),解開一看發現真的是 hash <span style="font-size:78%;">(註一)</span>,沒有轉成一般可見的文字,跟以前看過的驗證碼<span style="font-size:78%;">(註二)</span>不一樣 ,還以為是我下錯指令或編碼不是 base64 ,翻了說明文件才發現是我見識淺薄,用 hashlib 的 hash.digest() 就可以得到相同結果,使用 hash.hexdigest() 才會得到一般的驗證碼,但是這串文字又不能直接 decode("hex"),在 Python 裡面 decode("hex") 或 encode("hex") 都是已經轉碼好了<span style="font-size:78%;">(註三)</span>,身為一個懶得思考的傢伙,就直接跑去看人家 <a href="http://hg.python.org/cpython/file/5395f96588d4/Modules/shamodule.c">hashlib 原始碼</a>是怎麼寫的,結果人家是用 C 寫的,後來又發現 <a href="http://docs.python.org/library/binascii.html">binascii</a> 這個 module 可以直接用 hexlify 這個 function 轉換字串,又跑去看<a href="http://hg.python.org/cpython/file/5395f96588d4/Modules/binascii.c">原始碼</a>,看到註解還真有點囧<br /><pre class="brush:text">/* make hex version of string, taken from shamodule.c */<br /><br />for(i=j=0; i<sizeof(digest); i++) {<br />char c;<br />c = (digest[i] >> 4) & 0xf;<br />c = (c>9) ? c+'a'-10 : c + '0';<br />hex_digest[j++] = c;<br />c = (digest[i] & 0xf);<br />c = (c>9) ? c+'a'-10 : c + '0';<br />hex_digest[j++] = c;<br />}<br /></pre><br />沒想到我連這麼簡單的字元轉換都記不起來,還用<br />bin( ord("a") >> 4 & 0xf )<br />配合 ascii 表查了一下才瞭解這段程式<br />算 hash 的時候還忘記要用 binary mode 讀檔...Orz<br /><br />後來寫了<a href="https://bitbucket.org/lefthaha/scripts/src/3a639dfa46c3/sha1sum_base64.py">一小段 script </a>來比對驗證碼是否符合,如果明年幫忙安裝報稅軟體的時候可以拿來用 ( 感覺機會不大 XD ),最後要抱怨一下,這 "個人綜合所得稅電子結算申報程式" 真是他媽的難用,難用到我只是幫家人操作讀取檔案和列印單據就想摔滑鼠的程度。<br /><br /><br /><span style="font-size:85%;">註一</span>: <span style="font-size:85%;">\xe6@\x0e\x86\xdeD\xdeW\x87\xf8\t\x9c=o\xee\xd3\xdcw\xdc<br /><span style="font-size:100%;"><span style="font-size:85%;">註二</span>:</span></span><span style="font-size:85%;"> 60e6400e86de44de5787f8099c3d6feed3dc77dc</span> <span style="font-size:85%;"><br /></span><span style="font-size:85%;"><span style="font-size:100%;"><span style="font-size:85%;">註三</span>:</span></span>"abc".encode("hex") == "616263"lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-50491426361734454632011-05-09T23:18:00.012+08:002011-08-23T00:36:48.926+08:00Arch Linux Live USB一直很想弄個 Live USB Stick 來玩玩,但是試了 UNetbootin 和 Universal USB Installer,不管是 GNOME 3 Live CD、Ubuntu、Xubuntu、Mint 都沒辦法成功開機,不然就是畫面有問題,進入 X 後變成模糊畫面,燒到 CD 來測試卻是正常,後來又看到了 <a href="http://live.debian.net/">Debian Live Project</a>,翻了文件發現要搞定一套可以用的系統得花上更多的時間,乾脆就直接把 Arch Linux 安裝到 USB Stick 上面,對 Arch Linux 比較熟悉,操作起來會比較順手一點,要保存資料和設定也很方便<br /><br />OS: Arch Linux<br />USB Stick minimal disk space: 4G ( About 3.1G after GNOME 3 installed )<br /><br />因為希望這隨身碟還是能拿來存一些資料,所以有另外切一個 vfat 的分割,而且這個分割的順序必須是第一個,Windows 才讀的到<br /><pre class="brush: bash ">fdisk -l<br />Disk /dev/sdd: 8032 MB, 8032092160 bytes<br />248 heads, 62 sectors/track, 1020 cylinders, total 15687680 sectors<br />Units = sectors of 1 * 512 = 512 bytes<br />Sector size (logical/physical): 512 bytes / 512 bytes<br />I/O size (minimum/optimal): 512 bytes / 512 bytes<br />Disk identifier: 0xdacf2b24<br /><br />Device Boot Start End Blocks Id System<br />/dev/sdd1 * 2048 1435647 716800 c W95 FAT32 (LBA)<br />/dev/sdd2 1435648 9824255 4194304 83 Linux<br />/dev/sdd3 9824256 15687679 2931712 83 Linux<br /></pre><br />系統安裝在 /dev/sdd2 ,type ext4,掛載的時候時候加上 noatime 這個 flag<br /><br />這次是用 pacman -r /mnt/arch_live 的方式去安裝,要手動設定一些 /dev 的 nodes ,有點麻煩,不知道利用 CD Image 的 AIF 會不會比較簡單<br /><br />裝完需要的 packages ,像 xorg-server、nvidia、gnome 後,<a href="https://wiki.archlinux.org/index.php/Installing_Arch_Linux_on_a_USB_key#USB_Support">要記得在 /etc/mkinitcpio.conf 裡的 HOOKS 加上 usb</a>,因為 grub-install 失敗,所以是用<a href="https://wiki.archlinux.org/index.php/Install_from_Existing_Linux#Setup_Grub">手動安裝</a>的方式,沒搞清楚設定檔,結果卡了一天都沒辦法進入系統...Orz<br /><br />整體上來講,照著 wiki 上的指示安裝,再依 Beginner's Guide 做設定,應該是沒什麼大問題,另外網路頻寬也要夠,否則下個 pacman -Syu 大概會抓到睡著<br /><br />常常用 sudo ,下指令和複製本機設定檔的時候要再三檢查路徑,搞錯的話就要跟太陽公公說再見了;還有之前沒試過 chroot ,每次 sudo mount proc, sys, dev 都有點怕打錯,也有寫個 bash script 來幫忙,倒是 umount 還要自己 key,還要再研究一下怎麼寫,最怕的就是沒辦法 umount ,就要回想剛剛是不是下了什麼指令動到 /dev 下面的東西...<br /><br />碰到卡比較久的問題:<br /><ol><li>GRUB 出現 Error 15: File not found:<br />問題是在 menu.lst 的設定,當初安裝 GRUB 的時候是<a href="https://wiki.archlinux.org/index.php/GRUB#Installing_to_the_MBR">安裝到 MBR</a>,設定的 root 是 (hd0,0) ,但是我的系統是安裝在第二個分割,所以必須要改成 (hd0,1);由於 /boot 沒有獨立一個分割區給他,所以 kernel 和 initrd 前面必須加上 /boot/ ,GRUB 才知道要到 boot 這個資料夾下尋找 kernel image<br /><pre class="brush: bash ">## /boot/grub/menu.lst<br /># (0) Arch Linux<br />title Arch Linux [/boot/vmlinuz26]<br />root (hd0,1)<br />kernel /boot/vmlinuz26 root=/dev/disk/by-uuid/544dccdf-2aaf-4843-973c-f04c305f5e1f ro vga=792<br />initrd /boot/kernel26.img<br /></pre><br /></li><li>開機後無法進入 X:<br />錯誤訊息有好幾個,條列如下:<br /><pre class="brush: bash "># 開機以後進入 X ,畫面閃了幾下出現類似<br />gdm-binary[3684]: WARNING: GdmDisplay: display lasted 0,858447 seconds<br />gdm-binary[3684]: WARNING: GdmDisplay: display lasted 0,864611 seconds<br />gdm-binary[3684]: WARNING: GdmLocalDisplayFactory: maximum number of X display failures reached: check X server log for errors<br /># 進 console 裡下 `startx` 則是出現以下錯誤<br />(EE) USB USB Keyboard failed to initialize for relative axes.<br /># 在 Xorg.0.log 除了上面鍵盤的問題之外還有一些其他的錯誤訊息<br />(WW) Open ACPI failed (/var/run/acpid.socket) (No such file or directory)<br />(WW) `fonts.dir' not found (or not valid) in "/usr/share/fonts/X11/100dpi/".<br />Entry deleted from font path.<br />(Run 'mkfontdir' on "/usr/share/fonts/X11/100dpi/").<br /><br />### 解決方法:不太確定是哪個方式解決的,只好把做過的修改一樣樣列出來 ###<br /># 1.在 /etc/rc.conf 的 DAEMONS 中加入 hal 和 acpid<br />DAEMONS=(syslog-ng dbus hal acpid @network netfs crond @openntpd @alsa)<br /># 2.依錯誤訊息指示,在 /usr/share/fonts/X11/... 中執行 mkfontdir<br /># 另外也安裝了一些字型像 ttf-fireflysung, wqy-zenhei, ttf-dejavu 之類...<br /># 3.Reinstall xorg-server,gdm,並檢查 ~/.xinitrc 是不是有加上<br />exec ck-launch-session gnome-session<br /><br /></pre></li><li>網際網路無法連線:<br />區網是使用 DHCP,一開機就會啟動,網際網路連線則是使用 PPPoE 手動啟用<br />ping 區網上的電腦沒有問題,但是對外像 www.google.com, 168.95.1.1 都 ping 不到,後來才想到可能是 route table 的問題<br /><pre class="brush: bash "># 預設的 gateway 是 eth0 ,照理說 PPPoE 啟動應該會把預設改成 ppp0 才對<br />[left]$ route -n<br />Kernel IP routing table<br />Destination Gateway Genmask Flags Metric Ref Use Iface<br />h254.s98.ts.hin * 255.255.255.255 UH 0 0 0 ppp0<br />192.168.1.0 * 255.255.255.0 U 0 0 0 eth0<br />default * 0.0.0.0 U 0 0 0 eth0<br /><br /># 手動更改 gateway 就正常了<br />[left]$ sudo route del default<br />[left]$ sudo route add default ppp0<br /><br /># 測試確定是 route 的問題的話,可以在 /etc/ppp/ 下面新增名為 ip-pre-up 的 script<br /># 這樣 pppd 在啟動的時候就會去執行它,內容如下 ( 記得要 chmod +x 才能執行)<br /><br />[left]$ cat /etc/ppp/ip-pre-up<br />#! /bin/sh<br />/sbin/route del default<br /><br />[left]$ sudo chmod +x /etc/ppp/ip-preup<br /></pre></li><br /></ol><a href="https://bitbucket.org/lefthaha/arch_live_usb/overview">在 bitbucket 上面開了 repository </a>放些設定檔,有興趣的可以參考看看。<br /><br /><br />Reference on Arch Linux Wiki:<br /><a href="https://wiki.archlinux.org/index.php/Installing_Arch_Linux_on_a_USB_key">Installing Arch Linux on a USB key</a><br /><a href="https://wiki.archlinux.org/index.php/Install_from_Existing_Linux">Install from Existing Linux</a><br /><a href="https://wiki.archlinux.org/index.php/Change_Root">Change Root</a><br /><a href="https://wiki.archlinux.org/index.php/SSD#Tips_for_Minimizing_SSD_Read.2FWrites">Tips for Minimizing SSD Read/Writes</a><br /><a href="https://wiki.archlinux.org/index.php/Beginners%27_Guide">Beginners' Guide</a><div><a href="https://wiki.archlinux.org/index.php/PPPoE_Setup_with_pppd">PPPoE Setup with pppd</a><br /><a href="https://wiki.archlinux.org/index.php/Xorg">Xorg</a><br /><a href="https://wiki.archlinux.org/index.php/GNOME_3">GNOME 3</a><br /><a href="https://wiki.archlinux.org/index.php/Fonts">Fonts</a></div>lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-54261243844343540942011-04-08T23:58:00.009+08:002011-08-23T00:36:48.926+08:00log cron jobs output之前在看 /var/log/crond.log 的時候常會看到以下類似的訊息<br /><pre class="brush: text ">Mar 20 18:37:01 `hostname` crond[1234]: FILE /var/spool/cron/root USER root PID 9999 job sys-daily<br />Mar 20 18:37:16 `hostname` crond[5678]: mailing cron output for user root job sys-daily<br />Mar 20 18:37:16 `hostname` crond[5678]: unable to exec /usr/sbin/sendmail: cron output for user root job sys-daily to /dev/null<br /></pre>Arch Linux 預設不會安裝 sendmail,所以 cron jobs 所產生的訊息沒辦法傳給使用者,但是又懶得去安裝與設定 postfix ,乾脆就寫個 <a href="https://bitbucket.org/lefthaha/scripts/src/2021b754e5e4/cron_output_to_log.sh">script</a><a href="https://bitbucket.org/lefthaha/scripts/src/2021b754e5e4/cron_output_to_log.sh"> </a>把這些訊息存到 /var/log/cron_output/ 這個目錄下面,沒想到這一寫也是花了不少時間,我果然是個遜泡...<br /><br />因為 crond 執行 cron jobs 時會把權限切換到該使用者一樣,寫入 log 的時候會有權限問題,如果 root 沒有幫忙在 /var/log/cron_output/ 下面建立 ${USER}.cron_output.log,會改成存到使用者的家目錄。<br /><br />開放讓使用者能寫入 /var/ 下的檔案雖然有點危險,如果帳號被盜可能會把硬碟空間吃光導致其他 log 寫不進去,雖然可以用 quota 或另外準備一個 cron job 來偵測硬碟剩餘空間判斷要不要砍掉這個檔案或拿掉寫入權限,但身為一個不喜歡分開看 log 檔的懶惰傢伙,就讓他隨風而去吧~<br />把這支 <a href="https://bitbucket.org/lefthaha/scripts/src/2021b754e5e4/cron_output_to_log.sh">script</a> 丟到 /var/log/cron_output/ 後<br /><br /><pre class="brush: text ">sudo mkdir -v /var/log/cron_output/<br />sudo touch /var/log/${USER}.cron_output.log<br />sudo chmod 600 /var/log/${USER}.cron_output.log<br />sudo chattr +a /var/log/${USER}.cron_output.log<br /><br />再修改 /etc/conf.d/crond,將<br />CROND_ARGS="-S -l info"<br />改成<br />CROND_ARGS="-S -l info -M /var/log/cron_output/cron_output_to_log.sh"<br /></pre><br />順便利用 <a href="https://bitbucket.org/lefthaha/conf/src/ca98740cb608/etc/logrotate.d/cron_output">logrotate </a>來管理這些 log<br /><br />結果隔天馬上就發現有兩個問題要改,還是去年的問題,一堆 pacnew 檔案到現在都還沒 merge XDD~<br /><br />Reference:<br /><a href="http://www.jimpryor.net/linux/crond.8">dcron man package</a><br /><a href="http://linux.vbird.org/linux_basic/0570syslog.php#rotate">鳥哥的 Linux 私房菜:登錄檔的輪替 (logrotate)</a><br /><a href="https://bugs.archlinux.org/task/15707"></a>lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-30102985610195165022011-03-04T22:39:00.005+08:002011-08-23T00:36:48.927+08:00stop X from listening on Port 6000OS: Arch Linux<br />Display Manager: xdm<br />Desktop Environment: Xfce 4.8<br /><br />之前用<br /><br />netstat -tnlp<br /><br />都會看到一個 6000 的 Port 開著,雖然知道那是 X 啟動的,而且 iptables 有設定好應該也不會出什麼問題,但還是有點討厭,查了一些資料,設定 ~/.xinitrc 也沒用,今天突然想到從 xdm 這邊下手,果然一試就成功。<br /><br />目前是照 <a href="https://wiki.archlinux.org/index.php/Xorg#Methods_for_starting_your_Graphical_Environment">ArchWiki</a> 上所寫,修改 /etc/inittab 來啟動 xdm,要關閉 6000 的 Port 必須在啟動 X 的時候傳個參數 -nolisten tcp ( 請參考 man xserver ),需要修改的檔案是 /etc/X11/xdm/Xservers<br /><br />將原本的<br />:0 local /usr/bin/X :0<br /><br />改成<br />:0 local /usr/bin/X -nolisten tcp :0<br /><br />接著 sudo init 3 關閉 X ,sudo init 5 重新啟動 X 應該就不會看到 6000 Port 開著了 :)<br /><br /><br />Reference:<br /><a href="http://nst.sourceforge.net/nst/docs/faq/ch08s06.html">How Do I Prevent X From Exposing A TCP Port?</a><br /><a href="https://bbs.archlinux.org/viewtopic.php?id=10903">Arch Linux Forums: X is listening on port 6000?</a>lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-81543522710294270642011-02-21T23:04:00.006+08:002011-08-23T00:36:48.928+08:00use `tree` to list current directory contents想要看某個目錄下面的目錄和檔案結構,但是用 `ls` 一層層列出來實在是太麻煩了,而且也很不直觀,用 `tree` 可以過濾不想要的 pattern,也可以設定 level,寫了支小 script 來處理各項變數;將查詢的 script 放在同一個目錄下面,方便管理,將每次的查詢結果加上日期儲存起來。<br /><br />放在 bitbucket 上的 <a href="https://bitbucket.org/lefthaha/scripts/src">repository</a> 裡,以後如果寫些 script 也會丟進裡面( 年輕人就是要玩 HG ! )<br /><br /><pre class="brush: bash "><br />#!/bin/bash<br /># using `tree` to list current directory<br /># extract current directory name, record time and append to output file<br /># original: tree -L 3 -I "porn*|tree*" --noreport ./ >> ./tree.txt<br /><br />LEVEL=3<br />EXCLUDE_PATTERN="porn*|tree*"<br />DIRNAME=`basename $PWD`<br />OUTPUT_FILE="tree.txt"<br /><br />echo "Using \`tree\` to list contents of \"" $DIRNAME "\" to" $OUTPUT_FILE<br /><br />echo >> $OUTPUT_FILE<br />echo "********" >> $OUTPUT_FILE<br />echo `date` >> $OUTPUT_FILE<br />echo "********" >> $OUTPUT_FILE<br />echo >> $OUTPUT_FILE<br /><br />cd ..<br />tree -L $LEVEL -I "$EXCLUDE_PATTERN" --noreport $DIRNAME >> $DIRNAME/$OUTPUT_FILE<br /></pre><a href="https://bitbucket.org/lefthaha/scripts/raw/342256786925/tree_pwd.sh">script download</a><br /><br />Reference:<br /><a href="http://linux.die.net/man/1/tree">tree man page</a><br /><a href="http://www.linux.com/archive/feature/120291">Four ways to extract the current directory name</a>lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-2431695487676145582011-01-25T01:03:00.003+08:002011-08-23T00:36:48.928+08:00fix emesene 1.6.3 login error一兩個月前開始,登入 emesene 1.6.3 版的時候都會跳出下列錯誤:<br /><blockquote>emesene error<br />Exception<br />You are using emesene 1.6.3 - "Uberlândia" so you're free to complain here:<br />http://forum.emesene.org/index.php/board,19.0.html<br />Check already existing tickets for duplicates first, please.<br />Traceback (most recent call last):<br /><br />File "/usr/share/emesene/emesenelib/soap/manager.py", line 139, in process<br />return process()<br /><br />File "/usr/share/emesene/emesenelib/soap/manager.py", line 76, in process<br />response.callback(response, *response.args)<br /><br />File "/usr/share/emesene/emesenelib/ProfileManager.py", line 155, in onGetProfile<br />photo = response.body.split('&lt;/Photo>')[0].split('&lt;Photo>')[1]<br /><br />IndexError: list index out of range</blockquote>接著 MSN 暱稱變成註冊信箱,個人狀態一片空白,在官方論壇看到討論說這是 MSN 傳回的內容有改變,造成 emesene 抓不到暱稱和狀態,只要更新到最新的 SVN 版本就可解決。<br /><br />因為懶得再去找 SVN 版本下來安裝,就直接上 <a href="http://emesene.svn.sourceforge.net/viewvc/emesene/trunk/emesene/emesenelib/">Repository</a> 抓 ProfileManager.py 下來產生 patch,反正有問題再用 patch -R 就可以更改回來,目前使用起來一切正常,不知道 emesene2 什麼時候才會發佈 stable 版本?<br /><pre class="brush: bash "><br />diff -u /usr/share/emesene/emesenelib/ProfileManager.py ~/ProfileManager.py > emesene_profile.patch<br />patch -v /usr/share/emesene/emesenelib/ProfileManager.py emesene_profile.patch<br /></pre>lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-84894157670553004442010-12-26T11:44:00.003+08:002010-12-26T12:02:07.179+08:00幾個有趣的 Project 和文章因為分頁開著放很久了,又沒時間去看,先紀錄下來,以後如果有空再...。<br /><br /><a href="http://pypi.python.org/pypi/pep8/">pep8</a>:<br /><div style="text-align: left;"> pep8 is a tool to check your Python code against some of the style conventions in PEP 8.<br /></div><a href="https://github.com/djmelik/archey"><br />archery</a>:<br /> Archey is a system information tool written in Python.<br /><br /><a href="http://code.google.com/p/psutil/">psutil</a> :<span style="text-decoration: underline;"><br /></span> psutil is a module providing an interface for retrieving information on running processes and system utilization (CPU, memory) in a portable way by using <strong>Python</strong>, implementing many functionalities offered by command line tools like <strong>ps</strong>, <strong>top</strong>, <strong>kill</strong>, <strong>lsof</strong> and <strong>netstat</strong>.<br /><br /><span style=""><a href="http://code.google.com/p/shellinabox/">shellinabox</a></span>:<br /> Shell In A Box implements a web server that can export arbitrary command line tools to a web based terminal emulator. This emulator is accessible to any JavaScript and CSS enabled web browser and does not require any additional browser plugins.<br /><br /><a href="http://people.redhat.com/%7Erjones/how-to-supply-code-to-open-source-projects/">How to get your code into an open source project</a>lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-90539034519499564582010-11-14T18:58:00.004+08:002011-08-23T00:36:48.929+08:00讓 xpdf 能正常顯示無內嵌字型的檔案之前有寫過一篇 <a href="http://leftsnb.blogspot.com/2009/10/xpdf-arch-linux.html">讓 xpdf 能正常顯示中文 (Arch Linux)</a>;但是捐血中心寄來的檢驗報告一直都是亂碼,原本以為是捐血中心的問題,直到前幾天想下載 <a href="http://edt1023.sayya.org/vim/">大家來學 Vim 一個歷久彌新的編輯器</a> 的 pdf 才發現沒有內嵌字型的 pdf 也是亂碼,於是就用 shell 呼叫 xpdf 開檔案,再由錯誤訊息去 google ,找了一堆討論,發現 xpdf 的語言包可以解決這個問題;自己測試沒有問題後,再追到 Arch Linux 的 package 上面,發現最新的 PKGBUILD 沒有複製 Adobe-CNS1.cidToUnicode 到 /usr/share/xpdf/ 下面,丟了個 bug report ,隔天 trunk 的 PKGBUILD 就更新了,雖然不知道什麼時候才會移到正式版上面去,但是能貢獻自己小小心力,還有學到一丁點知識,有點開心 :)<br /><br />Reference:<br /><a href="http://ftp10.tw.freebsd.org/pub/Mirror/FreeBSD/Howto/embbed-pdf.html">FreeBSD Chinese HOWTO - 6.9. 以 gs 觀看不內嵌的 pdf 檔</a><br /><a href="http://people.ofset.org/%7Eckhung/b/gnu/font.php">"資訊人權貴" 之家 - 字形/中文</a><br /><a href="http://edt1023.sayya.org/misc/xpdfrc3-sample">Edward G.J. Lee 的 xpdfrc 範例檔</a><br /><a href="http://www.foolabs.com/xpdf/download.html">xpdf - Download</a><br /><a href="http://www.archlinux.org/packages/extra/any/xpdf-chinese-traditional/">Arch Linux Package - xpdf-chinese-traditional</a><br /><a href="https://wiki.archlinux.org/index.php/Creating_Packages">Arch Wiki - Creating Packages</a>lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-82490626262101458412010-11-02T22:21:00.009+08:002011-08-23T00:36:48.930+08:00mount /var to a new partition當初安裝的時候沒有把 /var 獨立出一個分割區,最近發現 / 剩餘空間愈來愈少,利用<br /><blockquote>sudo du -h --max-depth=1 /<br /></blockquote>才發現 /var 就佔了超過 2G ,大部份都是被 Cache 這個目錄吃掉,這是 pacman 的暫存檔,雖然可以用<br /><blockquote>sudo pacman -Sc<br /></blockquote>清掉,但是身為一個懶惰的傢伙,加上不曉得什麼時候會需要 downgrade 某個套件,乾脆就另外準備一個分割區來放。<br /><br /><br />備份資料到隨身碟時,發現裡面中文目錄或檔案都變成亂碼,似乎是 xfce4 的問題,<br /><pre class="brush: text ">修改 /etc/xdg/xfce4/mount.rc<br />在 [vfat] 下面增加一行<br />utf8=true<br /></pre>下次插入隨身碟時就可以正常顯示中文了。<br /><br />使用 Gparted Live CD 以預設選項進入 X 時,螢幕會出現<br /><blockquote>Out of Range</blockquote>無法顯示畫面,逼的我用 Alt + SysRq + [ U , B ] 來重開機,改手動設定解析度就可以正常進入 X,切好分割區並格式化後,mount 原本的 / 與 新切割給 /var 的分割區,複製舊資料,更改原本的 /etc/fstab 。<br /><pre class="brush:bash ">mkdir ~/rrt ~/new_var<br /><br />mount /dev/real_root_partition ~/rrt<br />mount /dev/new_var_partition ~/new_var<br /><br /># 複製原本 var 下的檔案到新分割區<br /># 重新命名原本的 var,避免重新開機後掛載到內有檔案的資料夾<br />sudo cp -ax ~/rrt/var/* ~/new_var/<br />sudo mv ~/rrt/var ~/rrt/var.old<br />sudo mkdir ~/rrt/var<br /><br />sudo cp ~/rrt/etc/fstab ~/rrt/etc/fstab.old<br /><br /># 利用 blkid 來查 uuid 資料並更新 fstab 資料<br />blkid > ~/uuid.txt<br />cat ~/rrt/etc/fstab ~/uuid.txt > ~/fstab.new<br /># 使用 vi 修改完畢後覆蓋回原本的 /etc/fstab<br />sudo cp ~/fstab.new ~/rrt/etc/fstab<br /># 重新開機,測試是否有成功掛載<br /># 自己重新開機後有碰到一個問題,blkid 顯示的還是舊的分割區資料<br /># 後來 man blkid 才知道是讀取 cache 的問題<br /># 使用 blkid -g 就可以清除 ( 但是要用 root 權限去跑,否則沒用 )<br />sudo blkid -g<br />sudo blkid<br /></pre><br />Reference:<br /><a href="https://wiki.archlinux.org/index.php/Xfce#Change_mount_options">ArchWiki:Xfce</a><br /><a href="http://ubuntuforums.org/archive/index.php/t-238190.html">Ubuntu Forums:I want to move /var to a new partition</a>lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-25624946114604791932010-11-01T18:58:00.004+08:002011-08-23T00:36:48.931+08:00Hide Opera system tray icon with Opera 10.63過去都是使用 <blockquote>opera -notrayicon</blockquote> 來隱藏 Opera 的圖示,現在已經沒有這個 argument,改成直接在 opera:config 裡面設定<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_NwOaqWIIg1k/TM6ecvjGFiI/AAAAAAAAACk/Q2KUs2lQDJM/s1600/opera_tray.png"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 146px;" src="http://1.bp.blogspot.com/_NwOaqWIIg1k/TM6ecvjGFiI/AAAAAAAAACk/Q2KUs2lQDJM/s320/opera_tray.png" alt="" id="BLOGGER_PHOTO_ID_5534535208722109986" border="0" /></a><br /><br />取消勾選 Show Tray Icon 就行了。lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-57692711576885291802010-10-28T20:45:00.004+08:002011-08-23T00:36:48.931+08:00在 linux 下的 UTF-8 termial 使用 telnet 連上中文 bbs 與 mud目前是使用 PCMan X 上 bbs,在巴哈洽特上看到有人推廣 doommud,連過去卻無法輸入任何字元,在 termial 裡使用 telnet 連上去則是中文全變亂碼,google 了一下才發現解法,只要使用 luit 就行了<br /><br /><pre class="brush: bash "><br />luit -encoding big5 telnet doommud.twbbs.org 4000<br /></pre><br /><br />在 Xfce Terminal Emulator 和 rxvt-unicode 測試過,拿來上 bbs 也行,只是不在 big5 範圍內的文字會無法顯示,一些 ascii art 也會跑掉,單純看文章應該是夠用的,但是只能在 X window 下的 terminal emulator 使用,一般的 terminal 大概要使用 zhcon 才能正常顯示? (沒試過)<br /><br />參考:<br /><a href="http://blog.toknow.idv.tw/?p=224">[Tips]解決utf8環境下,telnet bbs亂碼</a><br /><a href="http://www.pps.jussieu.fr/%7Ejch/software/luit/">Luit -- locale and ISO 2022 support for Unicode terminals</a>lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-40737900198659094972010-09-30T22:21:00.010+08:002011-08-23T00:36:48.932+08:00利用 shell script 一次同步多個目錄買了顆日立 1T 硬碟搭配 CyberSLIM S1 來備份資料,雖然只能使用 USB 傳輸,但總比再弄張 sata 轉接卡接硬碟來的方便。<br /><br />平常電源都是關閉,只有要傳資料時才會開啟,但每次都要 sudo mount ,接著在不同目錄內找新資料傳過去,實在很麻煩,這時想到可以利用 rsync 來同步資料夾,不用自己比對,想說這麼簡單的東西不必再用 Python ,練習寫個 shell script 就行了,沒想到也是卡了快一天...Orz<br /><br />作法是在 /etc/fstab 內先將硬碟設定為一般使用者可以 mount <span style="font-style: italic;font-size:85%;" >( pass 要設為 0 ,不然一開機就會檢查,然後卡住... )</span><span style="font-size:85%;"><br /></span><pre class="brush:bash "># get UUID<br />blkid<br /><br /># In /etc/fstab, set user, noauto<br />/dev/disk/by-uuid/a123-456a-789d-abcd /mnt/HDD ext4 rw,user,noauto,suid,dev,exec,async 0 0<br /></pre><br />sync.sh:<br /><pre class="brush:shell "><br />#!/bin/bash<br /># Description:<br /># sync multiple folders to external Hard disk<br /><br />MOUNT_POINT=/mnt/HDD<br /><br />### array in shell script<br />SOURCE_DIR=(<br />/mnt/SOURCE_1/<br />/mnt/SOURCE_2/<br />/mnt/SOURCE_3/<br />)<br /><br />DEST_DIR=(<br />/mnt/DEST_1<br />/mnt/DEST_2<br />/mnt/DEST_3<br />)<br /><br /># check if Hard disk mounted or not<br />if [[ -z `mount | grep "$MOUNT_POINT"` ]]<br />then<br />mount $MOUNT_POINT<br />echo "mount $MOUNT_POINT "<br />else <br />echo "$MOUNT_POINT already mounted !!"<br />fi<br /><br />echo<br /><br /># if unable to mount external Hard disk , stop the script and leave<br />if [[ -z `mount | grep "$MOUNT_POINT"`]]<br />then<br />echo "***** Unable to mount $MOUNT_POINT *****"<br />exit 1<br />fi<br /><br />### seq : like range() in python<br />### ${#SOURCE_DIR[*]} : total element number in $SOURCE_DIR<br /><br /># use for loop to sync multiple directories, counter start from 0<br />for counter in `seq 0 $(( ${#SOURCE_DIR[*]} - 1 ))`<br />do<br />echo "*********************************************"<br />echo "Source:" ${SOURCE_DIR[$counter]}<br />echo "Dest: " ${DEST_DIR[$counter]}<br />echo "*********************************************"<br />echo<br />rsync -av --exclude="*.sh" ${SOURCE_DIR[$counter]} \<br />${DEST_DIR[$counter]}<br />echo<br />done<br /><br />exit 0;<br /></pre>裡面大部份程式碼都是從網路上的範例 copy 過來,應該還有更好的寫法,但可以正常運作就足夠了。<br /><br />令我驚訝的是 shell script 內也有 for ... in ... ( 不好意思,我什麼都不知道 ),命令串接也很好用;但變數存取、運算和陣列相關的操作讓我很想用 python ;一些簡單的東西用 shell script 寫起來應該會很方便,只是目前還不熟...lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-73551875563208648802010-07-18T14:09:00.002+08:002010-07-18T14:12:08.902+08:00944 Happy Numbers範圍 1 ~ 99999<br />( 9^2 ) * 5 = 405<br />1 ~ 405 共有 67 個 Happy Number<br /><br />最後卡 WA 的原因是<br />Print a blank line <span style="font-size:100%;"><span style="font-weight: bold;">between</span></span> two consecutive test cases.<br /><br />between 而非 after each case ...Orzlefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0tag:blogger.com,1999:blog-7697244583481643766.post-88762579073214614862010-07-10T21:41:00.007+08:002011-08-23T00:36:48.933+08:00mount DVD and windows share folder with chinese characters在 Windows 下有燒錄一些光碟,裡面資料包含了中文檔名,換用 Linux 讀取時發現全部變成問號,網路上搜尋後發現要在 /etc/fstab 內設定 iocharset=utf8 就能正常顯示中文<br /><pre class="brush:bash"><br />/dev/dvd /media/dvd auto ro,user,noauto,unhide,iocharset=utf8 0 0<br /></pre><br /><br />家中有台 windows 開分享資料夾,要丟資料到那台列印前,先使用<br /><pre class="brush:bash"><br />smbclient -L //WINDOWS_SERVER_NAME_OR_IP -U username<br /></pre><br />輸入正確密碼後,就會列出該台電腦上有分享的服務,確認要連線的分享資料夾後<br /><pre class="brush:bash"><br />sudo mount -t cifs -o iocharset=utf8,username=USER_NAME //WINDOWS_SERVER_NAME_OR_IP/SHARE_FOLDER /mnt/SHARE_FOLDER<br /></pre><br />一樣驗證密碼後就能使用分享資料夾。<br /><br />在測試的時候才發現不輸入帳號密碼也可以看到 XP 上面的所有磁碟分割和服務,嚇了一跳,趕快把 guest 的帳號停用,另外建帳號作分享之用;查了一下,XP 預設會共用所有磁碟分割 (連線還是要輸入帳號密碼) , 雖然只要管理者有設密碼,就不會隨便被連進去,遠端管理也很方便,但還是覺得不太安心,如果要隱藏共用磁碟的話,可以參考下方第四個連結。<br /><br />Reference:<br /><a href="http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?topic_id=4490&forum=8&post_id=16997">如何讓ubuntu顯示ms燒入光碟的文字</a><a href="http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?topic_id=968&forum=11&post_id=17040"><br />[分享] 在 ubuntu 下使用 big5 編碼的光碟片的注意事項</a><br /><a href="http://www.howtogeek.com/wiki/Mount_a_Windows_Shared_Folder_on_Linux_with_Samba">Mount a Windows Shared Folder on Linux with Samba</a><br /><a href="http://support.microsoft.com/kb/288164">如何防止 Windows NT Server 4.0 的系統管理共用的建立</a>lefthahahttp://www.blogger.com/profile/02130874951667047722noreply@blogger.com0