-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.nu
39 lines (33 loc) · 1.82 KB
/
build.nu
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
use std log
def addcap [binpath: path] {
if ($nu.os-info.name == "linux") {
print $"(ansi red)Warning(ansi reset): To access the PIDs of applications running as root or other users, you need to add the following capabilities to the plugin binary: net_admin, sys_ptrace, dac_read_search."
print $"(ansi red)sudo setcap 'cap_net_admin,cap_sys_ptrace,cap_dac_read_search=ep' '($binpath)'(ansi reset)"
print "Do you want to run this command with sudo? [y/N]"
match (input listen --types [key]) {
{code: $key} if ($key | str downcase) == "y" => {
let caps = (['cap_net_admin', 'cap_sys_ptrace', 'cap_dac_read_search'] | input list --multi "Choose which specific capabilities you want to add" | str join ",")
let cmd = $"setcap '($caps)=ep' '($binpath)'"
print $"Executing `($cmd)` with sudo."
sh -c $"sudo ($cmd)"
}
_ => {
print "If you prefer to add the capabilities manually, use the following command:"
print $"sudo setcap 'cap_net_admin,cap_sys_ptrace,cap_dac_read_search=ep' '($binpath)'"
}
}
}
}
def main [package_file: path] {
let repo_root = $package_file | path dirname
let install_root = $env.NUPM_HOME | path join "plugins"
let name = open ($repo_root | path join "Cargo.toml") | get package.name
let cmd = $"cargo install --path ($repo_root) --root ($install_root)"
log info $"building plugin using: (ansi blue)($cmd)(ansi reset)"
nu -c $cmd
let ext: string = if ($nu.os-info.name == 'windows') { '.exe' } else { '' }
let bin_path = $"($install_root | path join "bin" $name)($ext)"
plugin add $bin_path
addcap $bin_path
log info "do not forget to restart Nushell for the plugin to be fully available!"
}