-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.ps1
64 lines (51 loc) · 1.99 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
64
<#
.SYNOPSIS
Install chezmoi (and optionally starship) and apply the dotfiles.
.EXAMPLE
.\install.ps1 -All -BinDir C:\bin -WithoutStarship
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $false)]
[switch]
$All,
[Parameter(Mandatory = $false)]
[string]
$BinDir = "~\.local\bin",
[Parameter(Mandatory = $false)]
[switch]
$WithoutStarship
)
$ChezmoiBin = "chezmoi.exe"
# Install chezmoi
if (-not (Get-Command $ChezmoiBin -ErrorAction SilentlyContinue)) {
$ChezmoiBin = [IO.Path]::Combine($BinDir, "chezmoi.exe")
Invoke-Expression "&{$(Invoke-RestMethod 'https://get.chezmoi.io/ps1')} -b '$BinDir'"
}
# Install Starship
if ((-not $WithoutStarship) -and (-not (Get-Command "starship.exe" -ErrorAction SilentlyContinue))) {
if (-not (Test-Path -PathType Container $BinDir)) {
New-Item -ItemType Directory -Force -Path $BinDir
}
$ZipFile = [IO.Path]::Combine($env:Temp, "starship.zip")
$LatestReleaseReq = Invoke-WebRequest -Uri "https://github.com/starship/starship/releases/latest" -Method Head
if ($LatestReleaseReq.BaseResponse.ResponseUri -ne $null) {
# PowerShell 5
$RedirectUri = $LatestReleaseReq.BaseResponse.ResponseUri.AbsoluteUri
} elseif ($LatestReleaseReq.BaseResponse.RequestMessage.RequestUri -ne $null) {
# PowerShell core
$RedirectUri = $LatestReleaseReq.BaseResponse.RequestMessage.RequestUri.AbsoluteUri
} else {
Write-Error "Couldn't retrieve the latest Starship release URL" -ErrorAction Stop
}
$DownloadUri = ($RedirectUri -Replace "\/tag\/", "/download/") + "/starship-x86_64-pc-windows-msvc.zip"
Invoke-WebRequest -Uri $DownloadUri -OutFile $ZipFile
Expand-Archive -LiteralPath $ZipFile -DestinationPath $BinDir
Remove-Item -Path $ZipFile -Force
}
if ($All) {
$Exclude = ""
} else {
$Exclude = "--exclude=encrypted"
}
& $ChezmoiBin init --apply --source="$PSScriptRoot" $Exclude