2012年4月23日 星期一

Ubuntu下gitosis架設


安裝 git 及 gitosis
$ sudo apt-get install gitosis git-core

在 Client 端電腦生成 SSH公鑰並上傳至Server端
$ ssh-keygen -t rsa
(生成出來的key,預設是放在 ~/.ssh/下面)
$ scp ~/.ssh/id_rsa.pub serverIP:/tmp/id_rsa_user.pub

初使化gitosis
在client端電腦連線至server端
$ ssh account@serviceIP
$ sudo -H -u gitosis gitosis-init < /tmp/id_rsa_user.pub
(因為目前只有一位使用者,所以將他設為admin權限)
完成後若出現下列訊息,即代表成功
Initialized empty Git repository in /srv/gitosis/repositories/gitosis-admin.git/
Reinitialized existing Git repository in /srv/gitosis/repositories/gitosis-admin.git/

修改執行權限
$ sudo chmod 755 /srv/gitosis/repositories/gitosis-admin.git/hooks/post-update

設定專案權限、新增帳號
$ git clone gitosis@serviceIP:gitosis-admin.git
抓下來後可以看到,主要分成兩個部份
gitosis.conf
keydir/

接下來將使用者的public key複製到 keydir下面,再新增 git 帳號
$ cp /tmp/id_rsa_user2.pub keydir/user2.pub
$ git add keydir/user2.pub
$ git commit -m 'add user2'
$ git push

$vi gitosis.conf
可以看見預設的管理員權限
[group gitosis-admin]
writable = gitosis-admin
members = admin@example.com
若要新增一個 project,可以輸入
[group project_team_name]
writable = project_name
member = user_name
$ git commit -m 'create a new project and add user2'
$ git push
(這裡的 user_name必需與剛才所加的 .pub 名稱是一致的才行)

建立新專案
$ mkdir project_name
$ cd project_name
$ git init
$ git remote add origin gitosis@serverIP:project_name.git
$ git add.
$ git commit
$ git push origin master

2012年3月29日 星期四

Android Simple File Browser


private ArrayList mFiles = null;
private final String ROOT = "/";

// main file browse function
private void browse(String path) {
mFiles.clear(); // clean previous file list
mPath.setText(path); // a TextView, record file path

File folder = new File(path);
File[] files = folder.listFiles();

if(files != null) {
for(File f : files) {
// add file name to list
if(f.isDirectory()) {
mFiles.add(f.getName() + "/");
}
else {
mFiles.add(f.getName());
}
}
}

ArrayAdapter fileAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, mFiles);
mList.setAdapter(fileAdapter);
}


@Override
public void onClick(View v) {
int id = v.getId();
switch(id) {
case R.id.home:
browse(ROOT);
break;
case R.id.back:
String current = (String) mPath.getText();
if(!current.equals(ROOT)) {
// get parent folder location
String parent = current.substring(0, current.lastIndexOf("/", current.length()-2)+1);
browse(parent);
}
break;
}
}

@Override
public void onItemClick(AdapterView l, View v, int position, long id) {

String path = mPath.getText() + mFiles.get(position);
File file = new File(path);

if(file.isDirectory()) {
file = null;
browse(path);
}
else {
// do something you wants
}
}