gitoliteでプライベートリポジトリ作成

ゆーすけべー日記を読んで、そういえばgitのprivate repositoryを持ってないし何かのときのために設定しておくか、と思ってさくらVPSのサーバにgitoliteを入れてみた。
Hosting Git Repositories
以下、手順メモ。

gitoliteのインストール

yumでサクっと。

sugyan@remote $ sudo yum install gitolite
gitユーザを作成

専用ユーザを作ってそいつの$HOME以下でリポジトリ管理するようにした方がなにかとラクなので

sugyan@remote $ sudo useradd -m git
adminになるため公開鍵をコピー
sugyan@remote $ sudo cp $HOME/.ssh/id_dsa.pub /home/git/admin.pub
setup

コピーしてきた公開鍵を使ってsetup。使うコマンドはgl-setupだけ

sugyan@remote $ su - git
git@remote $ gl-setup -q admin.pub
creating gitolite-admin...
Initialized empty Git repository in /home/git/repositories/gitolite-admin.git/
creating testing...
Initialized empty Git repository in /home/git/repositories/testing.git/
[master (root-commit) 9a57094] start
 2 files changed, 6 insertions(+), 0 deletions(-)
 create mode 100644 conf/gitolite.conf
 create mode 100644 keydir/admin.pub
git@remote $ ls repositories/
gitolite-admin.git  testing.git

repositoryが出来上がってる。

gitolite-adminをclone

adminとしてgitolite-adminをcloneしてくる。同一サーバ内から持ってくるのでhost名はlocalhost指定で良い

sugyan@remote $ mkdir ~/temp
sugyan@remote $ cd ~/temp
sugyan@remote $ git clone git@localhost:gitolite-admin
Initialized empty Git repository in /home/sugyan/temp/gitolite-admin/.git/
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (6/6), done.
sugyan@remote $ ls
gitolite-admin

cloneできた。

ローカルからも使えるようにする

ローカル環境の公開鍵を持ってきて登録する。

sugyan@local $ scp $HOME/.ssh/id_dsa.pub vps:temp/gitolite-admin/keydir/sugyan-local.pub

再びsshvpsサーバに入ってgitolite-admin上で公開鍵をaddしてpush

sugyan@local $ ssh vps
sugyan@remote $ cd ~/temp/gitolite-admin
sugyan@remote $ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       keydir/sugyan-local.pub
nothing added to commit but untracked files present (use "git add" to track)
sugyan@remote $ git add keydir/sugyan-local.pub
sugyan@remote $ git commit -m 'add sugyan-local'
[master a193304] add sugyan-local
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 keydir/sugyan-local.pub
sugyan@remote $ git push
Counting objects: 6, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 842 bytes, done.
Total 4 (delta 0), reused 0 (delta 0)
remote: 
remote:                 ***** WARNING *****
remote:         the following users (pubkey files in parens) do not appear in the config file:
remote: sugyan-local(sugyan-local.pub)
To git@localhost:gitolite-admin
   9a57094..a193304  master -> master

confに何も書き足していないので警告は出るけど、まぁ今は問題無し。
ローカルから確認。gitolite-adminは権限ないからcloneできないけど、デフォルトでtestingは@allに対してRW+になっているのでcloneできるしpushもできる。

sugyan@local $ git clone git@vps:gitolite-admin
Cloning into gitolite-admin...
R access for gitolite-admin DENIED to sugyan-local
(Or there may be no repository at the given path. Did you spell it correctly?)
fatal: The remote end hung up unexpectedly
sugyan@local $ git clone git@vps:testing
Cloning into testing...
warning: You appear to have cloned an empty repository.
sugyan@local $ cd testing
sugyan@local $ echo hoge > hoge
sugyan@local $ git add hoge
sugyan@local $ git commit -m 'add hoge'
[master (root-commit) 3285627] add hoge
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 hoge
sugyan@local $ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 205 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@vps:testing
 * [new branch]      master -> master

大丈夫げ。

グループとリポジトリを作る

gitolite-adminにてconf/gitolite.confを編集。@sugyanというグループを作り、そこにsugyan-localを加える

sugyan@remote $ emacs conf/gitolite.conf
sugyan@remote $ git diff
diff --git a/conf/gitolite.conf b/conf/gitolite.conf
index 2d55bf8..202384a 100644
--- a/conf/gitolite.conf
+++ b/conf/gitolite.conf
@@ -1,5 +1,10 @@
+@sugyan = sugyan-local
+
 repo    gitolite-admin
         RW+     =   admin
 
 repo    testing
         RW+     =   @all
