subversion
SVN是subversion的缩写,是一个开放源代码的版本控制系统,通过采用分支管理系统的高效管理,简而言之就是用于多个人共同开发同一个项目,实现共享资源,实现最终集中式的管理。
TortoiseSVN
TortoiseSVN 是 Subversion 版本控制系统的一个免费开源客户端,可以超越时间的管理文件和目录。文件保存在中央版本库,除了能记住文件和目录的每次修改以外,版本库非常像普通的文件服务器。你可以将文件恢复到过去的版本,并且可以通过检查历史知道数据做了哪些修改,谁做的修改。这就是为什么许多人将 Subversion 和版本控制系统看作一种“时间机器”。
Subversion目录说明
- C:\svn\repos\project
目录 | 说明 |
---|---|
db | 存放所有的版本控制数据文件。 |
hooks | 放置hook脚本文件。 |
locks | 用来追踪存取文件库的客户端。 |
format | 一个文本文件,文件中只包含一个整数,表示当前文件库配置的版本号。 |
conf | SVN版本库的配置文件(版本库的访问账号、权限等)。 |
创建一键自动化部署subversion
- 最终实现下载Subversion,解压,安装,创建系统服务,配置Subversion,防火墙配置,企业微信机器人通知
- C:\svn\repos #存储库根目录
- C:\svn\repos\project #创建版本库
- C:\svn\repos\project\trunk #创建和使用一个仓库,最终的软件上传的目录
- C:\svn\repos\project\conf\svnserve.conf #SVN业务配置
- C:\svn\repos\project\conf\passwd #设置存储库的用户名和密码
- 用户名密码,只允许test01,test02用户访问project全局目录下所有文件的增删改查权限,登录,test03只读project下的trunk目录文件,不允许创建删除操作
test01/test@123
test02/test@123
test03/test@123
- C:\svn\repos\project\conf\authz #设置组和用户,允许开发者组在SVN文档-root上读写,允许读取fedora用户的[trunk]文件夹
- $webhook_wechat_robot #企业微信机器人通知实现需要更改此部分地址
- subversion命令参考
- 更改文件名称或者磁盘请仔细查看变量部分内容
powershell-install-subversion.ps1
<# Powershell Install subversion
+++++++++++++++++++++++++++++++++++++++++++++++++++++
+ _____ _____ _ _ _ +
+ | __ \ / ____| | | | |+
+ | |__) |____ _____ _ _| (___ | |__ ___| | |+
+ | ___/ _ \ \ /\ / / _ \ '__\___ \| '_ \ / _ \ | |+
+ | | | (_) \ V V / __/ | ____) | | | | __/ | |+
+ |_| \___/ \_/\_/ \___|_| |_____/|_| |_|\___|_|_|+
+ +++++++++++++++++++++++++++++++++++++++++++++++++++
# Powershell Install subversion
# .\powershell-install-subversion.ps1
#>
$drive="c:"
$subversion_url="https://www.visualsvn.com/files/"
$subversion_zip="Apache-Subversion-1.14.2.zip"
$subversion_catalogue="subversion-1.14.2"
$subversion_site="C:\Program Files"
$subversion_catalogue_new="subversion"
$subversion_bin="bin"
#Create the repository root
$subversion_repository_svn="svn"
$subversion_repository_svn_repo="repos"
$subversion_project="project"
$subversion_trunk="trunk"
#svnserve config
$svnserve_project_conf="conf"
$svnserve_conf="svnserve.conf"
$svnserve_passwd="passwd"
$svnserve_authz="authz"
$webhook_wechat_robot="https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=XXXX"
Write-Host "download vc_redist x86 x64" -ForegroundColor Green
Invoke-WebRequest -Uri https://aka.ms/vs/17/release/vc_redist.x64.exe -UseBasicParsing -OutFile "$drive\vc_redist.x64.exe"
Invoke-WebRequest -Uri https://aka.ms/vs/17/release/vc_redist.x86.exe -UseBasicParsing -OutFile "$drive\vc_redist.x86.exe"
Write-Host "install vc_redist x86 x64" -ForegroundColor Green
Start-Process -FilePath "$drive\vc_redist.x64.exe" -ArgumentList {/q /install} -Wait
Start-Process -FilePath "$drive\vc_redist.x86.exe" -ArgumentList {/q /install} -Wait
Write-Host "download subversion" -ForegroundColor Green
Invoke-WebRequest -Uri $subversion_url\$subversion_zip -UseBasicParsing -OutFile $drive\$subversion_zip
Write-Host "Create a directory for storing database data" -ForegroundColor Green
New-Item -ItemType Directory $subversion_site\$subversion_catalogue_new
Write-Host "decompression subversion" -ForegroundColor Green
Expand-Archive -Path $drive\$subversion_zip -DestinationPath $subversion_site\$subversion_catalogue_new
Write-Host "Create subversion environment variables" -ForegroundColor Green
$env:path += ";$subversion_site\$subversion_catalogue_new\$subversion_bin"
setx PATH $env:path /M
Write-Host "Create the repository root" -ForegroundColor Green
New-Item -ItemType Directory $drive\$subversion_repository_svn
New-Item -ItemType Directory $drive\$subversion_repository_svn\$subversion_repository_svn_repo
Write-Host "ApacheSubversion system service" -ForegroundColor Green
$svnserve_service="svnservice"
$svnserve_BinaryPathName="$subversion_site\$subversion_catalogue_new\$subversion_bin\svnserve.exe --service -r $drive\$subversion_repository_svn\$subversion_repository_svn_repo"
$svnserve_Description="Subversion Server"
New-Service -Name $svnserve_service -BinaryPathName $svnserve_BinaryPathName -DisplayName $svnserve_service -Description $svnserve_Description -StartupType Automatic
Start-Service $svnserve_service
Write-Host "Command to create subversion project" -ForegroundColor Green
svnadmin create $drive\$subversion_repository_svn\$subversion_repository_svn_repo\$subversion_project
Write-Host "Create a repository" -ForegroundColor Green
$svn_repository_trunk="file:///$subversion_repository_svn/$subversion_repository_svn_repo/$subversion_project/$subversion_trunk"
svn mkdir $svn_repository_trunk -m "create"
Write-Host "Delete default svnserve.conf authz passwd" -ForegroundColor Green
Remove-Item -Path "$drive\$subversion_repository_svn\$subversion_repository_svn_repo\$subversion_project\$svnserve_project_conf\$svnserve_conf", "$drive\$subversion_repository_svn\$subversion_repository_svn_repo\$subversion_project\$svnserve_project_conf\$svnserve_passwd", "$drive\$subversion_repository_svn\$subversion_repository_svn_repo\$subversion_project\$svnserve_project_conf\$svnserve_authz" -Recurse -Force -Verbose
Write-Host "create svnserve.conf" -ForegroundColor Green
$functionText = @"
[general]
anon-access = none
auth-access = write
password-db = passwd
authz-db = authz
"@
New-Item "$drive\$subversion_repository_svn\$subversion_repository_svn_repo\$subversion_project\$svnserve_project_conf\$svnserve_conf" -type file -force -value $functionText
Write-Host "create passwd" -ForegroundColor Green
$functionText = @"
[users]
test01 = test@123
test02 = test@123
test03 = test@123
"@
New-Item "$drive\$subversion_repository_svn\$subversion_repository_svn_repo\$subversion_project\$svnserve_project_conf\$svnserve_passwd" -type file -force -value $functionText
Write-Host "create authz" -ForegroundColor Green
$functionText = @"
[groups]
developer = test01,test02
[/]
@developer = rw
[/trunk]
test03 = r
"@
New-Item "$drive\$subversion_repository_svn\$subversion_repository_svn_repo\$subversion_project\$svnserve_project_conf\$svnserve_authz" -type file -force -value $functionText
Write-Host "Restart svnserve service" -ForegroundColor Green
Restart-Service $svnserve_service
Write-Host "create firewall subversion port" -ForegroundColor Green
New-NetFirewallRule -DisplayName "subversion" -Direction Outbound -profile any -LocalPort 3690 -Protocol TCP -Action Allow
New-NetFirewallRule -DisplayName "subversion" -Direction Inbound -profile any -LocalPort 3690 -Protocol TCP -Action Allow
Write-Host "Delete package" -ForegroundColor Green
Remove-Item -Path "$drive\$subversion_zip", "$drive\*.exe" -Recurse -Force -Verbose
#Enterprise wechat robot address
$webhook = $webhook_wechat_robot
#svnservice service state
$svn_service = Get-Service -Name $svnserve_service | Select-Object -ExpandProperty Status
#svnservice service port state
$svn_service_state = Test-NetConnection -ComputerName localhost -Port 3690 | Select-Object -ExpandProperty TcpTestSucceeded
#Obtain the Windows host system version
$Win_version = Get-WmiObject -Class Win32_OperatingSystem | Select-Object -ExpandProperty Caption
$Win_version_Names = echo $Win_version
#svnservice version
$svn_version = (Get-Item "$subversion_site\$subversion_catalogue_new\$subversion_bin\svnserve.exe").VersionInfo.FileVersion
$content = Write-Output ""Win_version: $Win_version_Names" `n "svn_service: $svn_service" `n "svn_service_state: $svn_service_state" `n "svn_version: $svn_version""
$body = "{
`"msgtype`":`"text`",
`"text`":{
`"content`":`"$content`",
`"mentioned_list`":[`"jason`"]
}
}"
Write-Host "The variable value obtained is transferred to the enterprise wechat robot" -ForegroundColor Green
Invoke-RestMethod $webhook -ContentType "application/json;charset=utf-8" -Method Post -Body $body
执行安装
.\powershell-install-subversion.ps1
输出结果展示
企业微信机器人通知
使用TortoiseSVN连接测试
- PowerShell install 一键部署TortoiseSVN 参考
- 用户名密码,只允许test01,test02用户访问project全局目录下所有文件的增删改查权限,登录,test03只读project下的trunk目录文件,不允许创建删除操作
上传容易文件到trunk 目录
提交上传文件到svn 服务器
选择需要上传到svn服务器的文件