Mercurialをcoreserver上で稼働させる必要が出てきて
人やwebに教えてもらいながら実施。
事前の確認
===========
手元のクライアントに Mercurial がインストールされていること
サーバで CGI が動くこと(サーバ仕様を確認する)
サーバでシェルが使える(ssh でログインできる)こと
サーバで Python 2.3 以降が使えること (python -V で確認) <<Vは大文字で
サーバで C コンパイラが使えること (which gcc で確認) << ほんとに必要かな?
Coreserverでは、CGIも使えるし、ssh,PythonもOK、gccもOK
まずインストール
==============
http://mercurial.selenic.com/release/
からダウンロード
サーバ側で
$mkdir tools
$cd tools
ここで最新バージョンをhttp://mercurial.selenic.com/release/ で確認後
ftpでクライアント経由でコピーした (^_^;)
$tar -xvzf mercurial-1.3.tar.gz
$cd mercurial-1.3
$python setup.py install --home=$HOME/local --force
これでインストール完了。簡単です。butここからが結構手間です。
ちょっと確認してみましょう。
------
$ export PYTHONPATH=$HOME/local/lib/python
$ export PATH=$PATH:$HOME/local/bin
$ hg debuginstall
Checking encoding (UTF-8)...
Checking extensions...
Checking templates...
Checking patch...
Checking commit editor...
Checking username...
No username found, using 'me@sxyz.coreserver.jp' instead
(specify a username in your .hgrc file)
No problems detected
$
------
なんかできているようです。
確認のためのデモジトリ作成
====================
クライアント側で、デモレポジトリを作成しておく方法がwebには出ていたけど
サーバ側で作成するので簡単にできるみたい。
サーバ側:
$cd ~/hg/repos
(デポジトリ置き場のディレクトリを作成し、そこに移動する)
$mkdir test
$cd test
$hg init
$vi ./.hg/hgrc でhgrcに以下の内容を記載:
################
[web]
push_ssl = false
allow_push = *
################
※ これを忘れるとwindowsからpushするときにエラーになってしまいます。
Mervurialは基本的に sslを使うことになっている模様。
参考(http://d.hatena.ne.jp/torutk/20070914/p1)
サーバ側(クライアントから実行の場合は実行ユーザ注意)でcloneを実行してみる
$ hg -v clone ssh://scm.xyz.com//virtual/xxx/hg/repos/test
running ssh scm.xyz.com "hg -R /virtual/xxx/hg/repos/test serve --stdio"
The authenticity of host 'scm.xyz.com (xx.xx.xx.xx)' can't be established.
RSA key fingerprint is ・・・・・・
Are you sure you want to continue connecting (yes/no)? yes
me@scm.xyz.com's password:
destination directory: test
no changes found
updating working directory
resolving manifests
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
remote: Warning: Permanently added 'scm.xyz.com,xx.xx.xx.xx' (RSA) to
the list of known hosts.
$
よろしいらしい
web経由のアクセス設定
==================
インストールのときにmercurialのインストールモジュールを解凍したところにある
hgweb.cgi とhgwebdir.cgi というファイルが、webアクセスのときに使うcgiファイルらしい。
hgweb.cgiはひとつのレポジトリにアクセスするためのcgi
hgwebdir.cgiは、設定ファイルに記述されたグループをアクセスできるようにするcgi
今回は、複数のレポジトリ管理を考えてhgwebdir.cgi にて設定
hgwebdir.cgiをアクセスルートにコピーする
$cp ./hgwebdir.cgi ~/publuc_html/scm.xyz.com
hgwebdir.cgiの以下を変更
★以下のパスを変更してコメントアウト
(インストールするとローカルディレクトリ配下のlocal/lib/python にライブラリが入る)
################
#import sys
#sys.path.insert(0, "/path/to/python/lib")
↓
import sys
sys.path.insert(0, "/virtual/xxx/local/lib/python")
################
★こちらはコメントアウト
(あとでやろうと思って忘れて失敗。日本語を使いたいときには
ここで忘れずにやりましょう)
################
#import os
#os.environ["HGENCODING"] = "UTF-8"
↓
import os
os.environ["HGENCODING"] = "UTF-8"
################
次にhgweb.config と言うファイルを作成
$vi gweb.config
で以下を記載
################
[collections]
/virtual/xxx/hg/repos/ = /virtual/xxx/hg/repos/
################
ここでwebアクセスのテストであくせすしてみる
こんな感じ http://scm.xyz.com/hgwebdir.cgi/test
おおっ!読めました。
ちなみに、レポジトリを多数作らない場合は
hgweb.cgiを以下の変更でOK
まず日本語を使えるようにして
################
#import os
#os.environ["HGENCODING"] = "UTF-8"
↓
import os
os.environ["HGENCODING"] = "UTF-8"
################
あとはレポジトリの場所の指定を書き換えてやる
################
application = hgweb("/path/to/repo", "repository name")
↓
application = hgweb("/virtual/xxx/hg/repos/test", "test")
################
これで、hgwebdir.cgiをindex.cgiに変更しておくとアクセスしやすい
次はセキュリティ設定
ベーシック認証を設定
==================
まず、セキュリティアップのためのベーシック認証を .htaccess に設定
################
AuthUserFile /virtual/xxx/.htpasswd
AuthGroupFile /dev/null
AuthName MembersOnly
AuthType Basic
<Limit GET POST PUT>
require valid-user
</Limit>
################
.htpasswd というパスワードファイルを作って/virtual/xxx/に入れておく
(細かいことは省略、ベーシック認証の設定をご参考に)
ということで、ここからは使い勝手向上のためにURLをきれいに
(もちろんこれは、hgwebdir.cgiを使う場合の設定)
URLアクセス調整
===============
アクセスするURLを http://scm.xyz.com/test という形式にしたいので
.htaccessに以下を設定
################
RewriteEngine On
RewriteRule ^$ hgwebdir.cgi [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) hgwebdir.cgi/$1 [QSA,L]
################
hgwebdir.cgi に以下を設定(なるべく初めの方に記載するのが良いらしい)
################
import os
os.environ['SCRIPT_NAME'] = ''
################
※ import os は一回やれば良いと思うので、文字コードの設定と並べて
初めの方に持ってくればきれいかも。
参考(http://8-p.info/mercurial-dreamhost.html
http://www.selenic.com/pipermail/mercurial/2008-March/017455.html
http://d.hatena.ne.jp/a666666/20080812 )
さてさて、これでアクセスもしやすくなりました。
これでクライアントからの、hgコマンドやTortoiseHgから利用可能。
あとは、レポジトリ毎のユーザ管理とかバックアップの設定でしょうか。
以下のサイト、参考にさせていただきました。 (ありがとうございました)
http://www.dodgson.org/omo/t/?date=20070519
http://8-p.info/mercurial-dreamhost.html
http://www.horaguchi.net/search.php?q=mercurial
http://w.nikori.tk/index.php?xrea/mercurial
http://mercurial.selenic.com/wiki/HgWebDirStepByStep
http://d.hatena.ne.jp/torutk/20070914/p1
http://www.selenic.com/pipermail/mercurial/2008-March/017455.html
http://d.hatena.ne.jp/a666666/20080812