-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.nu
More file actions
executable file
·336 lines (315 loc) · 10.2 KB
/
install.nu
File metadata and controls
executable file
·336 lines (315 loc) · 10.2 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#!/usr/bin/env nu
def command_exists [cmd: string] {
(which $cmd | length) > 0
}
let is_linux = (uname | get kernel-name | str downcase) == "linux"
let is_macos = (uname | get kernel-name | str downcase) == "darwin"
let is_windows = (uname | get kernel-name | str downcase) == "windows_nt"
let is_x86_64 = (uname | get machine) == "x86_64"
let is_aarch64 = (uname | get machine) == "aarch64" or (uname | get machine) == "arm64"
mut requirements = if $is_linux {
{
"git": "git",
"make": "build-essential",
"pkg-config": "pkg-config",
"autoconf": "autoconf",
"gawk": "gawk",
}
} else if $is_macos {
{
"git": "git",
"make": "make",
"pkg-config": "pkg-config",
"autoconf": "autoconf",
"gawk": "gawk",
}
} else {
{
"git": "Git.Git"
}
}
mut missing = []
for $cmd in ($requirements | columns) {
if not (command_exists $cmd) {
$missing = $missing ++ [$cmd]
}
}
if ($missing | length) > 0 {
print $"Please install the following packages first:"
for pkg in $missing {
print $" - ($requirements | get $pkg) for command ($pkg)"
}
if $is_windows {
print "Run:"
print -n " winget install"
for pkg in $missing {
print -n $" ($requirements | get $pkg)"
}
print ""
} else if $is_macos {
print "You can install them using Homebrew:"
print -n " brew install"
for pkg in $missing {
print -n $" ($requirements | get $pkg)"
}
print ""
} else if $is_linux {
print "You can install them using your package manager, e.g., on Debian/Ubuntu:"
print -n " sudo apt-get install"
for pkg in $missing {
print -n $" ($requirements | get $pkg)"
}
print ""
}
exit 1
}
print "All required commands are available."
if $is_linux {
let ruby_build_requirements = {
"openssl": "libssl-dev",
"yaml-0.1": "libyaml-dev",
"zlib": "zlib1g-dev",
"libffi": "libffi-dev",
"gmp": "libgmp-dev",
}
mut missing_ruby_build = []
for $pkg in ($ruby_build_requirements | columns) {
if (try {
pkg-config --exists $pkg
false
} catch {
true
}) {
$missing_ruby_build = $missing_ruby_build ++ [($ruby_build_requirements | get $pkg)]
}
}
if ($missing_ruby_build | length) > 0 {
print $"Please install the following packages for ruby-build first:"
for pkg in $missing_ruby_build {
print $" - ($pkg)"
}
print "On Debian/Ubuntu, you can run:"
print -n " sudo apt-get install"
for pkg in $missing_ruby_build {
print -n $" ($pkg)"
}
exit 1
}
} else if $is_macos {
let ruby_build_requirements = [
"openssl@3",
"readline",
"libyaml",
"gmp",
"autoconf"
]
mut missing_ruby_build = []
for pkg in $ruby_build_requirements {
if (try {
brew list $pkg
false
} catch {
true
}) {
$missing_ruby_build = $missing_ruby_build ++ [$pkg]
}
}
if ($missing_ruby_build | length) > 0 {
print $"Please install the following Homebrew packages for ruby-build first:"
for pkg in $missing_ruby_build {
print $" - ($pkg)"
}
print "You can run:"
print -n " brew install"
for pkg in $missing_ruby_build {
print -n $" ($pkg)"
}
print ""
exit 1
}
}
let dotfiles_install_path = ($env.DOTFILES_INSTALL_PATH? | default "~/dotfiles") | path expand
if ($dotfiles_install_path | path exists) {
print $"Dotfiles installation path ($dotfiles_install_path) already exists."
git -C $dotfiles_install_path pull
} else {
print $"Cloning dotfiles to ($dotfiles_install_path)"
git clone https://github.com/sevenc-nanashi/dotfiles $dotfiles_install_path
}
cd $dotfiles_install_path
def download [url: string, dest?: string] {
if $dest == null {
try {
http -r $url
} catch {
curl -sSL $url
}
} else {
let dest_path = ($dest | path expand)
if not ($dest_path | path dirname | path exists) {
mkdir ($dest_path | path dirname)
}
try {
http $url o> $dest_path
} catch {
curl -sSL $url -o $dest_path
}
}
}
if not (command_exists "rustup") {
print "Installing rustup"
download https://sh.rustup.rs | sh -s -- -y
if $is_windows {
$env.PATH = ($env.PATH | prepend $"($env.USERPROFILE)\\.cargo\\bin")
} else {
$env.PATH = ($env.PATH | prepend $"($env.HOME)/.cargo/bin")
}
}
if not (command_exists "nvim") {
print "Installing nightly nvim"
let nvim_bin = ("~/.local/bin/nvim" | path expand)
if $is_linux {
let nvim_variant = if $is_x86_64 {
"linux-x86_64"
} else if $is_aarch64 {
"linux-aarch64"
} else {
print "Unsupported architecture for nvim nightly"
exit 1
}
download $"https://github.com/neovim/neovim/releases/download/nightly/nvim-($nvim_variant).appimage" $nvim_bin
chmod +x $nvim_bin
} else if $is_macos {
let nvim_variant = if $is_x86_64 {
"macos-x86_64"
} else if $is_aarch64 {
"macos-arm64"
} else {
print "Unsupported architecture for nvim nightly"
exit 1
}
download $"https://github.com/neovim/neovim/releases/download/nightly/nvim-($nvim_variant).tar.gz" /tmp/nvim.tar.gz
let nvim_install_dir = ($env.NVIM_INSTALL_DIR? | default "~/nvim-nightly") | path expand
tar -xzf /tmp/nvim.tar.gz -C /tmp
mkdir $nvim_install_dir
mv $"/tmp/nvim-(nvim_variant)"/* $nvim_install_dir
if not ($nvim_bin | path dirname | path exists) {
mkdir ($nvim_bin | path dirname)
}
ln -s ($nvim_install_dir | path join "bin" "nvim") $nvim_bin
} else if $is_windows {
print "Nightly nvim is available here:"
print "https://github.com/neovim/neovim/releases/nightly"
} else {
print "Unsupported host for nvim nightly"
}
}
print "Installing vim-jetpack"
let jetpack_path = if $is_windows {
$"($env.LOCALAPPDATA)\\nvim-data\\site\\pack\\jetpack\\opt\\vim-jetpack\\plugin\\jetpack.vim"
} else {
"~/.local/share/nvim/site/pack/jetpack/opt/vim-jetpack/plugin/jetpack.vim"
}
download https://raw.githubusercontent.com/tani/vim-jetpack/master/plugin/jetpack.vim $jetpack_path
# Needs sudo
# TODO: better way to handle Homebrew installation
# print "Installing Homebrew"
# curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh | bash
print "Creating symbolic links for configuration files"
def link [src: string, dest: string] {
let src_path = ($src | path expand -n)
let dest_path = ($dest | path expand -n)
let dest_realpath = (try {
$dest_path | path expand
} catch {
""
})
if $dest_realpath == $src_path {
print $"($dest_path) already symlinked, skipping"
return
}
if ($dest_path | path exists) {
print $"Backing up existing file ($dest_path) to ($dest_path).bak"
mv $dest_path $"($dest_path).bak"
}
print $"Linking ($src_path) to ($dest_path)"
if not ($dest_path | path dirname | path exists) {
mkdir ($dest_path | path dirname)
}
ln -s $src_path $dest_path
}
link ($dotfiles_install_path | path join ".bashrc") ~/.bashrc
link ($dotfiles_install_path | path join "neovim") ~/.config/nvim
link ($dotfiles_install_path | path join ".irbrc") ~/.irbrc
link ($dotfiles_install_path | path join global_agents.md) ~/.codex/AGENTS.md
link ($dotfiles_install_path | path join ".gitconfig") ~/.gitconfig
link ($dotfiles_install_path | path join ".gitignore_global") ~/.gitignore_global
link ($dotfiles_install_path | path join "starship.toml") ~/.config/starship.toml
link ($dotfiles_install_path | path join "bat.config") ~/.config/bat/config
link ($dotfiles_install_path | path join "gh.config.yml") ~/.config/gh/config.yml
link ($dotfiles_install_path | path join "mise") ~/.config/mise
link ($dotfiles_install_path | path join "nushell") ($nu.config-path | path dirname)
link ($dotfiles_install_path | path join "online-judge-tools") ~/.config/online-judge-tools
print "Installing tools managed by mise"
let mise_path = ($env.MISE_PATH? | (which mise).0?.path | default "~/.local/bin/mise") | path expand
let mise_bin_dir = ($mise_path | path dirname)
if ($mise_bin_dir | path exists) {
$env.PATH = ($env.PATH | prepend $mise_bin_dir)
}
let mise_shims_dir = ("~/.local/share/mise/shims" | path expand)
$env.PATH = ($env.PATH | prepend $mise_shims_dir)
^($mise_path) trust .
^($mise_path) settings experimental=true # Why not?
^($mise_path) settings lockfile=true
# ^($mise_path) install
print "Install neovim plugins"
if $is_linux {
$env.APPIMAGE_EXTRACT_AND_RUN = "1"
}
nvim --headless +JetpackSync +qall
# print "Installing carapace overlay"
# # carapace e>| parse -r 'Config is written to \[(?<config_dir>.+)\]'
# let config_dir = (carapace e>| parse -r 'Config is written to \[(?<config_dir>.+)\]' | get 0.config_dir | str trim)
# print $"Carapace config directory: ($config_dir)"
# link ($dotfiles_install_path | path join "carapace") ($config_dir | path join "overlays")
print "Creating symbolic links for custom binaries"
let local_bin_dir = ("~/.local/bin" | path expand)
let bin_dir = ($dotfiles_install_path | path join "bin")
for file in (ls $bin_dir | get name) {
link $file ($local_bin_dir | path join ($file | path basename))
chmod +x ($local_bin_dir | path join ($file | path basename))
}
if ($is_linux or $is_macos) {
print "Installing ble.sh"
let blesh_path = ("~/.local/share/ble.sh" | path expand)
if ($blesh_path | path exists) {
print "ble.sh already installed, skipping"
} else {
git clone --recursive --depth 1 --shallow-submodules https://github.com/akinomyoga/ble.sh.git $blesh_path
let local_prefix = ("~/.local" | path expand)
make -C $blesh_path install $"PREFIX=($local_prefix)"
}
}
print "Setting up git remote to use SSH"
git -C $dotfiles_install_path remote set-url origin git@github.com:sevenc-nanashi/dotfiles.git
print "Adding SSH keys from GitHub"
let ssh_dir = ("~/.ssh" | path expand)
if not ($ssh_dir | path exists) {
mkdir $ssh_dir
}
let ssh_keys = (download https://github.com/sevenc-nanashi.keys | str trim)
let current_authorized_keys = if ($ssh_dir | path join "authorized_keys" | path exists) {
($ssh_dir | path join "authorized_keys") | open | str trim
} else {
""
}
for key in ($ssh_keys | lines) {
if not ($current_authorized_keys | str contains $key) {
print $"Adding key: ($key)"
echo $key o>> ($ssh_dir | path join "authorized_keys")
} else {
print $"Key already exists, skipping: ($key)"
}
}
echo "Installation complete!"
download https://sevenc7c.com