-
Notifications
You must be signed in to change notification settings - Fork 153
/
install.ps1
64 lines (53 loc) · 2.34 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
$account = "jayharris"
$repo = "dotfiles-windows"
$branch = "master"
$dotfilesTempDir = Join-Path $env:TEMP "dotfiles"
if (![System.IO.Directory]::Exists($dotfilesTempDir)) {[System.IO.Directory]::CreateDirectory($dotfilesTempDir)}
$sourceFile = Join-Path $dotfilesTempDir "dotfiles.zip"
$dotfilesInstallDir = Join-Path $dotfilesTempDir "$repo-$branch"
function Download-File {
param (
[string]$url,
[string]$file
)
Write-Host "Downloading $url to $file"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri $url -OutFile $file
}
function Unzip-File {
param (
[string]$File,
[string]$Destination = (Get-Location).Path
)
$filePath = Resolve-Path $File
$destinationPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Destination)
If (($PSVersionTable.PSVersion.Major -ge 3) -and
(
[version](Get-ItemProperty -Path "HKLM:\Software\Microsoft\NET Framework Setup\NDP\v4\Full" -ErrorAction SilentlyContinue).Version -ge [version]"4.5" -or
[version](Get-ItemProperty -Path "HKLM:\Software\Microsoft\NET Framework Setup\NDP\v4\Client" -ErrorAction SilentlyContinue).Version -ge [version]"4.5"
)) {
try {
[System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") | Out-Null
[System.IO.Compression.ZipFile]::ExtractToDirectory("$filePath", "$destinationPath")
} catch {
Write-Warning -Message "Unexpected Error. Error details: $_.Exception.Message"
}
} else {
try {
$shell = New-Object -ComObject Shell.Application
$shell.Namespace($destinationPath).copyhere(($shell.NameSpace($filePath)).items())
} catch {
Write-Warning -Message "Unexpected Error. Error details: $_.Exception.Message"
}
}
}
Download-File "https://github.com/$account/$repo/archive/$branch.zip" $sourceFile
if ([System.IO.Directory]::Exists($dotfilesInstallDir)) {[System.IO.Directory]::Delete($dotfilesInstallDir, $true)}
Unzip-File $sourceFile $dotfilesTempDir
Push-Location $dotfilesInstallDir
& .\bootstrap.ps1
Pop-Location
$newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
$newProcess.Arguments = "-nologo";
[System.Diagnostics.Process]::Start($newProcess);
exit