repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

package.nu: provisioner actions

056a6cd6a5e50240fa4731ae06236b88e4a312c2

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (3)

+46 / −13 text lines

Diff layout

nushell/modules/package/extractor.nu

Modified

+10 / −1 text lines

1515 # run-external tar '--extract' $"--($type)" $"--file=($archive)" $"--directory=($target)" '--strip-components=1'
1717 # TODO: test on win32
18 let is_single_dir = (run-external tar '--list' $'--file=($archive)' | lines | path split | first | uniq | length) == 1
18 let files = ( run-external tar '--list' $'--file=($archive)' | lines )
19 let uniq_parents = (
20 $files
21 | path split
22 | each { first }
23 | uniq
24 | length
25 )
26 let is_single_dir = (($files | length) > 1) and ($uniq_parents) == 1
1927 let strip = if $is_single_dir { 1 } else { 0 }
28 print $'Unpacking ($archive) into ($target) with strip ($strip)'
2029 run-external tar '--extract' $"--file=($archive)" $"--directory=($target)" $'--strip-components=($strip)'

nushell/modules/package/installer.nu

Modified

+8 / −4 text lines

2424 if ($candidates | has-one) {
2525 let candidate = ($candidates | first)
26 print $"Found only match for ($query): ($candidate)."
2726 $package = $candidate
2827 } else {
2928 print $"Found multiple matches for ($query). Pick one!"
3029 $package = ($candidates | input list --fuzzy "Which package to install? ")
3130 }
33 let manifest = open $package | from nuon
32 let manifest = open $package
3433 install-manifest $manifest
5352 'win32 package name': any
5453 >
5554] {
55 let destination = [(folders programs) $manifest.organisation $manifest.name $manifest.version] | path join
56 if ($destination | path exists) {
57 print $'($manifest.name)/($manifest.organisation) already installed. Doing nothing.'
58 return
59 }
5660 mut url = match ($nu.os-info.family) {
5761 'unix' => {
5862 match ($nu.os-info.arch) {
7478 http get --raw --max-time 30sec $url | save --progress --raw $artifact_path
7579 }
77 let destination = [(folders programs) $manifest.organisation $manifest.name $manifest.version] | path join
7881 mkdir $destination
7982 extractor unpack $artifact_path $destination
9194 match ($source | path type) {
9295 'file' => {
93 let target = ([(folders binaries) $bin] | path join)
96 let target = ([(folders binaries) ($bin | path basename)] | path join)
97 print $'Linking ($source) to ($target)'
9498 slink $source $target
9599 }
96100 'directory' => {

nushell/modules/package/provider.nu

Modified

+28 / −8 text lines

1010use ./folders.nu
1111use ./path.nu
1212use ./installer.nu
13use ./native-package-manager
15const INSTALL_ACTION = 'install'
16const UNINSTALL_ACTION = 'uninstall'
1814export def provision [] {
1915 cd (folders manifests)
20 let manifests = ls | get name | str replace '.nuon' '' | wrap manifest
16 let manifests = ls
17 | get name
18 | str replace '.nuon' ''
19 | wrap manifest
20 | upsert action uninstall
2121 cd (folders provisions)
22 let provisions = open **/*.nuon | uniq
22 let provisions = open **/*.nuon
23 | uniq
24 | wrap manifest
25 | upsert action install
27 let actions = $provisions | merge deep --strategy append $manifests | uniq-by manifest
29 $actions | each {
30 |item|
31 match $item.action {
32 'install' => {
33 print $'Installing ($item.manifest)'
34 installer install $item.manifest
35 }
36 'uninstall' => {
37 print $'Uninstalling ($item.manifest)'
38 # installer uninstall $item.manifest
39 }
40 }
41 }
2444 # check if installed packages are synced with current manifests
2545 # check if current installed packages are installed via correct source
26 # install all missing. reinstall all with higher precedence
27 # uninstall non-provisioned ?
47 # uninstall non-provisioned
2848 # setup path