hostMonster配置svn

Add a comment November 9th, 2010

过去写的代码很少,当然现在也很少;这些天发现自己真可以称得上是游击队队员,在这放一泼代码然后走人,再去那放一泼走人,最后到处是代码,不知道什么玩意是什么玩意,所以有了把代码都导入到svn server上,很多人都用code.google来管理project,我知道;不过我总有一个潜意识告诉自己:不要钱的东西是不可靠的。所以打算自己弄一下,要不空间就浪费了。
无论是baidu还是google都可以找到一些资料,告诉你怎样在hostMonster上配置svn;就我切身体会,这些帖子的方法应该都能解决问题,我也是尝试了好几次才勉强算是成功了,说勉强是因为我还有一些问题没解决,这是后话。按照我最后参考的帖子的方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
mkdir src
cd src
wget http://archive.apache.org/dist/apr/apr-1.4.2.tar.bz2
wget http://archive.apache.org/dist/apr/apr-util-1.3.9.tar.gz
wget http://subversion.tigris.org/downloads/subversion-1.6.9.tar.gz
wget http://www.webdav.org/neon/neon-0.29.3.tar.gz
wget http://www.sqlite.org/sqlite-amalgamation-3.6.22.tar.gz
 
tar -xzf apr-util-1.3.9.tar.gz
tar -xzf apr-1.4.2.tar.gz
tar -xzf subversion-1.6.9.tar.gz
tar -xzf neon-0.29.3.tar.gz
tar -xzvf sqlite-amalgamation-3.6.22.tar.gz 
 
cd apr-1.4.2
./configure --prefix=$HOME LDFLAGS="-L/lib64"
make
make install
 
cd ../apr-util-1.3.9
./configure --prefix=$HOME --with-apr=$HOME LDFLAGS="-L/lib64"
make
make install
 
cd ../neon-0.29.3
./configure --enable-shared --prefix=$HOME LDFLAGS="-L/lib64"
make
make install
 
cd ../sqlite-3.6.22/
mkdir ~/src/subversion-1.6.9/sqlite-amalgamation
cp sqlite3.c ~/src/subversion-1.6.9/sqlite-amalgamation/
 
cd ../subversion-1.6.9
./configure --with-apr=$HOME --prefix=$HOME --without-berkeley-db --with-zlib=/usr --with-ssl LDFLAGS="-L/lib64"
make
make install

执行如上脚本即可安装svn,如果不出意外应该和我一样最后遇到个什么权限导致的错误,无视之,反正我的权限就这么点,不可能得到root权限。接着,创建一个目录svnroot作为版本库的根目录,然后再在svnroot/下创建个版本库:

svn create code_xiaoe

貌似这样就完事了,当然实践连接一下的话(通过ssh连接):

svn list svn+ssh://sshUser@yourHost/code_xiaoe

如果不出意外应该和我一样遇到:

bash: svnserve: command not found

显然是没找到svnserve在哪,普遍想法就是去.bashrc文件下,把svnserve的位置加入到PATH,当然我曾经也是这么干的,问题没有解决。根据我找到的帖子等,比较正确的说法是:

因为svn调用ssh后得到是非登陆shell。

还有个老外说:
.bash_profile is only loaded if you actually have a “login” session.
.bashrc is always loaded for your user
但是实际情况是.bashrc不好使,不排除我用的不对,对bash了解有限。
最终,解决方法如下:
用ssh-keygen生成一对公钥(user.public)和密钥(user.private),把user.public弄到hostMonster自己$HOME目录下,然后用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# this script assists in adding an svn user to a hostmonster account.
# they have to authenticate each with their own ssh key than only allows ssh access for their
# svn username as we're only allowed one ssh login for root
# and this prevents people give svn accounts having root access to the hostmonster account!
# written by Jon Booth see www.sharpstep.com/Articles/HostMonster-svn
 
# check for an argument - the username to add
if [ "$1" == "" ]; then
	echo Usage $0 [username] [public key file]
	exit
fi
 
#check for the second argument - the public key file.
if [ "$2" == "" ]; then
	echo Usage $0 [username] [public key file]
	exit
fi
 
if [ -f "$2" ]; then
	echo public keyfile "$2" found
else
	echo unable to find public key "$2"
	echo Usage $0 [username] [public key file]
	exit
fi
 
# check to see if the given username already exists in the keys (only works if added with this script).
if [ -f  ~/.ssh/authorized_keys ]; then
	if [ "$(cat ~/.ssh/authorized_keys | grep svnrepos | grep \\-\\-tunnel-user=$1\\\" | egrep $1\$)" != "" ]; then
		echo it appears svn user \"$1\" already exists
		exit
	fi
else
	echo no authorized keys file found... skipping existing check
fi
# check that svnserve is properly in the path
if [ "$(which svnserve)" == "" ]; then
	echo
	echo Can\'t continue as svnserve doesn\'t appear to be installed on the path.
	echo it\'s part of the svn package
	exit
fi
 
echo Creating svn user $1
# create the keys
# this is no good as putty on windows won't use them - also it's safer for the users to provide the key files so now
# I'm checking them as the second argument.
#ssh-keygen -q -t rsa -f $1_key -N "" -C "svn user $1"
# append the user line to the authorised keys
echo command=\"$(which svnserve) -t -r ~/svnrepos --tunnel-user=$1\",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty $(cat "$2") svn user $1 >> ~/.ssh/authorized_keys
# remove the public key now it's in the authorized_keys file
rm $2
echo user $1 now added and authenticated

此脚本create_svn_user.sh,运行 sh create_svn_user.sh user.public user.public,把用户公钥等信息加入$HOME/.ssh/authorized_keys文件里;然后authorized_keys文件中:

command="/home2/liulinli/bin/bin/svnserve -t -r /home2/liulinli/svnroot

-t之前是svnserve的位置,-r后边是版本库的根目录,这里根据自己情况相应修改即可。
本地机器上也有相应的修改,这里以*nix为例(winXP系统我没有测试通过,这就是我为什么说勉强成功。。。在写完这篇文档后,又修改了下居然成功了。。),修改~/.subversion/config,在文件中[tunnels]之后加入一行:ssh=ssh -i /home/rt77789/.ssh/user.private -q
/home/rt77789/.ssh/user.private就是刚生成的私钥,就是说导入私钥。然后,测试:

svn list svn+ssh://sshUser@yourHost/code_xiaoe

这次没有bash: svnserve: command not found出现,svn + ssh成功。
另外,还有一个问题就是密钥公钥的问题,开始在winXP下用PuTTyGen生成一对,但是在ubuntu下死活不好使,最后用ssh-keygen才好使;可能,svn不能识别puttyGen生成的private key吧。有这一出后,我想难道winXP下tortoiseSVN可能也是密钥之类的问题呗,然后用putty读入ssh-keygen生成的密钥,保存一下不就是putty的格式了么,然后修改tortoiseSVN配置文件[tunnels]后边加了句话:

ssh = "D:/Program Files/TortoiseSVN/bin/TortoisePlink.exe" -i "d:/xiaoe.org/xiaoe.org.private.key.nix.ppk" -q

结果这样不work啊。。。xiaoe.org.private.key.nix.ppk是puttyGen导出的由ubuntu生成的密钥。
接着,我在setting->network->ssh client直接写

"D:\Program Files\TortoiseSVN\bin\TortoisePlink.exe" -i "D:\xiaoe.org\xiaoe.org.private.key.nix.ppk"

这样就好使了。。。
配置这个东西耗了一天多,别人有的几乎没有问题就搞定了,由此证明技术上的差距是很大的;有时间再看看tortoise怎么才好使吧,累得我屁颠屁颠的。
参考文献:

http://cache.baidu.com/c?m=9f65cb4a8c8507ed4fece7631043803b5c0ecb743ca08d552ac9d11bc6334640426cf4ba535e0705a5b368225cef1f53baa37728200250a09abb9f4aacfad6746edf6770270b873105d26ab8cb37749c7fcf09b5f90ee7cbac6fd5b9d2a28b09149605&p=87769a46d2840bff57ed9529427acd&user=baidu

http://sharpstep.com/Articles/HostMonster-svn/
http://hostmonsterforum.com/showthread.php?1294-Subversion

http://archive.apache.org/dist/apr/

http://bbs.idcspy.com/thread-94575-1-1.html

4 Comments

  • At 2010.11.16 13:16, liulinlin said:

    不错啊,能在hostmonster上配置svn server的话,就有自己的svn server了。原来hostmonster还能用来干这个啊,呵呵。

    [回复]

    xiaoe 回复:

    毛弟,我有时间给你再给你生成个pair啊,建好了发你邮箱;这两天跑程序该程序弄的焦头烂额。。:(

    [回复]

    • At 2010.11.16 15:46, xiaoe said:

      @: ssh貌似除了点问题。。。

      [回复]

      • At 2010.12.04 15:38, cheap jordans said:

        wow! it’s amazing blog and it’s very help full for our knowledge

        [回复]

        (Required)
        (Required, will not be published)

        *
        To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
        Click to hear an audio file of the anti-spam word