当前位置: 首页 > article >正文

ubuntu安装配置svn

目录

  • 简介
  • 安装
  • SVN 启动模式
    • 方式1:单库svnserve方式
    • 方式2:多库svnserve方式
  • SVN 创建版本库
    • 1.svn 服务配置文件 svnserve.conf
    • 2.用户名口令文件 passwd
    • 3.权限配置文件
    • 4.多库方式运行
  • SVN 检出操作
  • SVN 解决冲突
  • SVN 提交操作
  • SVN 版本回退
  • SVN 查看历史信息
    • 1.svn log
    • 2.svn diff
    • 3.svn cat
    • 4.svn list
  • SVN分支
  • SVN 标签(tag)
  • authentication realm
  • Cyrus SASL authentication
  • Implementing Repository Hooks
  • 密码生成器
  • 相关链接

简介

svn可以检出单个文件,git不具备这个特点,大多数公司使用svn服务器作为文档管理,二进制镜像,可执行文件等发布用途.

主要参考https://svnbook.red-bean.com/这本书.

安装

#安装
sudo apt install subversion
#查看是否安装
svn --version

SVN 启动模式

#手动新建版本库目录
sudo mkdir -p /data/svn

#利用svn命令创建版本库
svnadmin create /data/svn/company

#使用命令svnserve启动服务
svnserve -d -r /data/svn/company --listen-port 3690
#-r: 配置方式决定了版本库访问方式
#--listen-port: 指定SVN监听端口,不加此参数,SVN默认监听3690

#由于-r 配置方式的不一样,SVN启动就可以有两种不同的访问方式

方式1:单库svnserve方式

-r直接指定到版本库(称之为单库svnserve方式)

svnserve -d -r /data/svn/company

在这种情况下,一个svnserve只能为一个版本库工作。

authz配置文件中对版本库权限的配置应这样写:

[groups]
admin=user1
dev=user2
[/]
@admin=rw
user2=r

使用类似这样的URL:svn://192.168.0.1/ 即可访问runoob版本库

方式2:多库svnserve方式

指定到版本库的上级目录

svnserve -d -r /data/svn

这种情况,一个svnserve可以为多个版本库工作

authz配置文件中对版本库权限的配置应这样写:

[groups]
admin=user1
dev=user2
[runoob:/]
@admin=rw
user2=r

[runoob01:/]
@admin=rw
user2=r

如果此时你还用[/],则表示所有库的根目录,同理,[/src]表示所有库的根目录下的src目录。

使用类似这样的URL:svn://192.168.0.1/company 即可访问company版本库。

SVN 创建版本库

使用 svn 命令创建资源库:

svnadmin create /data/svn/company
tree /data/svn/company/conf/
/data/svn/company/conf/
├── authz
├── hooks-env.tmpl
├── passwd
└── svnserve.conf

1.svn 服务配置文件 svnserve.conf

该文件仅由一个 [general] 配置段组成, 此文件已经复制出来,可以查看阅读.

主要选项说明如下:

[general]
anon-access = none
auth-access = write
password-db = passwd
authz-db = authz
realm = tiku 
### This file controls the configuration of the svnserve daemon, if you
### use it to allow access to this repository.  (If you only allow
### access through http: and/or file: URLs, then this file is
### irrelevant.)

### Visit http://subversion.apache.org/ for more information.

[general]
### The anon-access and auth-access options control access to the
### repository for unauthenticated (a.k.a. anonymous) users and
### authenticated users, respectively.
### Valid values are "write", "read", and "none".
### Setting the value to "none" prohibits both reading and writing;
### "read" allows read-only access, and "write" allows complete 
### read/write access to the repository.
### The sample settings below are the defaults and specify that anonymous
### users have read-only access to the repository, while authenticated
### users have read and write access to the repository.
anon-access = none
auth-access = write

### The password-db option controls the location of the password
### database file.  Unless you specify a path starting with a /,
### the file's location is relative to the directory containing
### this configuration file.
### If SASL is enabled (see below), this file will NOT be used.
### Uncomment the line below to use the default password file.
password-db = passwd

### The authz-db option controls the location of the authorization
### rules for path-based access control.  Unless you specify a path
### starting with a /, the file's location is relative to the
### directory containing this file.  The specified path may be a
### repository relative URL (^/) or an absolute file:// URL to a text
### file in a Subversion repository.  If you don't specify an authz-db,
### no path-based access control is done.
### Uncomment the line below to use the default authorization file.
authz-db = authz

### The groups-db option controls the location of the file with the
### group definitions and allows maintaining groups separately from the
### authorization rules.  The groups-db file is of the same format as the
### authz-db file and should contain a single [groups] section with the
### group definitions.  If the option is enabled, the authz-db file cannot
### contain a [groups] section.  Unless you specify a path starting with
### a /, the file's location is relative to the directory containing this
### file.  The specified path may be a repository relative URL (^/) or an
### absolute file:// URL to a text file in a Subversion repository.
### This option is not being used by default.
# groups-db = groups

