Subversion Repositories DevTools

Rev

Rev 5287 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5287 dpurdie 1
<#
2
.SYNOPSIS
3
This Powershell script will update the repo-Wide hook in all the Repos
4
 
5
.DESCRIPTION
6
	This Powershell script update the repo-Wide hook in all the Repos on
5288 dpurdie 7
    the current machine and the named servers
5287 dpurdie 8
 
9
	It will
5288 dpurdie 10
		Locate the Repository Root
5287 dpurdie 11
        Copy *.cmd file from the root into each Repo Subdir
12
            Unless the special hooks/specialhooks file exists
5288 dpurdie 13
        Process each Named server
14
            Copy the global files to the server
15
            Copy the global files to each (non-special) repo on the server
5287 dpurdie 16
 
5288 dpurdie 17
.PARAMETER	Servers
18
A list of Slave servers that are a part of the subversion network
19
The hooks will be propergated to all the servers and all the Repos on all the Servers
20
 
5287 dpurdie 21
.EXAMPLE
5288 dpurdie 22
UpdateHooks.ps1 -Servers auawsasvn001,cloudasvn03
5287 dpurdie 23
 
24
.NOTES
25
Uses a number of cmdlets provided by VisualSVN.
26
 
27
#>
28
#
29
 
5288 dpurdie 30
Param
31
(
32
    [ parameter () ]
33
    [string[]] $Servers
34
)
35
 
5287 dpurdie 36
#
37
#   Get information on a named repo
38
function GetRepoInfo( $repoName )
39
{
40
    $repoData = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Repository | Where { $_.Name -eq $repoName } 
41
    Return $RepoData
42
}
43
 
44
#
5288 dpurdie 45
#   Get information on a named repo on the named Computer
46
function GetRemoteRepoInfo( $repoName, $ComputerName )
47
{
48
    $repoData = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Repository -ComputerName $ComputerName | Where { $_.Name -eq $repoName } 
49
    Return $RepoData
50
}
51
 
52
#
5287 dpurdie 53
#   Get information on the current SVN server
54
#
55
function GetSvnInfo()
56
{
57
    $repoData = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Service
58
    Return $RepoData
59
}
60
 
61
#
5288 dpurdie 62
#   Get information on the SVN server on the named Computer
63
#
64
function GetRemoteSvnInfo($ComputerName)
65
{
66
    $repoData = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Service -ComputerName $ComputerName 
67
    Return $RepoData
68
}
69
 
70
#
71
# Convert Absolute Path to UNC on a named computer
72
#
73
Function AbsToUnc( $ComputerName, $absPath )
74
{
75
    return '\\' + $ComputerName + '\' + $absPath.Replace(":","$")
76
}
77
 
78
#
79
# Test a server to see if it exists
80
#
81
Function CheckServer( $ComputerName)
82
{
83
    $testSession = New-CimSession $ComputerName -ErrorAction Ignore
84
    If($testSession -eq $null)
85
    {
86
        #Write-Error "The named computer ($ComputerName) does not exist" -Category InvalidArgument
87
        Return $false    
88
    }
89
    Remove-CimSession $testSession
90
    Return $true
91
}
92
 
93
#
5287 dpurdie 94
# Determine the root of the Repositores
95
$SvnInfo = GetSvnInfo
96
if ($SvnInfo -eq $null)
97
{
98
    Write-Error 'Cannot get VisualSVN info'
99
    Exit
100
}
101
 
102
# Validate the Repo Root
103
$repoRoot = $SvnInfo.RepositoriesRoot
104
If (!(Test-Path $repoRoot)) 
105
{
106
    Write-Error 'RepositoriesRoot - Does not exist'
107
    Exit
108
}
109
 
110
#
111
# Process each Repo
112
$HookSrc = $repoRoot
113
Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Repository | Sort-Object Name | ForEach-Object {
114
    $hookPath = $_.Path  + '/hooks'
115
    $repoName = $_.Name
116
 
117
    If (!(Test-Path ($hookPath + '/specialhooks')))
118
    {
119
 
120
        $HookFileCount = 0
121
        Get-ChildItem $HookSrc -Filter '*.cmd' | ForEach-Object {
122
            $srcFile = $_.Name
123
            Copy-Item $_.FullName -Destination $hookPath 
124
            $HookFileCount++
125
        }
126
        Write-Host ("{0,20} : {1}" -f $repoName, "Hooks copied: $HookFileCount")
127
    }
128
    else
129
    {
130
        Write-Host ("{0,20} : {1}" -f $repoName, "SPECIAL - No hooks copied")
131
    }
132
 
133
}
134
 
5288 dpurdie 135
#
136
# Process named servers
137
#
138
If ($Servers)
139
{
140
    $Servers | ForEach-Object{
141
        $Server = $_
142
        Write-Host 'Server:' $Server
143
        If ( ! (CheckServer $Server))
144
        {
145
            Write-Host -ForegroundColor Red "The server ($Server) does not exist"
146
            Return
147
        }
148
 
149
        #
150
        #
151
        $remoteServer = GetRemoteSvnInfo ($Server)
152
        $remoteRepoBase =  AbsToUnc $Server $remoteServer.RepositoriesRoot
153
 
154
        $HookFileCount = 0
155
        Get-ChildItem $HookSrc -Filter '*.cmd' | ForEach-Object {
156
            $srcFile = $_.Name
157
            Copy-Item $_.FullName -Destination $remoteRepoBase 
158
            $HookFileCount++
159
        }
160
        Write-Host ("{0,20}, {1,20} : {2}" -f $Server, 'Global Hooks', "Hooks copied: $HookFileCount")
161
 
162
        #
163
        # Update all Repos on the Server
164
        #
165
        Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Repository -ComputerName $Server | Sort-Object Name | ForEach-Object {
166
            $hookPath = AbsToUnc $Server ($_.Path  + '\hooks')
167
            $repoName = $_.Name
168
 
169
            If (!(Test-Path ($hookPath + '\specialhooks')))
170
            {
171
 
172
                $HookFileCount = 0
173
                Get-ChildItem $HookSrc -Filter '*.cmd' | ForEach-Object {
174
                    $srcFile = $_.Name
175
                    Copy-Item $_.FullName -Destination $hookPath 
176
                    $HookFileCount++
177
                }
178
                Write-Host ("{0,20}, {1,20} : {2}" -f $Server, $repoName, "Hooks copied: $HookFileCount")
179
            }
180
            else
181
            {
182
                Write-Host ("{0,20}, {1,20} : {2}" -f $Server, $repoName, "SPECIAL - No hooks copied")
183
            }
184
 
185
        }
186
 
187
    }
188
}
189