SubminでSVNリポジトリを管理する


## はじめに
Subminを利用して、SVNリポジトリをブラウザから管理する方法を記述します。

## 環境

* CentOS 6.7
* subversion 1.6.11
* Submin 2.2.1-1
* httpd 2.2.15
* python 2.6.6


## 依存ライブラリ等のインストール

```shell
$ sudo yum install subversion httpd mod_dav_svn apr-util-sqlite
```

## Subminのインストール

```shell
$ wget http://supermind.nl/submin/current/submin-2.2.1-1.tar.gz
$ tar zxvf submin-2.2.1-1.tar.gz
$ cd submin-2.2.1-1
$ sudo python setup.py install --record install-files.txt
```

## Subminのセットアップ

```shell
$ sudo submin2-admin /var/lib/submin initenv your@email.address
Submin can enable features for you automatically. Please answer which features
you want to enable. You can choose to enable: 'svn', 'git', 'trac', 'apache'
and 'nginx'.

Which features do you want to enable? [svn, git, apache, nginx]> svn,apache

Please provide a location for the Subversion repositories. For new Subversion
repositories, the default setting is ok. If the path is not absolute, it will
be relative to the submin environment. If you want to use an existing
repository, please provide the full pathname to the Subversion parent
directory (ie. /var/lib/svn).

Path to the repository? [svn]> /var/lib/svn

Please provide a hostname that can be used to reach the web interface. This
hostname will be used in communication to the user (a link in email, links
in the web interface). The hostname should be a FQDN, so instead of 'foo' it
should be 'foo.example.com'. Please correct if the default is incorrect.

Hostname? [localhost.localdomain]> ${サーバのIPアドレス}

The HTTP path tells Submin where the website is located relative to the root.
This is needed for proper working of the website. Submin will be accesible
from <http base>/submin, Subversion will be accessible from <http base>/svn.
If you use Trac, it will be accessible from <http base>/trac.

HTTP base? [/]>

Submin will send emails for password resets and for commit message (if
enabled). You can set the sender email address that Submin will use. The
default might work in some places, but not all.

Email from envelope? [Submin <root@localhost.localdomain>]>
Apache files created:
/var/lib/submin/conf/apache-webui-cgi.conf
/var/lib/submin/conf/apache-webui-wsgi.conf
/var/lib/submin/conf/apache-svn.conf
/var/lib/submin/conf/apache-trac-modpython.conf
/var/lib/submin/conf/apache-trac-cgi.conf
/var/lib/submin/conf/apache-trac-modwsgi.conf
/var/lib/submin/conf/apache-trac-fcgid.conf
/var/lib/submin/conf/apache-trac-no-anonymous.conf
/var/lib/submin/conf/apache-2.4-webui-cgi.conf
/var/lib/submin/conf/apache-2.4-webui-wsgi.conf
/var/lib/submin/conf/apache-2.4-svn.conf
/var/lib/submin/conf/apache-2.4-trac-modpython.conf
/var/lib/submin/conf/apache-2.4-trac-cgi.conf
/var/lib/submin/conf/apache-2.4-trac-modwsgi.conf
/var/lib/submin/conf/apache-2.4-trac-fcgid.conf
/var/lib/submin/conf/apache-2.4-trac-no-anonymous.conf

   Please include ONE of the -webui- files and optionally -trac- and -svn-
   files (if you need/want that functionality). The -trac-no-anonymous.conf
   file can be used together with ONE other trac config file. The -2.4- files
   are for apache >= 2.4.

   Hint: cgi is simpler, but performs worse.

   Please read the instructions in the file for caveats and on how to include!
```

## Apacheの設定

* /etc/httpd/conf.d/z000-httpd-submin.confの作成


```conf:/etc/httpd/conf.d/z000-httpd-submin.conf
LoadModule authn_dbd_module modules/mod_authn_dbd.so
LoadModule dbd_module modules/mod_dbd.so
```

* Submin用設定の追加

```shell
$ sudo ln -s /var/lib/submin/conf/apache-webui-cgi.conf /etc/httpd/conf.d/z001-httpd-submin.conf
$ sudo ln -s /var/lib/submin/conf/apache-svn.conf /etc/httpd/conf.d/z002-httpd-submin.conf
$ ls -l /etc/httpd/conf.d/
合計 16
-rw-r--r-- 1 root root  392  8月 25 02:53 2015 README
-rw-r--r-- 1 root root 1042  8月 17 17:41 2015 subversion.conf
-rw-r--r-- 1 root root  299  8月 18 14:57 2015 welcome.conf
-rw-r--r-- 1 root root   94  9月 26 15:13 2015 z000-httpd-submin.conf
lrwxrwxrwx 1 root root   42  9月 26 15:14 2015 z001-httpd-submin.conf -> /var/lib/submin/conf/apache-webui-cgi.conf
lrwxrwxrwx 1 root root   36  9月 26 15:14 2015 z002-httpd-submin.conf -> /var/lib/submin/conf/apache-svn.conf
```

* 起動

```shell
$ sudo service httpd start
```

## adminユーザの初期パスワード設定

* パスワードリセット用のキーの確認