+
+repo    my-private
+        RW+     =   @sugyan
sugyan@remote $ git add conf/gitolite.conf
sugyan@remote $ git commit -m 'add new group and repository'
[master e3c35ed] add new group and repository
 1 files changed, 5 insertions(+), 0 deletions(-)
sugyan@remote $ git push
Counting objects: 7, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 409 bytes, done.
Total 4 (delta 0), reused 0 (delta 0)
remote: creating my-private...
remote: Initialized empty Git repository in /home/git/repositories/my-private.git/
To git@localhost:gitolite-admin
   a193304..e3c35ed  master -> master

my-privateレポジトリが新しく作成された。
ローカルから確認。

sugyan@local $ git clone git@vps:my-private
Cloning into my-private...
warning: You appear to have cloned an empty repository.
sugyan@local $ cd my-private
sugyan@local $ echo fuga > fuga
sugyan@local $ git add fuga
sugyan@local $ git commit -m 'add fuga'
[master (root-commit) 5955bdb] add fuga
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 fuga
sugyan@local $ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 207 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@vps:my-private
 * [new branch]      master -> master

testing同様に読み書きできた。
別のマシンからも使いたい場合は公開鍵を登録して@sugyanグループに追加してやれば良いし、他の人と共同で使うことになれば都度グループなり権限なりを追加していけば良い。

感想

最初なんだかよく分からずちょっと詰まったけど、一度設定できてしまえば結構ラクに管理できて良さそう。もっと細かい権限設定なども出来るらしい。必要になったら調べて設定してみよう

tiarra+stoneを卒業してZNCを使い始めた

IRC Bouncers(IRC Proxy)あれこれ - すぎゃーんメモIRC Bouncerを調べたりしつつも結局tiarra(+SSL接続のためにstone併用)でやっていたけど、ようやくZNCに以降できたっぽいのでメモを書き残しておく。

ZNCの特徴
  • yumなどのpackage managerで簡単にインストールできる
  • 設定ファイルを対話的に作成できる
  • Web管理画面を使った設定確認/変更も可能
  • 様々なプラグイン機構(あんまり試してないけど)
  • SSL接続可能
  • 複数ネットワークに接続するためには複数ユーザを作る必要がある

最後のがちょっとネックではあるけれど、逆にその方が自然な気もするしそれで良いのかも知れない。

ZNCのインストール
$ sudo yum install znc
ZNCの初期設定

znc --makeconfで対話的に設定を行うことができる。例:

