-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.ps1
123 lines (109 loc) · 4.01 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
$Base = "$HOME\.dotfiles"
if ($PSEdition -ne 'Core') {
Write-Host "Install the pre-requisites from the Microsoft Store first."
write-Host
return
}
Write-Host "Installing dotfiles to $Base ..."
Write-Host
# Bootstrap scoop
if (-not (Get-Command scoop)) {
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
& scoop install git
# Install scoop apps
$ScoopApps = Get-Content "$Base/Scoopfile"
& scoop bucket add extras
& scoop bucket add java
& scoop bucket add versions
& scoop install @ScoopApps
}
# Bootstrap winget
& winget install --id Microsoft.OpenSSH.Preview
# Bootstrap this repository
if (-not (Test-Path $Base)) {
& git clone https://github.com/wjrogers/dotfiles.git "$Base"
& git -C "$Base" submodule update --init
& git -C "$Base" remote set-url origin [email protected]:wjrogers/dotfiles.git
}
# Configure services
$Services = @{
"ssh-agent" = "Disabled"
"sshd" = "Disabled"
}
foreach ($Service in $Services.Keys) {
$DesiredStartType = $Services[$Service]
$ServiceObject = Get-Service $Service
if ($ServiceObject -and $ServiceObject.StartType -ne $DesiredStartType -and $DesiredStartType -eq "Automatic") {
Start-Process powershell.exe -Verb RunAs -Wait -ArgumentList @"
-Command & {
Set-Service $Service -StartupType $DesiredStartType
Start-Service $Service -PassThru | Format-List *
pause
}
"@
} elseif ($ServiceObject -and $ServiceObject.StartType -ne $DesiredStartType) {
Start-Process powershell.exe -Verb RunAs -Wait -ArgumentList @"
-Command & {
Set-Service $Service -StartupType $DesiredStartType
Stop-Service $Service -PassThru | Format-List *
pause
}
"@
} elseif (-not $ServiceObject) {
Write-Error "Service '$Service' not found."
}
$ServiceObject = $null
}
# Symlinks
$Links = @{
"$Profile" = "$Base/powershell/Microsoft.PowerShell_profile.ps1"
"$Env:LOCALAPPDATA/Microsoft/Windows Terminal/Fragments/nord" = "$Base/terminal/nord"
"$Env:LOCALAPPDATA/Packages/Microsoft.WindowsTerminal_8wekyb3d8bbwe/LocalState/settings.json" = "$Base/terminal/settings.json"
"$Env:APPDATA/mintty/config" = "$Base/mintty/config"
"$Env:APPDATA/wsltty/config" = "$Base/mintty/config"
"$HOME/.gitconfig" = "$Base/home/.gitconfig"
"$HOME/.gvimrc" = "$Base/home/.gvimrc"
"$HOME/.vimrc" = "$Base/home/.vimrc"
"$HOME/.vim" = "$Base/home/.vim"
"$HOME/.vsvimrc" = "$Base/vsvimrc"
"$HOME/vimfiles" = "$Base/home/.vim"
"$Env:LOCALAPPDATA/nvim" = "$Base/home/.config/nvim"
}
foreach ($Source in $Links.Keys) {
$Target = Resolve-Path $Links[$Source]
New-Item -Force -ItemType SymbolicLink -Path "$Source" -Target "$Target"
if (-not $?) {
throw "Try enabling Developer Mode in Windows Settings."
}
}
# Environment -- Machine
$SystemPathBlocklist = @(
"$($Env:SystemRoot)\System32\OpenSSH"
)
$SystemPath = [System.Environment]::GetEnvironmentVariable("PATH", "Machine").Split(";")
$SystemPathModified = $SystemPath | Where-Object { $SystemPathBlocklist -notcontains $_ }
$SystemPathItemsRemoved = $SystemPath | Where-Object { $SystemPathModified -notcontains $_ }
foreach ($item in $SystemPathItemsRemoved) {
Write-Host "Please remove '$item' from the system PATH!"
}
# Environment (nulls delete old stuff if it's still around)
$Environment = @{
"DOTFILES_HOME" = $Base
"GITHUB_TOKEN" = $null
"GITHUB_USER" = $null
"GIT_SSH" = "C:\Program Files\OpenSSH\ssh.exe"
"HOME" = $null
"HTML_TIDY" = (Resolve-Path "$Base/home/.tidyrc")
"RIPGREP_CONFIG_PATH" = (Resolve-Path "$Base/home/.ripgreprc")
"TERM" = $null
}
foreach ($Key in $Environment.Keys) {
$Value = $Environment[$Key]
[System.Environment]::SetEnvironmentVariable($Key, $Value, "User")
Set-Item "Env:$Key" "$Value"
}
# Modules
Install-Module -Scope CurrentUser PSFzf
# Done!
Write-Host "Bootstrapping complete."
Write-Host