```shell
$ sudo sqlite3 /var/lib/submin/conf/submin.db
SQLite version 3.6.20
Enter ".help" for instructions
Enter SQL statements terminated with a ";"

sqlite> .tables
group_members   managers        password_reset  ssh_keys
groups          notifications   permissions     users
hook_jobs       options         sessions

sqlite> .schema password_reset
CREATE TABLE password_reset (
			userid  integer not null references user(id) primary key, -- valid for this user
			expires integer not null, -- this entry expires at Unix Time
			key     text not null -- random secret
		);


sqlite> select * from password_reset;
1|1443333976|iJhl80FE80AYnOmNJE2qXxtqAPqx0B8B7XGqKbLj2PvSG3T3bV
```

* ブラウザでアクセス

```URL
http://${サーバIPアドレス}/submin/admin/password/iJhl80FE80AYnOmNJE2qXxtqAPqx0B8B7XGqKbLj2PvSG3T3bV
```

![Submin-reset-password.png](https://qiita-image-store.s3.amazonaws.com/0/52459/b9b496ed-070c-ea36-401d-7d64fd5aec3e.png "Submin-reset-password.png")

![Submin-top-page.png](https://qiita-image-store.s3.amazonaws.com/0/52459/6073b4d3-6baa-4710-7a3b-50ab21f312b1.png "Submin-top-page.png")

![Submin-diagnostics.png](https://qiita-image-store.s3.amazonaws.com/0/52459/17f8306b-f7a1-1218-83df-6938b7af7286.png "Submin-diagnostics.png")

* Git supportを無効

```shell
$ sudo submin2-admin /var/lib/submin config set vcs_plugins svn
```

![Submin-diagnostics02.png](https://qiita-image-store.s3.amazonaws.com/0/52459/3c128e40-e99d-29ce-10da-93d9945301a0.png "Submin-diagnostics02.png")

* パスワード設定

![Submin-admin.png](https://qiita-image-store.s3.amazonaws.com/0/52459/af07d3fa-95b1-416e-08e3-4a8d0a7d1498.png "Submin-admin.png")

## リポジトリ作成

* パーミッションの設定

```shell
$ ls -ld /var/lib/svn
drwx------ 2 root root 4096  9月 26 15:06 2015 /var/lib/svn

$ sudo chown apache:apache /var/lib/svn
$ sudo chmod 775 /var/lib/svn

$ ls -ld /var/lib/svn
drwxrwxr-x 2 apache apache 4096  9月 26 15:06 2015 /var/lib/svn
```

![Submin-add-repository.png](https://qiita-image-store.s3.amazonaws.com/0/52459/b34fc3ed-6b2c-356a-9794-764179923e46.png "Submin-add-repository.png")

![Submin-add-repository-02.png](https://qiita-image-store.s3.amazonaws.com/0/52459/6397e705-e726-fa5f-393f-a25458f1080f.png "Submin-add-repository-02.png")

## リポジトリの操作

* リポジトリのチェックアウト

```shell
$ svn checkout http://${サーバIPアドレス}/svn/sample --username=admin
認証領域: <http://${サーバIPアドレス}:80> Subversion repository
'admin' のパスワード:

-----------------------------------------------------------------------
ATTENTION!  Your password for authentication realm:

   <http://${サーバIPアドレス}:80> Subversion repository

can only be stored to disk unencrypted!  You are advised to configure
your system so that Subversion can store passwords encrypted, if
possible.  See the documentation for details.

You can avoid future appearances of this warning by setting the value
of the 'store-plaintext-passwords' option to either 'yes' or 'no' in
'/home/vagrant/.subversion/servers'.
-----------------------------------------------------------------------
暗号化されていないパスワードを保存しますか (yes/no)? yes

-----------------------------------------------------------------------
ATTENTION!  Your password for authentication realm:

   <http://${サーバIPアドレス}:80> Subversion repository

can only be stored to disk unencrypted!  You are advised to configure
your system so that Subversion can store passwords encrypted, if
possible.  See the documentation for details.

You can avoid future appearances of this warning by setting the value
of the 'store-plaintext-passwords' option to either 'yes' or 'no' in
'/home/vagrant/.subversion/servers'.
-----------------------------------------------------------------------
暗号化されていないパスワードを保存しますか (yes/no)? yes
リビジョン 0 をチェックアウトしました。
```

* リポジトリへ追加

```shell
$ cd sample
$ mkdir trunk branches tags
$ svn status
?       trunk
?       branches
?       tags

$ svn add *
A         branches
A         tags
A         trunk

$ svn commit -m 'initial commit.'
追加しています              branches
追加しています              tags
追加しています              trunk

リビジョン 1 をコミットしました。

$ svn list http://${サーバIPアドレス}/svn/sample
branches/
tags/
trunk/
```

* ブラウザでリポジトリを参照

```URL
http://${サーバIPアドレス}/svn/sample/
```

![Submin-repository-sample.png](https://qiita-image-store.s3.amazonaws.com/0/52459/d9aa59f9-ae4f-75ee-95a6-3bb523e773e9.png "Submin-repository-sample.png")


## 参考
* [SVN/git web administration](https://supermind.nl/submin/)