### This option specifies the authentication realm of the repository.
### If two repositories have the same authentication realm, they should
### have the same password database, and vice versa.  The default realm
### is repository's uuid.
realm = jw

### The force-username-case option causes svnserve to case-normalize
### usernames before comparing them against the authorization rules in the
### authz-db file configured above.  Valid values are "upper" (to upper-
### case the usernames), "lower" (to lowercase the usernames), and
### "none" (to compare usernames as-is without case conversion, which
### is the default behavior).
# force-username-case = none

### The hooks-env options specifies a path to the hook script environment 
### configuration file. This option overrides the per-repository default
### and can be used to configure the hook script environment for multiple 
### repositories in a single file, if an absolute path is specified.
### Unless you specify an absolute path, the file's location is relative
### to the directory containing this file.
# hooks-env = hooks-env

[sasl]
### This option specifies whether you want to use the Cyrus SASL
### library for authentication. Default is false.
### Enabling this option requires svnserve to have been built with Cyrus
### SASL support; to check, run 'svnserve --version' and look for a line
### reading 'Cyrus SASL authentication is available.'
use-sasl = false

### These options specify the desired strength of the security layer
### that you want SASL to provide. 0 means no encryption, 1 means
### integrity-checking only, values larger than 1 are correlated
### to the effective key length for encryption (e.g. 128 means 128-bit
### encryption). The values below are the defaults.
# min-encryption = 0
# max-encryption = 256

2.用户名口令文件 passwd

用户名口令文件由 svnserve.conf 的配置项 password-db 指定,默认为 conf 目录中的 passwd。该文件仅由一个 [users] 配置段组成。

### This file is an example password file for svnserve.
### Its format is similar to that of svnserve.conf. As shown in the
### example below it contains one section labelled [users].
### The name and password for each user follow, one account per line.

[users]
# harry = harryssecret
username = 123456

3.权限配置文件

权限配置文件由 svnserve.conf 的配置项 authz-db 指定,默认为 conf 目录中的 authz。该配置文件由一个 [groups] 配置段和若干个版本库路径权限段组成。

[groups]配置段中配置行格式如下:

<用户组> = <用户列表>

版本库路径权限段的段名格式如下:

[<版本库名>:<路径>]

例子

[groups]
g_admin = admin,thinker

[admintools:/]
@g_admin = rw
* =

[test:/home/thinker]
thinker = rw
* = r

在版本库目录下/data/svn/company/conf, 默认内容:

### This file is an example authorization file for svnserve.
### Its format is identical to that of mod_authz_svn authorization
### files.
### As shown below each section defines authorizations for the path and
### (optional) repository specified by the section name.
### The authorizations follow. An authorization line can refer to:
###  - a single user,
###  - a group of users defined in a special [groups] section,
###  - an alias defined in a special [aliases] section,
###  - all authenticated users, using the '$authenticated' token,
###  - only anonymous users, using the '$anonymous' token,
###  - anyone, using the '*' wildcard.
###
### A match can be inverted by prefixing the rule with '~'. Rules can
### grant read ('r') access, read-write ('rw') access, or no access
### ('').

[aliases]
# joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average

[groups]
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe
admin = username

# [/foo/bar]
# harry = rw
# &joe = r
# * =

# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r
[company:/]
@admin = rw
$authenticated =rw

4.多库方式运行

svnserve -d -r /data/svn
#访问地址
svn://106.15.109.116/company

SVN 检出操作

svn checkout svn://106.15.109.116/company --username=username

SVN 解决冲突

svn update
svn update -r6
#edit
svn commit -m "change HelloWorld.html second"

SVN 提交操作

svn status
svn add readme 
svn status 
svn commit -m "SVN readme."
#edit
svn commit

SVN 版本回退

#edit
svn status
svn revert readme.md 
#目录
svn revert -R trunk

但是,假如我们想恢复一个已经提交的版本怎么办。

为了消除一个旧版本,我们必须撤销旧版本里的所有更改然后提交一个新版本。这种操作叫做 reverse merge。

首先,找到仓库的当前版本,现在是版本 22,我们要撤销回之前的版本,比如版本 21。

svn merge -r 22:21 readme 

SVN 查看历史信息

1.svn log

用来展示svn 的版本作者、日期、路径等等

#查看特定的某两个版本之间的信息
svn log -r 6:8
#查看某一个文件的版本修改信息
svn log trunk/HelloWorld.html 
#如果希望得到目录的信息要加 -v
#如果希望显示限定N条记录的目录信息,使用 svn log -l N -v

