PowerShell/Scripts/clone-repos.ps1

40 lines
967 B
PowerShell
Raw Normal View History

2021-02-09 19:30:45 +01:00
#!/bin/powershell
2020-12-29 15:14:21 +01:00
<#
2021-02-28 18:49:53 +01:00
.SYNTAX ./clone-repos.ps1 [<target-dir>]
.DESCRIPTION clones well-known Git repositories into the current/given directory.
2020-12-29 15:14:21 +01:00
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
2020-12-01 12:24:56 +01:00
2021-02-28 18:49:53 +01:00
param($TargetDir = "$PWD")
2021-02-13 10:26:14 +01:00
try {
& git --version
} catch {
2021-02-15 12:00:23 +01:00
write-error "ERROR: can't execute 'git' - make sure Git is installed and available"
2021-02-13 10:26:14 +01:00
exit 1
}
2020-12-01 12:24:56 +01:00
2020-12-09 10:30:55 +01:00
try {
2021-02-13 10:26:14 +01:00
$PathToRepo = "$PSScriptRoot/.."
2021-01-20 16:11:38 +01:00
$Table = import-csv "$PathToRepo/Data/repos.csv"
2021-02-28 18:49:53 +01:00
set-location $TargetDir
2021-01-20 16:11:38 +01:00
foreach($Row in $Table) {
$URL = $Row.URL
2021-01-21 15:19:24 +01:00
$Directory = $Row.Directory
2021-01-20 16:11:38 +01:00
write-output ""
2021-02-22 08:19:03 +01:00
if (Test-Path $Directory) {
2021-02-13 10:26:14 +01:00
write-output "Skipping existing $Directory ..."
2021-01-21 15:19:24 +01:00
continue
}
2021-01-20 16:38:46 +01:00
write-output "Cloning from $URL..."
2021-02-13 10:26:14 +01:00
& git clone --recurse-submodules $URL
2021-02-15 12:00:23 +01:00
if ($lastExitCode -ne "0") { throw "'git clone $URL' failed" }
2020-12-01 12:24:56 +01:00
}
2020-12-09 10:30:55 +01:00
exit 0
} catch {
2021-02-15 12:00:23 +01:00
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2020-12-09 10:30:55 +01:00
exit 1
}