Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5288 dpurdie 1
<#
2
.SYNOPSIS
3
This Powershell script will create a Master and Slave Repos
4
 
5
.DESCRIPTION
6
	This Powershell script will create a Master and Slave Repos
7
 
8
	It will
9
		Create the Master on the current machine
10
            Copy Global Hooks into the new Repo
11
        Create Slaves
12
            Copy Global Hooks into the new slaves
13
 
14
 
15
.PARAMETER  Repo
16
Name of the Repo to create
17
 
18
.PARAMETER	Slaves
19
A list of Slave servers that are a part of the subversion network
20
These will be reconfigured to communicate with the new master
21
 
22
If none are provided then only the Master Repo will be created
23
 
24
.EXAMPLE
25
CreateRepo.ps1 -Slave auawssvn01,cloudasvn03
26
 
27
.NOTES
28
Uses a number of cmdlets provided by VisualSVN.
29
 
30
#>
31
#
32
Param
33
(
34
    [ parameter (Mandatory=$true,
35
	             HelpMessage="Enter the name of the new Repository")]
36
    [string] $Repo,
37
    [ parameter () ]
38
    [string[]] $Slaves
39
)
40
 
41
#
42
#   Get information on the current SVN server
43
#
44
function GetSvnInfo()
45
{
46
    $repoData = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Service
47
    Return $RepoData
48
}
49
 
50
#
51
#   Get information on a named repo
52
function GetRepoInfo( $repoName )
53
{
54
    $repoData = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Repository | Where { $_.Name -eq $repoName } 
55
    Return $RepoData
56
}
57
 
58
#
59
#   Get information on a named repo on the named Computer
60
function GetRemoteRepoInfo( $repoName, $ComputerName )
61
{
62
    $repoData = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Repository -ComputerName $ComputerName | Where { $_.Name -eq $repoName } 
63
    Return $RepoData
64
}
65
 
66
#
67
# Convert Absolute Path to UNC on a named computer
68
#
69
Function AbsToUnc( $ComputerName, $absPath )
70
{
71
    return '\\' + $ComputerName + '\' + $absPath.Replace(":","$")
72
}
73
#
74
# Determine the root of the Repositores
75
$SvnInfo = GetSvnInfo
76
if ($SvnInfo -eq $null)
77
{
78
    Write-Error 'Cannot get VisualSVN info'
79
    Exit
80
}
81
 
82
# Validate the Repo Root
83
$repoRoot = $SvnInfo.RepositoriesRoot
84
If (!(Test-Path $repoRoot)) 
85
{
86
    Write-Error 'RepositoriesRoot - Does not exist'
87
    Exit
88
}
89
 
90
#
91
# Ensure the named repo does not exist
92
#
93
$RepoData = Get-SvnRepository -Name $Repo -ErrorAction SilentlyContinue
94
If ( $RepoData )
95
{
96
    Write-Host "Repository ($Repo) already exists"
97
    Return
98
}
99
 
100
#
101
# Create the Master Repo
102
#
103
Write-Host 'Creating Master Repository'
104
$RepoData = New-SvnRepository -Name $Repo -Type VdfsMaster
105
 
106
#
107
# Copy in global hooks
108
#
109
Write-Host 'Transfer Global Hooks'
110
$RepoInfo = GetRepoInfo $Repo
111
$HookSrc = $repoRoot
112
$hookPath = $RepoInfo.Path  + '/hooks'
113
$HookFileCount = 0
114
 
115
Get-ChildItem $HookSrc -Filter '*.cmd' | ForEach-Object {
116
    $srcFile = $_.Name
117
    Copy-Item $_.FullName -Destination $hookPath 
118
    $HookFileCount++
119
}
120
Write-Host "Hook Files Copied: $HookFileCount"
121
 
122
#
123
# Create Slaves too
124
#
125
If ( $Slaves )
126
{
127
    #Write-Host $Slaves
128
 
129
    #
130
    # Add Slave list to the Master
131
    #
132
    $Replicators = $Slaves |  ForEach-Object { $_ + '$' }
133
    Set-SvnRepositoryReplication $Repo -Replicators $Replicators -Enabled:$true
134
 
135
    $Slaves | ForEach-Object {
136
 
137
        Write-Host "Creating Slave Repository $_"
138
        $NewRepo = New-SvnRepository $Repo -MasterServer $env:COMPUTERNAME -Type VdfsSlave -CimSession $_
139
 
140
        #
141
        # Copy Hooks to the Slave
142
        #
143
        # Get target Repo Information
144
        #     Want the path to the hooks directory
145
        #
146
        $targetRepo = GetRemoteRepoInfo $Repo $_
147
        $hookPath = $targetRepo.Path  + '\hooks'
148
        $hookPathUnc = AbsToUnc $_  $hookPath
149
 
150
 
151
        #
152
        # Copy files to Remote Computer
153
        #
154
        #Write-Host "Hooks Found", $hookPathUnc
155
        $HookFileCount = 0
156
 
157
        Get-ChildItem $HookSrc -Filter '*.cmd' | ForEach-Object {
158
            $srcFile = $_.Name
159
            Copy-Item $_.FullName -Destination $hookPathUnc 
160
            $HookFileCount++
161
        }
162
        Write-Host "Hook Files Copied: $HookFileCount"
163
    }
164
}
165