Subversion Repositories DevTools

Rev

Rev 5287 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5287 Rev 5288
Line 2... Line 2...
2
.SYNOPSIS
2
.SYNOPSIS
3
This Powershell script will update the repo-Wide hook in all the Repos
3
This Powershell script will update the repo-Wide hook in all the Repos
4
 
4
 
5
.DESCRIPTION
5
.DESCRIPTION
6
	This Powershell script update the repo-Wide hook in all the Repos on
6
	This Powershell script update the repo-Wide hook in all the Repos on
7
    the current machine.
7
    the current machine and the named servers
8
 
8
 
9
	It will
9
	It will
10
		Locate the Repositoties Root
10
		Locate the Repository Root
11
        Copy *.cmd file from the root into each Repo Subdir
11
        Copy *.cmd file from the root into each Repo Subdir
12
            Unless the special hooks/specialhooks file exists
12
            Unless the special hooks/specialhooks file exists
-
 
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
-
 
16
 
-
 
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
13
 
20
 
14
.EXAMPLE
21
.EXAMPLE
15
UpdateHooks.ps1
22
UpdateHooks.ps1 -Servers auawsasvn001,cloudasvn03
16
 
23
 
17
.NOTES
24
.NOTES
18
Uses a number of cmdlets provided by VisualSVN.
25
Uses a number of cmdlets provided by VisualSVN.
19
 
26
 
20
#>
27
#>
21
#
28
#
22
 
29
 
-
 
30
Param
-
 
31
(
-
 
32
    [ parameter () ]
-
 
33
    [string[]] $Servers
-
 
34
)
-
 
35
 
23
#
36
#
24
#   Get information on a named repo
37
#   Get information on a named repo
25
function GetRepoInfo( $repoName )
38
function GetRepoInfo( $repoName )
26
{
39
{
27
    $repoData = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Repository | Where { $_.Name -eq $repoName } 
40
    $repoData = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Repository | Where { $_.Name -eq $repoName } 
28
    Return $RepoData
41
    Return $RepoData
29
}
42
}
30
 
43
 
31
#
44
#
-
 
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
#
32
#   Get information on the current SVN server
53
#   Get information on the current SVN server
33
#
54
#
34
function GetSvnInfo()
55
function GetSvnInfo()
35
{
56
{
36
    $repoData = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Service
57
    $repoData = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Service
37
    Return $RepoData
58
    Return $RepoData
38
}
59
}
39
 
60
 
40
#
61
#
-
 
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
#
41
# Determine the root of the Repositores
94
# Determine the root of the Repositores
42
$SvnInfo = GetSvnInfo
95
$SvnInfo = GetSvnInfo
43
if ($SvnInfo -eq $null)
96
if ($SvnInfo -eq $null)
44
{
97
{
45
    Write-Error 'Cannot get VisualSVN info'
98
    Write-Error 'Cannot get VisualSVN info'
Line 63... Line 116...
63
 
116
 
64
    If (!(Test-Path ($hookPath + '/specialhooks')))
117
    If (!(Test-Path ($hookPath + '/specialhooks')))
65
    {
118
    {
66
 
119
 
67
        $HookFileCount = 0
120
        $HookFileCount = 0
68
 
-
 
69
        Get-ChildItem $HookSrc -Filter '*.cmd' | ForEach-Object {
121
        Get-ChildItem $HookSrc -Filter '*.cmd' | ForEach-Object {
70
            $srcFile = $_.Name
122
            $srcFile = $_.Name
71
            Copy-Item $_.FullName -Destination $hookPath 
123
            Copy-Item $_.FullName -Destination $hookPath 
72
            $HookFileCount++
124
            $HookFileCount++
73
        }
125
        }
Line 78... Line 130...
78
        Write-Host ("{0,20} : {1}" -f $repoName, "SPECIAL - No hooks copied")
130
        Write-Host ("{0,20} : {1}" -f $repoName, "SPECIAL - No hooks copied")
79
    }
131
    }
80
 
132
 
81
}
133
}
82
 
134
 
-
 
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