2.svn diff

用来显示特定修改的行级详细信息。

  • 检查本地修改
  • 比较工作拷贝与版本库
  • 比较版本库与版本库
#如果用 svn diff,不带任何参数,它将会比较你的工作文件与缓存在 .svn 的"原始"拷贝
svn diff

#比较工作拷贝和版本库
svn diff -r 3 rule.txt

#比较版本库与版本库
svn diff -r 2:3 rule.txt

3.svn cat

取得在特定版本的某文件显示在当前屏幕。

#如果只是希望检查一个过去版本,不希望查看他们的区别,可使用svn cat
svn cat -r 版本号 rule.txt

4.svn list

显示一个目录或某一版本存在的文件

#svn list 可以在不下载文件到本地目录的情况下来察看目录中的文件:
svn list svn://106.15.109.116/company

SVN分支

#新建一个分支
svn copy trunk/ branches/my_branch
#提交新增的分支到版本库
svn commit -m "add my_branch"
#到 my_branch 分支进行开发
cd branches/my_branch/
#切换到 trunk,执行 svn update,然后将 my_branch 分支合并到 trunk 中
svn merge ../branches/my_branch/
#将合并好的 trunk 提交到版本库中。
svn commit -m "add index.html"

SVN 标签(tag)

#创建标签
svn copy trunk/ tags/v1.0
#提交标签
svn commit -m "tags v1.0" 

authentication realm

### This option specifies the authentication realm of the repository.
### If two repositories have the same authentication realm, they should
### have the same password database, and vice versa.  The default realm
### is repository's uuid.
# realm = My First Repository

假如要共享密码库文件,authentication realm必须相同

Cyrus SASL authentication

需要的时间太多,暂时不用

svn.conf
in the directory where SASL plug-ins are located
/usr/lib/sasl2/ 
/etc/sasl2/

/usr/lib/sasl2
/usr/lib/x86_64-linux-gnu/sasl2
pwcheck_method: auxprop
auxprop_plugin: sasldb
sasldb_path: /etc/my_sasldb
mech_list: DIGEST-MD5
saslpasswd2 -c -f /etc/my_sasldb -u realm username

Implementing Repository Hooks

实现提交必须听有注释

hooks/pre-commit

REPOS="$1"
TXN="$2"

# Make sure that the log message contains some text.
SVNLOOK=/usr/bin/svnlook
LOGMSG=`$SVNLOOK log -t $TXN $REPOS | wc -m`


#echo $LOGMSG > /data/svn/company/hooks/test.txt
#一个汉字对应8个字符
if [ "$LOGMSG" -lt 16 ];then
	echo "\n提交失败:至少输入2个汉字或16个英语字母数字" 1>&2 
	exit 1
fi

# Exit on all errors.
set -e

# All checks passed, so allow the commit.
exit 0

密码生成器

由于使用内建的认证方式,用户不能修改密码,增加用户时请找管理员.管理员可以使用密码生成器一次生成多个密码.

sudo apt install pwgen
pwgen

相关链接

SVN 教程

SVN 官网

Github SVN 源码

Linux服务器搭建SVN服务

sasl认证


http://www.kler.cn/a/106048.html

相关文章:

  • 4.2 Android NDK 基础概念
  • SpringSecurity+jwt+captcha登录认证授权总结
  • 自动化运维(k8s):一键获取指定命名空间镜像包脚本
  • 关于 Oracle Database Express Edition 的功能和安装
  • “fc-async”提供了基本的异步处理能力
  • 如何使用正则表达式验证域名
  • ChatGLM系列五:Lora微调
  • Python轮廓追踪【OpenCV形态学操作】
  • JAVA实现生活废品回收系统 开源
  • 世界经济论坛:ChatGPT等生成式AI,对全球23%岗位产生巨大影响
  • advanced installer 做包教程
  • C++学习笔记之三(标准库、标准模板库、vector类)
  • 2023高频前端面试题-浏览器
  • Python爬虫(二十四)_selenium案例:执行javascript脚本
  • RFNet模型数据集采集处理流程
  • JS清除字符串中的空格
  • 平安校园智慧安防监控摄像头的布控建议
  • 优化改进YOLOv5算法:加入ODConv+ConvNeXt提升小目标检测能力——(超详细)
  • Jenkins自动化测试
  • python把ChestX-Det-Dataset的json样本转为COCO数据集的json格式
  • C语言文件读写,文件相关操作
  • 【TES641】基于VU13P FPGA的4路FMC接口基带信号处理平台
  • AWTK实现汽车仪表Cluster/DashBoard嵌入式GUI开发(六):一个AWTK工程
  • Go学习第十一章——协程goroutine与管道channel
  • Windows server服务器允许多用户远程的设置
  • sourcetree Incorrect username or password (access token)