chore: add current provisioning state before migration
This commit is contained in:
parent
a9703b4748
commit
50745b0f22
660 changed files with 88126 additions and 0 deletions
87
core/nulib/lib_provisioning/setup/config.nu
Normal file
87
core/nulib/lib_provisioning/setup/config.nu
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
|
||||
export def env_file_providers [
|
||||
filepath: string
|
||||
]: nothing -> list {
|
||||
if not ($filepath | path exists) { return [] }
|
||||
(open $filepath | lines | find 'provisioning/providers/' |
|
||||
each {|it| $it | split row 'providers/' | get -o 1 | str replace '/nulib' '' }
|
||||
)
|
||||
}
|
||||
export def install_config [
|
||||
ops: string
|
||||
provisioning_cfg_name: string = "provisioning"
|
||||
--context
|
||||
]: nothing -> nothing {
|
||||
$env.PROVISIONING_DEBUG = ($env | get -o PROVISIONING_DEBUG | default false | into bool)
|
||||
let reset = ($ops | str contains "reset")
|
||||
let use_context = if ($ops | str contains "context") or $context { true } else { false }
|
||||
let provisioning_config_path = $nu.default-config-dir | path dirname | path join $provisioning_cfg_name | path join "nushell"
|
||||
let provisioning_root = if ($env | get -o PROVISIONING | is-not-empty) {
|
||||
$env.PROVISIONING
|
||||
} else {
|
||||
let base_path = if ($env.PROCESS_PATH | str contains "provisioning") {
|
||||
$env.PROCESS_PATH
|
||||
} else {
|
||||
$env.PWD
|
||||
}
|
||||
$"($base_path | split row "provisioning" | get -o 0)provisioning"
|
||||
}
|
||||
let shell_dflt_template = $provisioning_root | path join "templates"| path join "nushell" | path join "default"
|
||||
if not ($shell_dflt_template | path exists) {
|
||||
_print $"🛑 Template path (_ansi red_bold)($shell_dflt_template)(_ansi reset) not found"
|
||||
exit 1
|
||||
}
|
||||
let context_filename = "default_context.yaml"
|
||||
let context_template = $provisioning_root | path join "templates"| path join $context_filename
|
||||
let provisioning_context_path = ($nu.default-config-dir | path dirname | path join $provisioning_cfg_name | path join $context_filename)
|
||||
let op = if $env.PROVISIONING_DEBUG { "v" } else { "" }
|
||||
if $reset {
|
||||
if ($provisioning_context_path | path exists) {
|
||||
rm -rf $provisioning_context_path
|
||||
_print $"Restore context (_ansi default_dimmed) ($provisioning_context_path)(_ansi reset)"
|
||||
}
|
||||
if not $use_context and ($provisioning_config_path | path exists) {
|
||||
rm -rf $provisioning_config_path
|
||||
_print $"Restore defaults (_ansi default_dimmed) ($provisioning_config_path)(_ansi reset)"
|
||||
}
|
||||
}
|
||||
if ($provisioning_context_path | path exists) {
|
||||
_print $"Intallation on (_ansi yellow)($provisioning_context_path)(_ansi reset) (_ansi purple_bold)already exists(_ansi reset)"
|
||||
_print $"use (_ansi purple_bold)provisioning context(_ansi reset) to manage context \(create, default, set, etc\)"
|
||||
} else {
|
||||
mkdir ($provisioning_context_path | path dirname)
|
||||
let data_context = (open -r $context_template)
|
||||
$data_context | str replace "HOME" $nu.home-path | save $provisioning_context_path
|
||||
#$use_context | update infra_path ($context.infra_path | str replace "HOME" $nu.home-path) | save $provisioning_context_path
|
||||
_print $"Intallation on (_ansi yellow)($provisioning_context_path) (_ansi green_bold)completed(_ansi reset)"
|
||||
_print $"use (_ansi purple_bold)provisioning context(_ansi reset) to manage context \(create, default, set, etc\)"
|
||||
}
|
||||
if ($provisioning_config_path | path exists) {
|
||||
_print $"Intallation on (_ansi yellow)($provisioning_config_path)(_ansi reset) (_ansi purple_bold)already exists(_ansi reset)"
|
||||
_print ( $"with library path in (_ansi default_dimmed)env.nu(_ansi reset) for: " +
|
||||
$" (_ansi blue)(env_file_providers $"($provisioning_config_path)/env.nu" | str join ' ')(_ansi reset)"
|
||||
)
|
||||
} else {
|
||||
mkdir $provisioning_config_path
|
||||
mut providers_lib_paths = $provisioning_root | path join "providers"
|
||||
mut providers_list = ""
|
||||
for it in (ls $"($provisioning_root)/providers" | get name) {
|
||||
#if not ($"($it)/templates" | path exists) { continue }
|
||||
if not ($"($it)/nulib" | path exists) { continue }
|
||||
if $providers_list != "" { $providers_list += " " }
|
||||
$providers_list += ($it | path basename)
|
||||
if $providers_lib_paths != "" { $providers_lib_paths += "\n " }
|
||||
$providers_lib_paths += ($it | path join "nulib")
|
||||
}
|
||||
^cp $"-p($op)r" ...(glob $"($shell_dflt_template)/*") $provisioning_config_path
|
||||
if ($provisioning_config_path | path join "env.nu" | path exists) {
|
||||
( open ($provisioning_config_path | path join "env.nu") -r |
|
||||
str replace "# PROVISIONING_NULIB_DIR" ($provisioning_root | path join "core"| path join "nulib") |
|
||||
str replace "# PROVISIONING_NULIB_PROVIDERS" $providers_lib_paths |
|
||||
save -f $"($provisioning_config_path)/env.nu"
|
||||
)
|
||||
_print $"providers libs added for: (_ansi blue)($providers_list)(_ansi reset)"
|
||||
}
|
||||
_print $"Intallation on (_ansi yellow)($provisioning_config_path) (_ansi green_bold)completed(_ansi reset)"
|
||||
}
|
||||
}
|
||||
2
core/nulib/lib_provisioning/setup/mod.nu
Normal file
2
core/nulib/lib_provisioning/setup/mod.nu
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
export use utils.nu *
|
||||
export use config.nu *
|
||||
96
core/nulib/lib_provisioning/setup/utils.nu
Normal file
96
core/nulib/lib_provisioning/setup/utils.nu
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
#use ../lib_provisioning/defs/lists.nu providers_list
|
||||
|
||||
export def setup_config_path [
|
||||
provisioning_cfg_name: string = "provisioning"
|
||||
]: nothing -> string {
|
||||
($nu.default-config-dir) | path dirname | path join $provisioning_cfg_name
|
||||
}
|
||||
export def tools_install [
|
||||
tool_name?: string
|
||||
run_args?: string
|
||||
]: nothing -> bool {
|
||||
print $"(_ansi cyan)($env.PROVISIONING_NAME)(_ansi reset) (_ansi yellow_bold)tools(_ansi reset) check:\n"
|
||||
let bin_install = ($env.PROVISIONING | path join "core" | path join "bin" | path join "tools-install")
|
||||
if not ($bin_install | path exists) {
|
||||
print $"🛑 Error running (_ansi yellow)tools_install(_ansi reset) not found (_ansi red_bold)($bin_install | path basename)(_ansi reset)"
|
||||
if $env.PROVISIONING_DEBUG { print $"($bin_install)" }
|
||||
return false
|
||||
}
|
||||
let res = (^$"($bin_install)" $run_args $tool_name | complete)
|
||||
if ($res.exit_code == 0 ) {
|
||||
print $res.stdout
|
||||
true
|
||||
} else {
|
||||
print $"🛑 Error running (_ansi yellow)tools-install(_ansi reset) (_ansi red_bold)($bin_install | path basename)(_ansi reset)\n($res.stdout)"
|
||||
if $env.PROVISIONING_DEBUG { print $"($bin_install)" }
|
||||
false
|
||||
}
|
||||
}
|
||||
export def providers_install [
|
||||
prov_name?: string
|
||||
run_args?: string
|
||||
]: nothing -> list {
|
||||
if not ($env.PROVISIONING_PROVIDERS_PATH | path exists) { return }
|
||||
providers_list "full" | each {|prov|
|
||||
let name = ($prov | get -o name | default "")
|
||||
if ($prov_name | is-not-empty ) and $prov_name != $name { continue }
|
||||
let bin_install = ($env.PROVISIONING_PROVIDERS_PATH | path join $name | path join "bin" | path join "install.sh" )
|
||||
if not ($bin_install | path exists) { continue }
|
||||
let res = (^$"($bin_install)" $run_args | complete)
|
||||
if ($res.exit_code != 0 ) {
|
||||
print ($"🛑 Error running (_ansi yellow)($name)(_ansi reset) (_ansi red_bold)($bin_install | path basename)(_ansi reset)\n($res.stdout)")
|
||||
if $env.PROVISIONING_DEBUG { print $"($bin_install)" }
|
||||
continue
|
||||
}
|
||||
print -n $"(_ansi green)($name)(_ansi reset) tools:"
|
||||
$prov | get -o tools | default [] | transpose key value | each {|item| print -n $" (_ansi yellow)($item | get -o key | default "")(_ansi reset)" }
|
||||
print ""
|
||||
if ($res.exit_code == 0 ) {
|
||||
_print $res.stdout
|
||||
}
|
||||
}
|
||||
}
|
||||
export def create_versions_file [
|
||||
targetname: string = "versions"
|
||||
]: nothing -> bool {
|
||||
let target_name = if ($targetname | is-empty) { "versions" } else { $targetname }
|
||||
if ($env.PROVISIONING_PROVIDERS_PATH | path exists) {
|
||||
providers_list "full" | each {|prov|
|
||||
let name = ($prov | get -o name | default "")
|
||||
let prov_versions = ($env.PROVISIONING_PROVIDERS_PATH | path join $name | path join $target_name )
|
||||
mut $line = ""
|
||||
print -n $"\n(_ansi blue)($name)(_ansi reset) => "
|
||||
for item in ($prov | get -o tools | default [] | transpose key value) {
|
||||
let tool_name = ($item | get -o key | default "")
|
||||
for data in ($item | get -o value | default {} | transpose ky val) {
|
||||
let sub_name = ($data.ky | str upcase)
|
||||
$line += $"($name | str upcase)_($tool_name | str upcase)_($sub_name)=\"($data | get -o val | default "")\"\n"
|
||||
}
|
||||
print -n $"(_ansi yellow)($tool_name)(_ansi reset)"
|
||||
}
|
||||
$line | save --force $prov_versions
|
||||
print $"\n(_ansi blue)($name)(_ansi reset) versions file (_ansi green_bold)($target_name)(_ansi reset) generated"
|
||||
if $env.PROVISIONING_DEBUG { _print $"($prov_versions)" }
|
||||
}
|
||||
_print ""
|
||||
}
|
||||
if not ($env.PROVISIONING_REQ_VERSIONS | path exists ) { return false }
|
||||
let versions_source = open $env.PROVISIONING_REQ_VERSIONS
|
||||
let versions_target = ($env.PROVISIONING_REQ_VERSIONS | path dirname | path join $target_name)
|
||||
if ( $versions_target | path exists) { rm -f $versions_target }
|
||||
$versions_source | transpose key value | each {|it|
|
||||
let name = ($it.key | str upcase)
|
||||
mut $line = ""
|
||||
for data in ($it.value | transpose ky val) {
|
||||
let sub_name = ($data.ky | str upcase)
|
||||
$line += $"($name)_($sub_name)=\"($data.val | default "")\"\n"
|
||||
}
|
||||
$line | save -a $versions_target
|
||||
}
|
||||
print (
|
||||
$"(_ansi cyan)($env.PROVISIONING_NAME)(_ansi reset) (_ansi blue)core versions(_ansi reset) file " +
|
||||
$"(_ansi green_bold)($target_name)(_ansi reset) generated"
|
||||
)
|
||||
if $env.PROVISIONING_DEBUG { print ($env.PROVISIONING_REQ_VERSIONS) }
|
||||
true
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue