This commit is contained in:
despiegk 2024-01-13 13:19:52 +03:00
parent 833d3eeb43
commit 08dfdc6fa4
Signed by: despiegk
GPG Key ID: 99E4E1492F73BC18
6 changed files with 73 additions and 42 deletions

View File

@ -5,5 +5,12 @@
```bash ```bash
#following will start your virtual shell #following will start your virtual shell
start.sh start.sh
#then in the shell open the hero shell (based on nushell, will set all paths to make this dir sandboxed)
./hero_shell.sh
#if you want hero and mycelium do
herotools install_hero
#if you want mycelium
herotools install_mycelium
``` ```

View File

@ -1,6 +1,6 @@
use tools/varia.nu use tools/download.nu
use tools/runonce.nu use tools/runonce.nu
use tools/extractors.nu
use tools/git.nu use tools/git.nu
use tools/herotools.nu

View File

@ -1,3 +1,4 @@
# Function to extract archives with different extensions. # Function to extract archives with different extensions.
export def extract [path:string] { export def extract [path:string] {
let $destdir = $path | path dirname let $destdir = $path | path dirname
@ -32,4 +33,54 @@ export def extract [path:string] {
cd $destdir cd $destdir
nu -c ($handler.command + ' ' + $name) nu -c ($handler.command + ' ' + $name)
} }
} }
export def "download_do" [ dest: string url: string , --minsize=1] {
let $destdir = $dest | path dirname
mkdir $destdir
print $"download url:($url) to dest:($dest)"
# Download the file
http get $url | save -f $dest
let minsize = $minsize * 1000000
if ($minsize > 0) {
let p = ls $dest
if (($p.size | into int).0 < $minsize) {
print $"The download was too small for ($dest)"
exit 1
} else {
print $"Download ok for ($dest)"
}
}
# echo $"File size: $file_size bytes"
}
export def "download_expand" [ dest: string url: string , --minsize=1] {
mkdir $dest
print $"download expand url:($url) to dest:($dest)"
let $file_name = $url | split row '/' | last
let $ext = $file_name | split row '.' | skip 1 | | str join "." | str downcase
let $dest2 = $"($dest)/downloadedfile.($ext)"
print $dest2
download_do $dest2 $url --minsize=$minsize
let $e = extract $dest2
}
# export def init_plugins [] {
# runonce run init_plugins {
# register bin/nu_plugin_dns
# register bin/nu_plugin_desktop_notifications
# register bin/nu_plugin_net
# register bin/nu_plugin_port_list
# register bin/nu_plugin_port_scan
# register bin/nu_plugin_query
# } --reset true
# }

View File

@ -1,5 +1,5 @@
use git.nu use git.nu
use varia.nu use download.nu
def url_crystal [] { def url_crystal [] {
let $ssha = sshagent_loaded let $ssha = sshagent_loaded
@ -12,14 +12,14 @@ def url_crystal [] {
export def clone_crystal [ --reset=false , --pull=false ] string { export def clone_crystal [ --reset=false , --pull=false ] string {
let $url = url_crystal let $url = url_crystal
let $r = git_clone crystallib $url let $r = git git_clone crystallib $url
return $r return $r
} }
let os = $nu.os-info.name
let arch = $nu.os-info.arch
def url_mycelium [] string { def url_mycelium [] string {
let $os = $nu.os-info.name
let $arch = $nu.os-info.arch
if $os == "macos" { if $os == "macos" {
if $arch == "aarch64" { if $arch == "aarch64" {
return "https://github.com/threefoldtech/mycelium/releases/download/v0.2.3/mycelium-aarch64-apple-darwin.tar.gz" return "https://github.com/threefoldtech/mycelium/releases/download/v0.2.3/mycelium-aarch64-apple-darwin.tar.gz"
@ -37,20 +37,22 @@ def url_mycelium [] string {
} }
} }
def install_mycelium [] { export def install_mycelium [] {
let $name = "mycelium" let $name = "mycelium"
let tmppath = $"/tmp/($name)" let tmppath = $"/tmp/($name)"
let $bin_dir = $"($env.BASE)/bin" let $bin_dir = $"($env.BASE)/bin"
mkdir $bin_dir mkdir $bin_dir
let $url = url_mycelium let $url = url_mycelium
print $url print $url
download_expand $tmppath $"($url)" --minsize 2 download download_expand $tmppath $"($url)" --minsize 2
mv $"($tmppath)/($name)" $"($bin_dir)/($name)" mv -f $"($tmppath)/($name)" $"($bin_dir)/($name)"
chmod +x $"($bin_dir)/($name)" chmod +x $"($bin_dir)/($name)"
} }
def url_hero [] string { def url_hero [] string {
let $os = $nu.os-info.name
let $arch = $nu.os-info.arch
if $os == "macos" { if $os == "macos" {
if $arch == "aarch64" { if $arch == "aarch64" {
return "https://f003.backblazeb2.com/file/threefold/macos-arm64/hero" return "https://f003.backblazeb2.com/file/threefold/macos-arm64/hero"
@ -68,11 +70,11 @@ def url_hero [] string {
} }
} }
def install_hero [] { export def install_hero [] {
let $name = "hero" let $name = "hero"
let $destpath = $"($env.BASE)/bin/hero" let $destpath = $"($env.BASE)/bin/hero"
let $url = url_hero let $url = url_hero
print $url print $url
download $destpath $"($url)" --minsize 4 download download_do $destpath $"($url)" --minsize 4
chmod +x $destpath chmod +x $destpath
} }

View File

@ -1,28 +0,0 @@
export def init [] {
let envpath = $env.PATH
| where ($it | str contains -n '.apple.security')
| where ($it | str contains -n 'Cryptexes')
| where ($it | str contains -n 'dotnet')
| where ($it | str contains -n -i 'gpg')
| append ($env.HOME | path join .cargo/bin)
| append ($env.HOME | path join hero/bin)
| uniq
| sort
load-env {PATH:$envpath}
}
# runonce once 'lls' { ls / } --reset true
# let envpath = $env.PATH
# | where ($it | str contains -n '.apple.security')
# | where ($it | str contains -n 'Cryptexes')
# | where ($it | str contains -n 'dotnet')
# | where ($it | str contains -n -i 'gpg')
# | append ($env.HOME | path join .cargo/bin)
# | append ($env.HOME | path join hero/bin)
# | uniq
# | sort
# load-env {PATH:$envpath}

View File

@ -1,5 +1,4 @@
use runonce.nu # use runonce.nu
use extractors.nu
export def "cargo search" [ query: string, --limit=10] { export def "cargo search" [ query: string, --limit=10] {