-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.ps1
37 lines (32 loc) · 1.19 KB
/
install.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
New-Module -name Installer -scriptblock {
function w() {
param (
[Parameter(Mandatory = $true)] $user,
[Parameter(Mandatory = $true)] $repo,
[string]$branch = "master",
[bool]$remove = $false
)
$zipFile = "$repo.zip"
$project = "$repo-$branch"
$reposUrl = "https://api.github.com/repos/$user/$repo"
$archiveUrl = "https://github.com/$user/$repo/archive/$branch.zip"
$statusCode = Invoke-WebRequest $reposUrl -UseBasicParsing | Select-Object -Expand StatusCode
if ($statusCode -eq 200) {
Invoke-WebRequest $archiveUrl -OutFile $zipFile
Expand-Archive -Path $zipFile -DestinationPath . -Force
Set-Location $project
if ($remove -eq $false) {
Start-Process .\setup.bat -Wait -NoNewWindow
}
else {
Start-Process .\setup.bat -ArgumentList "-r" -Wait -NoNewWindow
}
Set-Location ..
Remove-Item $zipFile, $project -Recurse
}
else {
Write-Error "$user/$repo repository not found"
}
}
Export-ModuleMember -function "w"
}