Popular Posts
Enable SSL connection for Jsoup import org.jsoup.Connection; import org.jsoup.Jsoup; import javax.net.ssl.*; import java.io.IOException; import java.security.KeyManagement... Get files name in batch Windows Batch : get filename using [%%~ni] Linux Shell Script : get filename using [awk, sed] windows sample : rename all *.htm file to ... Translating 2.0 <html> <head>     <title>Translation 2.0</title>     <meta http-equiv="content-type" content="text...
Stats
Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts
Compacting VirtualBox Disk Images - Linux Guests
  1. Start the Linux virtual machine;
  2. Clean the free space on the disk of the Linux virtual machine;
    dd if=/dev/zero of=zerofillfile bs=1M
    • if= specifies the input file;
    • /dev/zero indicates a bit-stream of zeros
    • of= specifies the output file
    • zerofillfile name of the file containing the bit-stream of zeros
    • bs= indicates the block size
    • 1M indicates that the block size will be 1 megabyte
    rm zerofillfile
  3. Shutdown the Linux virtual machine;
  4. Use the VirtualBox VBoxManage utility to compact the Linux guest image.

Ref: Compacting VirtualBox Disk Images - Linux Guests

Grant permission for virtualbox shared folder

The regular way of getting access to the files now, is to allow VirtualBox to automount the shared folder (which will make it show up under /media/sf_directory_name) and then to add your regular user to the vboxsf group (as root #).

usermod -aG vboxsf <youruser>
Build an OpenVPN server on android device

Preparation


  1. An android device, in this case, Sony xperia Z is used
  2. Root permission required
  3. Linux Deploy for deploy image via chroot/proot
  4. OpenVPN


Step

1. Root android device for superuser permission
2. Install Linux Deploy from play store or custom apk.
3. Install linux
  • Click download icon to select which image to deploy

  • Select which distribution and suite to use
  • Set user name & password
  • Allow init system
  • Enable SSH server

  • Deploy distribution

  • After installation completed, start linux

4. Connect to android via SSH
5. Install OpenVPN
  • Install required packages
  • Create certification folder and edit vars configuration
  • Edit vars as blow
  • Build ca, server and client certification

  • Copy required certification to the path of openvpn
  • Clone configuration file from sample config
  • Edit server.conf
  • Edit server.conf as blow, modify what your need
  • Modify networking config sysctl.conf
  • Modify content to allow transfer traffic from vpn
  • Make changes work
  • Edit firewall rules
  • Add following content to allow route from vpn subnet to wireless
  • Edit firewall configuration
  • Allow forward policy
  • Add firewall rule for vpn and ssh
  • Make changes work. (In this case, there was some error but I ignore that)
  • Start openvpn
  • Validate result

6. Use vpn client to connect android device
My Conky config

About Conky: Conky is a free, light-weight system monitor for X, that displays any kind of information on your desktop.


Preview:
Install subversion with apache server on linux (ubuntu)
# 更新 apt package
sudo apt-get update
# 安裝 package
sudo apt-get install subversion apache2 libapache2-svn apache2-utils
# 建立 svn 資料夾
sudo mkdir -p /svn/repos/
# 建立 svn 使用者 (apache)
sudo mkdir -p /svn/users/
# 建立使用者(第一次時有參數-c)
sudo htpasswd -cm /svn/users/svnpasswd nanashi07
# 刪除使用者後再重建(重設密碼)
#sudo htpasswd -D /svn/users/svnpasswd nanashi07
#sudo htpasswd -m /svn/users/svnpasswd nanashi07
# 修改 apache 設定
sudo vi /etc/apache2/mods-enabled/dav_svn.conf
<Location /svn>
  DAV svn
  SVNParentPath /svn/repos/
  AuthType Basic
  AuthName "SVN Repository"
  AuthUserFile /svn/users/svnpasswd
  Require valid-user
</Location>
# 修改 apache 監聽埠
sudo vi /etc/apache2/ports.conf
# 重新啟動 apache
sudo service apache2 restart
# 建立資源庫
sudo svnadmin create /svn/repos/myproject
# 設定資源庫權限
sudo chown -R www-data:www-data /svn/repos/myproject
# 設定資源庫權限
sudo chmod -R g+rws /svn/repos/myproject
vi hot key guide

  • 第一部份:一般模式可用的按鈕說明,游標移動、複製貼上、搜尋取代等

    移動游標的方法
    h 或 向左方向鍵(←)游標向左移動一個字元
    j 或 向下方向鍵(↓)游標向下移動一個字元
    k 或 向上方向鍵(↑)游標向上移動一個字元
    l 或 向右方向鍵(→)游標向右移動一個字元
    如果你將右手放在鍵盤上的話,你會發現 hjkl 是排列在一起的,因此可以使用這四個按鈕來移動游標。 如果想要進行多次移動的話,例如向下移動 30 行,可以使用 "30j" 或 "30↓" 的組合按鍵, 亦即加上想要進行的次數(數字)後,按下動作即可!
    [Ctrl] + [f]螢幕『向下』移動一頁,相當於 [Page Down]按鍵 (常用)
    [Ctrl] + [b]螢幕『向上』移動一頁,相當於 [Page Up] 按鍵 (常用)
    [Ctrl] + [d]螢幕『向下』移動半頁
    [Ctrl] + [u]螢幕『向上』移動半頁
    +游標移動到非空白字元的下一列
    -游標移動到非空白字元的上一列
    n那個 n 表示『數字』,例如 20 。按下數字後再按空白鍵,游標會向右移動這一行的 n 個字元。例如 20 則游標會向後面移動 20 個字元距離。
    0 或功能鍵[Home]這是數字『 0 』:移動到這一行的最前面字元處 (常用)
    $ 或功能鍵[End]移動到這一行的最後面字元處(常用)
    H游標移動到這個螢幕的最上方那一行的第一個字元
    M游標移動到這個螢幕的中央那一行的第一個字元
    L游標移動到這個螢幕的最下方那一行的第一個字元
    G移動到這個檔案的最後一行(常用)
    nGn 為數字。移動到這個檔案的第 n 行。例如 20G 則會移動到這個檔案的第 20 行(可配合 :set nu)
    gg移動到這個檔案的第一行,相當於 1G 啊! (常用)
    nn 為數字。游標向下移動 n 行(常用)
    搜尋與取代
    /word向游標之下尋找一個名稱為 word 的字串。例如要在檔案內搜尋 vbird 這個字串,就輸入 /vbird 即可! (常用)
    ?word向游標之上尋找一個字串名稱為 word 的字串。
    n這個 n 是英文按鍵。代表『重複前一個搜尋的動作』。舉例來說, 如果剛剛我們執行 /vbird 去向下搜尋 vbird 這個字串,則按下 n 後,會向下繼續搜尋下一個名稱為 vbird 的字串。如果是執行 ?vbird 的話,那麼按下 n 則會向上繼續搜尋名稱為 vbird 的字串!
    N這個 N 是英文按鍵。與 n 剛好相反,為『反向』進行前一個搜尋動作。 例如 /vbird 後,按下 N 則表示『向上』搜尋 vbird 。
    使用 /word 配合 n 及 N 是非常有幫助的!可以讓你重複的找到一些你搜尋的關鍵字!
    :n1,n2s/word1/word2/gn1 與 n2 為數字。在第 n1 與 n2 行之間尋找 word1 這個字串,並將該字串取代為 word2 !舉例來說,在 100 到 200 行之間搜尋 vbird 並取代為 VBIRD 則:
    『:100,200s/vbird/VBIRD/g』。(常用)
    :1,$s/word1/word2/g從第一行到最後一行尋找 word1 字串,並將該字串取代為 word2 !(常用)
    :1,$s/word1/word2/gc從第一行到最後一行尋找 word1 字串,並將該字串取代為 word2 !且在取代前顯示提示字元給使用者確認 (confirm) 是否需要取代!(常用)
    刪除、複製與貼上
    x, X在一行字當中,x 為向後刪除一個字元 (相當於 [del] 按鍵), X 為向前刪除一個字元(相當於 [backspace] 亦即是倒退鍵) (常用)
    nxn 為數字,連續向後刪除 n 個字元。舉例來說,我要連續刪除 10 個字元, 『10x』。
    dd刪除游標所在的那一整列(常用)
    nddn 為數字。刪除游標所在的向下 n 列,例如 20dd 則是刪除 20 列 (常用)
    d1G刪除游標所在到第一行的所有資料
    dG刪除游標所在到最後一行的所有資料
    d$刪除游標所在處,到該行的最後一個字元
    d0那個是數字的 0 ,刪除游標所在處,到該行的最前面一個字元
    yy複製游標所在的那一行(常用)
    nyyn 為數字。複製游標所在的向下 n 列,例如 20yy 則是複製 20 列(常用)
    y1G複製游標所在列到第一列的所有資料
    yG複製游標所在列到最後一列的所有資料
    y0複製游標所在的那個字元到該行行首的所有資料
    y$複製游標所在的那個字元到該行行尾的所有資料
    p, Pp 為將已複製的資料在游標下一行貼上,P 則為貼在游標上一行! 舉例來說,我目前游標在第 20 行,且已經複製了 10 行資料。則按下 p 後, 那 10 行資料會貼在原本的 20 行之後,亦即由 21 行開始貼。但如果是按下 P 呢? 那麼原本的第 20 行會被推到變成 30 行。 (常用)
    J將游標所在列與下一列的資料結合成同一列
    c重複刪除多個資料,例如向下刪除 10 行,[ 10cj ]
    u復原前一個動作。(常用)
    [Ctrl]+r重做上一個動作。(常用)
    這個 u 與 [Ctrl]+r 是很常用的指令!一個是復原,另一個則是重做一次~ 利用這兩個功能按鍵,你的編輯,嘿嘿!很快樂的啦!
    .不要懷疑!這就是小數點!意思是重複前一個動作的意思。 如果你想要重複刪除、重複貼上等等動作,按下小數點『.』就好了! (常用)
  • 第二部份:一般模式切換到編輯模式的可用的按鈕說明

    進入插入或取代的編輯模式
    i, I進入插入模式(Insert mode):
    i 為『從目前游標所在處插入』, I 為『在目前所在行的第一個非空白字元處開始插入』。 (常用)
    a, A進入插入模式(Insert mode):
    a 為『從目前游標所在的下一個字元處開始插入』, A 為『從游標所在行的最後一個字元處開始插入』。(常用)
    o, O進入插入模式(Insert mode):
    這是英文字母 o 的大小寫。o 為『在目前游標所在的下一行處插入新的一行』; O 為在目前游標所在處的上一行插入新的一行!(常用)
    r, R進入取代模式(Replace mode):
    r 只會取代游標所在的那一個字元一次;R會一直取代游標所在的文字,直到按下 ESC 為止;(常用)
    上面這些按鍵中,在 vi 畫面的左下角處會出現『--INSERT--』或『--REPLACE--』的字樣。 由名稱就知道該動作了吧!!特別注意的是,我們上面也提過了,你想要在檔案裡面輸入字元時, 一定要在左下角處看到 INSERT 或 REPLACE 才能輸入喔!
    [Esc]退出編輯模式,回到一般模式中(常用)
  • 第三部份:一般模式切換到指令列模式的可用的按鈕說明

    指令列的儲存、離開等指令
    :w將編輯的資料寫入硬碟檔案中(常用)
    :w!若檔案屬性為『唯讀』時,強制寫入該檔案。不過,到底能不能寫入, 還是跟你對該檔案的檔案權限有關啊!
    :q離開 vi (常用)
    :q!若曾修改過檔案,又不想儲存,使用 ! 為強制離開不儲存檔案。
    注意一下啊,那個驚嘆號 (!) 在 vi 當中,常常具有『強制』的意思~
    :wq儲存後離開,若為 :wq! 則為強制儲存後離開 (常用)
    ZZ這是大寫的 Z 喔!若檔案沒有更動,則不儲存離開,若檔案已經被更動過,則儲存後離開!
    :w [filename]將編輯的資料儲存成另一個檔案(類似另存新檔)
    :r [filename]在編輯的資料中,讀入另一個檔案的資料。亦即將 『filename』 這個檔案內容加到游標所在行後面
    :n1,n2 w [filename]將 n1 到 n2 的內容儲存成 filename 這個檔案。
    :! command暫時離開 vi 到指令列模式下執行 command 的顯示結果!例如
    『:! ls /home』即可在 vi 當中察看 /home 底下以 ls 輸出的檔案資訊!
    vim 環境的變更
    :set nu顯示行號,設定之後,會在每一行的字首顯示該行的行號
    :set nonu與 set nu 相反,為取消行號!

鳥哥私房菜