diff --git a/README.md b/README.md index 5f196f3..cc10fc2 100644 --- a/README.md +++ b/README.md @@ -5,5 +5,12 @@ ```bash #following will start your virtual shell 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 + ``` diff --git a/nushell/load.nu b/nushell/load.nu index 42afd77..6a514ca 100644 --- a/nushell/load.nu +++ b/nushell/load.nu @@ -1,6 +1,6 @@ -use tools/varia.nu +use tools/download.nu use tools/runonce.nu -use tools/extractors.nu use tools/git.nu +use tools/herotools.nu diff --git a/nushell/tools/extractors.nu b/nushell/tools/download.nu similarity index 50% rename from nushell/tools/extractors.nu rename to nushell/tools/download.nu index 8268291..148c155 100644 --- a/nushell/tools/extractors.nu +++ b/nushell/tools/download.nu @@ -1,3 +1,4 @@ + # Function to extract archives with different extensions. export def extract [path:string] { let $destdir = $path | path dirname @@ -32,4 +33,54 @@ export def extract [path:string] { cd $destdir nu -c ($handler.command + ' ' + $name) } -} \ No newline at end of file +} + + +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 +# } + diff --git a/nushell/tools/hero.nu b/nushell/tools/herotools.nu similarity index 83% rename from nushell/tools/hero.nu rename to nushell/tools/herotools.nu index 896befa..a8aea23 100644 --- a/nushell/tools/hero.nu +++ b/nushell/tools/herotools.nu @@ -1,5 +1,5 @@ use git.nu -use varia.nu +use download.nu def url_crystal [] { let $ssha = sshagent_loaded @@ -12,14 +12,14 @@ def url_crystal [] { export def clone_crystal [ --reset=false , --pull=false ] string { let $url = url_crystal - let $r = git_clone crystallib $url + let $r = git git_clone crystallib $url return $r } -let os = $nu.os-info.name -let arch = $nu.os-info.arch 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" @@ -37,20 +37,22 @@ def url_mycelium [] string { } } -def install_mycelium [] { +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_expand $tmppath $"($url)" --minsize 2 - mv $"($tmppath)/($name)" $"($bin_dir)/($name)" + 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" @@ -68,11 +70,11 @@ def url_hero [] string { } } -def install_hero [] { +export def install_hero [] { let $name = "hero" let $destpath = $"($env.BASE)/bin/hero" let $url = url_hero print $url - download $destpath $"($url)" --minsize 4 + download download_do $destpath $"($url)" --minsize 4 chmod +x $destpath } \ No newline at end of file diff --git a/nushell/tools/mypaths.nu b/nushell/tools/mypaths.nu deleted file mode 100644 index 17f834d..0000000 --- a/nushell/tools/mypaths.nu +++ /dev/null @@ -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} diff --git a/nushell/tools/varia.nu b/nushell/tools/varia.nu index 2202632..742d01e 100644 --- a/nushell/tools/varia.nu +++ b/nushell/tools/varia.nu @@ -1,5 +1,4 @@ -use runonce.nu -use extractors.nu +# use runonce.nu export def "cargo search" [ query: string, --limit=10] {