nuscripts/tools/herotools.nu
2024-01-13 13:51:29 +00:00

131 lines
4.3 KiB
Plaintext

use git.nu
use download.nu
use runonce.nu
def sshagent_loaded [ ] bool {
return ( (ssh-add -l | lines -s | length) > 0 )
}
def url_crystal [] {
let $ssha = sshagent_loaded
if $ssha {
return "git@github.com:freeflowuniverse/crystallib.git"
} else {
return "https://github.com/freeflowuniverse/crystallib"
}
}
def url_webcomponents [] {
let $ssha = sshagent_loaded
if $ssha {
return "git@github.com:freeflowuniverse/webcomponents.git"
} else {
return "https://github.com/freeflowuniverse/webcomponents"
}
}
export def install_crystal [ --reset=false , --pull=false ] string {
let $vpath = install_v
let $url = url_crystal
let $crlibpath = git git_clone crystallib $url --reset=$reset --pull=$pull
let $weburl = url_webcomponents
let $webpath = git git_clone webcomponents $weburl --reset=$reset --pull=$pull
let $vmodpath = $"($env.BASE)/.vmodules"
mkdir $"($vmodpath)/freeflowuniverse"
rm -f $"($vmodpath)/freeflowuniverse/crystallib"
rm -f $"($vmodpath)/freeflowuniverse/webcomponents"
ln -s $"($crlibpath)/crystallib" $"($vmodpath)/freeflowuniverse/crystallib"
ln -s $"($webpath)/webcomponents" $"($vmodpath)/freeflowuniverse/webcomponents"
return $crlibpath
}
export def clone_nuscripts [ --reset=false , --pull=false ] string {
let $ssha = sshagent_loaded
let $dest = $"($env.BASE)/nuscripts"
let $dest_org = $"($env.BASE)/nushell"
if $ssha {
let $r = git git_clone nuscripts "git@git.ourworld.tf:despiegk/nuscripts.git" --reset=$reset --pull=$pull
rm -f $dest
ln -s $r $dest
return $r
} else {
error make { msg: "load ssh-agent" }
}
}
export def install_v [ --reset=false , --pull=false ] string {
let $vpath = git git_clone v "https://github.com/vlang/v"
runonce run 'install_v' {
cd $vpath
print "will compile V, can take a long while."
^make
} --reset $reset
rm -f $"($env.BASE)/bin/v"
ln -s $"($vpath)/v" $"($env.BASE)/bin/v"
return $vpath
}
def url_mycelium [] string {
let $os = $nu.os-info.name
let $arch = $nu.os-info.arch
if $os == "macos" {
if $arch == "aarch64" {
return "https://github.com/threefoldtech/mycelium/releases/download/v0.2.3/mycelium-aarch64-apple-darwin.tar.gz"
} else if $arch == "x86_64" {
return "https://github.com/threefoldtech/mycelium/releases/download/v0.2.3/mycelium-x86_64-apple-darwin.tar.gz"
}
} else if $os == "linux" {
if $arch == "aarch64" {
return "https://github.com/threefoldtech/mycelium/releases/download/v0.2.3/mycelium-aarch64-unknown-linux-musl.tar.gz"
} else if $arch == "x86_64" {
return "https://github.com/threefoldtech/mycelium/releases/download/v0.2.3/mycelium-x86_64-unknown-linux-musl.tar.gz"
}
} else {
error make { msg: "only support darwin & linux" }
}
}
export def install_mycelium [] {
let $name = "mycelium"
let tmppath = $"/tmp/($name)"
let $bin_dir = $"($env.BASE)/bin"
mkdir $bin_dir
let $url = url_mycelium
print $url
download download_expand $tmppath $"($url)" --minsize 2
mv -f $"($tmppath)/($name)" $"($bin_dir)/($name)"
chmod +x $"($bin_dir)/($name)"
}
def url_hero [] string {
let $os = $nu.os-info.name
let $arch = $nu.os-info.arch
if $os == "macos" {
if $arch == "aarch64" {
return "https://f003.backblazeb2.com/file/threefold/macos-arm64/hero"
} else if $arch == "x86_64" {
return "https://f003.backblazeb2.com/file/threefold/macos-i64/hero"
}
} else if $os == "linux" {
if $arch == "aarch64" {
error make { msg: "find url for hero on linux arm" }
} else if $arch == "x86_64" {
return "https://f003.backblazeb2.com/file/threefold/linux-i64/hero"
}
} else {
error make { msg: "only support darwin & linux" }
}
}
export def install_hero [] {
let $name = "hero"
runonce run $'install_($name)' {
let $destpath = $"($env.BASE)/bin/hero"
let $url = url_hero
print $url
download download_do $destpath $"($url)" --minsize 4
chmod +x $destpath
}
}