-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.ps1
185 lines (162 loc) · 5.96 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
$dir_home = $env:USERPROFILE
$dir_dotfiles = Join-Path $dir_home ".dotfiles"
$url_dotfiles = "https://github.com/leviosa42/dotfiles.git"
# ====================
# Utilities
# ====================
function Write-Log([string]$message) {
Write-Host "[LOG] $message" -ForegroundColor Gray
}
function Write-Info([string]$message) {
Write-Host "[INFO] $message" -ForegroundColor Cyan
}
function Write-Success([string]$message) {
Write-Host "[SUCCSS] $message" -ForegroundColor Green
}
function Write-Warning([string]$message) {
Write-Host "[WARN] $message" -ForegroundColor Yellow
}
function Write-Error([string]$message) {
Write-Host "[ERR] $message" -ForegroundColor Red
}
function New-Symlink([string]$target, [string]$link) {
if (Test-Path $link) {
Write-Warning "Remove-Item $link"
Remove-Item $link -Recurse
}
Write-Log "New-Symlink: $link -> $target"
New-Item -ItemType SymbolicLink -Path $link -Value $target > $null
}
function Set-EnvironmentVariable([string]$name, [string]$value) {
Write-Log "Set-EnvironmentVariable: $name $value"
# if([Environment]::GetEnvironmentVariable($name, "User") -eq $value) {
# return
# } else {
# [Environment]::SetEnvironmentVariable($name, $value, "User")
# }
[Environment]::SetEnvironmentVariable($name, $value, "User")
Invoke-Expression "`$env:${name} = `"$value`""
}
function New-Directory([string]$path) {
if (!(Test-Path $path)) {
Write-Log "New-Directory: $path"
New-Item -ItemType Directory -Path $path > $null
}
}
function Install-WinGetPackage([string]$package) {
Write-Log "Install-WinGetPackage: $package"
winget install -e --no-upgrade --accept-source-agreements $package
}
function Install-ScoopPackage([string]$package) {
Write-Log "Install-ScoopPackage: $package"
scoop install $package
}
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole("Administrators")) {
Write-Error "Please run this script as Administrator"
Pause
exit
}
# check winget is installed
if (Get-Command winget -ErrorAction SilentlyContinue) {
Write-Info "winget is installed"
# Microsoft.PowerToys
Install-WinGetPackage("Microsoft.PowerToys")
# Microsoft.PowerShell
Install-WinGetPackage("Microsoft.PowerShell")
# Microsoft.Office
# [NOTE]: maybe it is recommended to install from Microsoft Store...
# Install-WinGetPackage("Microsoft.Office")
# Microsoft.Edge
Install-WinGetPackage("Microsoft.Edge")
# Microsoft.WindowsTerminal
Install-WinGetPackage("Microsoft.WindowsTerminal")
# Microsoft.VisualStudioCode
Install-WinGetPackage("Microsoft.VisualStudioCode")
# Git.Git
Install-WinGetPackage("Git.Git")
# GitHub.cli
Install-WinGetPackage("GitHub.cli")
# Oracle.VirtualBox
Install-WinGetPackage("Oracle.VirtualBox")
# Oracle.MySQL
# Install-WinGetPackage("Oracle.MySQL")
# eza-community.eza
Install-WinGetPackage("eza-community.eza")
# FastCopy.FastCopy
Install-WinGetPackage("FastCopy.FastCopy")
# Readdle.Spark
Install-WinGetPackage("Readdle.Spark")
} else {
Write-Error "winget is not installed"
exit
}
# ====================
# Environment Variables
# ====================
# HOME
Set-EnvironmentVariable "HOME" "$dir_home"
# ENV (for busybox's .ashrc)
Set-EnvironmentVariable "ENV" "$dir_home\.config\.ashrc"
# XDG_Base_Directory
Set-EnvironmentVariable "XDG_CONFIG_HOME" "$dir_home\.config"
Set-EnvironmentVariable "XDG_CACHE_HOME" "$dir_home\.cache"
Set-EnvironmentVariable "XDG_DATA_HOME" "$dir_home\.local\share"
Set-EnvironmentVariable "XDG_STATE_HOME" "$dir_home\.local\state"
New-Directory "$env:XDG_CONFIG_HOME"
New-Directory "$env:XDG_CACHE_HOME"
New-Directory "$env:XDG_DATA_HOME"
New-Directory "$env:XDG_STATE_HOME"
# vim
Set-EnvironmentVariable "VIMINIT" "if !has('nvim') | so `$XDG_CONFIG_HOME\vim\dot.vimrc | else | so `$XDG_CONFIG_HOME\nvim\init.lua | endif"
# ipython/jupiter
Set-EnvironmentVariable "IPYTHONDIR" "$env:XDG_CONFIG_HOME\jupyter"
Set-EnvironmentVariable "JUPYTER_CONFIG_DIR" "$env:XDG_CONFIG_HOME\jupyter"
# go
Set-EnvironmentVariable "GOPATH" "$env:XDG_DATA_HOME\go"
# rust#cargo
Set-EnvironmentVariable "CARGO_HOME" "$env:XDG_DATA_HOME\cargo"
# rust#rustup
Set-EnvironmentVariable "RUSTUP_HOME" "$env:XDG_DATA_HOME\rustup"
# ====================
# dotfiles
# ====================
# check dotfiles is cloned
if (!(Test-Path $dir_dotfiles)) {
Write-Info "git clone $url_dotfiles $dir_dotfiles"
git clone $url_dotfiles $dir_dotfiles
}
# # New-Symlink "$dir_dotfiles\.config\vim\dot.vimrc" "$dir_home\.vimrc"
# dotfiles\.config\nyagos\dot.nyagos -> %HOME%\.nyagos
New-Symlink "$dir_dotfiles\.config\nyagos\dot.nyagos" "$dir_home\.nyagos"
# Symlink each directory from $dir_dotfiles\.config\* to $env:XDG_CONFIG_HOME\*
# excludes: vscode, wt,
Get-ChildItem "$dir_dotfiles\.config" -Directory | Where-Object { $_.Name -notin @("vscode", "wt") } | ForEach-Object {
New-Symlink $_.FullName "$env:XDG_CONFIG_HOME\$($_.Name)"
}
# vscode
New-Symlink "$dir_dotfiles\.config\vscode\settings.json" "$env:APPDATA\Code\User\settings.json"
# New-Symlink "$dir_dotfiles\.config\vscode\keybindings.json" "$env:APPDATA\Code\User\keybindings.json"
# New-Symlink "$dir_dotfiles\.config\vscode\snippets" "$env:APPDATA\Code\User\snippets"
# wt(Windows Terminal)
New-Symlink "$dir_dotfiles\.config\wt\settings.json" "$env:USERPROFILE\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json"
# ====================
# scoop
# ====================
# check scoop is installed
if (!(Get-Command scoop -ErrorAction SilentlyContinue)) {
# bootstrap scoop
Invoke-Expression (new-object net.webclient).downloadstring('https://get.scoop.sh')
}
# ====================
# scoop
# ====================
# 7zip
Install-ScoopPackage("7zip")
# aria2
Install-ScoopPackage("aria2")
# vim
Install-ScoopPackage("vim")
# bat
Install-ScoopPackage("bat")
# nyagos
Install-ScoopPackage("nyagos")