$ znc --makeconf
[ ** ] Building new config
[ ** ]
[ ** ] First let's start with some global settings...
[ ** ]
[ ?? ] What port would you like ZNC to listen on? (1 to 65535): 16667
[ ?? ] Would you like ZNC to listen using SSL? (yes/no) [no]:
[ ?? ] Would you like ZNC to listen using ipv6? (yes/no) [yes]:
[ ?? ] Listen Host (Blank for all ips):
[ ok ] Verifying the listener...
[ ** ]
[ ** ] -- Global Modules --
[ ** ]
[ ** ] +-----------+----------------------------------------------------------+
[ ** ] | Name      | Description                                              |
[ ** ] +-----------+----------------------------------------------------------+
[ ** ] | partyline | Internal channels and queries for users connected to znc |
[ ** ] | webadmin  | Web based administration module                          |
[ ** ] +-----------+----------------------------------------------------------+
[ ** ] And 6 other (uncommon) modules. You can enable those later.
[ ** ]
[ ?? ] Load global module <partyline>? (yes/no) [no]:
[ ?? ] Load global module <webadmin>? (yes/no) [no]:
[ ** ]
[ ** ] Now we need to set up a user...
[ ** ] ZNC needs one user per IRC network.
[ ** ]
[ ?? ] Username (AlphaNumeric): sugyan
[ ?? ] Enter Password:
[ ?? ] Confirm Password:
[ ?? ] Would you like this user to be an admin? (yes/no) [yes]:
[ ?? ] Nick [sugyan]:
[ ?? ] Alt Nick [sugyan_]:
[ ?? ] Ident [sugyan]:
[ ?? ] Real Name [Got ZNC?]:
[ ?? ] Bind Host (optional):
[ ?? ] Number of lines to buffer per channel [50]:
[ ?? ] Would you like to keep buffers after replay? (yes/no) [no]:
[ ?? ] Default channel modes [+stn]:
[ ** ]
[ ** ] -- User Modules --
[ ** ]
[ ** ]
[ ** ] +-------------+------------------------------------------------------------------------------------------------------------+
[ ** ] | Name        | Description                                                                                                |
[ ** ] +-------------+------------------------------------------------------------------------------------------------------------+
[ ** ] | admin       | Dynamic configuration of users/settings through IRC. Allows editing only yourself if you're not ZNC admin. |
[ ** ] | chansaver   | Keep config up-to-date when user joins/parts                                                               |
[ ** ] | keepnick    | Keep trying for your primary nick                                                                          |
[ ** ] | kickrejoin  | Autorejoin on kick                                                                                         |
[ ** ] | nickserv    | Auths you with NickServ                                                                                    |
[ ** ] | perform     | Keeps a list of commands to be executed when ZNC connects to IRC.                                          |
[ ** ] | simple_away | Auto away when last client disconnects                                                                     |
[ ** ] +-------------+------------------------------------------------------------------------------------------------------------+
[ ** ] And 23 other (uncommon) modules. You can enable those later.
[ ** ]
[ ?? ] Load module <admin>? (yes/no) [no]:
[ ?? ] Load module <chansaver>? (yes/no) [no]:
[ ?? ] Load module <keepnick>? (yes/no) [no]:
[ ?? ] Load module <kickrejoin>? (yes/no) [no]:
[ ?? ] Load module <nickserv>? (yes/no) [no]:
[ ?? ] Load module <perform>? (yes/no) [no]:
[ ?? ] Load module <simple_away>? (yes/no) [no]:
[ ** ]
[ ** ] -- IRC Servers --
[ ** ] Only add servers from the same IRC network.
[ ** ] If a server from the list can't be reached, another server will be used.
[ ** ]
[ ?? ] IRC server (host only): irc.freenode.net
[ ?? ] [irc.freenode.net] Port (1 to 65535) [6667]:
[ ?? ] [irc.freenode.net] Password (probably empty):
[ ?? ] Does this server use SSL? (yes/no) [no]:
[ ** ]
[ ?? ] Would you like to add another server for this IRC network? (yes/no) [no]:
[ ** ]
[ ** ] -- Channels --
[ ** ]
[ ?? ] Would you like to add a channel for ZNC to automatically join? (yes/no) [yes]:
[ ?? ] Channel name: #sugyan
[ ?? ] Would you like to add another channel? (yes/no) [no]:
[ ** ]
[ ?? ] Would you like to set up another user (e.g. for connecting to another network)? (yes/no) [no]:
[ ok ] Writing config [./znc/configs/znc.conf]...
[ ** ]
[ ** ] To connect to this ZNC you need to connect to it as your IRC server
[ ** ] using the port that you supplied.  You have to supply your login info
[ ** ] as the IRC server password like this: user:pass.
[ ** ]
[ ** ] Try something like this in your IRC client...
[ ** ] /server <znc_server_ip> 16667 sugyan:<pass>
[ ** ] And this in your browser...
[ ** ] http://<znc_server_ip>:16667/
[ ** ]
[ ?? ] Launch ZNC now? (yes/no) [yes]: no

こんなカンジで質問に答えながら設定していくと、~/.znc/configs/znc.confに以下のようなファイルが作られる。

// WARNING
//
// Do NOT edit this file while ZNC is running!
// Use webadmin or *admin instead.
//
// Buf if you feel risky, you might want to read help on /znc saveconfig and /znc rehash.
// Also check http://en.znc.in/wiki/Configuration

Listener   = 16667

<User sugyan>
        Pass       = sha256#8c862ac8b97df7f45a1d29b9fdf24aa361a4b55ef0c4c473c63cb50b53713717#?EV5YKo5CJa8;ZhaGosH#
        Admin      = true
        Nick       = sugyan
        AltNick    = sugyan_
        Ident      = sugyan
        RealName   = Got ZNC?
        Buffer     = 50
        KeepBuffer = false
        ChanModes  = +stn


        Server     = irc.freenode.net 6667 

        <Chan #sugyan>
        </Chan>
</User>

あとはコレでzncコマンドで立ち上げれば"Listener"で指定したポートで待ち受けつつ指定したサーバに繋いでくれる。
普通にIRCクライアントからコマンド打って設定を変えても良いし、webadminモジュールを使って立ち上げると そのポートにhttpでアクセスすることで管理画面を開くことができ、そこで設定することも可能。
webadmin - ZNC

複数ネットワークに繋ぐ

irc.freenode.netにもirc.perl.orgにも繋ぎたい、みたいなとき。それぞれ別ユーザを作る必要がある。別名のユーザを作り、それぞれの接続先で別サーバを指定しておけば良い。IRCクライアント側で各ユーザとして接続する。
weechatの場合、同一host & 同一port でもserverをそれぞれ別名で登録しておくことで区別できるので、

/server add freenode 127.0.0.1/16667 -password=<username1>:<password1>
/server add perl 127.0.0.1/16667 -password=<username2>:<password2>
/connect freenode
/connect perl

