锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
浣滆咃細Dru Lavigne, author of BSD Hacks
緲昏瘧錛?A href="mailto:di_feng_ro@hotmail.com">di_feng_ro@hotmail.com
鏈榪戜竴涓鎴瘋仒璇蜂簡涓涓綉緇滃紑鍙戝洟闃熸潵甯姪浠栫殑宸ヤ綔榪囧害鐨勭綉綆°備粬浠姹傛垜瀹夎涓涓増鏈帶鍒剁郴緇燂紝榪欎釜緋葷粺鑳藉淇濊瘉鍥㈤槦涓殑浠諱綍鎴愬憳閬垮厤鏃犳剰涓慨鏀瑰埆浜虹殑鏂囦歡錛屽茍涓旇兘澶熺粰浜堢鐞嗗憳鎭㈠鏂囦歡鍒頒換浣曠増鏈殑鏈哄埗銆?/P>
鎴戠殑絎竴涓兂娉曞氨鏄疭ubversion銆傚洜涓哄畠鏄垜鍐?U>BSD Hacks 鏃跺拰緙栬緫鍣ㄤ竴璧風敤鐨勭増鏈帶鍒剁郴緇熴傚湪Ports Collection涓悳绱竴涓嬩箣鍚庡彂鐜幫紝Subversion闇瑕佸ソ鍑犱釜鐩稿叧鐨刾ort銆傛瘮濡傦紝esvn鐪嬭搗鏉ョ浉褰撻傚悎瀹㈡埛绔紝鍥犱負瀹冪殑GUI緇堢鑳藉榪愯鍦║nix,Mac OS X浠ュ強Windows涓傚浜庝竴涓Unix鎶鏈帉鎻′笉娣辯殑緗戠粶寮鍙戝洟闃熻岃█錛屽綋浠栦滑闇瑕佹妸鏁版嵁瀛樿串鍦‵reeBSD鏈嶅姟鍣ㄤ笂鑰屼粠闈濬reeBSD緋葷粺璇誨彇鏃訛紝esvn鏄潪甯稿ソ鐨勯夋嫨銆?/P>
鍓嶆湡鍑嗗
鍦ㄦ垜鐨勬兂娉曚腑錛屽彧鍏佽寮鍙戝洟闃熺殑鎴愬憳鍏鋒湁鏉冮檺璁塊棶浠撳簱鏄潪甯擱噸瑕佺殑銆傚悓鏃訛紝鎴戜滑鎶婁粨搴撴斁鍦ㄥ拰鐩墠鐨剋eb鏈嶅姟鍣ㄥ垎寮鐨勬搷浣滅郴緇熶笂錛屽綋web綆$悊鍛樼湅鍒伴傚悎鐨勬枃浠舵椂錛岀敱浠栬礋璐f妸鏂囦歡浠庝粨搴撳鍒跺埌web鏈嶅姟鍣ㄤ笂銆?/P>
涓轟簡瀹炵幇榪欎釜鐩殑錛屽厛瀵瑰凡瀛樺湪鐨勪綘鎯蟲斁鍒扮増鏈帶鍒剁郴緇熶笅鐨勭洰褰曠粨鏋勫仛涓涓浠斤紝鐒跺悗鎶婂畠瀹夊叏鍙戦佸埌浠撳簱鏈嶅姟鍣ㄣ傚湪鎴戠殑渚嬪瓙涓紝鎴戞妸web鏈嶅姟鍣ㄤ笂www鐩綍鐨勬暟鎹浠藉埌涓鍙板唴緗戞湇鍔″櫒 192.168.2.2涓娿?/P>
# tar czvf - /usr/local/etc/www/data | ssh dru@192.168.2.2 "cat > www.tar.gz"
涓嬩竴姝ユ槸鍦ㄤ粨搴撴湇鍔″櫒涓婂緩绔嬩竴涓猻vn緇勶紝騫舵妸宸插瓨鍦ㄧ殑闇瑕佽闂粨搴撶殑鐢ㄦ埛鍔犲埌榪欎釜緇勪腑銆傛瘮濡傦紝褰撴垜鍒涘緩svn緇勫悗錛屾垜鍦?etc/group鍔犲叆榪欏彞璇濇妸宸插瓨鍦ㄧ殑web綆$悊鍛樼敤鎴峰姞榪涘幓錛?/P>
# vi /etc/group
svn:*:3690:webadmin
鐒跺悗錛屾柊寤轟竴涓敤鎴穝vn銆傚鏋滄湁蹇呰錛屼綘榪橀渶鍒涘緩鎵鏈夎璁塊棶浠撳簱緋葷粺鐨勭敤鎴峰笎鍙?濡傛灉浠栦滑榪樻病鏈夊垱寤猴級銆傝淇濊瘉姣忎釜鐢ㄦ埛鏄痵vn鐨勬垚鍛樺茍涓旀湁瀵嗙爜鍜屽彲鐢ㄧ殑shell銆傛垜浣跨敤sysinstall涓烘柊鐨勭綉緇滃伐紼嬪笀寤虹珛鐢ㄦ埛甯愬彿銆傚畬鎴愪互鍚庯紝鎴戝弻鍑籹vn緇勭殑鎴愬憳銆傚ぇ姒傚氨璞¤繖鏍鳳細
# grep svn /etc/group
svn:*:3690:webadmin,devel1,devel2
澶勭悊 umask
鍦ㄥ畨瑁匰ubversion涔嬪墠錛屾垜浠厛鐪嬬湅svn鐢ㄦ埛鐨剈mask銆傚湪鎴戠殑FreeBSD緋葷粺涓婏紝瀹冩槸榪欐牱鐨勶細
# su -l svn
% umask
022
鍦║NIX涓紝鐢ㄦ埛umask鍊煎喅瀹氫簡鏂板緩鐩綍鎴栨枃浠剁殑榛樿鏉冮檺銆傝繖鏄氳繃鍏抽棴鏌愪簺鏉冮檺杈懼埌鐨勩傚鏋滀綘璁板緱錛?/P>
r = 4
w = 2
x = 1
浣犲簲璇ョ湅寰楀嚭榪欎釜umask娌℃湁瀵圭敤鎴?svn)鍏抽棴浠諱綍鏉冮檺(0);瀹冨緇?svn)鍏抽棴浜嗗啓鏉冮檺(2);瀹冨鍏朵粬緇勭敤鎴峰叧闂簡鍐欐潈闄?2)銆?/P>
鍥犱負svn緇勭殑鎴愬憳蹇呴』鑳藉鍐欏叆浠撳簱錛屾墍浠ユ妸umask涓叧浜庣粍鐨?2 鏀逛負 0銆傜敋鑷沖鏋滀綘涓嶆兂璁╁叾浠栫粍鎴愬憳鐭ラ亾榪欎釜浠撳簱鐨勫瓨鍦紝浣犲彲浠ユ妸鍏充簬鍏朵粬緇勬垚鍛樼殑 2 鏀逛負 7銆?/P>
淇敼鐢ㄦ埛svn鐨剆hell閰嶇疆姣旇緝綆鍗曘傚鏋滅敤鎴蜂嬌鐢?csh:
% vi ~svn/.cshrc
錛岄偅涔堟壘鍒皍mask閭h騫舵妸瀹冩敼涓?002 鎴?007銆傚鏋滀綘鐨剆vn鐢ㄦ埛涓嶇敤csh錛屼慨鏀逛綘鐨剆hell閰嶇疆鏂囦歡銆傚鏋滀綘鎶婁綘鐨勪慨鏀逛繚瀛樺湪 ~svn/.cshrc (鎴栧埆鐨勫湴鏂?,鍒繕浜嗗憡璇塻hell:
% source ~svn/.cshrc
鍐嶆暡涓嬈?umask 鍛戒護錛屼互淇濊瘉浣犵殑淇敼鏈夋晥銆?/P>
瀹夎Subversion 錛屽茍璁╁畠鎷ユ湁姝g‘鐨剈mask
濡傛灉浣犻夋嫨涓涓?02鐨剈mask,閭d箞褰撲綘浠巔orts collection鐢熸垚Subversion鐨勬椂鍊欙紝浣犺兘鎶婁竴涓獁rapper緙栬瘧榪涘幓銆傚鏋滀綘閫夋嫨涓涓?07鐨剈mask鎴栧畨瑁呭凡棰勭紪璇戝ソ鐨凷ubversion錛岄偅灝辮鍒涘緩涓涓獁rapper鑴氭湰鏉ヤ繚璇佷綘鐨凷ubversion浜岃繘鍒舵枃浠朵嬌鐢ㄤ綘鐨剈mask鍊箋?/P>
浣跨敤wrapper緙栬瘧錛屼嬌鍏秛mask鍊間負002錛?/P>
# cd /usr/ports/devel/subversion
# make -DWITH_SVNSERVE_WRAPPER install clean
鎴栬咃紝浣犲彲浠ュ畨瑁呭凡棰勭紪璇戠殑浜岃繘鍒朵唬鐮佸寘
# pkg_add -r subversion
娉ㄦ剰錛氭棤璁轟嬌鐢ㄤ綍縐嶆柟娉曪紝瀹夎涔嬪墠閮藉簲璇ユ妸榪欑瘒鏂囩珷鐪嬪畬錛佸洜涓轟綘鍙互鍙戠幇涓浜涢澶栫殑璁╀綘鎰熷叴瓚g殑緙栬瘧閫夐」錛?/P>
濡傛灉浣犱笉鍦╳rapper涓紪璇戯紝璇風Щ鍔ㄤ綘鐨勪唬鐮佸埌鐩稿簲鐨勪綅緗紝騫跺垱寤轟綘鑷繁鐨剋rapper鑴氭湰錛?/P>
# mv /usr/local/bin/svn /usr/local/bin/svn.orig
# vi /usr/local/bin/svn
#!/bin/sh
#wrapper script to set umask to 007 on subversion binaries
umask 007
/usr/local/bin/svn.orig "$@"
璁劇疆浣犵殑umask鍊間負002鎴?07錛屼嬌瀹冨拰syn鐢ㄦ埛鐨剈mask鍊間竴鏍楓傚埆蹇樹簡璁劇疆浣犵殑wrapper鑴氭湰涓哄彲鎵ц鐨勶細
# chmod +x /usr/local/bin/svn
鍒涘緩浠撳簱
鏃㈢劧鐜鎼ソ浜嗭紝閭d綘灝卞彲浠ュ垱寤轟粨搴撲簡銆傜敤svn鐢ㄦ埛鐧誨綍浠ヤ繚璇乻vn鐢ㄦ埛鍜宻vn緇勬嫢鏈変綘鍦ㄤ粨搴撲腑鍒涘緩鐨勬枃浠躲傚湪 /usr/home/svn/鐩綍涓?閿叆錛?/P>
% svnadmin create repository
鍦ㄨ繖涓緥瀛愪腑錛屾垜鐨勪粨搴撳悕涓簉epository銆備綘鍙互閫夋嫨浠諱綍瀵逛綘鏈夊府鍔╃殑鍚嶅瓧銆俿vnadmin create 浠呬粎鍒涘緩浜哠ubversion宸ュ叿鎵闇瑕佺殑鐩綍緇撴瀯銆?/P>
% ls -F repository
README.txt dav/ format locks/
conf/ db/ hooks/
娉ㄦ剰鐩綍db鏄粯璁ょ敓鎴愮殑銆傚洜涓篠ubversion浣跨敤鏁版嵁搴撹窡韙粨搴撲腑鏂囦歡鐨勫彉鍖栵紝鎵浠ヤ綘蹇呴』鎶婁綘鐨勬暟鎹斁鍒版暟鎹簱涓傜劧鍚庯紝鎴戞妸澶囦喚鏂囦歡瑙e帇緙╋紝榪欐牱灝辨湁鐨勪竴浜涘彲浠ユ斁榪涘幓鐨勬暟鎹備絾鏄娉ㄦ剰榪欎箞鍋氱殑鏃跺欙紝涓嶈鎶婂浠芥枃浠剁洿鎺ユ仮澶嶅埌~svn/repository鐩綍涓嬨?璁板緱鍚︼紝瀹冩槸涓暟鎹簱)銆傜浉鍙嶏紝鎴戞柊寤轟簡涓洰褰曠粨鏋勶細
% pwd
/usr/home/svn
% mkdir www && cd www
% mkdir branches tags trunk
% cd trunk
% tar xzvf /full/path/to/www.tar.gz .
% cd
榪欐牱錛宻vn鐢ㄦ埛鐨勪富鐩綍緇撴瀯鍍忚繖鏍?
% ls -F ~svn
repository/ www/
瀵煎叆鏁版嵁
涓嬩竴姝ワ紝搴旇鎶妦svn/www/鐨勬暟鎹鍏ュ埌Subversion鏈嶅姟鍣ㄤ簡銆備負浜嗗疄鐜拌繖涓洰鐨勶紝鍙互浣跨敤 svn import 鍛戒護錛?/P>
% svn import www file:///usr/home/svn/repository/www -m "initial import"
svn import 鏄痵vn鐨勮澶氬懡浠や腑鐢ㄦ埛鍙互浣跨敤鐨勪竴鏉°傞敭鍏?svn help 鍙互鐪嬪埌鎵鏈夊彲浠ヤ嬌鐢ㄧ殑鍛戒護鐨勫悕瀛椼傚鏋滀綘鍦╯vn鍜宧elp涓彃鍏ュ懡浠わ紝姣斿 svn import help,浣犲氨鍙互鐪嬪埌閭f潯鍛戒護鐨勮娉曞府鍔┿傚湪svn import鍚庨潰鐨勬槸鍖呭惈瑕佸鍏ユ暟鎹殑鐩綍鐨勫悕瀛?www)銆備綘鐨勬暟鎹笉涓瀹氶潪寰楀湪鐩稿悓鐨勭洰褰曚笅錛屽畠浠呬粎鏄畾涔変簡鍒版暟鎹殑瀹屾暣璺緞錛屼絾蹇呴』淇濊瘉浣犵殑svn緇勭敤鎴鋒嫢鏈夎闂鍏ユ暟鎹殑鏉冮檺銆傛敞鎰忥細濡傛灉浣犲凡緇忓鍏ョ殑鏁版嵁錛屽師濮嬫暟鎹氨娌℃湁蹇呰鐣欏湪紜洏涓婁簡銆傚湪鎴戠殑渚嬪瓙涓紝鎴戜嬌鐢ㄤ簡榪欐潯鍛戒護錛?/P>
rm -Rf www銆?/FONT>
鎺ヤ笅鏉ワ紝璇鋒敞鎰忓綋鎴戝畾涔変粨搴撶殑瀹屾暣璺緞鏃舵墍浣跨敤鐨勮娉曘係ubversion鏀寔澶歎RL妯″紡鎴栬匯A(repository access)妯″潡銆傛楠屼綘鐨凷ubversion鏀寔鍝妯″紡錛?/P>
#svn --version
svn, version 1.1.3 (r12730)
compiled Mar 20 2005, 11:04:16
Copyright (C) 2000-2004 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).
The following repository access (RA) modules are available:
* ra_dav : Module for accessing a repository via WebDAV (DeltaV) protocol.
- handles 'http' schema
- handles 'https' schema
* ra_local : Module for accessing a repository on local disk.
- handles 'file' schema
* ra_svn : Module for accessing a repository using the svn network protocol.
- handles svn schema
鍥犱負鎴戞兂瑕佸湪鏈湴璺緞璁塊棶浠撳簱錛屾墍浠ユ垜浣跨敤浜?A href="file:///">file:/// 妯″紡銆傛垜榪樺彲浠ュ湪榪橴RL鍚庨潰鍔犱笂www錛屽洜涓烘垜鎯寵闂粨搴撲腑鍚嶄負www鐨勭洰褰曘傚綋鐒訛紝浣犺兘鍦ㄥ悓涓涓粨搴撲腑瀵煎叆澶氫釜鐩綍緇撴瀯錛屽茍涓旂敤瀹規槗璁頒綇鐨勫悕瀛楀懡鍚嶃?BR>
鏈鍚庯紝鎴戜嬌鐢ㄤ簡 -m 娑堟伅寮鍏蟲妸娉ㄩ噴錛?initial import"鍔犲叆浠撳簱鏃ュ織涓傚鏋滄垜涓嶅寘鎷繖涓弬鏁幫紝svn灝嗕嬌鐢ㄩ粯璁ょ紪杈戝櫒(vi)鎵撳紑鏃ュ織騫惰姹傛垜濉叆娉ㄩ噴錛屽惁鍒欐棤娉曡繘鍏ヤ笅涓姝ャ?BR>
榪欐槸闈炲父鍏抽敭鐨勪竴涓湴鏂廣傚畨瑁呬竴涓増鏈帶鍒剁郴緇熺殑鍏ㄩ儴鍘熷洜鏄負浜嗗厑璁歌澶氱敤鎴蜂慨鏀規枃浠訛紝騫朵笖鏈夊彲鑳芥槸騫跺彂鐨勩傛瘡涓涓敤鎴烽兘搴旇璐熻矗浠葷殑璁板綍娓呮浠栦滑瀵瑰摢浜涙枃浠朵綔浜嗗摢浜涙敼鍔ㄣ備綘鐨勫伐浣滃氨鏄浠栦滑鏄庣櫧涓轟粈涔坰vn鍛戒護鎬繪槸鎻愮ず浠栦滑鍔犲叆娉ㄩ噴銆?/P>
紜畾濡備綍璁塊棶浠撳簱
鎭枩浣狅紒浣犵幇鍦ㄦ嫢鏈変簡涓涓彲浠ュ伐浣滅殑浠撳簱錛佺幇鍦ㄥ埌浜嗕粩緇嗘瘮杈冨悇縐嶄笉鍚岀殑URL妯″紡騫墮夊嚭鏈閫傚悎浣犻渶姹傜殑璁塊棶鏂規硶鐨勬渶濂界殑鏃墮棿銆?/P>
鍏嶈垂鐢靛瓙鏂囨。Version Control with Subversion絎叚绔犺緇嗕粙緇嶄簡鍚勭鍙兘鐨勯厤緗備綘鍙互鍦ㄧ紪璇慒reeBSD port鐨勬椂鍊?鍦?make 鍛戒護鍚庢坊鍔犲弬鏁?-DWITH_BOOK錛屾妸涔﹀畨瑁呬笂銆?/P>
濡傛灉浣犵殑鐢ㄦ埛閫氳繃鏈湴鎴杝sh鐧誨綍緋葷粺錛屽彲浠ヤ嬌鐢?file:/// 璁塊棶銆傚洜涓虹敤鎴峰浜庝粨搴撴椂鏈湴(local)鐨勶紝鎵浠ヨ繖縐嶆儏鍐典笅錛岀郴緇熶笉浼氭墦寮涓涓?TCP/IP绔彛鐩戝惉Subversion榪炴帴銆傜劧鑰岋紝瀹冨嵈瑕佹眰姣忎釜鐢ㄦ埛鏈変竴涓椿鍔ㄧ殑shell甯愬彿騫朵笖鍋囧畾浣犵殑鐢ㄦ埛鍙互鐧誨綍Unix鏈嶅姟鍣ㄣ傚拰鍒殑shell甯愭埛涓鏍鳳紝鍏跺畨鍏ㄦц兘鐢辮繖鍑犳柟闈㈠喅瀹氾細鐢ㄦ埛瀵嗙爜鐨勫仴澹э紱浠撳簱鏉冮檺浠ュ強緇勬垚鍛樼殑姝g‘閰嶇疆銆傝鐢ㄦ埛閫氳繃ssh鐧誨綍緋葷粺騫朵笉淇濊瘉session宸茶鍔犲瘑銆?/P>
鍙︿竴縐嶆柟妗堟槸鎶奡ubversion鏁村悎榪沘pache鏈嶅姟鍣ㄣ傞粯璁ゆ儏鍐典笅錛孲ubversion 鐨凢rssBSD port鏀寔SSL緙栬瘧錛岃繖鎰忓懗鐫浣犵殑鐢ㄦ埛鍙互鍦ㄦ祻瑙堝櫒涓嬌鐢?https:// 妯″紡璁塊棶浠撳簱銆傜劧鑰岋紝濡傛灉浣犵殑apache鐗堟湰鏄?.X鑰屼笉鏄?.X錛岃璁板緱鍦ㄧ紪璇戠殑鏃跺欐妸鍙傛暟-DWITH_MOD_DAV_SVN 鍔犲叆鍒?make鍚庨潰銆?/P>
濡傛灉浣犺冭檻璁╃敤鎴烽氳繃嫻忚鍣ㄨ闂紝瑕佸厛浠旂粏闃呰Subversion鏂囨。鍏充簬apahce httpd閰嶇疆閮ㄥ垎錛岀劧鍚庝綘瑕侀厤緗笉灝戜笢瑗褲傚垢榪愮殑鏄紝鏂囨。寰堝畬鏁達紒
絎笁縐嶆柟妗堟椂浣跨敤 svnserve 鐩戝惉緗戠粶榪炴帴銆傛枃妗e緩璁噰鐢ㄨ繖縐嶆ā寮忥紝鏃犺鏄氳繃inetd榪樻槸鐙珛榪涚▼銆傝繖
縐嶆ā寮忓厑璁稿尶鍚嶈闂垨鑰呭凡鎺堟潈鐨勭敤鎴瘋闂紝浠諱綍鏂瑰紡閮介氳繃CRAM-MD5鍔犲瘑銆傚鎴烽氳繃svn:// 璁塊棶svnserve銆?/P>
鎴戣涓哄尶鍚嶈闂槸涓嶆伆褰撶殑錛屾墍浠ユ垜渚濈収閰嶇疆閫夐」浣跨敤CRAM-MD5銆傜劧鑰岋紝鎴戝緢蹇彂鐜版垜鐨勭郴緇熶笂娌℃湁瀹夎CRAM-MD5銆傚湪Google涓婃悳绱㈠叧浜庢妸CRAM-MD5鏁村悎榪汼ubversion鏈嶅姟鍣ㄧ殑璧勬枡錛屼絾鏄病鏈夋壘鍒般傛垜灝卞喅瀹氬皾璇曟渶鍚庝竴縐嶆柟娉曘?BR>
閭e氨鏄湪鈥滈毀閬撴ā寮?tunnel mode)鈥濅腑璋冪敤svnserve,榪欑妯″紡鍙互璁╀綘鐨勭敤鎴烽櫎浜嗗彈浣犲湪/etc/ssh/sshd_config涓殑閰嶇疆綰︽潫澶栵紝榪樺彲浠ラ氳繃姝e父鐨凷SH鏈哄埗璁よ瘉銆傛瘮濡傦紝鎴戝彲浠ヤ嬌鐢ˋllowUsers鍏抽敭瀛楁帶鍒跺摢浜涚敤鎴鋒巿鏉冭闂郴緇熴傛敞鎰忥紝榪欑妯″紡浣跨敤svn+ssh://璁塊棶浠撳簱銆?/P>
榪欑鏂規硶鐨勫ソ澶勬槸鎴戝彲浠ヤ嬌鐢ㄥ凡鏈夌殑璁よ瘉浣撳埗鑰屼笉闇瑕佺敤鎴峰繀欏繪槸浠撳簱緋葷粺甯愭埛銆傜劧鑰岋紝榪欑妯″紡涓殑緗戠粶榪炴帴鏄病鏈夊姞瀵嗙殑錛涗嬌鐢⊿SH鍙槸涓轟簡鎺堟潈銆傚鏋滀綘鐨勬暟鎹槸鏁忔劅鐨勶紝閭d箞浣犲簲璇ヨ浣犵殑鐢ㄦ埛閫氳繃ssh鐧誨綍鍚庝嬌鐢╢ile:// 璁塊棶錛屾垨鑰呬嬌鐢╤ttps:// 璁塊棶錛屼笉榪囧繀欏繪紜厤緗ソApache銆?/P>
濡傛灉浣犲喅瀹氫嬌鐢╯vnserve鏈嶅姟鍣ㄥ茍涓斿湪wrapper涓紪璇戯紝瀹冨皢鐢熸垚涓涓悕涓簊vnserve.bin鐨勪簩榪涘埗鏂囦歡銆備綘蹇呴』榪欎箞鍋氱敤鎴鋒墠鑳借闂粨搴擄細
# cp /usr/local/bin/svnserve.bin /usr/local/bin/svnserve
鍥犱負瀹冩槸Subversion鏈嶅姟鍣ㄧ殑涓閮ㄥ垎銆傚湪涓嬩竴鏈熶笓鏍忎腑錛屾垜灝嗕粙緇嶅浣曞鎴風濡備綍璁塊棶浠撳簱銆?/P>
Dru Lavigne 鏄弗澶崕Marketbridge Technologies 鐨勮甯堝拰Open Protocol Resource鐨勭淮鎶や漢鍛樸?/P>
Recently a client hired a team of web developers to assist his overworked web administrator. They asked me to set up a revision-control system to ensure that no one on the team inadvertently overwrote another member's work and to give the administrator the flexibility of rolling back to any version of a file.
This week's article demonstrates how to create a secure repository using Subversion. The next installment will show how to train your users to access the repository using a GUI client.
In my scenario, it was important that only the members of the development team have access to the repository. We also chose to have the repository on a system separate from the actual web server and left it up to the web administrator to copy over files from the repository to the web server as he saw fit.
To accomplish this, start by creating a backup of the existing directory structure you wish to put under revision control, and send it securely to the repository server. In my case, I backed up the www
data on the web server to an internal server at 192.168.2.2.
# tar czvf - /usr/local/etc/www/data | ssh dru@192.168.2.2 "cat > www.tar.gz"
Next, on the repository system, create a new group called svn
and add to it any existing user accounts that need access to the repository. For example, I added my existing web administrator as I created the group by adding this line to /etc/group:
# vi /etc/group
svn:*:3690:webadmin
Then, create a new user called svn
and, if necessary, any missing user accounts that need access to the repository. Make sure each account is a member of the svn
group and has a password and a valid shell. I used sysinstall
to create user accounts for the new web developers. When I finished, I double-checked the membership of the svn
group. It looked something like this:
# grep svn /etc/group
svn:*:3690:webadmin,devel1,devel2
umask
Before installing Subversion, take a close look at the existing umask
for the svn
user. On my FreeBSD system it was:
# su -l svn
% umask
022
In Unix, the umask
value determines the default permissions of a newly created directory or file. It does this by defining which permissions to disable. If you remember:
r = 4
w = 2
x = 1
you'll see that this umask
doesn't turn off any (0) permissions for the user (svn
); it turns off write (2) for the group (svn
); and it turns off write (2) for world.
Because the members of the svn
group should be able to write to the repository, change that group 2
to a 0
. If you don't want nongroup members even to be aware of the existence of the repository, also change the world 2
to a 7
.
The easy part is changing the umask
for the svn
user's shell. If it uses csh
:
% vi ~svn/.cshrc
then find the existing umask
line and change it to either 002
or 007
.
If your svn
user has a shell other than csh
, make your edit in your chosen shell's configuration file.
Once you've saved your changes to ~svn/.cshrc (or wherever), don't forget to tell the shell:
% source ~svn/.cshrc
Repeat the umask
command to verify that your changes have taken place.
umask
If you chose a umask
of 002
, you can compile a wrapper into Subversion when you build it from the ports collection. If you chose a umask
of 007
or prefer to install the precompiled version of Subversion, create a wrapper script to ensure that the Subversion binaries use your umask
value.
To compile in a wrapper that sets a umask
of 002
:
# cd /usr/ports/devel/subversion
# make -DWITH_SVNSERVE_WRAPPER install clean
Alternatively, to install the precompiled binary:
# pkg_add -r subversion
Note: before installing by either method, finish reading the article. You may find some additional compile options that interest you.
If you didn't compile in your wrapper, move your existing binary and create your own wrapper script:
# mv /usr/local/bin/svn /usr/local/bin/svn.orig
# vi /usr/local/bin/svn
#!/bin/sh
#wrapper script to set umask to 007 on subversion binaries
umask 007
/usr/local/bin/svn.orig "$@"
Set your umask
to either 002
or 007
so that it is the same as the umask
for your svn
user.
Don't forget to make your wrapper script executable:
# chmod +x /usr/local/bin/svn
Now that your environment is set up properly, you're ready to create the repository itself. Log in as the user svn
to ensure that both the svn
user and the svn
group own the files you create in the repository. From /usr/home/svn/, type:
% svnadmin create repository
In this example, I've called my repository repository
. You can choose any name that is useful to you.
svnadmin create
simply creates the directory infrastructure required by the Subversion tools:
% ls -F repository
README.txt dav/ format locks/
conf/ db/ hooks/
Notice that db
directory? By default, Subversion uses databases to track changes to the files that you place under revision control. This means that you must import your data into those databases.
At that point, I untarred my backup so that I had some data to import. If you do this, don't restore directly into the ~svn/repository directory. (It's a database, remember?) Instead, I first made a new directory structure:
% pwd
/usr/home/svn
% mkdir www && cd www
% mkdir branches tags trunk
% cd trunk
% tar xzvf /full/path/to/www.tar.gz .
% cd
That made the svn
user's home directory look like:
% ls -F ~svn
repository/ www/
Next, it's time to import the information from ~svn/www/
into the Subversion databases. To do so, use the svn import
command:
% svn import www file:///usr/home/svn/repository/www -m "initial import"
svn import
is one of many svn
commands available to users. Type svn help
to see the names of all the available commands. If you insert one of those commands between svn
and help
, as in svn import help
, you'll receive help on the syntax for that specified command.
After svn import
, specify the name of the directory containing the data to import (www
). Your data doesn't have to be in the same directory; simply specify the full path to the data, but ensure that your svn
user has permission to access the data you wish to import. Note: once you've successfully imported your data, you don't have to keep an original copy on disk. In my case, I issued the command rm -Rf www
.
Next, notice the syntax I used when specifying the full path to the repository. Subversion supports multiple URL schemas or "repository access" RA modules. Verify which schemas your svn
supports with:
% svn --version
svn, version 1.1.3 (r12730)
compiled Mar 20 2005, 11:04:16
Copyright (C) 2000-2004 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).
The following repository access (RA) modules are available:
* ra_dav : Module for accessing a repository via WebDAV (DeltaV) protocol.
- handles 'http' schema
- handles 'https' schema
* ra_local : Module for accessing a repository on local disk.
- handles 'file' schema
* ra_svn : Module for accessing a repository using the svn network protocol.
- handles svn schema
Because I wished to access the repository on the local disk, I used the file:///
schema. I also appended www
at the very end of the URL, as I wish that particular part of the repository to be available by that name. Yes, you can import multiple directory structures into the same Subversion repository, so give each one a name that is easy for you and your users to remember.
Finally, I used the -m
message switch to append the comment "initial import"
to the repository log. If I hadn't included this switch, svn
would have opened the log for me in the user's default editor (vi
) and asked me to add a comment before continuing.
This is a very important point. The whole reason to install a revision control system is to allow multiple users to modify files, possibly even simultaneously. It's up to each user to log clearly which changes they made to which files. It's your job to make your users aware of the importance of adding useful comments whenever an svn
command prompts them to do so.
Congratulations! You now have a working repository. Now's the best time to take a closer look at the various URL schemas and choose the access method that best suits your needs.
Chapter 6 of the freely available e-book Version Control with Subversion gives details about the possible configurations. You can choose to install the book when you compile the FreeBSD port by adding -DWITH_BOOK
to your make
command.
If all of your users log in to the system either locally or through ssh
, use the file:///
schema. Because users are "local" to the repository, this scenario doesn't open a TCP/IP port to listen for Subversion connections. However, it does require an active shell account for each user and assumes that your users are comfortable logging in to a Unix server. As with any shell account, your security depends upon your users choosing good passwords and you setting up repository permissions and group memberships correctly. Having users ssh
to the system does ensure that they have encrypted sessions.
Another possibility is to integrate Subversion into an existing Apache server. By default, the FreeBSD port of Subversion compiles in SSL support, meaning your users can have the ability to access your repository securely from their browsers using the https://
schema. However, if you're running Apache 2.x instead of Apache 1.x, remember to pass the -DWITH_MOD_DAV_SVN
option to make
when you compile your FreeBSD port.
If you're considering giving browser access to your users, read carefully through the Apache httpd configuration section of the Subversion book first. You'll have to go through a fair bit of configuration; fortunately, the documentation is complete.
A third approach is to use svnserve
to listen for network connections. The book suggests running this process either through inetd
or as a stand-alone daemon. Both of these approaches allow either anonymous access or access once the system has authorized a user using CRAM-MD5. Clients connect to svnserve
using the svn://
schema.
Anonymous access wasn't appropriate in my scenario, so I followed the configuration options for CRAM-MD5. However, I quickly discovered that CRAM-MD5 wasn't on my FreeBSD system. When a Google search failed to find a technique for integrating CRAM-MD5 with my Subversion binary, I decided to try the last option.
This was to invoke svnserve
in tunnel mode, which allows user authentication through the normal SSH mechanism as well as any restrictions you have placed in your /etc/ssh/sshd_config file. For example, I could use the AllowUsers
keyword to control which users can authenticate to the system. Note that this schema uses svn+ssh://
.
The appeal of this method is that I could use an existing authentication scheme without forcing the user to actually be "on" the repository system. However, this network connection is unencrypted; the use of SSH is only to authenticate. If your data is sensitive, either have your users use file://
after ssh
ing in or use https://
after you've properly configured Apache.
If you decide to use the svnserve
server and you compiled in the wrapper, it created a binary called svnserve.bin. Users won't be able to access the repository until:
# cp /usr/local/bin/svnserve.bin /usr/local/bin/svnserve
That's it for this installment. In the next column, I'll show how to start accessing the repository as a client.
Dru Lavigne is an instructor at Marketbridge Technologies in Ottawa and the maintainer of the Open Protocol Resource.