のようなコマンドで(接続先host/portは同じでも)それぞれ別々のネットワークに接続することができる。

SSL接続

znc --makeconfで"Does this server use SSL?"で訊かれたときに"yes"と答えればそれだけで良いのだけど。SSL接続を使う場合はport番号に"+"が付くらしい。設定ファイルでは

        Server     = irc.****.**** +6667 password****

のような形になる。これだけでSSL接続できるっぽい。簡単。

その他

デフォルトでバックグラウンドでのデーモン起動してくれるけど、"-f"オプションでforeground起動してくれるので、一応"-f -D"とデバッグ出力付きでdaemontoolsを使って動かしてみてる。
結局接続先ネットワーク分けることになったためにmobircで繋げる先も1つに限られてしまった…複数ネットワークに対してmobircから繋ぐためには結局

znc <- tiarra <- mobirc

のように繋げるとかしないといけなくなってしまうのだろうか…?

特定のキーワードをim.kayac.comに通知するZNCモジュール書いた

IRCで自分の名前が呼ばれたときとかにiPhoneに通知してくれるようなやつ、いわゆるhilight2im的なもの。を、ZNCのモジュールとして作った。IRC Bouncer上で動かしておけば、weechatなどのクライアントからの接続が無い状態でも通知してくれるので便利。

使い方

NotifyImkayac.pm~/.znc/modules/以下に配置。clientからzncにコマンドを送って

/msg *status LoadMod NotifyImkayac username=sugyan keyword=sugyan,すぎゃーん

のように読み込ませるか、~/.znc/configs/znc.confなどの設定ファイル上で

<User hoge>
    ...
    LoadModule = NotifyImkayac username=sugyan keyword=sugyan,すぎゃーん
    ...
</User>

のように書いておいて読み込ませる。
引数で"username", "type", "password", "secret_key"などを指定することでim.kayac.comへの通知に使うパラメータを設定。"keyword"の指定はカンマ区切り、複数あればそれぞれマッチを試みて一つでもマッチすれば通知する。

ZNCのモジュールをPerlで使う

ドキュメントはこちら。 http://wiki.znc.in/Modperl
global moduleのmodeperlを使う必要がある。yumでzncを入れた場合にはznc-modperlを追加でインストールすれば使えるようになるはず。

ZNCのモジュールをPerlで書く
pakcage Hoge;
use base 'ZNC::Module';

sub description {
    "Example perl module for ZNC"
}

sub OnChanMsg {
    my $self = shift;
    my ($nick, $chan, $msg) = @_;
    ...
    return $ZNC::CONTINUE;
}

1;

のような形で書けるらしい。中身を詳しく知りたければソースのmodules/modperl/ZNC.pmmodules/modperl/startup.plなどを参照すれば大体わかると思う。C++用のAPIに揃えてあるようなのでそちらを見ると良い。

ちなみに通知モジュールとしてnotifoなどに通知できるC++モジュールは既に存在している。結構参考にした。

Perlモジュールの例はあまり探してない。

無駄にハマった話

yumでinstallした場合はsystem perlを使うことになるので別のモジュールに依存する場合はsystem perlにモジュールをインストールしていかないといけない。自分はそれがイヤだったのでperlbrewでインストールしたperlを使えるように、zncを自前でビルドすることにした。

$ mkdir ~/temp
$ cd ~/temp
$ wget http://znc.in/releases/znc-0.204.tar.gz
$ tar zxvf znc-0.204.tar.gz
$ cd znc-0.204
$ ./configure --prefix=$HOME/local --enable-perl
$ make

するとこける。

/usr/bin/ld: /home/sugyan/perl5/perlbrew/perls/perl-5.14.2/lib/5.14.2/x86_64-linux/CORE/libperl.a(op.o): relocation R_X86_64_32S against `PL_sv_yes' can not be used when making a shared object; recompile with -fPIC
/home/sugyan/perl5/perlbrew/perls/perl-5.14.2/lib/5.14.2/x86_64-linux/CORE/libperl.a: could not read symbols: Bad value

ググると色々出てくる。

mod_perlを使うために"-fPIC"オプションを追加してperlをビルドしなおす必要がありそう…

$ perlbrew install --as perl-5.14.2-fPIC -Accflags='-fPIC' perl-5.14.2

のような形で別のperlとしてビルド。。オプションの指定の仕方はよく分かっていない。
とりあえずコレを使うことでmod_perlも使えるzncをビルドできた。
素直にsystem perlにモジュール入れるとかlocal::libを上手く使うとかすれば良かったのかもしれない…。