diff --git a/Testing/Temporary/CTestCostData.txt b/Testing/Temporary/CTestCostData.txt new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/Testing/Temporary/CTestCostData.txt @@ -0,0 +1 @@ +--- diff --git a/aiprompts/ai_core/osal_os_system_tools.md b/aiprompts/ai_core/osal_os_system_tools.md index 02e662e7..6a449a5c 100644 --- a/aiprompts/ai_core/osal_os_system_tools.md +++ b/aiprompts/ai_core/osal_os_system_tools.md @@ -195,7 +195,7 @@ e.g. systemd, bash, zinit fn ipaddr_pub_get() !string Returns the ipaddress as known on the public side is using resolver4.opendns.com fn is_linux() bool -fn is_linux_arm() bool +fn is_linux_arm()! bool fn is_linux_intel() bool fn is_osx() bool fn is_osx_arm() bool @@ -243,7 +243,7 @@ add the following path to a profile fn profile_path_add_hero() !string fn profile_path_source() string return the source statement if the profile exists -fn profile_path_source_and() string +fn profile_path_source_and()! string return source $path && . or empty if it doesn't exist fn sleep(duration int) sleep in seconds diff --git a/examples/installers/installers.vsh b/examples/installers/installers.vsh index 1d6b6077..d0820656 100755 --- a/examples/installers/installers.vsh +++ b/examples/installers/installers.vsh @@ -5,6 +5,9 @@ import freeflowuniverse.herolib.installers.lang.rust import freeflowuniverse.herolib.installers.lang.python import freeflowuniverse.herolib.installers.lang.nodejs import freeflowuniverse.herolib.installers.lang.golang +import freeflowuniverse.herolib.core + +core.interactive_set()! //make sure the sudo works so we can do things even if it requires those rights // import freeflowuniverse.herolib.data.dbfs @@ -34,5 +37,6 @@ import freeflowuniverse.herolib.installers.lang.golang // b2_installer.install()! // rust.install(reset:false)! - -nodejs.install(reset:false)! \ No newline at end of file +// python.install(reset:false)! +// nodejs.install(reset:false)! +golang.install(reset:true)! \ No newline at end of file diff --git a/lib/clients/mailclient/mailclient_factory_.v b/lib/clients/mailclient/mailclient_factory_.v index 3190fd9f..125569f1 100644 --- a/lib/clients/mailclient/mailclient_factory_.v +++ b/lib/clients/mailclient/mailclient_factory_.v @@ -1,104 +1,121 @@ + module mailclient import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.data.encoderhero + __global ( - mailclient_global map[string]&MailClient - mailclient_default string + mailclient_global map[string]&MailClient + mailclient_default string ) /////////FACTORY + + @[params] -pub struct ArgsGet { +pub struct ArgsGet{ pub mut: - name string + name string } -fn args_get(args_ ArgsGet) ArgsGet { - mut model := args_ - if model.name == '' { - model.name = mailclient_default - } - if model.name == '' { - model.name = 'default' - } - return model +fn args_get (args_ ArgsGet) ArgsGet { + mut model:=args_ + if model.name == ""{ + model.name = mailclient_default + } + if model.name == ""{ + model.name = "default" + } + return model } -pub fn get(args_ ArgsGet) !&MailClient { - mut model := args_get(args_) - if model.name !in mailclient_global { - if model.name == 'default' { - if !config_exists(model) { - if default { - config_save(model)! - } - } - config_load(model)! - } - } - return mailclient_global[model.name] or { - println(mailclient_global) - panic('could not get config for mailclient with name:${model.name}') - } +pub fn get(args_ ArgsGet) !&MailClient { + mut args := args_get(args_) + if !(args.name in mailclient_global) { + if args.name=="default"{ + if ! config_exists(args){ + if default{ + mut context:=base.context() or { panic("bug") } + context.hero_config_set("mailclient",model.name,heroscript_default()!)! + } + } + load(args)! + } + } + return mailclient_global[args.name] or { + println(mailclient_global) + panic("could not get config for ${args.name} with name:${model.name}") + } } -fn config_exists(args_ ArgsGet) bool { - mut model := args_get(args_) - mut context := base.context() or { panic('bug') } - return context.hero_config_exists('mailclient', model.name) + + +//set the model in mem and the config on the filesystem +pub fn set(o MailClient)! { + mut o2:=obj_init(o)! + mailclient_global[o.name] = &o2 + mailclient_default = o.name } -fn config_load(args_ ArgsGet) ! { - mut model := args_get(args_) - mut context := base.context()! - mut heroscript := context.hero_config_get('mailclient', model.name)! - play(heroscript: heroscript)! +//check we find the config on the filesystem +pub fn exists(args_ ArgsGet) bool { + mut model := args_get(args_) + mut context:=base.context() or { panic("bug") } + return context.hero_config_exists("mailclient",model.name) } -fn config_save(args_ ArgsGet) ! { - mut model := args_get(args_) - mut context := base.context()! - context.hero_config_set('mailclient', model.name, heroscript_default()!)! +//load the config error if it doesn't exist +pub fn load(args_ ArgsGet) ! { + mut model := args_get(args_) + mut context:=base.context()! + mut heroscript := context.hero_config_get("mailclient",model.name)! + play(heroscript:heroscript)! } -fn set(o MailClient) ! { - mut o2 := obj_init(o)! - mailclient_global[o.name] = &o2 - mailclient_default = o.name +//save the config to the filesystem in the context +pub fn save(o MailClient)! { + mut context:=base.context()! + heroscript := encoderhero.encode[MailClient](o)! + context.hero_config_set("mailclient",model.name,heroscript)! } @[params] pub struct PlayArgs { pub mut: - heroscript string // if filled in then plbook will be made out of it - plbook ?playbook.PlayBook - reset bool + heroscript string //if filled in then plbook will be made out of it + plbook ?playbook.PlayBook + reset bool } pub fn play(args_ PlayArgs) ! { - mut model := args_ + + mut model:=args_ + + if model.heroscript == "" { + model.heroscript = heroscript_default()! + } + mut plbook := model.plbook or { + playbook.new(text: model.heroscript)! + } + + mut configure_actions := plbook.find(filter: 'mailclient.configure')! + if configure_actions.len > 0 { + for config_action in configure_actions { + mut p := config_action.params + mycfg:=cfg_play(p)! + console.print_debug("install action mailclient.configure\n${mycfg}") + set(mycfg)! + save(mycfg)! + } + } - if model.heroscript == '' { - model.heroscript = heroscript_default()! - } - mut plbook := model.plbook or { playbook.new(text: model.heroscript)! } - mut install_actions := plbook.find(filter: 'mailclient.configure')! - if install_actions.len > 0 { - for install_action in install_actions { - mut p := install_action.params - mycfg := cfg_play(p)! - console.print_debug('install action mailclient.configure\n${mycfg}') - set(mycfg)! - } - } } -// switch instance to be used for mailclient -pub fn switch(name string) { - mailclient_default = name -} + + + diff --git a/lib/clients/meilisearch/meilisearch_factory_.v b/lib/clients/meilisearch/meilisearch_factory_.v index 6ab4e1ea..8baa0a1b 100644 --- a/lib/clients/meilisearch/meilisearch_factory_.v +++ b/lib/clients/meilisearch/meilisearch_factory_.v @@ -1,104 +1,121 @@ + module meilisearch import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.data.encoderhero + __global ( - meilisearch_global map[string]&MeilisearchClient - meilisearch_default string + meilisearch_global map[string]&MeilisearchClient + meilisearch_default string ) /////////FACTORY + + @[params] -pub struct ArgsGet { +pub struct ArgsGet{ pub mut: - name string + name string } -fn args_get(args_ ArgsGet) ArgsGet { - mut model := args_ - if model.name == '' { - model.name = meilisearch_default - } - if model.name == '' { - model.name = 'default' - } - return model +fn args_get (args_ ArgsGet) ArgsGet { + mut model:=args_ + if model.name == ""{ + model.name = meilisearch_default + } + if model.name == ""{ + model.name = "default" + } + return model } -pub fn get(args_ ArgsGet) !&MeilisearchClient { - mut model := args_get(args_) - if model.name !in meilisearch_global { - if model.name == 'default' { - if !config_exists(model) { - if default { - config_save(model)! - } - } - config_load(model)! - } - } - return meilisearch_global[model.name] or { - println(meilisearch_global) - panic('could not get config for meilisearch with name:${model.name}') - } +pub fn get(args_ ArgsGet) !&MeilisearchClient { + mut args := args_get(args_) + if !(args.name in meilisearch_global) { + if args.name=="default"{ + if ! config_exists(args){ + if default{ + mut context:=base.context() or { panic("bug") } + context.hero_config_set("meilisearch",model.name,heroscript_default()!)! + } + } + load(args)! + } + } + return meilisearch_global[args.name] or { + println(meilisearch_global) + panic("could not get config for ${args.name} with name:${model.name}") + } } -fn config_exists(args_ ArgsGet) bool { - mut model := args_get(args_) - mut context := base.context() or { panic('bug') } - return context.hero_config_exists('meilisearch', model.name) + + +//set the model in mem and the config on the filesystem +pub fn set(o MeilisearchClient)! { + mut o2:=obj_init(o)! + meilisearch_global[o.name] = &o2 + meilisearch_default = o.name } -fn config_load(args_ ArgsGet) ! { - mut model := args_get(args_) - mut context := base.context()! - mut heroscript := context.hero_config_get('meilisearch', model.name)! - play(heroscript: heroscript)! +//check we find the config on the filesystem +pub fn exists(args_ ArgsGet) bool { + mut model := args_get(args_) + mut context:=base.context() or { panic("bug") } + return context.hero_config_exists("meilisearch",model.name) } -fn config_save(args_ ArgsGet) ! { - mut model := args_get(args_) - mut context := base.context()! - context.hero_config_set('meilisearch', model.name, heroscript_default()!)! +//load the config error if it doesn't exist +pub fn load(args_ ArgsGet) ! { + mut model := args_get(args_) + mut context:=base.context()! + mut heroscript := context.hero_config_get("meilisearch",model.name)! + play(heroscript:heroscript)! } -fn set(o MeilisearchClient) ! { - mut o2 := obj_init(o)! - meilisearch_global[o.name] = &o2 - meilisearch_default = o.name +//save the config to the filesystem in the context +pub fn save(o MeilisearchClient)! { + mut context:=base.context()! + heroscript := encoderhero.encode[MeilisearchClient](o)! + context.hero_config_set("meilisearch",model.name,heroscript)! } @[params] pub struct PlayArgs { pub mut: - heroscript string // if filled in then plbook will be made out of it - plbook ?playbook.PlayBook - reset bool + heroscript string //if filled in then plbook will be made out of it + plbook ?playbook.PlayBook + reset bool } pub fn play(args_ PlayArgs) ! { - mut model := args_ + + mut model:=args_ + + if model.heroscript == "" { + model.heroscript = heroscript_default()! + } + mut plbook := model.plbook or { + playbook.new(text: model.heroscript)! + } + + mut configure_actions := plbook.find(filter: 'meilisearch.configure')! + if configure_actions.len > 0 { + for config_action in configure_actions { + mut p := config_action.params + mycfg:=cfg_play(p)! + console.print_debug("install action meilisearch.configure\n${mycfg}") + set(mycfg)! + save(mycfg)! + } + } - if model.heroscript == '' { - model.heroscript = heroscript_default()! - } - mut plbook := model.plbook or { playbook.new(text: model.heroscript)! } - mut install_actions := plbook.find(filter: 'meilisearch.configure')! - if install_actions.len > 0 { - for install_action in install_actions { - mut p := install_action.params - mycfg := cfg_play(p)! - console.print_debug('install action meilisearch.configure\n${mycfg}') - set(mycfg)! - } - } } -// switch instance to be used for meilisearch -pub fn switch(name string) { - meilisearch_default = name -} + + + diff --git a/lib/clients/mycelium/mycelium_factory_.v b/lib/clients/mycelium/mycelium_factory_.v index 693ed161..9f4e1543 100644 --- a/lib/clients/mycelium/mycelium_factory_.v +++ b/lib/clients/mycelium/mycelium_factory_.v @@ -1,104 +1,84 @@ + module mycelium import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.data.encoderhero + __global ( - mycelium_global map[string]&Mycelium - mycelium_default string + mycelium_global map[string]&Mycelium + mycelium_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string + + + +//set the model in mem and the config on the filesystem +pub fn set(o Mycelium)! { + mut o2:=obj_init(o)! + mycelium_global[o.name] = &o2 + mycelium_default = o.name } -fn args_get(args_ ArgsGet) ArgsGet { - mut model := args_ - if model.name == '' { - model.name = mycelium_default - } - if model.name == '' { - model.name = 'default' - } - return model +//check we find the config on the filesystem +pub fn exists(args_ ArgsGet) bool { + mut model := args_get(args_) + mut context:=base.context() or { panic("bug") } + return context.hero_config_exists("mycelium",model.name) } -pub fn get(args_ ArgsGet) !&Mycelium { - mut model := args_get(args_) - if model.name !in mycelium_global { - if model.name == 'default' { - if !config_exists(model) { - if default { - config_save(model)! - } - } - config_load(model)! - } - } - return mycelium_global[model.name] or { - println(mycelium_global) - panic('could not get config for mycelium with name:${model.name}') - } +//load the config error if it doesn't exist +pub fn load(args_ ArgsGet) ! { + mut model := args_get(args_) + mut context:=base.context()! + mut heroscript := context.hero_config_get("mycelium",model.name)! + play(heroscript:heroscript)! } -fn config_exists(args_ ArgsGet) bool { - mut model := args_get(args_) - mut context := base.context() or { panic('bug') } - return context.hero_config_exists('mycelium', model.name) -} - -fn config_load(args_ ArgsGet) ! { - mut model := args_get(args_) - mut context := base.context()! - mut heroscript := context.hero_config_get('mycelium', model.name)! - play(heroscript: heroscript)! -} - -fn config_save(args_ ArgsGet) ! { - mut model := args_get(args_) - mut context := base.context()! - context.hero_config_set('mycelium', model.name, heroscript_default()!)! -} - -fn set(o Mycelium) ! { - mut o2 := obj_init(o)! - mycelium_global[o.name] = &o2 - mycelium_default = o.name +//save the config to the filesystem in the context +pub fn save(o Mycelium)! { + mut context:=base.context()! + heroscript := encoderhero.encode[Mycelium](o)! + context.hero_config_set("mycelium",model.name,heroscript)! } @[params] pub struct PlayArgs { pub mut: - heroscript string // if filled in then plbook will be made out of it - plbook ?playbook.PlayBook - reset bool + heroscript string //if filled in then plbook will be made out of it + plbook ?playbook.PlayBook + reset bool } pub fn play(args_ PlayArgs) ! { - mut model := args_ + + mut model:=args_ + + if model.heroscript == "" { + model.heroscript = heroscript_default()! + } + mut plbook := model.plbook or { + playbook.new(text: model.heroscript)! + } + + mut configure_actions := plbook.find(filter: 'mycelium.configure')! + if configure_actions.len > 0 { + for config_action in configure_actions { + mut p := config_action.params + mycfg:=cfg_play(p)! + console.print_debug("install action mycelium.configure\n${mycfg}") + set(mycfg)! + save(mycfg)! + } + } - if model.heroscript == '' { - model.heroscript = heroscript_default()! - } - mut plbook := model.plbook or { playbook.new(text: model.heroscript)! } - mut install_actions := plbook.find(filter: 'mycelium.configure')! - if install_actions.len > 0 { - for install_action in install_actions { - mut p := install_action.params - mycfg := cfg_play(p)! - console.print_debug('install action mycelium.configure\n${mycfg}') - set(mycfg)! - } - } } -// switch instance to be used for mycelium -pub fn switch(name string) { - mycelium_default = name -} + + + diff --git a/lib/clients/openai/openai_factory_.v b/lib/clients/openai/openai_factory_.v index 23ee6c0d..15a19044 100644 --- a/lib/clients/openai/openai_factory_.v +++ b/lib/clients/openai/openai_factory_.v @@ -1,105 +1,57 @@ + module openai import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook +import freeflowuniverse.herolib.ui.console + __global ( - openai_global map[string]&OpenAI - openai_default string + openai_global map[string]&OpenAI + openai_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string = 'default' -} -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = openai_default - } - if args.name == '' { - args.name = 'default' - } - return args -} - -pub fn get(args_ ArgsGet) !&OpenAI { - mut args := args_get(args_) - if args.name !in openai_global { - if !config_exists() { - if default { - config_save()! - } - } - config_load()! - } - return openai_global[args.name] or { - println(openai_global) - panic('bug in get from factory: ') - } -} - -fn config_exists(args_ ArgsGet) bool { - mut args := args_get(args_) - mut context := base.context() or { panic('bug') } - return context.hero_config_exists('openai', args.name) -} - -fn config_load(args_ ArgsGet) ! { - mut args := args_get(args_) - mut context := base.context()! - mut heroscript := context.hero_config_get('openai', args.name)! - play(heroscript: heroscript)! -} - -fn config_save(args_ ArgsGet) ! { - mut args := args_get(args_) - mut context := base.context()! - context.hero_config_set('openai', args.name, heroscript_default()!)! -} - -fn set(o OpenAI) ! { - mut o2 := obj_init(o)! - openai_global['default'] = &o2 -} @[params] -pub struct PlayArgs { +pub struct ArgsGet{ pub mut: - name string = 'default' - heroscript string // if filled in then plbook will be made out of it - plbook ?playbook.PlayBook - reset bool - - start bool - stop bool - restart bool - delete bool - configure bool // make sure there is at least one installed + name string } -pub fn play(args_ PlayArgs) ! { - mut args := args_ - - if args.heroscript == '' { - args.heroscript = heroscript_default()! - } - mut plbook := args.plbook or { playbook.new(text: args.heroscript)! } - - mut install_actions := plbook.find(filter: 'openai.configure')! - if install_actions.len > 0 { - for install_action in install_actions { - mut p := install_action.params - cfg_play(p)! - } - } +fn args_get (args_ ArgsGet) ArgsGet { + mut model:=args_ + if model.name == ""{ + model.name = openai_default + } + if model.name == ""{ + model.name = "default" + } + return model } -// switch instance to be used for openai -pub fn switch(name string) { - openai_default = name +pub fn get(args_ ArgsGet) !&OpenAI { + mut args := args_get(args_) + if !(args.name in openai_global) { + if args.name=="default"{ + if ! config_exists(args){ + if default{ + mut context:=base.context() or { panic("bug") } + context.hero_config_set("openai",model.name,heroscript_default()!)! + } + } + load(args)! + } + } + return openai_global[args.name] or { + println(openai_global) + panic("could not get config for ${args.name} with name:${model.name}") + } } + + + + + diff --git a/lib/clients/postgresql_client/postgresql_client_factory_.v b/lib/clients/postgresql_client/postgresql_client_factory_.v index 9ae95577..0fd6eadb 100644 --- a/lib/clients/postgresql_client/postgresql_client_factory_.v +++ b/lib/clients/postgresql_client/postgresql_client_factory_.v @@ -1,27 +1,20 @@ + module postgresql_client import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + __global ( - postgresql_client_global map[string]&PostgresClient - postgresql_client_default string + postgresql_client_global map[string]&PostgresClient + postgresql_client_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&PostgresClient { - return &PostgresClient{} -} -// switch instance to be used for postgresql_client -pub fn switch(name string) { - postgresql_client_default = name -} + + + diff --git a/lib/clients/rclone/rclone_factory_.v b/lib/clients/rclone/rclone_factory_.v index c5ac3a67..1d390f24 100644 --- a/lib/clients/rclone/rclone_factory_.v +++ b/lib/clients/rclone/rclone_factory_.v @@ -1,103 +1,84 @@ + module rclone import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook +import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.data.encoderhero + __global ( - rclone_global map[string]&RCloneClient - rclone_default string + rclone_global map[string]&RCloneClient + rclone_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string + + + +//set the model in mem and the config on the filesystem +pub fn set(o RCloneClient)! { + mut o2:=obj_init(o)! + rclone_global[o.name] = &o2 + rclone_default = o.name } -fn args_get(args_ ArgsGet) ArgsGet { - mut model := args_ - if model.name == '' { - model.name = rclone_default - } - if model.name == '' { - model.name = 'default' - } - return model +//check we find the config on the filesystem +pub fn exists(args_ ArgsGet) bool { + mut model := args_get(args_) + mut context:=base.context() or { panic("bug") } + return context.hero_config_exists("rclone",model.name) } -pub fn get(args_ ArgsGet) !&RCloneClient { - mut model := args_get(args_) - if model.name !in rclone_global { - if model.name == 'default' { - if !config_exists(model) { - if default { - config_save(model)! - } - } - config_load(model)! - } - } - return rclone_global[model.name] or { - println(rclone_global) - panic('could not get config for rclone with name:${model.name}') - } +//load the config error if it doesn't exist +pub fn load(args_ ArgsGet) ! { + mut model := args_get(args_) + mut context:=base.context()! + mut heroscript := context.hero_config_get("rclone",model.name)! + play(heroscript:heroscript)! } -fn config_exists(args_ ArgsGet) bool { - mut model := args_get(args_) - mut context := base.context() or { panic('bug') } - return context.hero_config_exists('rclone', model.name) -} - -fn config_load(args_ ArgsGet) ! { - mut model := args_get(args_) - mut context := base.context()! - mut heroscript := context.hero_config_get('rclone', model.name)! - play(heroscript: heroscript)! -} - -fn config_save(args_ ArgsGet) ! { - mut model := args_get(args_) - mut context := base.context()! - context.hero_config_set('rclone', model.name, heroscript_default()!)! -} - -fn set(o RCloneClient) ! { - mut o2 := obj_init(o)! - rclone_global[o.name] = &o2 - rclone_default = o.name +//save the config to the filesystem in the context +pub fn save(o RCloneClient)! { + mut context:=base.context()! + heroscript := encoderhero.encode[RCloneClient](o)! + context.hero_config_set("rclone",model.name,heroscript)! } @[params] pub struct PlayArgs { pub mut: - heroscript string // if filled in then plbook will be made out of it - plbook ?playbook.PlayBook - reset bool + heroscript string //if filled in then plbook will be made out of it + plbook ?playbook.PlayBook + reset bool } pub fn play(args_ PlayArgs) ! { - mut model := args_ + + mut model:=args_ + + if model.heroscript == "" { + model.heroscript = heroscript_default()! + } + mut plbook := model.plbook or { + playbook.new(text: model.heroscript)! + } + + mut configure_actions := plbook.find(filter: 'rclone.configure')! + if configure_actions.len > 0 { + for config_action in configure_actions { + mut p := config_action.params + mycfg:=cfg_play(p)! + console.print_debug("install action rclone.configure\n${mycfg}") + set(mycfg)! + save(mycfg)! + } + } - if model.heroscript == '' { - model.heroscript = heroscript_default()! - } - mut plbook := model.plbook or { playbook.new(text: model.heroscript)! } - mut install_actions := plbook.find(filter: 'rclone.configure')! - if install_actions.len > 0 { - for install_action in install_actions { - mut p := install_action.params - cfg_play(p)! - // console.print_debug('install action rclone.configure\n${mycfg}') - // set(mycfg)! - } - } } -// switch instance to be used for rclone -pub fn switch(name string) { - rclone_default = name -} + + + diff --git a/lib/clients/sendgrid/sendgrid_factory_.v b/lib/clients/sendgrid/sendgrid_factory_.v index 4d8b0831..97e30a19 100644 --- a/lib/clients/sendgrid/sendgrid_factory_.v +++ b/lib/clients/sendgrid/sendgrid_factory_.v @@ -1,27 +1,20 @@ + module sendgrid import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + __global ( - sendgrid_global map[string]&SendGrid - sendgrid_default string + sendgrid_global map[string]&SendGrid + sendgrid_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&SendGrid { - return &SendGrid{} -} -// switch instance to be used for sendgrid -pub fn switch(name string) { - sendgrid_default = name -} + + + diff --git a/lib/clients/zerodb_client/zerodb_client_factory_.v b/lib/clients/zerodb_client/zerodb_client_factory_.v index fbcc19e4..f280cde4 100644 --- a/lib/clients/zerodb_client/zerodb_client_factory_.v +++ b/lib/clients/zerodb_client/zerodb_client_factory_.v @@ -1,27 +1,20 @@ + module zerodb_client import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + __global ( - zerodb_client_global map[string]&ZeroDBClient - zerodb_client_default string + zerodb_client_global map[string]&ZeroDBClient + zerodb_client_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&ZeroDBClient { - return &ZeroDBClient{} -} -// switch instance to be used for zerodb_client -pub fn switch(name string) { - zerodb_client_default = name -} + + + diff --git a/lib/code/generator/installer_client/templates/objname_actions.vtemplate b/lib/code/generator/installer_client/templates/objname_actions.vtemplate index 391c2638..619e6967 100644 --- a/lib/code/generator/installer_client/templates/objname_actions.vtemplate +++ b/lib/code/generator/installer_client/templates/objname_actions.vtemplate @@ -4,6 +4,7 @@ import freeflowuniverse.herolib.osal import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.core.texttools import freeflowuniverse.herolib.core.pathlib +import freeflowuniverse.herolib.core import freeflowuniverse.herolib.installers.ulist import freeflowuniverse.herolib.installers.base @@ -83,7 +84,7 @@ fn stop_post()!{ // checks if a certain version or above is installed fn installed_() !bool { //THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED - // res := os.execute('??{osal.profile_path_source_and()} ${model.name} version') + // res := os.execute('??{osal.profile_path_source_and()!} ${model.name} version') // if res.exit_code != 0 { // return false // } @@ -116,13 +117,13 @@ fn install_() ! { console.print_header('install ${model.name}') //THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // mut url := '' - // if osal.is_linux_arm() { + // if core.is_linux_arm()! { // url = 'https://github.com/${model.name}-dev/${model.name}/releases/download/v??{version}/${model.name}_??{version}_linux_arm64.tar.gz' - // } else if osal.is_linux_intel() { + // } else if core.is_linux_intel()! { // url = 'https://github.com/${model.name}-dev/${model.name}/releases/download/v??{version}/${model.name}_??{version}_linux_amd64.tar.gz' - // } else if osal.is_osx_arm() { + // } else if core.is_osx_arm()! { // url = 'https://github.com/${model.name}-dev/${model.name}/releases/download/v??{version}/${model.name}_??{version}_darwin_arm64.tar.gz' - // } else if osal.is_osx_intel() { + // } else if core.is_osx_intel()! { // url = 'https://github.com/${model.name}-dev/${model.name}/releases/download/v??{version}/${model.name}_??{version}_darwin_amd64.tar.gz' // } else { // return error('unsported platform') @@ -148,7 +149,7 @@ fn build_() ! { //url := 'https://github.com/threefoldtech/${model.name}' // make sure we install base on the node - // if osal.platform() != .ubuntu { + // if core.platform()!= .ubuntu { // return error('only support ubuntu for now') // } // golang.install()! diff --git a/lib/code/generator/installer_client/templates/objname_factory_.vtemplate b/lib/code/generator/installer_client/templates/objname_factory_.vtemplate index 474ffdbd..571655c6 100644 --- a/lib/code/generator/installer_client/templates/objname_factory_.vtemplate +++ b/lib/code/generator/installer_client/templates/objname_factory_.vtemplate @@ -4,6 +4,7 @@ module ${model.name} import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.core @if model.hasconfig import freeflowuniverse.herolib.data.encoderhero @end diff --git a/lib/core/base/readme.md b/lib/core/base/readme.md index 83ddbbab..3d165c88 100644 --- a/lib/core/base/readme.md +++ b/lib/core/base/readme.md @@ -1,105 +1,76 @@ -## Context & Sessions +# Base Module -Everything we do in hero lives in a context, each context has a unique name and ID. A context can have multiple sessions, where each session represents a specific execution environment. +The Base module is a foundational component of the Hero framework that provides essential context and session management functionality. + +## Features + +- **Context Management**: Handles application context with support for: + - Parameter management + - Redis integration + - Database collections + - Configuration storage and retrieval + - Path management + +- **Session Handling**: Provides session management capabilities through the Base and Session structures + +- **Configuration Management**: + - heroscript configuration system + - Support for environment variable expansion + +- **Security Features**: + - Secret management + - AES symmetric encryption/decryption + - Secure configuration storage + +- **Database Integration**: + - Redis database support with automatic database selection + - File-based database collections + - Key-value storage capabilities + +## Core Components ### Context -Each context has: -- A unique ID and name -- Secret management (encrypted) -- Database collection -- Configuration storage -- Code root path -- Parameters +The `Context` struct is the central component that manages: +- Application parameters +- Database connections +- Redis client +- File paths +- Configuration settings -### Sessions +### Base -Sessions exist within a context and provide: -- Unique name within the context -- Interactive mode control -- Environment variables -- Start/End time tracking -- Parameter storage -- Database access -- Logging +The `Base` struct provides: +- Session management +- Instance tracking +- Configuration type handling -### Storage Structure +## Usage -Redis is used to manage contexts and sessions: +The base module is typically used as a foundation for other Hero framework components. It provides the necessary infrastructure for: -- Redis DB X (where X is context ID): - - `context:config` - JSON encoded context configuration - - `sessions:config:$name` - JSON encoded session configuration for each session +- Managing application state +- Handling configurations +- Managing database connections +- Securing sensitive data +- Organizing application resources -### Database Structure +## Configuration -Each context has a database collection located at `~/hero/db/$contextid/`. Within this: -- Each session gets its own database named `session_$name` -- A shared `config` database exists for context-wide configuration +The module supports various configuration options through the `ContextConfig` struct: +- `id`: Unique identifier for the context +- `name`: Context name (defaults to 'default') +- `params`: Parameter string +- `coderoot`: Root path for code +- `interactive`: Interactive mode flag +- `secret`: Hashed secret for encryption +- `db_path`: Path to database collection +- `encrypt`: Encryption flag -### Hero Configuration +## Security -Contexts support hero-specific configuration files: -- Stored at `~/hero/context/$contextname/$category__$name.yaml` -- Supports categories for organization -- Automatically handles shell expansions - -### Example Usage - -```v -import freeflowuniverse.herolib.core.base - -// Create a new context -mut context := context_new( - id: 1 - name: 'mycontext' - coderoot: '/tmp/code' - interactive: true -)! - -// Create a new session in the context -mut session := session_new( - context: context - name: 'mysession1' - interactive: true -)! - -// Work with environment variables -session.env_set('KEY', 'value')! -value := session.env_get('KEY')! - -// Work with hero config -context.hero_config_set('category', 'name', 'content')! -content := context.hero_config_get('category', 'name')! - -// Access session database -mut db := session.db_get()! - -// Access context-wide config database -mut config_db := session.db_config_get()! -``` - -### Security - -- Context secrets are stored as MD5 hashes -- Support for encryption of sensitive data -- Interactive secret configuration available - -### File Structure - -Each context and session has its own directory structure: -- Context root: `~/hero/context/$contextname/` -- Session directory: `~/hero/context/$contextname/$sessionname/` - -This structure helps organize configuration files, logs, and other session-specific data. - -### Logging - -Each session has its own logger: - -```v -mut logger := session.logger()! -logger.log(log:'My log message') -``` - -For detailed logging capabilities and options, see the logger documentation in `lib/core/logger/readme.md`. +The module includes built-in security features: +- Secret management with encryption +- Secure configuration storage +- MD5 hashing for secrets +- AES symmetric encryption for sensitive data diff --git a/lib/core/interactive.v b/lib/core/interactive.v new file mode 100644 index 00000000..468f79ac --- /dev/null +++ b/lib/core/interactive.v @@ -0,0 +1,17 @@ +module core + +import base + +//check if we are interactive in current context +pub fn interactive()!bool{ + mut c:=base.context()! + if c.config.interactive{ + return true + } + return false +} + +pub fn interactive_set()!{ + mut c:=base.context()! + c.config.interactive = true +} diff --git a/lib/core/memdb.v b/lib/core/memdb.v new file mode 100644 index 00000000..8e3df5f8 --- /dev/null +++ b/lib/core/memdb.v @@ -0,0 +1,25 @@ +module core + +__global ( + memdb shared map[string]string +) + +pub fn memdb_set(key string, val string) { + lock memdb { + memdb[key] = val + } +} + +pub fn memdb_get(key string) string { + lock memdb { + return memdb[key] or { return '' } + } + return '' +} + +pub fn memdb_exists(key string) bool { + if memdb_get(key).len > 0 { + return true + } + return false +} diff --git a/lib/core/memdb_test.v b/lib/core/memdb_test.v new file mode 100644 index 00000000..bceb12f8 --- /dev/null +++ b/lib/core/memdb_test.v @@ -0,0 +1,28 @@ +module core + +fn test_memdb_set_get() { + // Test basic set/get + memdb_set('test_key', 'test_value') + assert memdb_get('test_key') == 'test_value' + + // Test overwriting value + memdb_set('test_key', 'new_value') + assert memdb_get('test_key') == 'new_value' + + // Test getting non-existent key + assert memdb_get('non_existent') == '' +} + +fn test_memdb_exists() { + // Test existing key + memdb_set('exists_key', 'value') + assert memdb_exists('exists_key') == true + + // Test non-existing key + assert memdb_exists('non_existent') == false + + // Test empty value + memdb_set('empty_key', '') + assert memdb_exists('empty_key') == false +} + diff --git a/lib/osal/platform.v b/lib/core/platform.v similarity index 64% rename from lib/osal/platform.v rename to lib/core/platform.v index 7b4ecfd4..c45fb619 100644 --- a/lib/osal/platform.v +++ b/lib/core/platform.v @@ -1,9 +1,20 @@ -module osal +module core import os + // import freeflowuniverse.herolib.ui.console // Returns the enum value that matches the provided string for PlatformType + +pub enum PlatformType { + unknown + osx + ubuntu + alpine + arch + suse +} + pub fn platform_enum_from_string(platform string) PlatformType { return match platform.to_lower() { 'osx' { .osx } @@ -14,18 +25,10 @@ pub fn platform_enum_from_string(platform string) PlatformType { } } -pub enum PlatformType { - unknown - osx - ubuntu - alpine - arch - suse -} // Returns the enum value that matches the provided string for CPUType -pub fn cputype_enum_from_string(cpytype string) CPUType { - return match cpytype.to_lower() { +pub fn cputype_enum_from_string(cputype string) CPUType { + return match cputype.to_lower() { 'intel' { .intel } 'arm' { .arm } 'intel32' { .intel32 } @@ -42,8 +45,16 @@ pub enum CPUType { arm32 } -pub fn platform() PlatformType { - mut logger := get_logger() +pub fn cmd_exists(cmd string) bool { + cmd1 := 'which ${cmd}' + res := os.execute(cmd1) + if res.exit_code > 0 { + return false + } + return true +} + +pub fn platform()! PlatformType { mut platform_ := PlatformType.unknown platform_ = platform_enum_from_string(memdb_get('platformtype')) if platform_ != PlatformType.unknown { @@ -58,7 +69,7 @@ pub fn platform() PlatformType { } else if cmd_exists('pacman') { platform_ = PlatformType.arch } else { - logger.error('Unknown platform') + return error('Unknown platform') } if platform_ != PlatformType.unknown { memdb_set('platformtype', platform_.str()) @@ -66,17 +77,18 @@ pub fn platform() PlatformType { return platform_ } -pub fn cputype() CPUType { - mut logger := get_logger() +pub fn cputype()! CPUType { mut cputype_ := CPUType.unknown cputype_ = cputype_enum_from_string(memdb_get('cputype')) if cputype_ != CPUType.unknown { return cputype_ } - sys_info := execute_stdout('uname -m') or { - logger.error('Failed to execute uname to get the cputype: ${err}') - return CPUType.unknown + res := os.execute('uname -m') + if res.exit_code >0{ + return error("can't execute uname -m") } + sys_info := res.output + cputype_ = match sys_info.to_lower().trim_space() { 'x86_64' { CPUType.intel @@ -87,9 +99,7 @@ pub fn cputype() CPUType { 'aarch64' { CPUType.arm } - // TODO 32 bit ones! else { - logger.error('Unknown cpu type ${sys_info}') CPUType.unknown } } @@ -100,37 +110,37 @@ pub fn cputype() CPUType { return cputype_ } -pub fn is_osx() bool { - return platform() == .osx +pub fn is_osx()! bool { + return platform()! == .osx } -pub fn is_osx_arm() bool { - return platform() == .osx && cputype() == .arm +pub fn is_osx_arm()! bool { + return platform()! == .osx && cputype()! == .arm } -pub fn is_osx_intel() bool { - return platform() == .osx && cputype() != .intel +pub fn is_osx_intel()! bool { + return platform()! == .osx && cputype()! == .intel } -pub fn is_ubuntu() bool { - return platform() == .ubuntu +pub fn is_ubuntu()! bool { + return platform()! == .ubuntu } -pub fn is_linux() bool { - return platform() == .ubuntu || platform() == .arch || platform() == .suse - || platform() == .alpine +pub fn is_linux()! bool { + return platform()! == .ubuntu || platform()! == .arch || platform()! == .suse + || platform()! == .alpine } -pub fn is_linux_arm() bool { - // console.print_debug("islinux:${is_linux()} cputype:${cputype()}") - return is_linux() && cputype() == .arm +pub fn is_linux_arm()!bool { + // console.print_debug("islinux:${is_linux()!} cputype:${cputype()!}") + return is_linux()! && cputype()! == .arm } -pub fn is_linux_intel() bool { - return is_linux() && cputype() == .intel +pub fn is_linux_intel()! bool { + return is_linux()! && cputype()! == .intel } -pub fn hostname() !string { +pub fn hostname()!string { res := os.execute('hostname') if res.exit_code > 0 { return error("can't get hostname. Error.") diff --git a/lib/core/platform_test.v b/lib/core/platform_test.v new file mode 100644 index 00000000..aa9706a7 --- /dev/null +++ b/lib/core/platform_test.v @@ -0,0 +1,9 @@ +module core + +fn test_platform()! { + assert platform()! != .unknown +} + +fn test_cputype()! { + assert cputype()! != .unknown +} diff --git a/lib/core/readme.md b/lib/core/readme.md new file mode 100644 index 00000000..c52e8684 --- /dev/null +++ b/lib/core/readme.md @@ -0,0 +1,85 @@ +# Core Module + +The Core module provides fundamental system-level functionality for the Hero framework. It handles platform detection, system operations, and provides essential utilities used throughout the framework. + +## Main Features + +### Platform Management +- Platform detection (OSX, Ubuntu, Alpine, Arch) +- CPU architecture detection (Intel, ARM) +- System information retrieval (hostname, init system) +- Cross-platform compatibility utilities + +### Memory Database +- Thread-safe in-memory key-value store +- Global state management +- Caching for system information + +### Sudo Operations +- Permission management and verification +- Sudo requirement detection +- Path access rights checking +- Command elevation handling + +### Submodules + +- **base**: Context and session management +- **httpconnection**: HTTP client functionality +- **logger**: Logging infrastructure +- **pathlib**: Path manipulation and handling +- **playbook**: Execution playbooks +- **redisclient**: Redis database client +- **rootpath**: Root path management +- **smartid**: Identifier management +- **texttools**: Text manipulation utilities +- **vexecutor**: Command execution + +## Platform Support + +The module supports multiple platforms: +- macOS (Intel and ARM) +- Ubuntu +- Alpine Linux +- Arch Linux + +And CPU architectures: +- x86_64 (Intel) +- ARM64/AArch64 + +## Usage + +The core module provides essential functionality used by other Hero framework components. Key features include: + +### Platform Detection +```v +// Check platform type +if core.is_linux()! { + // Linux-specific code +} + +// Check CPU architecture +if core.is_linux_arm()! { + // ARM-specific code +} +``` + +### Memory Database +```v +// Store values +core.memdb_set('key', 'value') + +// Retrieve values +value := core.memdb_get('key') +``` + +### Sudo Operations +```v +// Check sudo requirements +if core.sudo_required()! { + // Handle sudo requirements +} + +// Verify path permissions +path := core.sudo_path_check('/protected/path', true)! +``` + diff --git a/lib/core/sudo.v b/lib/core/sudo.v new file mode 100644 index 00000000..092c5b01 --- /dev/null +++ b/lib/core/sudo.v @@ -0,0 +1,91 @@ +module core + +import base +import os + +//check path is accessible, e.g. do we need sudo and are we sudo +// if ok then will just return the same path string as output +pub fn sudo_path_check(path string)!string{ + if sudo_path_ok(path)!{ + return path + } + return error("Can't write/delete path:${path} because of no rights.") +} + +//return false if we can't work on the path +pub fn sudo_path_ok(path string)!bool{ + if sudo_rights_check()!{ + return true + } + // Check if path is in protected directories + for item in ["/usr/","/boot","/etc","/root/"]{ + if path.starts_with(item){ + return false + } + } + // If not in protected directories, path is accessible + return true +} + + +//if we know cmd requires sudo rights +pub fn sudo_cmd(cmd string)!bool{ + cmd2:=cmd.split(" ")[0] + if cmd2 in [ + "ufw" + ] { + return true + } + //TODO: need many more checks + return false +} + +//if sudo required and we are interactive then we will put sudo in front of returned cmd +pub fn sudo_cmd_check(cmd string)!string{ + // If we have sudo rights, no need to add sudo prefix + if sudo_rights_check()!{ + return cmd + } + + // Check if command requires sudo + needs_sudo := sudo_cmd(cmd)! + + if !needs_sudo { + return cmd + } + + if interactive()!{ + return "sudo ${cmd}" + } + + return error("can't execute the cmd, because no sudo rights.\ncmd:'${cmd}'") +} + + + +//check of we have sudo rights, if yes return true +pub fn sudo_rights_check() ! bool { + // Check if the user is root + if os.getenv('USER') == 'root' { + return true + } + //TOOD: we can do more + return false +} + +// Method to check if sudo is required (i.e., if the user is root or has sudo privileges) +pub fn sudo_required()!bool { + // Check if the user is root + if sudo_rights_check()!{ + return false + } + platform_ := platform()! + + if platform_ == .osx { + return false + } + + // Check if the user has sudo privileges (test with `sudo -v`) + sudo_check := os.execute('sudo -v') + return sudo_check.exit_code == 0 +} diff --git a/lib/core/sudo_test.v b/lib/core/sudo_test.v new file mode 100644 index 00000000..60c0daca --- /dev/null +++ b/lib/core/sudo_test.v @@ -0,0 +1,67 @@ +module core +import os +import base + +fn init_context() ! { + mut c := base.context()! + c.config.id = 1 + c.config.interactive = true + c.save()! +} + +fn test_sudo_required()! { + init_context()! + // Test if sudo requirement detection works + required := sudo_required()! + // We can't assert specific value as it depends on system state + // but we can verify it returns a valid bool + assert required == true || required == false +} + +fn test_sudo_cmd() { + init_context()! + // Test known sudo commands + assert sudo_cmd('ufw allow 80')! == true + assert sudo_cmd('echo test')! == false +} + +fn test_sudo_path_ok() { + init_context()! + // Test path permission checks + user_home := os.home_dir() + assert sudo_path_ok(user_home)! == true +} + +fn test_sudo_path_protected() { + init_context()! + // Test path permission checks for protected paths + p := "/usr/local" + + // Protected paths should require sudo + assert sudo_path_ok(p)! == false +} + + +fn test_sudo_cmd_check() { + init_context()! + assert interactive()!, 'interactive mode should be set' + + // Test command sudo requirement checking for non-sudo command + cmd := 'echo test' + + result := sudo_cmd_check(cmd)! + assert result == cmd + +} + +fn test_sudo_cmd_check_sudo_required()! { + init_context()! + assert interactive()!, 'interactive mode should be set' + + // Test command sudo requirement checking for sudo-required command + cmd := 'ufw something' + + result := sudo_cmd_check(cmd)! + assert result == 'sudo ${cmd}' + +} diff --git a/lib/data/ipaddress/ipaddress.v b/lib/data/ipaddress/ipaddress.v index 38f398e7..c67498e9 100644 --- a/lib/data/ipaddress/ipaddress.v +++ b/lib/data/ipaddress/ipaddress.v @@ -142,7 +142,7 @@ pub fn (mut ipaddr IPAddress) ping(args_ PingArgs) bool { if ipaddr.cat == IpAddressType.ipv4 { cmd = 'ping -c 1 -W ${args.timeout} ${ipaddr.addr}' } else { - if osal.is_osx() { + if core.is_osx()! { cmd = 'ping6 -c 1 -i ${timeout} ${ipaddr.addr}' } else { cmd = 'ping -6 -c 1 -W ${args.timeout} ${ipaddr.addr}' diff --git a/lib/data/markdownparser/parsers/parser_line.v b/lib/data/markdownparser/parsers/parser_line.v index 6c2a658a..1b7fc6ea 100644 --- a/lib/data/markdownparser/parsers/parser_line.v +++ b/lib/data/markdownparser/parsers/parser_line.v @@ -120,21 +120,21 @@ fn (mut parser Parser) next() { // move further and reset the state fn (mut parser Parser) next_start() ! { // means we need to add paragraph because we don't know what comes next - if parser.doc.last()! !is elements.Paragraph { + if parser.doc.last()!is elements.Paragraph { parser.doc.paragraph_new(mut parser.doc, '') } parser.next() } fn (mut parser Parser) next_start_lf() ! { - if parser.doc.last()! !is elements.Paragraph { + if parser.doc.last()!is elements.Paragraph { parser.doc.paragraph_new(mut parser.doc, '\n') } parser.next() } fn (mut parser Parser) ensure_last_is_paragraph() ! { - if parser.doc.last()! !is elements.Paragraph { + if parser.doc.last()!is elements.Paragraph { parser.doc.paragraph_new(mut parser.doc, '') } } diff --git a/lib/installers/base/installer.v b/lib/installers/base/installer.v index 46316035..936b2756 100644 --- a/lib/installers/base/installer.v +++ b/lib/installers/base/installer.v @@ -2,6 +2,7 @@ module base import freeflowuniverse.herolib.osal import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.core import os @[params] @@ -14,7 +15,7 @@ pub mut: // install base will return true if it was already installed pub fn install(args_ InstallArgs) ! { console.print_header('install base (reset: ${args_.reset})') - pl := osal.platform() + pl := core.platform()! mut args := args_ @@ -93,7 +94,7 @@ pub fn sshkeysinstall(args InstallArgs) ! { pub fn develop(args InstallArgs) ! { console.print_header('install base develop (reset: ${args.reset})') - pl := osal.platform() + pl := core.platform()! if args.reset == false && osal.done_exists('hero_development') { return diff --git a/lib/installers/base/redis.v b/lib/installers/base/redis.v index 3a963b5f..ceb176f0 100644 --- a/lib/installers/base/redis.v +++ b/lib/installers/base/redis.v @@ -4,6 +4,7 @@ import freeflowuniverse.herolib.osal import freeflowuniverse.herolib.core.pathlib import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.sysadmin.startupmanager +import freeflowuniverse.herolib.core import time import os @@ -39,7 +40,7 @@ pub fn redis_install(args_ RedisInstallArgs) ! { console.print_header('install redis.') if !(osal.cmd_exists_profile('redis-server')) { - if osal.is_linux() { + if core.is_linux()! { osal.package_install('redis-server')! } else { osal.package_install('redis')! @@ -54,7 +55,7 @@ pub fn redis_install(args_ RedisInstallArgs) ! { } fn configfilepath(args RedisInstallArgs) string { - if osal.is_linux() { + if core.is_linux() or {panic(err)} { return '/etc/redis/redis.conf' } else { return '${args.datadir}/redis.conf' @@ -83,7 +84,7 @@ pub fn start(args RedisInstallArgs) ! { // remove all redis in memory osal.process_kill_recursive(name: 'redis-server')! - if osal.platform() == .osx { + if core.platform()! == .osx { osal.exec(cmd: 'redis-server ${configfilepath()} --daemonize yes')! // osal.exec(cmd:"brew services start redis") or { // osal.exec(cmd:"redis-server ${configfilepath()} --daemonize yes")! diff --git a/lib/installers/db/meilisearchinstaller/meilisearchinstaller_actions.v b/lib/installers/db/meilisearchinstaller/meilisearchinstaller_actions.v index ba60b779..9e1acf63 100644 --- a/lib/installers/db/meilisearchinstaller/meilisearchinstaller_actions.v +++ b/lib/installers/db/meilisearchinstaller/meilisearchinstaller_actions.v @@ -9,7 +9,7 @@ import freeflowuniverse.herolib.installers.ulist import os fn installed_() !bool { - res := os.execute('${osal.profile_path_source_and()} meilisearch -V') + res := os.execute('${osal.profile_path_source_and()!} meilisearch -V') if res.exit_code != 0 { return false } @@ -28,13 +28,13 @@ fn install_() ! { console.print_header('install meilisearch') mut url := '' - if osal.is_linux_arm() { + if core.is_linux_arm()! { url = 'https://github.com/meilisearch/meilisearch/releases/download/v${version}/meilisearch-linux-aarch64' - } else if osal.is_linux_intel() { + } else if core.is_linux_intel()! { url = 'https://github.com/meilisearch/meilisearch/releases/download/v${version}/meilisearch-linux-amd64' - } else if osal.is_osx_arm() { + } else if core.is_osx_arm()! { url = 'https://github.com/meilisearch/meilisearch/releases/download/v${version}/meilisearch-macos-apple-silicon' - } else if osal.is_osx_intel() { + } else if core.is_osx_intel()! { url = 'https://github.com/meilisearch/meilisearch/releases/download/v${version}/meilisearch-macos-amd64' } else { return error('unsported platform') @@ -62,7 +62,7 @@ fn build_() ! { // console.print_header('compile meilisearch') // rust.install()! // mut dest_on_os := '${os.home_dir()}/hero/bin' - // if osal.is_linux() { + // if core.is_linux()! { // dest_on_os = '/usr/local/bin' // } // console.print_debug(' - dest path for meilisearchs is on: ${dest_on_os}') diff --git a/lib/installers/db/meilisearchinstaller/meilisearchinstaller_factory_.v b/lib/installers/db/meilisearchinstaller/meilisearchinstaller_factory_.v index ef8ae112..7490d7f0 100644 --- a/lib/installers/db/meilisearchinstaller/meilisearchinstaller_factory_.v +++ b/lib/installers/db/meilisearchinstaller/meilisearchinstaller_factory_.v @@ -1,271 +1,301 @@ + module meilisearchinstaller import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.data.encoderhero + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - meilisearchinstaller_global map[string]&MeilisearchServer - meilisearchinstaller_default string + meilisearchinstaller_global map[string]&MeilisearchServer + meilisearchinstaller_default string ) /////////FACTORY + + @[params] -pub struct ArgsGet { +pub struct ArgsGet{ pub mut: - name string + name string } -fn args_get(args_ ArgsGet) ArgsGet { - mut model := args_ - if model.name == '' { - model.name = meilisearchinstaller_default - } - if model.name == '' { - model.name = 'default' - } - return model +fn args_get (args_ ArgsGet) ArgsGet { + mut model:=args_ + if model.name == ""{ + model.name = meilisearchinstaller_default + } + if model.name == ""{ + model.name = "default" + } + return model } -pub fn get(args_ ArgsGet) !&MeilisearchServer { - mut model := args_get(args_) - if model.name !in meilisearchinstaller_global { - if model.name == 'default' { - if !config_exists(model) { - if default { - config_save(model)! - } - } - config_load(model)! - } - } - return meilisearchinstaller_global[model.name] or { - println(meilisearchinstaller_global) - panic('could not get config for meilisearchinstaller with name:${model.name}') - } +pub fn get(args_ ArgsGet) !&MeilisearchServer { + mut args := args_get(args_) + if !(args.name in meilisearchinstaller_global) { + if args.name=="default"{ + if ! config_exists(args){ + if default{ + mut context:=base.context() or { panic("bug") } + context.hero_config_set("meilisearchinstaller",model.name,heroscript_default()!)! + } + } + load(args)! + } + } + return meilisearchinstaller_global[args.name] or { + println(meilisearchinstaller_global) + panic("could not get config for ${args.name} with name:${model.name}") + } } -fn config_exists(args_ ArgsGet) bool { - mut model := args_get(args_) - mut context := base.context() or { panic('bug') } - return context.hero_config_exists('meilisearchinstaller', model.name) + + +//set the model in mem and the config on the filesystem +pub fn set(o MeilisearchServer)! { + mut o2:=obj_init(o)! + meilisearchinstaller_global[o.name] = &o2 + meilisearchinstaller_default = o.name } -fn config_load(args_ ArgsGet) ! { - mut model := args_get(args_) - mut context := base.context()! - mut heroscript := context.hero_config_get('meilisearchinstaller', model.name)! - play(heroscript: heroscript)! +//check we find the config on the filesystem +pub fn exists(args_ ArgsGet) bool { + mut model := args_get(args_) + mut context:=base.context() or { panic("bug") } + return context.hero_config_exists("meilisearchinstaller",model.name) } -fn config_save(args_ ArgsGet) ! { - mut model := args_get(args_) - mut context := base.context()! - context.hero_config_set('meilisearchinstaller', model.name, heroscript_default()!)! +//load the config error if it doesn't exist +pub fn load(args_ ArgsGet) ! { + mut model := args_get(args_) + mut context:=base.context()! + mut heroscript := context.hero_config_get("meilisearchinstaller",model.name)! + play(heroscript:heroscript)! } -fn set(o MeilisearchServer) ! { - mut o2 := obj_init(o)! - meilisearchinstaller_global[o.name] = &o2 - meilisearchinstaller_default = o.name +//save the config to the filesystem in the context +pub fn save(o MeilisearchServer)! { + mut context:=base.context()! + heroscript := encoderhero.encode[MeilisearchServer](o)! + context.hero_config_set("meilisearchinstaller",model.name,heroscript)! } @[params] pub struct PlayArgs { pub mut: - heroscript string // if filled in then plbook will be made out of it - plbook ?playbook.PlayBook - reset bool + heroscript string //if filled in then plbook will be made out of it + plbook ?playbook.PlayBook + reset bool } pub fn play(args_ PlayArgs) ! { - mut model := args_ + + mut model:=args_ - if model.heroscript == '' { - model.heroscript = heroscript_default()! - } - mut plbook := model.plbook or { playbook.new(text: model.heroscript)! } + if model.heroscript == "" { + model.heroscript = heroscript_default()! + } + mut plbook := model.plbook or { + playbook.new(text: model.heroscript)! + } + + mut configure_actions := plbook.find(filter: 'meilisearchinstaller.configure')! + if configure_actions.len > 0 { + for config_action in configure_actions { + mut p := config_action.params + mycfg:=cfg_play(p)! + console.print_debug("install action meilisearchinstaller.configure\n${mycfg}") + set(mycfg)! + save(mycfg)! + } + } - mut install_actions := plbook.find(filter: 'meilisearchinstaller.configure')! - if install_actions.len > 0 { - for install_action in install_actions { - mut p := install_action.params - mycfg := cfg_play(p)! - console.print_debug('install action meilisearchinstaller.configure\n${mycfg}') - set(mycfg)! - } - } + mut other_actions := plbook.find(filter: 'meilisearchinstaller.')! + for other_action in other_actions { + if other_action.name in ["destroy","install","build"]{ + mut p := other_action.params + reset:=p.get_default_false("reset") + if other_action.name == "destroy" || reset{ + console.print_debug("install action meilisearchinstaller.destroy") + destroy_()! + } + if other_action.name == "install"{ + console.print_debug("install action meilisearchinstaller.install") + install_()! + } + } + if other_action.name in ["start","stop","restart"]{ + mut p := other_action.params + name := p.get('name')! + mut meilisearchinstaller_obj:=get(name:name)! + console.print_debug("action object:\n${meilisearchinstaller_obj}") + if other_action.name == "start"{ + console.print_debug("install action meilisearchinstaller.${other_action.name}") + meilisearchinstaller_obj.start()! + } - mut other_actions := plbook.find(filter: 'meilisearchinstaller.')! - for other_action in other_actions { - if other_action.name in ['destroy', 'install', 'build'] { - mut p := other_action.params - reset := p.get_default_false('reset') - if other_action.name == 'destroy' || reset { - console.print_debug('install action meilisearchinstaller.destroy') - destroy()! - } - if other_action.name == 'install' { - console.print_debug('install action meilisearchinstaller.install') - install()! - } - } - if other_action.name in ['start', 'stop', 'restart'] { - mut p := other_action.params - name := p.get('name')! - mut meilisearchinstaller_obj := get(name: name)! - console.print_debug('action object:\n${meilisearchinstaller_obj}') - if other_action.name == 'start' { - console.print_debug('install action meilisearchinstaller.${other_action.name}') - meilisearchinstaller_obj.start()! - } + if other_action.name == "stop"{ + console.print_debug("install action meilisearchinstaller.${other_action.name}") + meilisearchinstaller_obj.stop()! + } + if other_action.name == "restart"{ + console.print_debug("install action meilisearchinstaller.${other_action.name}") + meilisearchinstaller_obj.restart()! + } + } + } - if other_action.name == 'stop' { - console.print_debug('install action meilisearchinstaller.${other_action.name}') - meilisearchinstaller_obj.stop()! - } - if other_action.name == 'restart' { - console.print_debug('install action meilisearchinstaller.${other_action.name}') - meilisearchinstaller_obj.restart()! - } - } - } } + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// -fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } + +//load from disk and make sure is properly intialized +pub fn (mut self MeilisearchServer) reload() ! { + switch(self.name) + self=obj_init(self)! } -// load from disk and make sure is properly intialized -pub fn (mut self MeilisearchServer) reload() ! { - switch(self.name) - self = obj_init(self)! + +fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { + // unknown + // screen + // zinit + // tmux + // systemd + match cat{ + .zinit{ + console.print_debug("startupmanager: zinit") + return startupmanager.get(cat:.zinit)! + } + .systemd{ + console.print_debug("startupmanager: systemd") + return startupmanager.get(cat:.systemd)! + }else{ + console.print_debug("startupmanager: auto") + return startupmanager.get()! + } + } } pub fn (mut self MeilisearchServer) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('meilisearchinstaller start') + console.print_header('meilisearchinstaller start') - if !installed()! { - install()! - } + if ! installed_()!{ + install_()! + } - configure()! + configure()! - start_pre()! + start_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! - console.print_debug('starting meilisearchinstaller with ${zprocess.startuptype}...') + console.print_debug('starting meilisearchinstaller with ${zprocess.startuptype}...') - sm.new(zprocess)! + sm.new(zprocess)! - sm.start(zprocess.name)! - } + sm.start(zprocess.name)! + } - start_post()! + start_post()! + + for _ in 0 .. 50 { + if self.running()! { + return + } + time.sleep(100 * time.millisecond) + } + return error('meilisearchinstaller did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('meilisearchinstaller did not install properly.') } pub fn (mut self MeilisearchServer) install_start(model InstallArgs) ! { - switch(self.name) - self.install(model)! - self.start()! + switch(self.name) + self.install(model)! + self.start()! } pub fn (mut self MeilisearchServer) stop() ! { - switch(self.name) - stop_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - sm.stop(zprocess.name)! - } - stop_post()! + switch(self.name) + stop_pre()! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + sm.stop(zprocess.name)! + } + stop_post()! } pub fn (mut self MeilisearchServer) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self MeilisearchServer) running() !bool { - switch(self.name) + switch(self.name) - // walk over the generic processes, if not running return - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - r := sm.running(zprocess.name)! - if r == false { - return false - } - } - return running()! + //walk over the generic processes, if not running return + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + r:=sm.running(zprocess.name)! + if r==false{ + return false + } + } + return running()! } @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self MeilisearchServer) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +//switch instance to be used for meilisearchinstaller +pub fn switch(name string) { + meilisearchinstaller_default = name +} + + +pub fn (mut self MeilisearchServer) install(args InstallArgs) ! { + switch(self.name) + if args.reset { + destroy_()! + } + if ! (installed_()!){ + install_()! + } } pub fn (mut self MeilisearchServer) build() ! { - switch(self.name) - build()! + switch(self.name) + build_()! } pub fn (mut self MeilisearchServer) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! + switch(self.name) + self.stop() or {} + destroy_()! } -// switch instance to be used for meilisearchinstaller -pub fn switch(name string) { - meilisearchinstaller_default = name -} + + + diff --git a/lib/installers/db/postgresql/postgresql_factory_.v b/lib/installers/db/postgresql/postgresql_factory_.v index 04ac3d84..9829b96f 100644 --- a/lib/installers/db/postgresql/postgresql_factory_.v +++ b/lib/installers/db/postgresql/postgresql_factory_.v @@ -1,266 +1,252 @@ + module postgresql import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.data.encoderhero + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - postgresql_global map[string]&Postgresql - postgresql_default string + postgresql_global map[string]&Postgresql + postgresql_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string + + + +//set the model in mem and the config on the filesystem +pub fn set(o Postgresql)! { + mut o2:=obj_init(o)! + postgresql_global[o.name] = &o2 + postgresql_default = o.name } -fn args_get(args_ ArgsGet) ArgsGet { - mut model := args_ - if model.name == '' { - model.name = postgresql_default - } - if model.name == '' { - model.name = 'default' - } - return model +//check we find the config on the filesystem +pub fn exists(args_ ArgsGet) bool { + mut model := args_get(args_) + mut context:=base.context() or { panic("bug") } + return context.hero_config_exists("postgresql",model.name) } -pub fn get(args_ ArgsGet) !&Postgresql { - mut model := args_get(args_) - if model.name !in postgresql_global { - if model.name == 'default' { - if !config_exists(model) { - if default { - config_save(model)! - } - } - config_load(model)! - } - } - return postgresql_global[model.name] or { - println(postgresql_global) - panic('could not get config for postgresql with name:${model.name}') - } +//load the config error if it doesn't exist +pub fn load(args_ ArgsGet) ! { + mut model := args_get(args_) + mut context:=base.context()! + mut heroscript := context.hero_config_get("postgresql",model.name)! + play(heroscript:heroscript)! } -fn config_exists(args_ ArgsGet) bool { - mut model := args_get(args_) - mut context := base.context() or { panic('bug') } - return context.hero_config_exists('postgresql', model.name) -} - -fn config_load(args_ ArgsGet) ! { - mut model := args_get(args_) - mut context := base.context()! - mut heroscript := context.hero_config_get('postgresql', model.name)! - play(heroscript: heroscript)! -} - -fn config_save(args_ ArgsGet) ! { - mut model := args_get(args_) - mut context := base.context()! - context.hero_config_set('postgresql', model.name, heroscript_default()!)! -} - -fn set(o Postgresql) ! { - mut o2 := obj_init(o)! - postgresql_global[o.name] = &o2 - postgresql_default = o.name +//save the config to the filesystem in the context +pub fn save(o Postgresql)! { + mut context:=base.context()! + heroscript := encoderhero.encode[Postgresql](o)! + context.hero_config_set("postgresql",model.name,heroscript)! } @[params] pub struct PlayArgs { pub mut: - heroscript string // if filled in then plbook will be made out of it - plbook ?playbook.PlayBook - reset bool + heroscript string //if filled in then plbook will be made out of it + plbook ?playbook.PlayBook + reset bool } pub fn play(args_ PlayArgs) ! { - mut model := args_ + + mut model:=args_ - if model.heroscript == '' { - model.heroscript = heroscript_default()! - } - mut plbook := model.plbook or { playbook.new(text: model.heroscript)! } + if model.heroscript == "" { + model.heroscript = heroscript_default()! + } + mut plbook := model.plbook or { + playbook.new(text: model.heroscript)! + } + + mut configure_actions := plbook.find(filter: 'postgresql.configure')! + if configure_actions.len > 0 { + for config_action in configure_actions { + mut p := config_action.params + mycfg:=cfg_play(p)! + console.print_debug("install action postgresql.configure\n${mycfg}") + set(mycfg)! + save(mycfg)! + } + } - mut install_actions := plbook.find(filter: 'postgresql.configure')! - if install_actions.len > 0 { - for install_action in install_actions { - mut p := install_action.params - mycfg := cfg_play(p)! - console.print_debug('install action postgresql.configure\n${mycfg}') - set(mycfg)! - } - } + mut other_actions := plbook.find(filter: 'postgresql.')! + for other_action in other_actions { + if other_action.name in ["destroy","install","build"]{ + mut p := other_action.params + reset:=p.get_default_false("reset") + if other_action.name == "destroy" || reset{ + console.print_debug("install action postgresql.destroy") + destroy_()! + } + if other_action.name == "install"{ + console.print_debug("install action postgresql.install") + install_()! + } + } + if other_action.name in ["start","stop","restart"]{ + mut p := other_action.params + name := p.get('name')! + mut postgresql_obj:=get(name:name)! + console.print_debug("action object:\n${postgresql_obj}") + if other_action.name == "start"{ + console.print_debug("install action postgresql.${other_action.name}") + postgresql_obj.start()! + } - mut other_actions := plbook.find(filter: 'postgresql.')! - for other_action in other_actions { - if other_action.name in ['destroy', 'install', 'build'] { - mut p := other_action.params - reset := p.get_default_false('reset') - if other_action.name == 'destroy' || reset { - console.print_debug('install action postgresql.destroy') - destroy()! - } - if other_action.name == 'install' { - console.print_debug('install action postgresql.install') - install()! - } - } - if other_action.name in ['start', 'stop', 'restart'] { - mut p := other_action.params - name := p.get('name')! - mut postgresql_obj := get(name: name)! - console.print_debug('action object:\n${postgresql_obj}') - if other_action.name == 'start' { - console.print_debug('install action postgresql.${other_action.name}') - postgresql_obj.start()! - } + if other_action.name == "stop"{ + console.print_debug("install action postgresql.${other_action.name}") + postgresql_obj.stop()! + } + if other_action.name == "restart"{ + console.print_debug("install action postgresql.${other_action.name}") + postgresql_obj.restart()! + } + } + } - if other_action.name == 'stop' { - console.print_debug('install action postgresql.${other_action.name}') - postgresql_obj.stop()! - } - if other_action.name == 'restart' { - console.print_debug('install action postgresql.${other_action.name}') - postgresql_obj.restart()! - } - } - } } + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// -fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } + +//load from disk and make sure is properly intialized +pub fn (mut self Postgresql) reload() ! { + switch(self.name) + self=obj_init(self)! } -// load from disk and make sure is properly intialized -pub fn (mut self Postgresql) reload() ! { - switch(self.name) - self = obj_init(self)! + +fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { + // unknown + // screen + // zinit + // tmux + // systemd + match cat{ + .zinit{ + console.print_debug("startupmanager: zinit") + return startupmanager.get(cat:.zinit)! + } + .systemd{ + console.print_debug("startupmanager: systemd") + return startupmanager.get(cat:.systemd)! + }else{ + console.print_debug("startupmanager: auto") + return startupmanager.get()! + } + } } pub fn (mut self Postgresql) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('postgresql start') + console.print_header('postgresql start') - if !installed()! { - install()! - } + if ! installed_()!{ + install_()! + } - configure()! + configure()! - start_pre()! + start_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! - console.print_debug('starting postgresql with ${zprocess.startuptype}...') + console.print_debug('starting postgresql with ${zprocess.startuptype}...') - sm.new(zprocess)! + sm.new(zprocess)! - sm.start(zprocess.name)! - } + sm.start(zprocess.name)! + } - start_post()! + start_post()! + + for _ in 0 .. 50 { + if self.running()! { + return + } + time.sleep(100 * time.millisecond) + } + return error('postgresql did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('postgresql did not install properly.') } pub fn (mut self Postgresql) install_start(model InstallArgs) ! { - switch(self.name) - self.install(model)! - self.start()! + switch(self.name) + self.install(model)! + self.start()! } pub fn (mut self Postgresql) stop() ! { - switch(self.name) - stop_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - sm.stop(zprocess.name)! - } - stop_post()! + switch(self.name) + stop_pre()! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + sm.stop(zprocess.name)! + } + stop_post()! } pub fn (mut self Postgresql) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self Postgresql) running() !bool { - switch(self.name) + switch(self.name) - // walk over the generic processes, if not running return - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - r := sm.running(zprocess.name)! - if r == false { - return false - } - } - return running()! + //walk over the generic processes, if not running return + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + r:=sm.running(zprocess.name)! + if r==false{ + return false + } + } + return running()! } @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self Postgresql) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self Postgresql) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! +pub fn destroy() ! { + destroy_()! } -// switch instance to be used for postgresql -pub fn switch(name string) { - postgresql_default = name -} + + + + + diff --git a/lib/installers/db/postgresql/postgresql_model.v b/lib/installers/db/postgresql/postgresql_model.v index bbb5907d..fd5eed9a 100644 --- a/lib/installers/db/postgresql/postgresql_model.v +++ b/lib/installers/db/postgresql/postgresql_model.v @@ -39,7 +39,7 @@ fn cfg_play(p paramsparser.Params) !Postgresql { fn obj_init(obj_ Postgresql) !Postgresql { mut obj := obj_ if obj.path == '' { - if osal.is_linux() { + if core.is_linux()! { obj.path = '/data/postgresql/${obj.name}' } else { obj.path = '${os.home_dir()}/hero/var/postgresql/${obj.name}' diff --git a/lib/installers/db/zerodb/zdb_installer.v b/lib/installers/db/zerodb/zdb_installer.v index f044fa53..6ecfae89 100644 --- a/lib/installers/db/zerodb/zdb_installer.v +++ b/lib/installers/db/zerodb/zdb_installer.v @@ -28,7 +28,7 @@ pub fn install_(args_ InstallArgs) ! { mut args := args_ version := '2.0.7' - res := os.execute('${osal.profile_path_source_and()} zdb --version') + res := os.execute('${osal.profile_path_source_and()!} zdb --version') if res.exit_code == 0 { r := res.output.split_into_lines().filter(it.trim_space().len > 0) if r.len != 3 { @@ -46,7 +46,7 @@ pub fn install_(args_ InstallArgs) ! { console.print_header('install zdb') mut url := '' - if osal.is_linux_intel() { + if core.is_linux_intel()! { url = 'https://github.com/threefoldtech/0-db/releases/download/v${version}/zdb-${version}-linux-amd64-static' } else { return error('unsported platform, only linux 64 for zdb for now') diff --git a/lib/installers/db/zerodb/zerodb_actions.v b/lib/installers/db/zerodb/zerodb_actions.v index c82dc370..a7db9c95 100644 --- a/lib/installers/db/zerodb/zerodb_actions.v +++ b/lib/installers/db/zerodb/zerodb_actions.v @@ -66,7 +66,7 @@ fn stop_post() ! { // checks if a certain version or above is installed fn installed_() !bool { // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED - // res := os.execute('${osal.profile_path_source_and()} zerodb version') + // res := os.execute('${osal.profile_path_source_and()!} zerodb version') // if res.exit_code != 0 { // return false // } @@ -98,13 +98,13 @@ fn install_() ! { console.print_header('install zerodb') // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // mut url := '' - // if osal.is_linux_arm() { + // if core.is_linux_arm()! { // url = 'https://github.com/zerodb-dev/zerodb/releases/download/v${version}/zerodb_${version}_linux_arm64.tar.gz' - // } else if osal.is_linux_intel() { + // } else if core.is_linux_intel()! { // url = 'https://github.com/zerodb-dev/zerodb/releases/download/v${version}/zerodb_${version}_linux_amd64.tar.gz' - // } else if osal.is_osx_arm() { + // } else if core.is_osx_arm()! { // url = 'https://github.com/zerodb-dev/zerodb/releases/download/v${version}/zerodb_${version}_darwin_arm64.tar.gz' - // } else if osal.is_osx_intel() { + // } else if core.is_osx_intel()! { // url = 'https://github.com/zerodb-dev/zerodb/releases/download/v${version}/zerodb_${version}_darwin_amd64.tar.gz' // } else { // return error('unsported platform') @@ -129,7 +129,7 @@ fn build_() ! { // url := 'https://github.com/threefoldtech/zerodb' // make sure we install base on the node - // if osal.platform() != .ubuntu { + // if core.platform()!= .ubuntu { // return error('only support ubuntu for now') // } // golang.install()! diff --git a/lib/installers/db/zerodb/zerodb_factory_.v b/lib/installers/db/zerodb/zerodb_factory_.v index 3d69cd0e..c80e04e7 100644 --- a/lib/installers/db/zerodb/zerodb_factory_.v +++ b/lib/installers/db/zerodb/zerodb_factory_.v @@ -1,153 +1,152 @@ + module zerodb import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - zerodb_global map[string]&ZeroDB - zerodb_default string + zerodb_global map[string]&ZeroDB + zerodb_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&ZeroDB { - return &ZeroDB{} -} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// + + + fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } + // unknown + // screen + // zinit + // tmux + // systemd + match cat{ + .zinit{ + console.print_debug("startupmanager: zinit") + return startupmanager.get(cat:.zinit)! + } + .systemd{ + console.print_debug("startupmanager: systemd") + return startupmanager.get(cat:.systemd)! + }else{ + console.print_debug("startupmanager: auto") + return startupmanager.get()! + } + } } pub fn (mut self ZeroDB) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('zerodb start') + console.print_header('zerodb start') - if !installed()! { - install()! - } + if ! installed_()!{ + install_()! + } - configure()! + configure()! - start_pre()! + start_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! - console.print_debug('starting zerodb with ${zprocess.startuptype}...') + console.print_debug('starting zerodb with ${zprocess.startuptype}...') - sm.new(zprocess)! + sm.new(zprocess)! - sm.start(zprocess.name)! - } + sm.start(zprocess.name)! + } - start_post()! + start_post()! + + for _ in 0 .. 50 { + if self.running()! { + return + } + time.sleep(100 * time.millisecond) + } + return error('zerodb did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('zerodb did not install properly.') } pub fn (mut self ZeroDB) install_start(model InstallArgs) ! { - switch(self.name) - self.install(model)! - self.start()! + switch(self.name) + self.install(model)! + self.start()! } pub fn (mut self ZeroDB) stop() ! { - switch(self.name) - stop_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - sm.stop(zprocess.name)! - } - stop_post()! + switch(self.name) + stop_pre()! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + sm.stop(zprocess.name)! + } + stop_post()! } pub fn (mut self ZeroDB) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self ZeroDB) running() !bool { - switch(self.name) + switch(self.name) - // walk over the generic processes, if not running return - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - r := sm.running(zprocess.name)! - if r == false { - return false - } - } - return running()! + //walk over the generic processes, if not running return + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + r:=sm.running(zprocess.name)! + if r==false{ + return false + } + } + return running()! } @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self ZeroDB) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self ZeroDB) build() ! { - switch(self.name) - build()! +pub fn destroy() ! { + destroy_()! } -pub fn (mut self ZeroDB) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! +pub fn build() ! { + build_()! } -// switch instance to be used for zerodb -pub fn switch(name string) { - zerodb_default = name -} + + + + diff --git a/lib/installers/db/zerofs/zerofs_actions.v b/lib/installers/db/zerofs/zerofs_actions.v index e07fb550..a2e900e4 100644 --- a/lib/installers/db/zerofs/zerofs_actions.v +++ b/lib/installers/db/zerofs/zerofs_actions.v @@ -66,7 +66,7 @@ fn stop_post() ! { // checks if a certain version or above is installed fn installed_() !bool { // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED - // res := os.execute('${osal.profile_path_source_and()} zerofs version') + // res := os.execute('${osal.profile_path_source_and()!} zerofs version') // if res.exit_code != 0 { // return false // } @@ -98,13 +98,13 @@ fn install_() ! { console.print_header('install zerofs') // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // mut url := '' - // if osal.is_linux_arm() { + // if core.is_linux_arm()! { // url = 'https://github.com/zerofs-dev/zerofs/releases/download/v${version}/zerofs_${version}_linux_arm64.tar.gz' - // } else if osal.is_linux_intel() { + // } else if core.is_linux_intel()! { // url = 'https://github.com/zerofs-dev/zerofs/releases/download/v${version}/zerofs_${version}_linux_amd64.tar.gz' - // } else if osal.is_osx_arm() { + // } else if core.is_osx_arm()! { // url = 'https://github.com/zerofs-dev/zerofs/releases/download/v${version}/zerofs_${version}_darwin_arm64.tar.gz' - // } else if osal.is_osx_intel() { + // } else if core.is_osx_intel()! { // url = 'https://github.com/zerofs-dev/zerofs/releases/download/v${version}/zerofs_${version}_darwin_amd64.tar.gz' // } else { // return error('unsported platform') @@ -129,7 +129,7 @@ fn build_() ! { // url := 'https://github.com/threefoldtech/zerofs' // make sure we install base on the node - // if osal.platform() != .ubuntu { + // if core.platform()!= .ubuntu { // return error('only support ubuntu for now') // } // golang.install()! diff --git a/lib/installers/db/zerofs/zerofs_factory_.v b/lib/installers/db/zerofs/zerofs_factory_.v index d885b669..8993fbff 100644 --- a/lib/installers/db/zerofs/zerofs_factory_.v +++ b/lib/installers/db/zerofs/zerofs_factory_.v @@ -1,153 +1,152 @@ + module zerofs import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - zerofs_global map[string]&ZeroFS - zerofs_default string + zerofs_global map[string]&ZeroFS + zerofs_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&ZeroFS { - return &ZeroFS{} -} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// + + + fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } + // unknown + // screen + // zinit + // tmux + // systemd + match cat{ + .zinit{ + console.print_debug("startupmanager: zinit") + return startupmanager.get(cat:.zinit)! + } + .systemd{ + console.print_debug("startupmanager: systemd") + return startupmanager.get(cat:.systemd)! + }else{ + console.print_debug("startupmanager: auto") + return startupmanager.get()! + } + } } pub fn (mut self ZeroFS) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('zerofs start') + console.print_header('zerofs start') - if !installed()! { - install()! - } + if ! installed_()!{ + install_()! + } - configure()! + configure()! - start_pre()! + start_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! - console.print_debug('starting zerofs with ${zprocess.startuptype}...') + console.print_debug('starting zerofs with ${zprocess.startuptype}...') - sm.new(zprocess)! + sm.new(zprocess)! - sm.start(zprocess.name)! - } + sm.start(zprocess.name)! + } - start_post()! + start_post()! + + for _ in 0 .. 50 { + if self.running()! { + return + } + time.sleep(100 * time.millisecond) + } + return error('zerofs did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('zerofs did not install properly.') } pub fn (mut self ZeroFS) install_start(model InstallArgs) ! { - switch(self.name) - self.install(model)! - self.start()! + switch(self.name) + self.install(model)! + self.start()! } pub fn (mut self ZeroFS) stop() ! { - switch(self.name) - stop_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - sm.stop(zprocess.name)! - } - stop_post()! + switch(self.name) + stop_pre()! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + sm.stop(zprocess.name)! + } + stop_post()! } pub fn (mut self ZeroFS) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self ZeroFS) running() !bool { - switch(self.name) + switch(self.name) - // walk over the generic processes, if not running return - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - r := sm.running(zprocess.name)! - if r == false { - return false - } - } - return running()! + //walk over the generic processes, if not running return + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + r:=sm.running(zprocess.name)! + if r==false{ + return false + } + } + return running()! } @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self ZeroFS) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self ZeroFS) build() ! { - switch(self.name) - build()! +pub fn destroy() ! { + destroy_()! } -pub fn (mut self ZeroFS) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! +pub fn build() ! { + build_()! } -// switch instance to be used for zerofs -pub fn switch(name string) { - zerofs_default = name -} + + + + diff --git a/lib/installers/infra/coredns/cdns_install.v b/lib/installers/infra/coredns/cdns_install.v index 560fc650..5cbf9f29 100644 --- a/lib/installers/infra/coredns/cdns_install.v +++ b/lib/installers/infra/coredns/cdns_install.v @@ -27,7 +27,7 @@ pub fn install_(args_ InstallArgs) ! { mut args := args_ version := '1.11.1' - res := os.execute('${osal.profile_path_source_and()} coredns version') + res := os.execute('${osal.profile_path_source_and()!} coredns version') if res.exit_code == 0 { r := res.output.split_into_lines().filter(it.trim_space().starts_with('CoreDNS-')) if r.len != 1 { @@ -44,13 +44,13 @@ pub fn install_(args_ InstallArgs) ! { console.print_header('install coredns') mut url := '' - if osal.is_linux_arm() { + if core.is_linux_arm()! { url = 'https://github.com/coredns/coredns/releases/download/v${version}/coredns_${version}_linux_arm64.tgz' - } else if osal.is_linux_intel() { + } else if core.is_linux_intel()! { url = 'https://github.com/coredns/coredns/releases/download/v${version}/coredns_${version}_linux_amd64.tgz' - } else if osal.is_osx_arm() { + } else if core.is_osx_arm()! { url = 'https://github.com/coredns/coredns/releases/download/v${version}/coredns_${version}_darwin_arm64.tgz' - } else if osal.is_osx_intel() { + } else if core.is_osx_intel()! { url = 'https://github.com/coredns/coredns/releases/download/v${version}/coredns_${version}_darwin_amd64.tgz' } else { return error('unsported platform') diff --git a/lib/installers/infra/gitea/.heroscript b/lib/installers/infra/gitea/.heroscript index e69de29b..ff8743d2 100644 --- a/lib/installers/infra/gitea/.heroscript +++ b/lib/installers/infra/gitea/.heroscript @@ -0,0 +1,11 @@ +!!hero_code.generate_installer + name: "gitea" + classname: "GiteaInstaller" + hasconfig: false + singleton: true + default: true + title: "" + templates: false + build: true + startupmanager: true + diff --git a/lib/installers/infra/gitea/gitea_actions.v b/lib/installers/infra/gitea/gitea_actions.v new file mode 100644 index 00000000..d8439e94 --- /dev/null +++ b/lib/installers/infra/gitea/gitea_actions.v @@ -0,0 +1,203 @@ +module gitea + +import freeflowuniverse.herolib.osal +import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.core.texttools +import freeflowuniverse.herolib.core.pathlib +import freeflowuniverse.herolib.installers.ulist +import freeflowuniverse.herolib.installers.base + +import freeflowuniverse.herolib.osal.systemd +import freeflowuniverse.herolib.osal.zinit + +import freeflowuniverse.herolib.installers.lang.golang +import freeflowuniverse.herolib.installers.lang.rust +import freeflowuniverse.herolib.installers.lang.python + +import os + +fn startupcmd () ![]zinit.ZProcessNewArgs{ + mut installer := get()! + mut res := []zinit.ZProcessNewArgs{} + //THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED + // res << zinit.ZProcessNewArgs{ + // name: 'gitea' + // cmd: 'gitea server' + // env: { + // 'HOME': '/root' + // } + // } + + return res + +} + +fn running_() !bool { + mut installer := get()! + //THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED + // this checks health of gitea + // curl http://localhost:3333/api/v1/s --oauth2-bearer 1234 works + // url:='http://127.0.0.1:${cfg.port}/api/v1' + // mut conn := httpconnection.new(name: 'gitea', url: url)! + + // if cfg.secret.len > 0 { + // conn.default_header.add(.authorization, 'Bearer ${cfg.secret}') + // } + // conn.default_header.add(.content_type, 'application/json') + // console.print_debug("curl -X 'GET' '${url}'/tags --oauth2-bearer ${cfg.secret}") + // r := conn.get_json_dict(prefix: 'tags', debug: false) or {return false} + // println(r) + // if true{panic("ssss")} + // tags := r['Tags'] or { return false } + // console.print_debug(tags) + // console.print_debug('gitea is answering.') + return false +} + +fn start_pre()!{ + +} + +fn start_post()!{ + +} + +fn stop_pre()!{ + +} + +fn stop_post()!{ + +} + + +//////////////////// following actions are not specific to instance of the object + +// checks if a certain version or above is installed +fn installed_() !bool { + //THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED + // res := os.execute('${osal.profile_path_source_and()!} gitea version') + // if res.exit_code != 0 { + // return false + // } + // r := res.output.split_into_lines().filter(it.trim_space().len > 0) + // if r.len != 1 { + // return error("couldn't parse gitea version.\n${res.output}") + // } + // if texttools.version(version) == texttools.version(r[0]) { + // return true + // } + return false +} + +//get the Upload List of the files +fn ulist_get() !ulist.UList { + //optionally build a UList which is all paths which are result of building, is then used e.g. in upload + return ulist.UList{} +} + +//uploads to S3 server if configured +fn upload_() ! { + // installers.upload( + // cmdname: 'gitea' + // source: '${gitpath}/target/x86_64-unknown-linux-musl/release/gitea' + // )! + +} + +fn install_() ! { + console.print_header('install gitea') + //THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED + // mut url := '' + // if core.is_linux_arm()! { + // url = 'https://github.com/gitea-dev/gitea/releases/download/v${version}/gitea_${version}_linux_arm64.tar.gz' + // } else if core.is_linux_intel()! { + // url = 'https://github.com/gitea-dev/gitea/releases/download/v${version}/gitea_${version}_linux_amd64.tar.gz' + // } else if core.is_osx_arm()! { + // url = 'https://github.com/gitea-dev/gitea/releases/download/v${version}/gitea_${version}_darwin_arm64.tar.gz' + // } else if core.is_osx_intel()! { + // url = 'https://github.com/gitea-dev/gitea/releases/download/v${version}/gitea_${version}_darwin_amd64.tar.gz' + // } else { + // return error('unsported platform') + // } + + // mut dest := osal.download( + // url: url + // minsize_kb: 9000 + // expand_dir: '/tmp/gitea' + // )! + + // //dest.moveup_single_subdir()! + + // mut binpath := dest.file_get('gitea')! + // osal.cmd_add( + // cmdname: 'gitea' + // source: binpath.path + // )! +} + +fn build_() ! { + //url := 'https://github.com/threefoldtech/gitea' + + // make sure we install base on the node + // if core.platform()!= .ubuntu { + // return error('only support ubuntu for now') + // } + // golang.install()! + + // console.print_header('build gitea') + + // gitpath := gittools.get_repo(coderoot: '/tmp/builder', url: url, reset: true, pull: true)! + + // cmd := ' + // cd ${gitpath} + // source ~/.cargo/env + // exit 1 #todo + // ' + // osal.execute_stdout(cmd)! + // + // //now copy to the default bin path + // mut binpath := dest.file_get('...')! + // adds it to path + // osal.cmd_add( + // cmdname: 'griddriver2' + // source: binpath.path + // )! + +} + +fn destroy_() ! { + + // mut systemdfactory := systemd.new()! + // systemdfactory.destroy("zinit")! + + // osal.process_kill_recursive(name:'zinit')! + // osal.cmd_delete('zinit')! + + // osal.package_remove(' + // podman + // conmon + // buildah + // skopeo + // runc + // ')! + + // //will remove all paths where go/bin is found + // osal.profile_path_add_remove(paths2delete:"go/bin")! + + // osal.rm(" + // podman + // conmon + // buildah + // skopeo + // runc + // /var/lib/containers + // /var/lib/podman + // /var/lib/buildah + // /tmp/podman + // /tmp/conmon + // ")! + + +} + diff --git a/lib/installers/infra/gitea/gitea_factory_.v b/lib/installers/infra/gitea/gitea_factory_.v new file mode 100644 index 00000000..41eb0054 --- /dev/null +++ b/lib/installers/infra/gitea/gitea_factory_.v @@ -0,0 +1,152 @@ + +module gitea + +import freeflowuniverse.herolib.core.base +import freeflowuniverse.herolib.core.playbook +import freeflowuniverse.herolib.ui.console + +import freeflowuniverse.herolib.sysadmin.startupmanager +import freeflowuniverse.herolib.osal.zinit +import time + +__global ( + gitea_global map[string]&GiteaInstaller + gitea_default string +) + +/////////FACTORY + + + + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////// + + + + +fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { + // unknown + // screen + // zinit + // tmux + // systemd + match cat{ + .zinit{ + console.print_debug("startupmanager: zinit") + return startupmanager.get(cat:.zinit)! + } + .systemd{ + console.print_debug("startupmanager: systemd") + return startupmanager.get(cat:.systemd)! + }else{ + console.print_debug("startupmanager: auto") + return startupmanager.get()! + } + } +} + +pub fn (mut self GiteaInstaller) start() ! { + switch(self.name) + if self.running()!{ + return + } + + console.print_header('gitea start') + + if ! installed_()!{ + install_()! + } + + configure()! + + start_pre()! + + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + + console.print_debug('starting gitea with ${zprocess.startuptype}...') + + sm.new(zprocess)! + + sm.start(zprocess.name)! + } + + start_post()! + + for _ in 0 .. 50 { + if self.running()! { + return + } + time.sleep(100 * time.millisecond) + } + return error('gitea did not install properly.') + +} + +pub fn (mut self GiteaInstaller) install_start(model InstallArgs) ! { + switch(self.name) + self.install(model)! + self.start()! +} + +pub fn (mut self GiteaInstaller) stop() ! { + switch(self.name) + stop_pre()! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + sm.stop(zprocess.name)! + } + stop_post()! +} + +pub fn (mut self GiteaInstaller) restart() ! { + switch(self.name) + self.stop()! + self.start()! +} + +pub fn (mut self GiteaInstaller) running() !bool { + switch(self.name) + + //walk over the generic processes, if not running return + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + r:=sm.running(zprocess.name)! + if r==false{ + return false + } + } + return running()! +} + +@[params] +pub struct InstallArgs{ +pub mut: + reset bool +} + + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } +} + +pub fn destroy() ! { + destroy_()! +} + +pub fn build() ! { + build_()! +} + + + + + diff --git a/lib/installers/infra/gitea/gitea_model.v b/lib/installers/infra/gitea/gitea_model.v new file mode 100644 index 00000000..1b190dff --- /dev/null +++ b/lib/installers/infra/gitea/gitea_model.v @@ -0,0 +1,29 @@ +module gitea +import freeflowuniverse.herolib.data.paramsparser +import os + +pub const version = '0.0.0' +const singleton = true +const default = true + + +//THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED +@[heap] +pub struct GiteaInstaller { +pub mut: + name string = 'default' +} + + +fn obj_init(obj_ GiteaInstaller)!GiteaInstaller{ + //never call get here, only thing we can do here is work on object itself + mut obj:=obj_ + return obj +} + +//called before start if done +fn configure() ! { + //mut installer := get()! +} + + diff --git a/lib/installers/infra/gitea/installer.v b/lib/installers/infra/gitea/installer.v index 61cfc525..16c0ca59 100644 --- a/lib/installers/infra/gitea/installer.v +++ b/lib/installers/infra/gitea/installer.v @@ -7,7 +7,7 @@ import freeflowuniverse.herolib.core.pathlib import freeflowuniverse.herolib.ui.console pub fn install_() ! { - if osal.platform() != .ubuntu || osal.platform() != .arch { + if core.platform()!= .ubuntu || core.platform()!= .arch { return error('only support ubuntu and arch for now') } @@ -42,7 +42,7 @@ pub fn install_() ! { } pub fn start() ! { - if osal.platform() != .ubuntu || osal.platform() != .arch { + if core.platform()!= .ubuntu || core.platform()!= .arch { return error('only support ubuntu and arch for now') } diff --git a/lib/installers/infra/gitea/readme.md b/lib/installers/infra/gitea/readme.md new file mode 100644 index 00000000..05fdfa5d --- /dev/null +++ b/lib/installers/infra/gitea/readme.md @@ -0,0 +1,44 @@ +# gitea + + + +To get started + +```vlang + + +import freeflowuniverse.herolib.installers.something.gitea as gitea_installer + +heroscript:=" +!!gitea.configure name:'test' + password: '1234' + port: 7701 + +!!gitea.start name:'test' reset:1 +" + +gitea_installer.play(heroscript=heroscript)! + +//or we can call the default and do a start with reset +//mut installer:= gitea_installer.get()! +//installer.start(reset:true)! + + + + +``` + +## example heroscript + +```hero +!!gitea.configure + homedir: '/home/user/gitea' + username: 'admin' + password: 'secretpassword' + title: 'Some Title' + host: 'localhost' + port: 8888 + +``` + + diff --git a/lib/installers/infra/livekit/livekit_actions.v b/lib/installers/infra/livekit/livekit_actions.v index 6166c4c6..04e6a53d 100644 --- a/lib/installers/infra/livekit/livekit_actions.v +++ b/lib/installers/infra/livekit/livekit_actions.v @@ -10,7 +10,7 @@ import os // checks if a certain version or above is installed fn installed_() !bool { - res := os.execute('${osal.profile_path_source_and()} livekit-server -v') + res := os.execute('${osal.profile_path_source_and()!} livekit-server -v') if res.exit_code != 0 { return false } diff --git a/lib/installers/infra/livekit/livekit_factory_.v b/lib/installers/infra/livekit/livekit_factory_.v index aa30571f..b7daf475 100644 --- a/lib/installers/infra/livekit/livekit_factory_.v +++ b/lib/installers/infra/livekit/livekit_factory_.v @@ -1,204 +1,297 @@ + module livekit import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook -import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.data.encoderhero + +import freeflowuniverse.herolib.sysadmin.startupmanager +import freeflowuniverse.herolib.osal.zinit import time __global ( - livekit_global map[string]&LivekitServer - livekit_default string + livekit_global map[string]&LivekitServer + livekit_default string ) /////////FACTORY + + @[params] -pub struct ArgsGet { +pub struct ArgsGet{ pub mut: - name string = 'default' + name string } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = livekit_default - } - if args.name == '' { - args.name = 'default' - } - return args +fn args_get (args_ ArgsGet) ArgsGet { + mut model:=args_ + if model.name == ""{ + model.name = livekit_default + } + if model.name == ""{ + model.name = "default" + } + return model } -pub fn get(args_ ArgsGet) !&LivekitServer { - mut args := args_get(args_) - if args.name !in livekit_global { - if !config_exists() { - if default { - config_save()! - } - } - config_load()! - } - return livekit_global[args.name] or { - println(livekit_global) - panic('bug in get from factory: ') - } +pub fn get(args_ ArgsGet) !&LivekitServer { + mut args := args_get(args_) + if !(args.name in livekit_global) { + if args.name=="default"{ + if ! config_exists(args){ + if default{ + mut context:=base.context() or { panic("bug") } + context.hero_config_set("livekit",model.name,heroscript_default()!)! + } + } + load(args)! + } + } + return livekit_global[args.name] or { + println(livekit_global) + panic("could not get config for ${args.name} with name:${model.name}") + } } -fn config_exists(args_ ArgsGet) bool { - mut args := args_get(args_) - mut context := base.context() or { panic('bug') } - return context.hero_config_exists('livekit', args.name) + + +//set the model in mem and the config on the filesystem +pub fn set(o LivekitServer)! { + mut o2:=obj_init(o)! + livekit_global[o.name] = &o2 + livekit_default = o.name } -fn config_load(args_ ArgsGet) ! { - mut args := args_get(args_) - mut context := base.context()! - mut heroscript := context.hero_config_get('livekit', args.name)! - play(heroscript: heroscript)! +//check we find the config on the filesystem +pub fn exists(args_ ArgsGet) bool { + mut model := args_get(args_) + mut context:=base.context() or { panic("bug") } + return context.hero_config_exists("livekit",model.name) } -fn config_save(args_ ArgsGet) ! { - mut args := args_get(args_) - mut context := base.context()! - context.hero_config_set('livekit', args.name, heroscript_default()!)! +//load the config error if it doesn't exist +pub fn load(args_ ArgsGet) ! { + mut model := args_get(args_) + mut context:=base.context()! + mut heroscript := context.hero_config_get("livekit",model.name)! + play(heroscript:heroscript)! } -fn set(o LivekitServer) ! { - mut o2 := obj_init(o)! - livekit_global['default'] = &o2 +//save the config to the filesystem in the context +pub fn save(o LivekitServer)! { + mut context:=base.context()! + heroscript := encoderhero.encode[LivekitServer](o)! + context.hero_config_set("livekit",model.name,heroscript)! } @[params] pub struct PlayArgs { pub mut: - name string = 'default' - heroscript string // if filled in then plbook will be made out of it - plbook ?playbook.PlayBook - reset bool - - start bool - stop bool - restart bool - delete bool - configure bool // make sure there is at least one installed + heroscript string //if filled in then plbook will be made out of it + plbook ?playbook.PlayBook + reset bool } pub fn play(args_ PlayArgs) ! { - mut args := args_ + + mut model:=args_ - if args.heroscript == '' { - args.heroscript = heroscript_default()! - } - mut plbook := args.plbook or { playbook.new(text: args.heroscript)! } + if model.heroscript == "" { + model.heroscript = heroscript_default()! + } + mut plbook := model.plbook or { + playbook.new(text: model.heroscript)! + } + + mut configure_actions := plbook.find(filter: 'livekit.configure')! + if configure_actions.len > 0 { + for config_action in configure_actions { + mut p := config_action.params + mycfg:=cfg_play(p)! + console.print_debug("install action livekit.configure\n${mycfg}") + set(mycfg)! + save(mycfg)! + } + } + + mut other_actions := plbook.find(filter: 'livekit.')! + for other_action in other_actions { + if other_action.name in ["destroy","install","build"]{ + mut p := other_action.params + reset:=p.get_default_false("reset") + if other_action.name == "destroy" || reset{ + console.print_debug("install action livekit.destroy") + destroy_()! + } + if other_action.name == "install"{ + console.print_debug("install action livekit.install") + install_()! + } + } + if other_action.name in ["start","stop","restart"]{ + mut p := other_action.params + name := p.get('name')! + mut livekit_obj:=get(name:name)! + console.print_debug("action object:\n${livekit_obj}") + if other_action.name == "start"{ + console.print_debug("install action livekit.${other_action.name}") + livekit_obj.start()! + } + + if other_action.name == "stop"{ + console.print_debug("install action livekit.${other_action.name}") + livekit_obj.stop()! + } + if other_action.name == "restart"{ + console.print_debug("install action livekit.${other_action.name}") + livekit_obj.restart()! + } + } + } - mut install_actions := plbook.find(filter: 'livekit.configure')! - if install_actions.len > 0 { - for install_action in install_actions { - mut p := install_action.params - mycfg := cfg_play(p)! - set(mycfg)! - } - } } + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// -// load from disk and make sure is properly intialized + +//load from disk and make sure is properly intialized pub fn (mut self LivekitServer) reload() ! { - switch(self.name) - self = obj_init(self)! + switch(self.name) + self=obj_init(self)! +} + + +fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { + // unknown + // screen + // zinit + // tmux + // systemd + match cat{ + .zinit{ + console.print_debug("startupmanager: zinit") + return startupmanager.get(cat:.zinit)! + } + .systemd{ + console.print_debug("startupmanager: systemd") + return startupmanager.get(cat:.systemd)! + }else{ + console.print_debug("startupmanager: auto") + return startupmanager.get()! + } + } } pub fn (mut self LivekitServer) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('livekit start') + console.print_header('livekit start') - configure()! + if ! installed_()!{ + install_()! + } - start_pre()! + configure()! - mut sm := startupmanager.get()! + start_pre()! - for zprocess in startupcmd()! { - sm.start(zprocess.name)! - } + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! - start_post()! + console.print_debug('starting livekit with ${zprocess.startuptype}...') + + sm.new(zprocess)! + + sm.start(zprocess.name)! + } + + start_post()! + + for _ in 0 .. 50 { + if self.running()! { + return + } + time.sleep(100 * time.millisecond) + } + return error('livekit did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('livekit did not install properly.') } -pub fn (mut self LivekitServer) install_start(args RestartArgs) ! { - switch(self.name) - self.install(args)! - self.start()! +pub fn (mut self LivekitServer) install_start(model InstallArgs) ! { + switch(self.name) + self.install(model)! + self.start()! } pub fn (mut self LivekitServer) stop() ! { - switch(self.name) - stop_pre()! - mut sm := startupmanager.get()! - for zprocess in startupcmd()! { - sm.stop(zprocess.name)! - } - stop_post()! + switch(self.name) + stop_pre()! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + sm.stop(zprocess.name)! + } + stop_post()! } pub fn (mut self LivekitServer) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self LivekitServer) running() !bool { - switch(self.name) - mut sm := startupmanager.get()! + switch(self.name) - // walk over the generic processes, if not running return - for zprocess in startupcmd()! { - r := sm.running(zprocess.name)! - if r == false { - return false - } - } - return running()! + //walk over the generic processes, if not running return + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + r:=sm.running(zprocess.name)! + if r==false{ + return false + } + } + return running()! } @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } + +//switch instance to be used for livekit +pub fn switch(name string) { + livekit_default = name +} + + pub fn (mut self LivekitServer) install(args InstallArgs) ! { - switch(self.name) - if args.reset || (!installed()!) { - install()! - } + switch(self.name) + if args.reset { + destroy_()! + } + if ! (installed_()!){ + install_()! + } } + pub fn (mut self LivekitServer) destroy() ! { - switch(self.name) - - self.stop()! - destroy()! + switch(self.name) + self.stop() or {} + destroy_()! } -// switch instance to be used for livekit -pub fn switch(name string) { - livekit_default = name -} + + + diff --git a/lib/installers/lang/golang/golang_actions.v b/lib/installers/lang/golang/golang_actions.v index faab57d5..db258c48 100644 --- a/lib/installers/lang/golang/golang_actions.v +++ b/lib/installers/lang/golang/golang_actions.v @@ -3,13 +3,15 @@ module golang import freeflowuniverse.herolib.osal import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.core.texttools +import freeflowuniverse.herolib.core import freeflowuniverse.herolib.installers.base import freeflowuniverse.herolib.installers.ulist import os // checks if a certain version or above is installed fn installed_() !bool { - res := os.execute('${osal.profile_path_source_and()} go version') + res := os.execute('${osal.profile_path_source_and()!} go version') + if res.exit_code == 0 { r := res.output.split_into_lines() .filter(it.contains('go version')) @@ -22,7 +24,9 @@ fn installed_() !bool { vstring = vstring.all_after_first('version').all_after_first('go').all_before(' ').trim_space() v := texttools.version(vstring) - if v == texttools.version(version) { + println(vstring) + println(v) + if v >= texttools.version(version) { return true } } @@ -35,13 +39,13 @@ fn install_() ! { //destroy()! mut url := '' - if osal.is_linux_arm() { + if core.is_linux_arm()! { url = 'https://go.dev/dl/go${version}.limux-arm64.tar.gz' - } else if osal.is_linux_intel() { + } else if core.is_linux_intel()! { url = 'https://go.dev/dl/go${version}.linux-amd64.tar.gz' - } else if osal.is_osx_arm() { + } else if core.is_osx_arm()! { url = 'https://go.dev/dl/go${version}.darwin-arm64.tar.gz' - } else if osal.is_osx_intel() { + } else if core.is_osx_intel()! { url = 'https://go.dev/dl/go${version}.darwin-amd64.tar.gz' } else { return error('unsupported platform') @@ -50,12 +54,15 @@ fn install_() ! { expand_dir := '/tmp/golang' // the downloader is cool, it will check the download succeeds and also check the minimum size - _ = osal.download( + dest := osal.download( url: url minsize_kb: 40000 expand_dir: expand_dir )! + println(dest) + if true{exit(0)} + go_dest := '${osal.usr_local_path()!}/go' os.mv('${expand_dir}/go', go_dest)! os.rmdir_all(expand_dir)! @@ -81,18 +88,14 @@ fn destroy_() ! { osal.profile_path_add_remove(paths2delete: 'go/bin')! osal.rm(' - #next will find go as a binary and remove, is like cmd delete - go - /usr/local/go + #next will find go as a binary and remove is like cmd delete + ~/hero/bin/go + #/usr/local/go /root/hero/bin/go ~/.go ~/go + ~/hero/go + go ')! } -pub fn install_reset() ! { - mut installer := get()! - - // will automatically do a destroy if the version changes, to make sure there are no left overs - installer.install()! -} diff --git a/lib/installers/lang/golang/golang_factory_.v b/lib/installers/lang/golang/golang_factory_.v index 1b7b0cc2..fdc62c90 100644 --- a/lib/installers/lang/golang/golang_factory_.v +++ b/lib/installers/lang/golang/golang_factory_.v @@ -1,79 +1,57 @@ + module golang import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - golang_global map[string]&GolangInstaller - golang_default string + golang_global map[string]&GolangInstaller + golang_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&GolangInstaller { - return &GolangInstaller{} -} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// -fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } -} + + @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self GolangInstaller) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self GolangInstaller) build() ! { - switch(self.name) - build()! +pub fn destroy() ! { + destroy_()! } -pub fn (mut self GolangInstaller) destroy() ! { - switch(self.name) - destroy()! +pub fn build() ! { + build_()! } -// switch instance to be used for golang -pub fn switch(name string) { - golang_default = name -} + + + + diff --git a/lib/installers/lang/nodejs/nodejs.v b/lib/installers/lang/nodejs/nodejs.v index 7deceb77..07530b75 100644 --- a/lib/installers/lang/nodejs/nodejs.v +++ b/lib/installers/lang/nodejs/nodejs.v @@ -13,7 +13,7 @@ import freeflowuniverse.herolib.osal // pub fn install_(args_ InstallArgs) ! { // _ := args_ -// pl := osal.platform() +// pl := core.platform()! // if pl == .arch { // osal.package_install('npm')! // } else { diff --git a/lib/installers/lang/nodejs/nodejs_actions.v b/lib/installers/lang/nodejs/nodejs_actions.v index bc01b6e0..7c55ba6b 100644 --- a/lib/installers/lang/nodejs/nodejs_actions.v +++ b/lib/installers/lang/nodejs/nodejs_actions.v @@ -15,6 +15,18 @@ import os //////////////////// following actions are not specific to instance of the object fn installed_() !bool { + + res := os.execute('pnpm -v') + if res.exit_code != 0 { + return false + } + r := res.output.split_into_lines().filter(it.trim_space().len > 0) + if r.len != 1 { + return error("couldn't parse pnpm version.\n${res.output}") + } + if texttools.version(r[0]) >= texttools.version(version) { + return true + } return false } diff --git a/lib/installers/lang/nodejs/nodejs_model.v b/lib/installers/lang/nodejs/nodejs_model.v index ced077fe..e9fbd94e 100644 --- a/lib/installers/lang/nodejs/nodejs_model.v +++ b/lib/installers/lang/nodejs/nodejs_model.v @@ -3,7 +3,7 @@ module nodejs import freeflowuniverse.herolib.data.paramsparser import os -pub const version = '0.0.0' +pub const version = '9.15.2' const singleton = true const default = true diff --git a/lib/installers/lang/python/python_actions.v b/lib/installers/lang/python/python_actions.v index 60e9ca80..6416712c 100644 --- a/lib/installers/lang/python/python_actions.v +++ b/lib/installers/lang/python/python_actions.v @@ -3,7 +3,7 @@ module python import freeflowuniverse.herolib.osal import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.core.texttools -import freeflowuniverse.herolib.core.pathlib +import freeflowuniverse.herolib.core import freeflowuniverse.herolib.installers.ulist import freeflowuniverse.herolib.installers.base @@ -16,6 +16,17 @@ import os // checks if a certain version or above is installed fn installed_() !bool { + res := os.execute('python3 --version') + if res.exit_code != 0 { + return false + } + r := res.output.split_into_lines().filter(it.trim_space().len > 0) + if r.len != 1 { + return error("couldn't parse pnpm version.\n${res.output}") + } + if texttools.version(r[0].all_after_first("ython")) >= texttools.version(version) { + return true + } return false } @@ -33,7 +44,7 @@ fn install_() ! { base.install()! osal.package_install('python3')! - pl := osal.platform() + pl := core.platform()! if pl == .arch { osal.package_install('python-pipx,sqlite')! } else if pl == .ubuntu { diff --git a/lib/installers/lang/python/python_model.v b/lib/installers/lang/python/python_model.v index f26f90a4..1054b7ef 100644 --- a/lib/installers/lang/python/python_model.v +++ b/lib/installers/lang/python/python_model.v @@ -3,7 +3,7 @@ module python import freeflowuniverse.herolib.data.paramsparser import os -pub const version = '0.0.0' +pub const version = '3.12.0' const singleton = true const default = true diff --git a/lib/installers/lang/rust/rust_actions.v b/lib/installers/lang/rust/rust_actions.v index f7e69530..5e5492c7 100644 --- a/lib/installers/lang/rust/rust_actions.v +++ b/lib/installers/lang/rust/rust_actions.v @@ -3,7 +3,7 @@ module rust import freeflowuniverse.herolib.osal import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.core.texttools -import freeflowuniverse.herolib.core.pathlib +import freeflowuniverse.herolib.core import freeflowuniverse.herolib.installers.ulist import freeflowuniverse.herolib.installers.base @@ -15,7 +15,7 @@ import os // checks if a certain version or above is installed fn installed_() !bool { - res := os.execute('${osal.profile_path_source_and()} rustc -V') + res := os.execute('${osal.profile_path_source_and()!} rustc -V') if res.exit_code != 0 { return false } @@ -51,7 +51,7 @@ fn install_() ! { base.install()! - pl := osal.platform() + pl := core.platform()! if pl == .ubuntu { osal.package_install('build-essential,openssl,pkg-config,libssl-dev,gcc')! diff --git a/lib/installers/net/mycelium/mycelium.v b/lib/installers/net/mycelium/mycelium.v index 5d55e5c2..007eeea3 100644 --- a/lib/installers/net/mycelium/mycelium.v +++ b/lib/installers/net/mycelium/mycelium.v @@ -19,7 +19,7 @@ pub fn installss(args_ InstallArgs) ! { version := '0.5.6' - res := os.execute('${osal.profile_path_source_and()} mycelium -V') + res := os.execute('${osal.profile_path_source_and()!} mycelium -V') if res.exit_code == 0 { r := res.output.split_into_lines().filter(it.trim_space().starts_with('mycelium')) if r.len != 1 { @@ -36,13 +36,13 @@ pub fn installss(args_ InstallArgs) ! { console.print_header('install mycelium') mut url := '' - if osal.is_linux_arm() { + if core.is_linux_arm()! { url = 'https://github.com/threefoldtech/mycelium/releases/download/v${version}/mycelium-aarch64-unknown-linux-musl.tar.gz' - } else if osal.is_linux_intel() { + } else if core.is_linux_intel()! { url = 'https://github.com/threefoldtech/mycelium/releases/download/v${version}/mycelium-x86_64-unknown-linux-musl.tar.gz' - } else if osal.is_osx_arm() { + } else if core.is_osx_arm()! { url = 'https://github.com/threefoldtech/mycelium/releases/download/v${version}/mycelium-aarch64-apple-darwin.tar.gz' - } else if osal.is_osx_intel() { + } else if core.is_osx_intel()! { url = 'https://github.com/threefoldtech/mycelium/releases/download/v${version}/mycelium-x86_64-apple-darwin.tar.gz' } else { return error('unsported platform') @@ -80,7 +80,7 @@ pub fn restart() ! { pub fn stop() ! { name := 'mycelium' console.print_debug('stop ${name}') - if osal.is_osx() { + if core.is_osx()! { mut scr := screen.new(reset: false)! scr.kill(name)! } else { @@ -94,19 +94,19 @@ pub fn start(args InstallArgs) ! { console.print_header('mycelium was already running') return } - myinitname := osal.initname()! + myinitname := core.initname()! name := 'mycelium' console.print_debug('start ${name} (startupmanger:${myinitname})') mut cmd := '' - if osal.is_osx() { + if core.is_osx()! { cmd = 'sudo -s ' } cmd += 'mycelium --key-file ${osal.hero_path()!}/cfg/priv_key.bin --peers tcp://188.40.132.242:9651 quic://185.69.166.7:9651 tcp://65.21.231.58:9651 --tun-name utun9' console.print_debug(cmd) - if osal.is_osx() { + if core.is_osx()! { // do not change, because we need this on osx at least mut scr := screen.new(reset: false)! @@ -152,7 +152,7 @@ pub fn start(args InstallArgs) ! { } pub fn check() bool { - // if osal.is_osx() { + // if core.is_osx()! { // mut scr := screen.new(reset: false) or {return False} // name := 'mycelium' // if !scr.exists(name) { diff --git a/lib/installers/net/mycelium/mycelium_actions.v b/lib/installers/net/mycelium/mycelium_actions.v index ebe3f184..e2edcbaa 100644 --- a/lib/installers/net/mycelium/mycelium_actions.v +++ b/lib/installers/net/mycelium/mycelium_actions.v @@ -66,7 +66,7 @@ fn stop_post() ! { // checks if a certain version or above is installed fn installed_() !bool { // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED - // res := os.execute('${osal.profile_path_source_and()} mycelium version') + // res := os.execute('${osal.profile_path_source_and()!} mycelium version') // if res.exit_code != 0 { // return false // } @@ -98,13 +98,13 @@ fn install_() ! { console.print_header('install mycelium') // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // mut url := '' - // if osal.is_linux_arm() { + // if core.is_linux_arm()! { // url = 'https://github.com/mycelium-dev/mycelium/releases/download/v${version}/mycelium_${version}_linux_arm64.tar.gz' - // } else if osal.is_linux_intel() { + // } else if core.is_linux_intel()! { // url = 'https://github.com/mycelium-dev/mycelium/releases/download/v${version}/mycelium_${version}_linux_amd64.tar.gz' - // } else if osal.is_osx_arm() { + // } else if core.is_osx_arm()! { // url = 'https://github.com/mycelium-dev/mycelium/releases/download/v${version}/mycelium_${version}_darwin_arm64.tar.gz' - // } else if osal.is_osx_intel() { + // } else if core.is_osx_intel()! { // url = 'https://github.com/mycelium-dev/mycelium/releases/download/v${version}/mycelium_${version}_darwin_amd64.tar.gz' // } else { // return error('unsported platform') @@ -129,7 +129,7 @@ fn build_() ! { // url := 'https://github.com/threefoldtech/mycelium' // make sure we install base on the node - // if osal.platform() != .ubuntu { + // if core.platform()!= .ubuntu { // return error('only support ubuntu for now') // } // golang.install()! diff --git a/lib/installers/net/mycelium/mycelium_factory_.v b/lib/installers/net/mycelium/mycelium_factory_.v index c6604270..54ff8215 100644 --- a/lib/installers/net/mycelium/mycelium_factory_.v +++ b/lib/installers/net/mycelium/mycelium_factory_.v @@ -1,153 +1,152 @@ + module mycelium import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - mycelium_global map[string]&MyceliumInstaller - mycelium_default string + mycelium_global map[string]&MyceliumInstaller + mycelium_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&MyceliumInstaller { - return &MyceliumInstaller{} -} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// + + + fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } + // unknown + // screen + // zinit + // tmux + // systemd + match cat{ + .zinit{ + console.print_debug("startupmanager: zinit") + return startupmanager.get(cat:.zinit)! + } + .systemd{ + console.print_debug("startupmanager: systemd") + return startupmanager.get(cat:.systemd)! + }else{ + console.print_debug("startupmanager: auto") + return startupmanager.get()! + } + } } pub fn (mut self MyceliumInstaller) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('mycelium start') + console.print_header('mycelium start') - if !installed()! { - install()! - } + if ! installed_()!{ + install_()! + } - configure()! + configure()! - start_pre()! + start_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! - console.print_debug('starting mycelium with ${zprocess.startuptype}...') + console.print_debug('starting mycelium with ${zprocess.startuptype}...') - sm.new(zprocess)! + sm.new(zprocess)! - sm.start(zprocess.name)! - } + sm.start(zprocess.name)! + } - start_post()! + start_post()! + + for _ in 0 .. 50 { + if self.running()! { + return + } + time.sleep(100 * time.millisecond) + } + return error('mycelium did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('mycelium did not install properly.') } pub fn (mut self MyceliumInstaller) install_start(model InstallArgs) ! { - switch(self.name) - self.install(model)! - self.start()! + switch(self.name) + self.install(model)! + self.start()! } pub fn (mut self MyceliumInstaller) stop() ! { - switch(self.name) - stop_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - sm.stop(zprocess.name)! - } - stop_post()! + switch(self.name) + stop_pre()! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + sm.stop(zprocess.name)! + } + stop_post()! } pub fn (mut self MyceliumInstaller) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self MyceliumInstaller) running() !bool { - switch(self.name) + switch(self.name) - // walk over the generic processes, if not running return - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - r := sm.running(zprocess.name)! - if r == false { - return false - } - } - return running()! + //walk over the generic processes, if not running return + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + r:=sm.running(zprocess.name)! + if r==false{ + return false + } + } + return running()! } @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self MyceliumInstaller) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self MyceliumInstaller) build() ! { - switch(self.name) - build()! +pub fn destroy() ! { + destroy_()! } -pub fn (mut self MyceliumInstaller) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! +pub fn build() ! { + build_()! } -// switch instance to be used for mycelium -pub fn switch(name string) { - mycelium_default = name -} + + + + diff --git a/lib/installers/net/yggdrasil/ygg.v b/lib/installers/net/yggdrasil/ygg.v index 2b4efdcc..1062cdef 100644 --- a/lib/installers/net/yggdrasil/ygg.v +++ b/lib/installers/net/yggdrasil/ygg.v @@ -33,7 +33,7 @@ Peers: config_path := '/etc/yggdrasil.conf' mut args := args_ - res := os.execute('${osal.profile_path_source_and()} yggdrasil -version') + res := os.execute('${osal.profile_path_source_and()!} yggdrasil -version') if res.exit_code != 0 { args.reset = true } @@ -91,7 +91,7 @@ pub fn start() ! { mut cmd2 := '' - if osal.is_osx() { + if core.is_osx()! { cmd2 = 'sudo -s ' } @@ -103,7 +103,7 @@ pub fn start() ! { console.print_debug('send done') - if osal.is_osx() { + if core.is_osx()! { mut myui := ui.new()! console.clear() diff --git a/lib/installers/net/yggdrasil/yggdrasil_actions.v b/lib/installers/net/yggdrasil/yggdrasil_actions.v index a0c4223f..a9b67111 100644 --- a/lib/installers/net/yggdrasil/yggdrasil_actions.v +++ b/lib/installers/net/yggdrasil/yggdrasil_actions.v @@ -66,7 +66,7 @@ fn stop_post() ! { // checks if a certain version or above is installed fn installed_() !bool { // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED - // res := os.execute('${osal.profile_path_source_and()} yggdrasil version') + // res := os.execute('${osal.profile_path_source_and()!} yggdrasil version') // if res.exit_code != 0 { // return false // } @@ -98,13 +98,13 @@ fn install_() ! { console.print_header('install yggdrasil') // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // mut url := '' - // if osal.is_linux_arm() { + // if core.is_linux_arm()! { // url = 'https://github.com/yggdrasil-dev/yggdrasil/releases/download/v${version}/yggdrasil_${version}_linux_arm64.tar.gz' - // } else if osal.is_linux_intel() { + // } else if core.is_linux_intel()! { // url = 'https://github.com/yggdrasil-dev/yggdrasil/releases/download/v${version}/yggdrasil_${version}_linux_amd64.tar.gz' - // } else if osal.is_osx_arm() { + // } else if core.is_osx_arm()! { // url = 'https://github.com/yggdrasil-dev/yggdrasil/releases/download/v${version}/yggdrasil_${version}_darwin_arm64.tar.gz' - // } else if osal.is_osx_intel() { + // } else if core.is_osx_intel()! { // url = 'https://github.com/yggdrasil-dev/yggdrasil/releases/download/v${version}/yggdrasil_${version}_darwin_amd64.tar.gz' // } else { // return error('unsported platform') @@ -129,7 +129,7 @@ fn build_() ! { // url := 'https://github.com/threefoldtech/yggdrasil' // make sure we install base on the node - // if osal.platform() != .ubuntu { + // if core.platform()!= .ubuntu { // return error('only support ubuntu for now') // } // golang.install()! diff --git a/lib/installers/net/yggdrasil/yggdrasil_factory_.v b/lib/installers/net/yggdrasil/yggdrasil_factory_.v index 45264e23..a540db74 100644 --- a/lib/installers/net/yggdrasil/yggdrasil_factory_.v +++ b/lib/installers/net/yggdrasil/yggdrasil_factory_.v @@ -1,153 +1,152 @@ + module yggdrasil import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - yggdrasil_global map[string]&YggdrasilInstaller - yggdrasil_default string + yggdrasil_global map[string]&YggdrasilInstaller + yggdrasil_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&YggdrasilInstaller { - return &YggdrasilInstaller{} -} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// + + + fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } + // unknown + // screen + // zinit + // tmux + // systemd + match cat{ + .zinit{ + console.print_debug("startupmanager: zinit") + return startupmanager.get(cat:.zinit)! + } + .systemd{ + console.print_debug("startupmanager: systemd") + return startupmanager.get(cat:.systemd)! + }else{ + console.print_debug("startupmanager: auto") + return startupmanager.get()! + } + } } pub fn (mut self YggdrasilInstaller) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('yggdrasil start') + console.print_header('yggdrasil start') - if !installed()! { - install()! - } + if ! installed_()!{ + install_()! + } - configure()! + configure()! - start_pre()! + start_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! - console.print_debug('starting yggdrasil with ${zprocess.startuptype}...') + console.print_debug('starting yggdrasil with ${zprocess.startuptype}...') - sm.new(zprocess)! + sm.new(zprocess)! - sm.start(zprocess.name)! - } + sm.start(zprocess.name)! + } - start_post()! + start_post()! + + for _ in 0 .. 50 { + if self.running()! { + return + } + time.sleep(100 * time.millisecond) + } + return error('yggdrasil did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('yggdrasil did not install properly.') } pub fn (mut self YggdrasilInstaller) install_start(model InstallArgs) ! { - switch(self.name) - self.install(model)! - self.start()! + switch(self.name) + self.install(model)! + self.start()! } pub fn (mut self YggdrasilInstaller) stop() ! { - switch(self.name) - stop_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - sm.stop(zprocess.name)! - } - stop_post()! + switch(self.name) + stop_pre()! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + sm.stop(zprocess.name)! + } + stop_post()! } pub fn (mut self YggdrasilInstaller) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self YggdrasilInstaller) running() !bool { - switch(self.name) + switch(self.name) - // walk over the generic processes, if not running return - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - r := sm.running(zprocess.name)! - if r == false { - return false - } - } - return running()! + //walk over the generic processes, if not running return + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + r:=sm.running(zprocess.name)! + if r==false{ + return false + } + } + return running()! } @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self YggdrasilInstaller) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self YggdrasilInstaller) build() ! { - switch(self.name) - build()! +pub fn destroy() ! { + destroy_()! } -pub fn (mut self YggdrasilInstaller) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! +pub fn build() ! { + build_()! } -// switch instance to be used for yggdrasil -pub fn switch(name string) { - yggdrasil_default = name -} + + + + diff --git a/lib/installers/sysadmintools/actrunner/actrunner_actions.v b/lib/installers/sysadmintools/actrunner/actrunner_actions.v index 21e8c800..c8bf2cba 100644 --- a/lib/installers/sysadmintools/actrunner/actrunner_actions.v +++ b/lib/installers/sysadmintools/actrunner/actrunner_actions.v @@ -66,7 +66,7 @@ fn stop_post() ! { // checks if a certain version or above is installed fn installed_() !bool { // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED - // res := os.execute('${osal.profile_path_source_and()} actrunner version') + // res := os.execute('${osal.profile_path_source_and()!} actrunner version') // if res.exit_code != 0 { // return false // } @@ -98,13 +98,13 @@ fn install_() ! { console.print_header('install actrunner') // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // mut url := '' - // if osal.is_linux_arm() { + // if core.is_linux_arm()! { // url = 'https://github.com/actrunner-dev/actrunner/releases/download/v${version}/actrunner_${version}_linux_arm64.tar.gz' - // } else if osal.is_linux_intel() { + // } else if core.is_linux_intel()! { // url = 'https://github.com/actrunner-dev/actrunner/releases/download/v${version}/actrunner_${version}_linux_amd64.tar.gz' - // } else if osal.is_osx_arm() { + // } else if core.is_osx_arm()! { // url = 'https://github.com/actrunner-dev/actrunner/releases/download/v${version}/actrunner_${version}_darwin_arm64.tar.gz' - // } else if osal.is_osx_intel() { + // } else if core.is_osx_intel()! { // url = 'https://github.com/actrunner-dev/actrunner/releases/download/v${version}/actrunner_${version}_darwin_amd64.tar.gz' // } else { // return error('unsported platform') @@ -129,7 +129,7 @@ fn build_() ! { // url := 'https://github.com/threefoldtech/actrunner' // make sure we install base on the node - // if osal.platform() != .ubuntu { + // if core.platform()!= .ubuntu { // return error('only support ubuntu for now') // } // golang.install()! diff --git a/lib/installers/sysadmintools/actrunner/actrunner_factory_.v b/lib/installers/sysadmintools/actrunner/actrunner_factory_.v index 7985ea10..babd15d9 100644 --- a/lib/installers/sysadmintools/actrunner/actrunner_factory_.v +++ b/lib/installers/sysadmintools/actrunner/actrunner_factory_.v @@ -1,153 +1,152 @@ + module actrunner import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - actrunner_global map[string]&ActRunner - actrunner_default string + actrunner_global map[string]&ActRunner + actrunner_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&ActRunner { - return &ActRunner{} -} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// + + + fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } + // unknown + // screen + // zinit + // tmux + // systemd + match cat{ + .zinit{ + console.print_debug("startupmanager: zinit") + return startupmanager.get(cat:.zinit)! + } + .systemd{ + console.print_debug("startupmanager: systemd") + return startupmanager.get(cat:.systemd)! + }else{ + console.print_debug("startupmanager: auto") + return startupmanager.get()! + } + } } pub fn (mut self ActRunner) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('actrunner start') + console.print_header('actrunner start') - if !installed()! { - install()! - } + if ! installed_()!{ + install_()! + } - configure()! + configure()! - start_pre()! + start_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! - console.print_debug('starting actrunner with ${zprocess.startuptype}...') + console.print_debug('starting actrunner with ${zprocess.startuptype}...') - sm.new(zprocess)! + sm.new(zprocess)! - sm.start(zprocess.name)! - } + sm.start(zprocess.name)! + } - start_post()! + start_post()! + + for _ in 0 .. 50 { + if self.running()! { + return + } + time.sleep(100 * time.millisecond) + } + return error('actrunner did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('actrunner did not install properly.') } pub fn (mut self ActRunner) install_start(model InstallArgs) ! { - switch(self.name) - self.install(model)! - self.start()! + switch(self.name) + self.install(model)! + self.start()! } pub fn (mut self ActRunner) stop() ! { - switch(self.name) - stop_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - sm.stop(zprocess.name)! - } - stop_post()! + switch(self.name) + stop_pre()! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + sm.stop(zprocess.name)! + } + stop_post()! } pub fn (mut self ActRunner) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self ActRunner) running() !bool { - switch(self.name) + switch(self.name) - // walk over the generic processes, if not running return - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - r := sm.running(zprocess.name)! - if r == false { - return false - } - } - return running()! + //walk over the generic processes, if not running return + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + r:=sm.running(zprocess.name)! + if r==false{ + return false + } + } + return running()! } @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self ActRunner) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self ActRunner) build() ! { - switch(self.name) - build()! +pub fn destroy() ! { + destroy_()! } -pub fn (mut self ActRunner) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! +pub fn build() ! { + build_()! } -// switch instance to be used for actrunner -pub fn switch(name string) { - actrunner_default = name -} + + + + diff --git a/lib/installers/sysadmintools/actrunner/install.v b/lib/installers/sysadmintools/actrunner/install.v index d96e83c7..b41f1334 100644 --- a/lib/installers/sysadmintools/actrunner/install.v +++ b/lib/installers/sysadmintools/actrunner/install.v @@ -9,7 +9,7 @@ pub fn installlll(args_ InstallArgs) ! { mut args := args_ version := '0.2.10' - res := os.execute('${osal.profile_path_source_and()} actrunner -v') + res := os.execute('${osal.profile_path_source_and()!} actrunner -v') if res.exit_code == 0 { r := res.output.split_into_lines().filter(it.contains('act_runner version')) if r.len != 1 { @@ -31,13 +31,13 @@ pub fn installlll(args_ InstallArgs) ! { console.print_header('install actrunner') mut url := '' - if osal.is_linux_arm() { + if core.is_linux_arm()! { url = 'https://dl.gitea.com/act_runner/${version}/act_runner-${version}-linux-arm64' - } else if osal.is_linux_intel() { + } else if core.is_linux_intel()! { url = 'https://dl.gitea.com/act_runner/${version}/act_runner-${version}-linux-amd64' - } else if osal.is_osx_arm() { + } else if core.is_osx_arm()! { url = 'https://dl.gitea.com/act_runner/${version}/act_runner-${version}-darwin-arm64' - } else if osal.is_osx_intel() { + } else if core.is_osx_intel()! { url = 'https://dl.gitea.com/act_runner/${version}/act_runner-${version}-darwin-amd64' } else { return error('unsported platform') diff --git a/lib/installers/sysadmintools/b2/b2_actions.v b/lib/installers/sysadmintools/b2/b2_actions.v index 28dcccad..3c8a612e 100644 --- a/lib/installers/sysadmintools/b2/b2_actions.v +++ b/lib/installers/sysadmintools/b2/b2_actions.v @@ -66,7 +66,7 @@ fn stop_post() ! { // checks if a certain version or above is installed fn installed_() !bool { // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED - // res := os.execute('${osal.profile_path_source_and()} b2 version') + // res := os.execute('${osal.profile_path_source_and()!} b2 version') // if res.exit_code != 0 { // return false // } @@ -98,13 +98,13 @@ fn install_() ! { console.print_header('install b2') // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // mut url := '' - // if osal.is_linux_arm() { + // if core.is_linux_arm()! { // url = 'https://github.com/b2-dev/b2/releases/download/v${version}/b2_${version}_linux_arm64.tar.gz' - // } else if osal.is_linux_intel() { + // } else if core.is_linux_intel()! { // url = 'https://github.com/b2-dev/b2/releases/download/v${version}/b2_${version}_linux_amd64.tar.gz' - // } else if osal.is_osx_arm() { + // } else if core.is_osx_arm()! { // url = 'https://github.com/b2-dev/b2/releases/download/v${version}/b2_${version}_darwin_arm64.tar.gz' - // } else if osal.is_osx_intel() { + // } else if core.is_osx_intel()! { // url = 'https://github.com/b2-dev/b2/releases/download/v${version}/b2_${version}_darwin_amd64.tar.gz' // } else { // return error('unsported platform') @@ -129,7 +129,7 @@ fn build_() ! { // url := 'https://github.com/threefoldtech/b2' // make sure we install base on the node - // if osal.platform() != .ubuntu { + // if core.platform()!= .ubuntu { // return error('only support ubuntu for now') // } // golang.install()! diff --git a/lib/installers/sysadmintools/b2/b2_factory_.v b/lib/installers/sysadmintools/b2/b2_factory_.v index 98cfaeb3..d1a3c32c 100644 --- a/lib/installers/sysadmintools/b2/b2_factory_.v +++ b/lib/installers/sysadmintools/b2/b2_factory_.v @@ -1,153 +1,152 @@ + module b2 import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - b2_global map[string]&BackBase - b2_default string + b2_global map[string]&BackBase + b2_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&BackBase { - return &BackBase{} -} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// + + + fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } + // unknown + // screen + // zinit + // tmux + // systemd + match cat{ + .zinit{ + console.print_debug("startupmanager: zinit") + return startupmanager.get(cat:.zinit)! + } + .systemd{ + console.print_debug("startupmanager: systemd") + return startupmanager.get(cat:.systemd)! + }else{ + console.print_debug("startupmanager: auto") + return startupmanager.get()! + } + } } pub fn (mut self BackBase) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('b2 start') + console.print_header('b2 start') - if !installed()! { - install()! - } + if ! installed_()!{ + install_()! + } - configure()! + configure()! - start_pre()! + start_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! - console.print_debug('starting b2 with ${zprocess.startuptype}...') + console.print_debug('starting b2 with ${zprocess.startuptype}...') - sm.new(zprocess)! + sm.new(zprocess)! - sm.start(zprocess.name)! - } + sm.start(zprocess.name)! + } - start_post()! + start_post()! + + for _ in 0 .. 50 { + if self.running()! { + return + } + time.sleep(100 * time.millisecond) + } + return error('b2 did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('b2 did not install properly.') } pub fn (mut self BackBase) install_start(model InstallArgs) ! { - switch(self.name) - self.install(model)! - self.start()! + switch(self.name) + self.install(model)! + self.start()! } pub fn (mut self BackBase) stop() ! { - switch(self.name) - stop_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - sm.stop(zprocess.name)! - } - stop_post()! + switch(self.name) + stop_pre()! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + sm.stop(zprocess.name)! + } + stop_post()! } pub fn (mut self BackBase) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self BackBase) running() !bool { - switch(self.name) + switch(self.name) - // walk over the generic processes, if not running return - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - r := sm.running(zprocess.name)! - if r == false { - return false - } - } - return running()! + //walk over the generic processes, if not running return + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + r:=sm.running(zprocess.name)! + if r==false{ + return false + } + } + return running()! } @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self BackBase) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self BackBase) build() ! { - switch(self.name) - build()! +pub fn destroy() ! { + destroy_()! } -pub fn (mut self BackBase) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! +pub fn build() ! { + build_()! } -// switch instance to be used for b2 -pub fn switch(name string) { - b2_default = name -} + + + + diff --git a/lib/installers/sysadmintools/fungistor/fungistor.v b/lib/installers/sysadmintools/fungistor/fungistor.v index 207ab71f..75302e1c 100644 --- a/lib/installers/sysadmintools/fungistor/fungistor.v +++ b/lib/installers/sysadmintools/fungistor/fungistor.v @@ -30,7 +30,7 @@ pub fn installlll(args_ InstallArgs) ! { console.print_header('install rfs') mut url := '' - if osal.is_linux_intel() { + if core.is_linux_intel()! { url = 'https://github.com/threefoldtech/rfs/releases/download/v${version}/rfs' } else { return error('unsported platform') diff --git a/lib/installers/sysadmintools/fungistor/fungistor_actions.v b/lib/installers/sysadmintools/fungistor/fungistor_actions.v index 05ee4daf..7771c5f7 100644 --- a/lib/installers/sysadmintools/fungistor/fungistor_actions.v +++ b/lib/installers/sysadmintools/fungistor/fungistor_actions.v @@ -66,7 +66,7 @@ fn stop_post() ! { // checks if a certain version or above is installed fn installed_() !bool { // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED - // res := os.execute('${osal.profile_path_source_and()} fungistor version') + // res := os.execute('${osal.profile_path_source_and()!} fungistor version') // if res.exit_code != 0 { // return false // } @@ -98,13 +98,13 @@ fn install_() ! { console.print_header('install fungistor') // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // mut url := '' - // if osal.is_linux_arm() { + // if core.is_linux_arm()! { // url = 'https://github.com/fungistor-dev/fungistor/releases/download/v${version}/fungistor_${version}_linux_arm64.tar.gz' - // } else if osal.is_linux_intel() { + // } else if core.is_linux_intel()! { // url = 'https://github.com/fungistor-dev/fungistor/releases/download/v${version}/fungistor_${version}_linux_amd64.tar.gz' - // } else if osal.is_osx_arm() { + // } else if core.is_osx_arm()! { // url = 'https://github.com/fungistor-dev/fungistor/releases/download/v${version}/fungistor_${version}_darwin_arm64.tar.gz' - // } else if osal.is_osx_intel() { + // } else if core.is_osx_intel()! { // url = 'https://github.com/fungistor-dev/fungistor/releases/download/v${version}/fungistor_${version}_darwin_amd64.tar.gz' // } else { // return error('unsported platform') @@ -129,7 +129,7 @@ fn build_() ! { // url := 'https://github.com/threefoldtech/fungistor' // make sure we install base on the node - // if osal.platform() != .ubuntu { + // if core.platform()!= .ubuntu { // return error('only support ubuntu for now') // } // golang.install()! diff --git a/lib/installers/sysadmintools/fungistor/fungistor_factory_.v b/lib/installers/sysadmintools/fungistor/fungistor_factory_.v index bdad3080..3720f860 100644 --- a/lib/installers/sysadmintools/fungistor/fungistor_factory_.v +++ b/lib/installers/sysadmintools/fungistor/fungistor_factory_.v @@ -1,153 +1,152 @@ + module fungistor import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - fungistor_global map[string]&FungiStor - fungistor_default string + fungistor_global map[string]&FungiStor + fungistor_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&FungiStor { - return &FungiStor{} -} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// + + + fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } + // unknown + // screen + // zinit + // tmux + // systemd + match cat{ + .zinit{ + console.print_debug("startupmanager: zinit") + return startupmanager.get(cat:.zinit)! + } + .systemd{ + console.print_debug("startupmanager: systemd") + return startupmanager.get(cat:.systemd)! + }else{ + console.print_debug("startupmanager: auto") + return startupmanager.get()! + } + } } pub fn (mut self FungiStor) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('fungistor start') + console.print_header('fungistor start') - if !installed()! { - install()! - } + if ! installed_()!{ + install_()! + } - configure()! + configure()! - start_pre()! + start_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! - console.print_debug('starting fungistor with ${zprocess.startuptype}...') + console.print_debug('starting fungistor with ${zprocess.startuptype}...') - sm.new(zprocess)! + sm.new(zprocess)! - sm.start(zprocess.name)! - } + sm.start(zprocess.name)! + } - start_post()! + start_post()! + + for _ in 0 .. 50 { + if self.running()! { + return + } + time.sleep(100 * time.millisecond) + } + return error('fungistor did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('fungistor did not install properly.') } pub fn (mut self FungiStor) install_start(model InstallArgs) ! { - switch(self.name) - self.install(model)! - self.start()! + switch(self.name) + self.install(model)! + self.start()! } pub fn (mut self FungiStor) stop() ! { - switch(self.name) - stop_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - sm.stop(zprocess.name)! - } - stop_post()! + switch(self.name) + stop_pre()! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + sm.stop(zprocess.name)! + } + stop_post()! } pub fn (mut self FungiStor) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self FungiStor) running() !bool { - switch(self.name) + switch(self.name) - // walk over the generic processes, if not running return - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - r := sm.running(zprocess.name)! - if r == false { - return false - } - } - return running()! + //walk over the generic processes, if not running return + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + r:=sm.running(zprocess.name)! + if r==false{ + return false + } + } + return running()! } @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self FungiStor) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self FungiStor) build() ! { - switch(self.name) - build()! +pub fn destroy() ! { + destroy_()! } -pub fn (mut self FungiStor) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! +pub fn build() ! { + build_()! } -// switch instance to be used for fungistor -pub fn switch(name string) { - fungistor_default = name -} + + + + diff --git a/lib/installers/sysadmintools/garage_s3/garage_s3_actions.v b/lib/installers/sysadmintools/garage_s3/garage_s3_actions.v index b7e2f97a..9bdbb9ab 100644 --- a/lib/installers/sysadmintools/garage_s3/garage_s3_actions.v +++ b/lib/installers/sysadmintools/garage_s3/garage_s3_actions.v @@ -66,7 +66,7 @@ fn stop_post() ! { // checks if a certain version or above is installed fn installed_() !bool { // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED - // res := os.execute('${osal.profile_path_source_and()} garage_s3 version') + // res := os.execute('${osal.profile_path_source_and()!} garage_s3 version') // if res.exit_code != 0 { // return false // } @@ -98,13 +98,13 @@ fn install_() ! { console.print_header('install garage_s3') // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // mut url := '' - // if osal.is_linux_arm() { + // if core.is_linux_arm()! { // url = 'https://github.com/garage_s3-dev/garage_s3/releases/download/v${version}/garage_s3_${version}_linux_arm64.tar.gz' - // } else if osal.is_linux_intel() { + // } else if core.is_linux_intel()! { // url = 'https://github.com/garage_s3-dev/garage_s3/releases/download/v${version}/garage_s3_${version}_linux_amd64.tar.gz' - // } else if osal.is_osx_arm() { + // } else if core.is_osx_arm()! { // url = 'https://github.com/garage_s3-dev/garage_s3/releases/download/v${version}/garage_s3_${version}_darwin_arm64.tar.gz' - // } else if osal.is_osx_intel() { + // } else if core.is_osx_intel()! { // url = 'https://github.com/garage_s3-dev/garage_s3/releases/download/v${version}/garage_s3_${version}_darwin_amd64.tar.gz' // } else { // return error('unsported platform') @@ -129,7 +129,7 @@ fn build_() ! { // url := 'https://github.com/threefoldtech/garage_s3' // make sure we install base on the node - // if osal.platform() != .ubuntu { + // if core.platform()!= .ubuntu { // return error('only support ubuntu for now') // } // golang.install()! diff --git a/lib/installers/sysadmintools/garage_s3/garage_s3_factory_.v b/lib/installers/sysadmintools/garage_s3/garage_s3_factory_.v index 7b2005f9..fd9eac3c 100644 --- a/lib/installers/sysadmintools/garage_s3/garage_s3_factory_.v +++ b/lib/installers/sysadmintools/garage_s3/garage_s3_factory_.v @@ -1,153 +1,152 @@ + module garage_s3 import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - garage_s3_global map[string]&GarageS3 - garage_s3_default string + garage_s3_global map[string]&GarageS3 + garage_s3_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&GarageS3 { - return &GarageS3{} -} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// + + + fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } + // unknown + // screen + // zinit + // tmux + // systemd + match cat{ + .zinit{ + console.print_debug("startupmanager: zinit") + return startupmanager.get(cat:.zinit)! + } + .systemd{ + console.print_debug("startupmanager: systemd") + return startupmanager.get(cat:.systemd)! + }else{ + console.print_debug("startupmanager: auto") + return startupmanager.get()! + } + } } pub fn (mut self GarageS3) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('garage_s3 start') + console.print_header('garage_s3 start') - if !installed()! { - install()! - } + if ! installed_()!{ + install_()! + } - configure()! + configure()! - start_pre()! + start_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! - console.print_debug('starting garage_s3 with ${zprocess.startuptype}...') + console.print_debug('starting garage_s3 with ${zprocess.startuptype}...') - sm.new(zprocess)! + sm.new(zprocess)! - sm.start(zprocess.name)! - } + sm.start(zprocess.name)! + } - start_post()! + start_post()! + + for _ in 0 .. 50 { + if self.running()! { + return + } + time.sleep(100 * time.millisecond) + } + return error('garage_s3 did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('garage_s3 did not install properly.') } pub fn (mut self GarageS3) install_start(model InstallArgs) ! { - switch(self.name) - self.install(model)! - self.start()! + switch(self.name) + self.install(model)! + self.start()! } pub fn (mut self GarageS3) stop() ! { - switch(self.name) - stop_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - sm.stop(zprocess.name)! - } - stop_post()! + switch(self.name) + stop_pre()! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + sm.stop(zprocess.name)! + } + stop_post()! } pub fn (mut self GarageS3) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self GarageS3) running() !bool { - switch(self.name) + switch(self.name) - // walk over the generic processes, if not running return - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - r := sm.running(zprocess.name)! - if r == false { - return false - } - } - return running()! + //walk over the generic processes, if not running return + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + r:=sm.running(zprocess.name)! + if r==false{ + return false + } + } + return running()! } @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self GarageS3) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self GarageS3) build() ! { - switch(self.name) - build()! +pub fn destroy() ! { + destroy_()! } -pub fn (mut self GarageS3) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! +pub fn build() ! { + build_()! } -// switch instance to be used for garage_s3 -pub fn switch(name string) { - garage_s3_default = name -} + + + + diff --git a/lib/installers/sysadmintools/garage_s3/install.v b/lib/installers/sysadmintools/garage_s3/install.v index f1a724b3..e7a4addd 100644 --- a/lib/installers/sysadmintools/garage_s3/install.v +++ b/lib/installers/sysadmintools/garage_s3/install.v @@ -28,9 +28,9 @@ pub fn installll(args_ S3Config) ! { console.print_header('install garage') mut url := '' - if osal.is_linux_arm() { + if core.is_linux_arm()! { url = 'https://garagehq.deuxfleurs.fr/_releases/v${version}/aarch64-unknown-linux-musl/garage' - } else if osal.is_linux_intel() { + } else if core.is_linux_intel()! { url = 'https://garagehq.deuxfleurs.fr/_releases/v${version}/x86_64-unknown-linux-musl/garage' } else { return error('unsported platform') diff --git a/lib/installers/sysadmintools/grafana/grafana.v b/lib/installers/sysadmintools/grafana/grafana.v index 0381b9b1..82b6d914 100644 --- a/lib/installers/sysadmintools/grafana/grafana.v +++ b/lib/installers/sysadmintools/grafana/grafana.v @@ -14,7 +14,7 @@ pub fn installll(args_ InstallArgs) ! { version := '11.1.4' - res := os.execute('${osal.profile_path_source_and()} grafana --version') + res := os.execute('${osal.profile_path_source_and()!} grafana --version') if res.exit_code == 0 { r := res.output.split_into_lines().filter(it.trim_space().starts_with('grafana')) if r.len != 1 { @@ -32,7 +32,7 @@ pub fn installll(args_ InstallArgs) ! { console.print_header('install grafana') mut url := '' - if osal.is_linux_intel() { + if core.is_linux_intel()! { url = 'https://dl.grafana.com/oss/release/grafana-${version}.linux-amd64.tar.gz' } else { return error('unsuported platform, only linux amd64 for now') diff --git a/lib/installers/sysadmintools/grafana/grafana_actions.v b/lib/installers/sysadmintools/grafana/grafana_actions.v index b32a4055..f5113640 100644 --- a/lib/installers/sysadmintools/grafana/grafana_actions.v +++ b/lib/installers/sysadmintools/grafana/grafana_actions.v @@ -66,7 +66,7 @@ fn stop_post() ! { // checks if a certain version or above is installed fn installed_() !bool { // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED - // res := os.execute('${osal.profile_path_source_and()} grafana version') + // res := os.execute('${osal.profile_path_source_and()!} grafana version') // if res.exit_code != 0 { // return false // } @@ -98,13 +98,13 @@ fn install_() ! { console.print_header('install grafana') // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // mut url := '' - // if osal.is_linux_arm() { + // if core.is_linux_arm()! { // url = 'https://github.com/grafana-dev/grafana/releases/download/v${version}/grafana_${version}_linux_arm64.tar.gz' - // } else if osal.is_linux_intel() { + // } else if core.is_linux_intel()! { // url = 'https://github.com/grafana-dev/grafana/releases/download/v${version}/grafana_${version}_linux_amd64.tar.gz' - // } else if osal.is_osx_arm() { + // } else if core.is_osx_arm()! { // url = 'https://github.com/grafana-dev/grafana/releases/download/v${version}/grafana_${version}_darwin_arm64.tar.gz' - // } else if osal.is_osx_intel() { + // } else if core.is_osx_intel()! { // url = 'https://github.com/grafana-dev/grafana/releases/download/v${version}/grafana_${version}_darwin_amd64.tar.gz' // } else { // return error('unsported platform') @@ -129,7 +129,7 @@ fn build_() ! { // url := 'https://github.com/threefoldtech/grafana' // make sure we install base on the node - // if osal.platform() != .ubuntu { + // if core.platform()!= .ubuntu { // return error('only support ubuntu for now') // } // golang.install()! diff --git a/lib/installers/sysadmintools/grafana/grafana_factory_.v b/lib/installers/sysadmintools/grafana/grafana_factory_.v index 355280f7..28fc8d06 100644 --- a/lib/installers/sysadmintools/grafana/grafana_factory_.v +++ b/lib/installers/sysadmintools/grafana/grafana_factory_.v @@ -1,153 +1,152 @@ + module grafana import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - grafana_global map[string]&Grafana - grafana_default string + grafana_global map[string]&Grafana + grafana_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&Grafana { - return &Grafana{} -} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// + + + fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } + // unknown + // screen + // zinit + // tmux + // systemd + match cat{ + .zinit{ + console.print_debug("startupmanager: zinit") + return startupmanager.get(cat:.zinit)! + } + .systemd{ + console.print_debug("startupmanager: systemd") + return startupmanager.get(cat:.systemd)! + }else{ + console.print_debug("startupmanager: auto") + return startupmanager.get()! + } + } } pub fn (mut self Grafana) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('grafana start') + console.print_header('grafana start') - if !installed()! { - install()! - } + if ! installed_()!{ + install_()! + } - configure()! + configure()! - start_pre()! + start_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! - console.print_debug('starting grafana with ${zprocess.startuptype}...') + console.print_debug('starting grafana with ${zprocess.startuptype}...') - sm.new(zprocess)! + sm.new(zprocess)! - sm.start(zprocess.name)! - } + sm.start(zprocess.name)! + } - start_post()! + start_post()! + + for _ in 0 .. 50 { + if self.running()! { + return + } + time.sleep(100 * time.millisecond) + } + return error('grafana did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('grafana did not install properly.') } pub fn (mut self Grafana) install_start(model InstallArgs) ! { - switch(self.name) - self.install(model)! - self.start()! + switch(self.name) + self.install(model)! + self.start()! } pub fn (mut self Grafana) stop() ! { - switch(self.name) - stop_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - sm.stop(zprocess.name)! - } - stop_post()! + switch(self.name) + stop_pre()! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + sm.stop(zprocess.name)! + } + stop_post()! } pub fn (mut self Grafana) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self Grafana) running() !bool { - switch(self.name) + switch(self.name) - // walk over the generic processes, if not running return - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - r := sm.running(zprocess.name)! - if r == false { - return false - } - } - return running()! + //walk over the generic processes, if not running return + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + r:=sm.running(zprocess.name)! + if r==false{ + return false + } + } + return running()! } @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self Grafana) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self Grafana) build() ! { - switch(self.name) - build()! +pub fn destroy() ! { + destroy_()! } -pub fn (mut self Grafana) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! +pub fn build() ! { + build_()! } -// switch instance to be used for grafana -pub fn switch(name string) { - grafana_default = name -} + + + + diff --git a/lib/installers/sysadmintools/prometheus/alertmanager_installer.v b/lib/installers/sysadmintools/prometheus/alertmanager_installer.v index 7e695f9a..a267662e 100644 --- a/lib/installers/sysadmintools/prometheus/alertmanager_installer.v +++ b/lib/installers/sysadmintools/prometheus/alertmanager_installer.v @@ -14,7 +14,7 @@ pub fn install_alertmanager(args_ InstallArgs) ! { version := '0.27.0' - res := os.execute('${osal.profile_path_source_and()} alertmanager --version') + res := os.execute('${osal.profile_path_source_and()!} alertmanager --version') if res.exit_code == 0 { r := res.output.split_into_lines().filter(it.trim_space().starts_with('alertmanager')) if r.len != 1 { @@ -32,7 +32,7 @@ pub fn install_alertmanager(args_ InstallArgs) ! { console.print_header('install alertmanager') mut url := '' - if osal.is_linux_intel() { + if core.is_linux_intel()! { url = 'https://github.com/prometheus/alertmanager/releases/download/v${version}/alertmanager-${version}.linux-amd64.tar.gz' } else { return error('unsported platform, only linux amd64 for now') diff --git a/lib/installers/sysadmintools/prometheus/blackbox_exporter.v b/lib/installers/sysadmintools/prometheus/blackbox_exporter.v index 5865f0a4..84c4d5bc 100644 --- a/lib/installers/sysadmintools/prometheus/blackbox_exporter.v +++ b/lib/installers/sysadmintools/prometheus/blackbox_exporter.v @@ -14,7 +14,7 @@ pub fn install_blackbox_exporter(args_ InstallArgs) ! { version := '0.25.0' - res := os.execute('${osal.profile_path_source_and()} blackbox_exporter --version') + res := os.execute('${osal.profile_path_source_and()!} blackbox_exporter --version') if res.exit_code == 0 { r := res.output.split_into_lines().filter(it.trim_space().starts_with('blackbox_exporter')) if r.len != 1 { @@ -32,7 +32,7 @@ pub fn install_blackbox_exporter(args_ InstallArgs) ! { console.print_header('install blackbox_exporter') mut url := '' - if osal.is_linux_intel() { + if core.is_linux_intel()! { url = 'https://github.com/prometheus/blackbox_exporter/releases/download/v${version}/blackbox_exporter-${version}.linux-amd64.tar.gz' } else { return error('unsuported platform, only linux amd64 for now') diff --git a/lib/installers/sysadmintools/prometheus/node_exporter.v b/lib/installers/sysadmintools/prometheus/node_exporter.v index 9e9c4763..a409fca3 100644 --- a/lib/installers/sysadmintools/prometheus/node_exporter.v +++ b/lib/installers/sysadmintools/prometheus/node_exporter.v @@ -14,7 +14,7 @@ pub fn install_node_exporter(args_ InstallArgs) ! { version := '1.8.2' - res := os.execute('${osal.profile_path_source_and()} node_exporter --version') + res := os.execute('${osal.profile_path_source_and()!} node_exporter --version') if res.exit_code == 0 { r := res.output.split_into_lines().filter(it.trim_space().starts_with('node_exporter')) if r.len != 1 { @@ -32,7 +32,7 @@ pub fn install_node_exporter(args_ InstallArgs) ! { console.print_header('install node_exporter') mut url := '' - if osal.is_linux_intel() { + if core.is_linux_intel()! { url = 'https://github.com/prometheus/node_exporter/releases/download/v${version}/node_exporter-${version}.linux-amd64.tar.gz' } else { return error('unsuported platform, only linux amd64 for now') diff --git a/lib/installers/sysadmintools/prometheus/prom2json.v b/lib/installers/sysadmintools/prometheus/prom2json.v index e09318a8..482e5478 100644 --- a/lib/installers/sysadmintools/prometheus/prom2json.v +++ b/lib/installers/sysadmintools/prometheus/prom2json.v @@ -14,7 +14,7 @@ pub fn install_prom2json(args_ InstallArgs) ! { version := '1.4.0' - res := os.execute('${osal.profile_path_source_and()} prom2json --help') + res := os.execute('${osal.profile_path_source_and()!} prom2json --help') if res.exit_code != 0 { args.reset = true } @@ -23,7 +23,7 @@ pub fn install_prom2json(args_ InstallArgs) ! { console.print_header('install prom2json') mut url := '' - if osal.is_linux_intel() { + if core.is_linux_intel()! { url = 'https://github.com/prometheus/prom2json/releases/download/v${version}/prom2json-${version}.linux-amd64.tar.gz' } else { return error('unsuported platform, only linux amd64 for now') diff --git a/lib/installers/sysadmintools/prometheus/prometheus_actions.v b/lib/installers/sysadmintools/prometheus/prometheus_actions.v index 530bb92f..924577ac 100644 --- a/lib/installers/sysadmintools/prometheus/prometheus_actions.v +++ b/lib/installers/sysadmintools/prometheus/prometheus_actions.v @@ -66,7 +66,7 @@ fn stop_post() ! { // checks if a certain version or above is installed fn installed_() !bool { // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED - // res := os.execute('${osal.profile_path_source_and()} prometheus version') + // res := os.execute('${osal.profile_path_source_and()!} prometheus version') // if res.exit_code != 0 { // return false // } @@ -98,13 +98,13 @@ fn install_() ! { console.print_header('install prometheus') // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // mut url := '' - // if osal.is_linux_arm() { + // if core.is_linux_arm()! { // url = 'https://github.com/prometheus-dev/prometheus/releases/download/v${version}/prometheus_${version}_linux_arm64.tar.gz' - // } else if osal.is_linux_intel() { + // } else if core.is_linux_intel()! { // url = 'https://github.com/prometheus-dev/prometheus/releases/download/v${version}/prometheus_${version}_linux_amd64.tar.gz' - // } else if osal.is_osx_arm() { + // } else if core.is_osx_arm()! { // url = 'https://github.com/prometheus-dev/prometheus/releases/download/v${version}/prometheus_${version}_darwin_arm64.tar.gz' - // } else if osal.is_osx_intel() { + // } else if core.is_osx_intel()! { // url = 'https://github.com/prometheus-dev/prometheus/releases/download/v${version}/prometheus_${version}_darwin_amd64.tar.gz' // } else { // return error('unsported platform') @@ -129,7 +129,7 @@ fn build_() ! { // url := 'https://github.com/threefoldtech/prometheus' // make sure we install base on the node - // if osal.platform() != .ubuntu { + // if core.platform()!= .ubuntu { // return error('only support ubuntu for now') // } // golang.install()! diff --git a/lib/installers/sysadmintools/prometheus/prometheus_factory_.v b/lib/installers/sysadmintools/prometheus/prometheus_factory_.v index 3b3adf55..eed1e159 100644 --- a/lib/installers/sysadmintools/prometheus/prometheus_factory_.v +++ b/lib/installers/sysadmintools/prometheus/prometheus_factory_.v @@ -1,153 +1,152 @@ + module prometheus import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - prometheus_global map[string]&Prometheus - prometheus_default string + prometheus_global map[string]&Prometheus + prometheus_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&Prometheus { - return &Prometheus{} -} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// + + + fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } + // unknown + // screen + // zinit + // tmux + // systemd + match cat{ + .zinit{ + console.print_debug("startupmanager: zinit") + return startupmanager.get(cat:.zinit)! + } + .systemd{ + console.print_debug("startupmanager: systemd") + return startupmanager.get(cat:.systemd)! + }else{ + console.print_debug("startupmanager: auto") + return startupmanager.get()! + } + } } pub fn (mut self Prometheus) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('prometheus start') + console.print_header('prometheus start') - if !installed()! { - install()! - } + if ! installed_()!{ + install_()! + } - configure()! + configure()! - start_pre()! + start_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! - console.print_debug('starting prometheus with ${zprocess.startuptype}...') + console.print_debug('starting prometheus with ${zprocess.startuptype}...') - sm.new(zprocess)! + sm.new(zprocess)! - sm.start(zprocess.name)! - } + sm.start(zprocess.name)! + } - start_post()! + start_post()! + + for _ in 0 .. 50 { + if self.running()! { + return + } + time.sleep(100 * time.millisecond) + } + return error('prometheus did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('prometheus did not install properly.') } pub fn (mut self Prometheus) install_start(model InstallArgs) ! { - switch(self.name) - self.install(model)! - self.start()! + switch(self.name) + self.install(model)! + self.start()! } pub fn (mut self Prometheus) stop() ! { - switch(self.name) - stop_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - sm.stop(zprocess.name)! - } - stop_post()! + switch(self.name) + stop_pre()! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + sm.stop(zprocess.name)! + } + stop_post()! } pub fn (mut self Prometheus) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self Prometheus) running() !bool { - switch(self.name) + switch(self.name) - // walk over the generic processes, if not running return - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - r := sm.running(zprocess.name)! - if r == false { - return false - } - } - return running()! + //walk over the generic processes, if not running return + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + r:=sm.running(zprocess.name)! + if r==false{ + return false + } + } + return running()! } @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self Prometheus) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self Prometheus) build() ! { - switch(self.name) - build()! +pub fn destroy() ! { + destroy_()! } -pub fn (mut self Prometheus) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! +pub fn build() ! { + build_()! } -// switch instance to be used for prometheus -pub fn switch(name string) { - prometheus_default = name -} + + + + diff --git a/lib/installers/sysadmintools/prometheus/prometheus_installer.v b/lib/installers/sysadmintools/prometheus/prometheus_installer.v index e010bf89..7b87c326 100644 --- a/lib/installers/sysadmintools/prometheus/prometheus_installer.v +++ b/lib/installers/sysadmintools/prometheus/prometheus_installer.v @@ -14,7 +14,7 @@ pub fn install_prometheus(args_ InstallArgs) ! { version := '2.54.0' - res := os.execute('${osal.profile_path_source_and()} prometheus --version') + res := os.execute('${osal.profile_path_source_and()!} prometheus --version') if res.exit_code == 0 { r := res.output.split_into_lines().filter(it.trim_space().starts_with('prometheus')) if r.len != 1 { @@ -32,7 +32,7 @@ pub fn install_prometheus(args_ InstallArgs) ! { console.print_header('install prometheus') mut url := '' - if osal.is_linux_intel() { + if core.is_linux_intel()! { url = 'https://github.com/prometheus/prometheus/releases/download/v${version}/prometheus-${version}.linux-amd64.tar.gz' } else { return error('unsported platform, only linux amd64 for now') diff --git a/lib/installers/sysadmintools/rclone/rclone_actions.v b/lib/installers/sysadmintools/rclone/rclone_actions.v index 6ad69c30..ec442e32 100644 --- a/lib/installers/sysadmintools/rclone/rclone_actions.v +++ b/lib/installers/sysadmintools/rclone/rclone_actions.v @@ -8,7 +8,7 @@ import os // checks if a certain version or above is installed fn installed_() !bool { - res := os.execute('${osal.profile_path_source_and()} rclone version') + res := os.execute('${osal.profile_path_source_and()!} rclone version') if res.exit_code != 0 { return false } @@ -27,13 +27,13 @@ fn install_() ! { console.print_header('install rclone') // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED mut url := '' - if osal.is_linux_arm() { + if core.is_linux_arm()! { url = 'https://github.com/rclone/rclone/releases/download/v${version}/rclone-v${version}-linux-arm64.zip' - } else if osal.is_linux_intel() { + } else if core.is_linux_intel()! { url = 'https://github.com/rclone/rclone/releases/download/v${version}/rclone-v${version}-linux-amd64.zip' - } else if osal.is_osx_arm() { + } else if core.is_osx_arm()! { url = 'https://downloads.rclone.org/rclone-current-osx-amd64.zip' - } else if osal.is_osx_intel() { + } else if core.is_osx_intel()! { url = 'https://github.com/rclone/rclone/releases/download/v${version}/rclone-v${version}-osx-amd64.zip' } else { return error('unsported platform') diff --git a/lib/installers/sysadmintools/rclone/rclone_factory_.v b/lib/installers/sysadmintools/rclone/rclone_factory_.v index 443b8104..8886e0d1 100644 --- a/lib/installers/sysadmintools/rclone/rclone_factory_.v +++ b/lib/installers/sysadmintools/rclone/rclone_factory_.v @@ -1,173 +1,182 @@ + module rclone import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.data.encoderhero + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - rclone_global map[string]&RClone - rclone_default string + rclone_global map[string]&RClone + rclone_default string ) /////////FACTORY + + @[params] -pub struct ArgsGet { +pub struct ArgsGet{ pub mut: - name string + name string } -fn args_get(args_ ArgsGet) ArgsGet { - mut model := args_ - if model.name == '' { - model.name = rclone_default - } - if model.name == '' { - model.name = 'default' - } - return model +fn args_get (args_ ArgsGet) ArgsGet { + mut model:=args_ + if model.name == ""{ + model.name = rclone_default + } + if model.name == ""{ + model.name = "default" + } + return model } -pub fn get(args_ ArgsGet) !&RClone { - mut model := args_get(args_) - if model.name !in rclone_global { - if model.name == 'default' { - if !config_exists(model) { - if default { - config_save(model)! - } - } - config_load(model)! - } - } - return rclone_global[model.name] or { - println(rclone_global) - panic('could not get config for rclone with name:${model.name}') - } +pub fn get(args_ ArgsGet) !&RClone { + mut args := args_get(args_) + if !(args.name in rclone_global) { + if args.name=="default"{ + if ! config_exists(args){ + if default{ + mut context:=base.context() or { panic("bug") } + context.hero_config_set("rclone",model.name,heroscript_default()!)! + } + } + load(args)! + } + } + return rclone_global[args.name] or { + println(rclone_global) + panic("could not get config for ${args.name} with name:${model.name}") + } } -fn config_exists(args_ ArgsGet) bool { - mut model := args_get(args_) - mut context := base.context() or { panic('bug') } - return context.hero_config_exists('rclone', model.name) + + +//set the model in mem and the config on the filesystem +pub fn set(o RClone)! { + mut o2:=obj_init(o)! + rclone_global[o.name] = &o2 + rclone_default = o.name } -fn config_load(args_ ArgsGet) ! { - mut model := args_get(args_) - mut context := base.context()! - mut heroscript := context.hero_config_get('rclone', model.name)! - play(heroscript: heroscript)! +//check we find the config on the filesystem +pub fn exists(args_ ArgsGet) bool { + mut model := args_get(args_) + mut context:=base.context() or { panic("bug") } + return context.hero_config_exists("rclone",model.name) } -fn config_save(args_ ArgsGet) ! { - mut model := args_get(args_) - mut context := base.context()! - context.hero_config_set('rclone', model.name, heroscript_default()!)! +//load the config error if it doesn't exist +pub fn load(args_ ArgsGet) ! { + mut model := args_get(args_) + mut context:=base.context()! + mut heroscript := context.hero_config_get("rclone",model.name)! + play(heroscript:heroscript)! } -fn set(o RClone) ! { - mut o2 := obj_init(o)! - rclone_global[o.name] = &o2 - rclone_default = o.name +//save the config to the filesystem in the context +pub fn save(o RClone)! { + mut context:=base.context()! + heroscript := encoderhero.encode[RClone](o)! + context.hero_config_set("rclone",model.name,heroscript)! } @[params] pub struct PlayArgs { pub mut: - heroscript string // if filled in then plbook will be made out of it - plbook ?playbook.PlayBook - reset bool + heroscript string //if filled in then plbook will be made out of it + plbook ?playbook.PlayBook + reset bool } pub fn play(args_ PlayArgs) ! { - mut model := args_ + + mut model:=args_ - if model.heroscript == '' { - model.heroscript = heroscript_default()! - } - mut plbook := model.plbook or { playbook.new(text: model.heroscript)! } + if model.heroscript == "" { + model.heroscript = heroscript_default()! + } + mut plbook := model.plbook or { + playbook.new(text: model.heroscript)! + } + + mut configure_actions := plbook.find(filter: 'rclone.configure')! + if configure_actions.len > 0 { + for config_action in configure_actions { + mut p := config_action.params + mycfg:=cfg_play(p)! + console.print_debug("install action rclone.configure\n${mycfg}") + set(mycfg)! + save(mycfg)! + } + } - mut install_actions := plbook.find(filter: 'rclone.configure')! - if install_actions.len > 0 { - for install_action in install_actions { - mut p := install_action.params - mycfg := cfg_play(p)! - console.print_debug('install action rclone.configure\n${mycfg}') - set(mycfg)! - } - } + mut other_actions := plbook.find(filter: 'rclone.')! + for other_action in other_actions { + if other_action.name in ["destroy","install","build"]{ + mut p := other_action.params + reset:=p.get_default_false("reset") + if other_action.name == "destroy" || reset{ + console.print_debug("install action rclone.destroy") + destroy_()! + } + if other_action.name == "install"{ + console.print_debug("install action rclone.install") + install_()! + } + } + } - mut other_actions := plbook.find(filter: 'rclone.')! - for other_action in other_actions { - if other_action.name in ['destroy', 'install', 'build'] { - mut p := other_action.params - reset := p.get_default_false('reset') - if other_action.name == 'destroy' || reset { - console.print_debug('install action rclone.destroy') - destroy()! - } - if other_action.name == 'install' { - console.print_debug('install action rclone.install') - install()! - } - } - } } + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// -fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } + +//load from disk and make sure is properly intialized +pub fn (mut self RClone) reload() ! { + switch(self.name) + self=obj_init(self)! } -// load from disk and make sure is properly intialized -pub fn (mut self RClone) reload() ! { - switch(self.name) - self = obj_init(self)! -} @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self RClone) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +//switch instance to be used for rclone +pub fn switch(name string) { + rclone_default = name } + +pub fn (mut self RClone) install(args InstallArgs) ! { + switch(self.name) + if args.reset { + destroy_()! + } + if ! (installed_()!){ + install_()! + } +} + + pub fn (mut self RClone) destroy() ! { - switch(self.name) - destroy()! + switch(self.name) + destroy_()! } -// switch instance to be used for rclone -pub fn switch(name string) { - rclone_default = name -} + + + diff --git a/lib/installers/sysadmintools/restic/builder.v b/lib/installers/sysadmintools/restic/builder.v index f9c72f3d..51421fe8 100644 --- a/lib/installers/sysadmintools/restic/builder.v +++ b/lib/installers/sysadmintools/restic/builder.v @@ -18,7 +18,7 @@ pub mut: // install restic will return true if it was already installed pub fn build_(args BuildArgs) ! { // make sure we install base on the node - if osal.platform() != .ubuntu { + if core.platform()!= .ubuntu { return error('only support ubuntu for now') } golang.install()! diff --git a/lib/installers/sysadmintools/restic/restic_actions.v b/lib/installers/sysadmintools/restic/restic_actions.v index 6d4866ef..44c4039c 100644 --- a/lib/installers/sysadmintools/restic/restic_actions.v +++ b/lib/installers/sysadmintools/restic/restic_actions.v @@ -66,7 +66,7 @@ fn stop_post() ! { // checks if a certain version or above is installed fn installed_() !bool { // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED - // res := os.execute('${osal.profile_path_source_and()} restic version') + // res := os.execute('${osal.profile_path_source_and()!} restic version') // if res.exit_code != 0 { // return false // } @@ -98,13 +98,13 @@ fn install_() ! { console.print_header('install restic') // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // mut url := '' - // if osal.is_linux_arm() { + // if core.is_linux_arm()! { // url = 'https://github.com/restic-dev/restic/releases/download/v${version}/restic_${version}_linux_arm64.tar.gz' - // } else if osal.is_linux_intel() { + // } else if core.is_linux_intel()! { // url = 'https://github.com/restic-dev/restic/releases/download/v${version}/restic_${version}_linux_amd64.tar.gz' - // } else if osal.is_osx_arm() { + // } else if core.is_osx_arm()! { // url = 'https://github.com/restic-dev/restic/releases/download/v${version}/restic_${version}_darwin_arm64.tar.gz' - // } else if osal.is_osx_intel() { + // } else if core.is_osx_intel()! { // url = 'https://github.com/restic-dev/restic/releases/download/v${version}/restic_${version}_darwin_amd64.tar.gz' // } else { // return error('unsported platform') @@ -129,7 +129,7 @@ fn build_() ! { // url := 'https://github.com/threefoldtech/restic' // make sure we install base on the node - // if osal.platform() != .ubuntu { + // if core.platform()!= .ubuntu { // return error('only support ubuntu for now') // } // golang.install()! diff --git a/lib/installers/sysadmintools/restic/restic_factory_.v b/lib/installers/sysadmintools/restic/restic_factory_.v index 755957a9..cffd7992 100644 --- a/lib/installers/sysadmintools/restic/restic_factory_.v +++ b/lib/installers/sysadmintools/restic/restic_factory_.v @@ -1,153 +1,152 @@ + module restic import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - restic_global map[string]&Restic - restic_default string + restic_global map[string]&Restic + restic_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&Restic { - return &Restic{} -} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// + + + fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } + // unknown + // screen + // zinit + // tmux + // systemd + match cat{ + .zinit{ + console.print_debug("startupmanager: zinit") + return startupmanager.get(cat:.zinit)! + } + .systemd{ + console.print_debug("startupmanager: systemd") + return startupmanager.get(cat:.systemd)! + }else{ + console.print_debug("startupmanager: auto") + return startupmanager.get()! + } + } } pub fn (mut self Restic) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('restic start') + console.print_header('restic start') - if !installed()! { - install()! - } + if ! installed_()!{ + install_()! + } - configure()! + configure()! - start_pre()! + start_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! - console.print_debug('starting restic with ${zprocess.startuptype}...') + console.print_debug('starting restic with ${zprocess.startuptype}...') - sm.new(zprocess)! + sm.new(zprocess)! - sm.start(zprocess.name)! - } + sm.start(zprocess.name)! + } - start_post()! + start_post()! + + for _ in 0 .. 50 { + if self.running()! { + return + } + time.sleep(100 * time.millisecond) + } + return error('restic did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('restic did not install properly.') } pub fn (mut self Restic) install_start(model InstallArgs) ! { - switch(self.name) - self.install(model)! - self.start()! + switch(self.name) + self.install(model)! + self.start()! } pub fn (mut self Restic) stop() ! { - switch(self.name) - stop_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - sm.stop(zprocess.name)! - } - stop_post()! + switch(self.name) + stop_pre()! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + sm.stop(zprocess.name)! + } + stop_post()! } pub fn (mut self Restic) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self Restic) running() !bool { - switch(self.name) + switch(self.name) - // walk over the generic processes, if not running return - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - r := sm.running(zprocess.name)! - if r == false { - return false - } - } - return running()! + //walk over the generic processes, if not running return + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + r:=sm.running(zprocess.name)! + if r==false{ + return false + } + } + return running()! } @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self Restic) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self Restic) build() ! { - switch(self.name) - build()! +pub fn destroy() ! { + destroy_()! } -pub fn (mut self Restic) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! +pub fn build() ! { + build_()! } -// switch instance to be used for restic -pub fn switch(name string) { - restic_default = name -} + + + + diff --git a/lib/installers/sysadmintools/restic/restic_install.v b/lib/installers/sysadmintools/restic/restic_install.v index 26cb69d0..6e335230 100644 --- a/lib/installers/sysadmintools/restic/restic_install.v +++ b/lib/installers/sysadmintools/restic/restic_install.v @@ -9,7 +9,7 @@ pub fn installll(args_ InstallArgs) ! { mut args := args_ version := '0.16.2' - res := os.execute('${osal.profile_path_source_and()} restic version') + res := os.execute('${osal.profile_path_source_and()!} restic version') if res.exit_code == 0 { r := res.output.split_into_lines().filter(it.contains('restic 0')) if r.len != 1 { @@ -31,11 +31,11 @@ pub fn installll(args_ InstallArgs) ! { console.print_header('install restic') mut url := '' - if osal.is_linux() { + if core.is_linux()! { url = 'https://github.com/restic/restic/releases/download/v${version}/restic_${version}_linux_amd64.bz2' - } else if osal.is_osx_arm() { + } else if core.is_osx_arm()! { url = 'https://github.com/restic/restic/releases/download/v${version}/restic_${version}_darwin_arm64.bz2' - } else if osal.is_osx_intel() { + } else if core.is_osx_intel()! { url = 'https://github.com/restic/restic/releases/download/v${version}/restic_${version}_darwin_amd64.bz2' } else { return error('unsported platform') diff --git a/lib/installers/sysadmintools/s3/builder.v b/lib/installers/sysadmintools/s3/builder.v index fb537f20..de56dc03 100644 --- a/lib/installers/sysadmintools/s3/builder.v +++ b/lib/installers/sysadmintools/s3/builder.v @@ -15,7 +15,7 @@ pub mut: // install s3cas will return true if it was already installed pub fn build_(args BuildArgs) ! { // make sure we install base on the node - if osal.platform() != .ubuntu { + if core.platform()!= .ubuntu { return error('only support ubuntu for now') } rust.install()! diff --git a/lib/installers/sysadmintools/s3/s3_actions.v b/lib/installers/sysadmintools/s3/s3_actions.v index 2421c74b..9fc3523c 100644 --- a/lib/installers/sysadmintools/s3/s3_actions.v +++ b/lib/installers/sysadmintools/s3/s3_actions.v @@ -66,7 +66,7 @@ fn stop_post() ! { // checks if a certain version or above is installed fn installed_() !bool { // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED - // res := os.execute('${osal.profile_path_source_and()} s3 version') + // res := os.execute('${osal.profile_path_source_and()!} s3 version') // if res.exit_code != 0 { // return false // } @@ -98,13 +98,13 @@ fn install_() ! { console.print_header('install s3') // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // mut url := '' - // if osal.is_linux_arm() { + // if core.is_linux_arm()! { // url = 'https://github.com/s3-dev/s3/releases/download/v${version}/s3_${version}_linux_arm64.tar.gz' - // } else if osal.is_linux_intel() { + // } else if core.is_linux_intel()! { // url = 'https://github.com/s3-dev/s3/releases/download/v${version}/s3_${version}_linux_amd64.tar.gz' - // } else if osal.is_osx_arm() { + // } else if core.is_osx_arm()! { // url = 'https://github.com/s3-dev/s3/releases/download/v${version}/s3_${version}_darwin_arm64.tar.gz' - // } else if osal.is_osx_intel() { + // } else if core.is_osx_intel()! { // url = 'https://github.com/s3-dev/s3/releases/download/v${version}/s3_${version}_darwin_amd64.tar.gz' // } else { // return error('unsported platform') @@ -129,7 +129,7 @@ fn build_() ! { // url := 'https://github.com/threefoldtech/s3' // make sure we install base on the node - // if osal.platform() != .ubuntu { + // if core.platform()!= .ubuntu { // return error('only support ubuntu for now') // } // golang.install()! diff --git a/lib/installers/sysadmintools/s3/s3_factory_.v b/lib/installers/sysadmintools/s3/s3_factory_.v index d4edb48d..77aab608 100644 --- a/lib/installers/sysadmintools/s3/s3_factory_.v +++ b/lib/installers/sysadmintools/s3/s3_factory_.v @@ -1,153 +1,152 @@ + module s3 import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - s3_global map[string]&S3Installer - s3_default string + s3_global map[string]&S3Installer + s3_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&S3Installer { - return &S3Installer{} -} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// + + + fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } + // unknown + // screen + // zinit + // tmux + // systemd + match cat{ + .zinit{ + console.print_debug("startupmanager: zinit") + return startupmanager.get(cat:.zinit)! + } + .systemd{ + console.print_debug("startupmanager: systemd") + return startupmanager.get(cat:.systemd)! + }else{ + console.print_debug("startupmanager: auto") + return startupmanager.get()! + } + } } pub fn (mut self S3Installer) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('s3 start') + console.print_header('s3 start') - if !installed()! { - install()! - } + if ! installed_()!{ + install_()! + } - configure()! + configure()! - start_pre()! + start_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! - console.print_debug('starting s3 with ${zprocess.startuptype}...') + console.print_debug('starting s3 with ${zprocess.startuptype}...') - sm.new(zprocess)! + sm.new(zprocess)! - sm.start(zprocess.name)! - } + sm.start(zprocess.name)! + } - start_post()! + start_post()! + + for _ in 0 .. 50 { + if self.running()! { + return + } + time.sleep(100 * time.millisecond) + } + return error('s3 did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('s3 did not install properly.') } pub fn (mut self S3Installer) install_start(model InstallArgs) ! { - switch(self.name) - self.install(model)! - self.start()! + switch(self.name) + self.install(model)! + self.start()! } pub fn (mut self S3Installer) stop() ! { - switch(self.name) - stop_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - sm.stop(zprocess.name)! - } - stop_post()! + switch(self.name) + stop_pre()! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + sm.stop(zprocess.name)! + } + stop_post()! } pub fn (mut self S3Installer) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self S3Installer) running() !bool { - switch(self.name) + switch(self.name) - // walk over the generic processes, if not running return - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - r := sm.running(zprocess.name)! - if r == false { - return false - } - } - return running()! + //walk over the generic processes, if not running return + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + r:=sm.running(zprocess.name)! + if r==false{ + return false + } + } + return running()! } @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self S3Installer) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self S3Installer) build() ! { - switch(self.name) - build()! +pub fn destroy() ! { + destroy_()! } -pub fn (mut self S3Installer) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! +pub fn build() ! { + build_()! } -// switch instance to be used for s3 -pub fn switch(name string) { - s3_default = name -} + + + + diff --git a/lib/installers/sysadmintools/zinit/zinit_actions.v b/lib/installers/sysadmintools/zinit/zinit_actions.v index f136b8fa..e4e7660a 100644 --- a/lib/installers/sysadmintools/zinit/zinit_actions.v +++ b/lib/installers/sysadmintools/zinit/zinit_actions.v @@ -30,7 +30,7 @@ fn installed_() !bool { fn install_() ! { console.print_header('install zinit') - if !osal.is_linux() { + if !core.is_linux()! { return error('only support linux for now') } @@ -53,7 +53,7 @@ fn install_() ! { } fn build_() ! { - if !osal.is_linux() { + if !core.is_linux()! { return error('only support linux for now') } @@ -70,7 +70,7 @@ fn build_() ! { )! gitpath := repo.get_path()! - // source ${osal.profile_path()} + // source ${osal.profile_path()!} cmd := ' source ~/.cargo/env diff --git a/lib/installers/sysadmintools/zinit/zinit_factory_.v b/lib/installers/sysadmintools/zinit/zinit_factory_.v index 86ee532a..090c4532 100644 --- a/lib/installers/sysadmintools/zinit/zinit_factory_.v +++ b/lib/installers/sysadmintools/zinit/zinit_factory_.v @@ -1,153 +1,152 @@ + module zinit import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - zinit_global map[string]&Zinit - zinit_default string + zinit_global map[string]&Zinit + zinit_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&Zinit { - return &Zinit{} -} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// + + + fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } + // unknown + // screen + // zinit + // tmux + // systemd + match cat{ + .zinit{ + console.print_debug("startupmanager: zinit") + return startupmanager.get(cat:.zinit)! + } + .systemd{ + console.print_debug("startupmanager: systemd") + return startupmanager.get(cat:.systemd)! + }else{ + console.print_debug("startupmanager: auto") + return startupmanager.get()! + } + } } pub fn (mut self Zinit) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('zinit start') + console.print_header('zinit start') - if !installed()! { - install()! - } + if ! installed_()!{ + install_()! + } - configure()! + configure()! - start_pre()! + start_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! - console.print_debug('starting zinit with ${zprocess.startuptype}...') + console.print_debug('starting zinit with ${zprocess.startuptype}...') - sm.new(zprocess)! + sm.new(zprocess)! - sm.start(zprocess.name)! - } + sm.start(zprocess.name)! + } - start_post()! + start_post()! + + for _ in 0 .. 50 { + if self.running()! { + return + } + time.sleep(100 * time.millisecond) + } + return error('zinit did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('zinit did not install properly.') } pub fn (mut self Zinit) install_start(model InstallArgs) ! { - switch(self.name) - self.install(model)! - self.start()! + switch(self.name) + self.install(model)! + self.start()! } pub fn (mut self Zinit) stop() ! { - switch(self.name) - stop_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - sm.stop(zprocess.name)! - } - stop_post()! + switch(self.name) + stop_pre()! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + sm.stop(zprocess.name)! + } + stop_post()! } pub fn (mut self Zinit) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self Zinit) running() !bool { - switch(self.name) + switch(self.name) - // walk over the generic processes, if not running return - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - r := sm.running(zprocess.name)! - if r == false { - return false - } - } - return running()! + //walk over the generic processes, if not running return + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + r:=sm.running(zprocess.name)! + if r==false{ + return false + } + } + return running()! } @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self Zinit) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self Zinit) build() ! { - switch(self.name) - build()! +pub fn destroy() ! { + destroy_()! } -pub fn (mut self Zinit) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! +pub fn build() ! { + build_()! } -// switch instance to be used for zinit -pub fn switch(name string) { - zinit_default = name -} + + + + diff --git a/lib/installers/threefold/griddriver/griddriver_actions.v b/lib/installers/threefold/griddriver/griddriver_actions.v index 05f54fdc..4d984bc0 100644 --- a/lib/installers/threefold/griddriver/griddriver_actions.v +++ b/lib/installers/threefold/griddriver/griddriver_actions.v @@ -10,7 +10,7 @@ import os // checks if a certain version or above is installed fn installed_() !bool { - res := os.execute('${osal.profile_path_source_and()} griddriver --version') + res := os.execute('${osal.profile_path_source_and()!} griddriver --version') if res.exit_code != 0 { return false } diff --git a/lib/installers/threefold/griddriver/griddriver_factory_.v b/lib/installers/threefold/griddriver/griddriver_factory_.v index eec6e8d4..374123b9 100644 --- a/lib/installers/threefold/griddriver/griddriver_factory_.v +++ b/lib/installers/threefold/griddriver/griddriver_factory_.v @@ -1,79 +1,57 @@ + module griddriver import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - griddriver_global map[string]&GridDriverInstaller - griddriver_default string + griddriver_global map[string]&GridDriverInstaller + griddriver_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&GridDriverInstaller { - return &GridDriverInstaller{} -} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// -fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } -} + + @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self GridDriverInstaller) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self GridDriverInstaller) build() ! { - switch(self.name) - build()! +pub fn destroy() ! { + destroy_()! } -pub fn (mut self GridDriverInstaller) destroy() ! { - switch(self.name) - destroy()! +pub fn build() ! { + build_()! } -// switch instance to be used for griddriver -pub fn switch(name string) { - griddriver_default = name -} + + + + diff --git a/lib/installers/threefold/tfrobot/tfrobot.v b/lib/installers/threefold/tfrobot/tfrobot.v index ca3c2095..1fcdf443 100644 --- a/lib/installers/threefold/tfrobot/tfrobot.v +++ b/lib/installers/threefold/tfrobot/tfrobot.v @@ -18,7 +18,7 @@ pub fn install_(args_ InstallArgs) ! { mut args := args_ version := '0.14.0' - res := os.execute('${osal.profile_path_source_and()} tfrobot version') + res := os.execute('${osal.profile_path_source_and()!} tfrobot version') if res.exit_code == 0 { r := res.output.split_into_lines().filter(it.trim_space().contains('v0.')) if r.len != 1 { @@ -43,7 +43,7 @@ pub fn build_() ! { g.install()! console.print_header('build tfrobot') mut dest_on_os := '${os.home_dir()}/hero/bin' - if osal.is_linux() { + if core.is_linux()! { dest_on_os = '/usr/local/bin' } diff --git a/lib/installers/virt/buildah/buildah_actions.v b/lib/installers/virt/buildah/buildah_actions.v index d9892bc7..dd0e9581 100644 --- a/lib/installers/virt/buildah/buildah_actions.v +++ b/lib/installers/virt/buildah/buildah_actions.v @@ -9,7 +9,7 @@ import os // checks if a certain version or above is installed fn installed_() !bool { - res := os.execute('${osal.profile_path_source_and()} buildah -v') + res := os.execute('${osal.profile_path_source_and()!} buildah -v') if res.exit_code != 0 { return false } diff --git a/lib/installers/virt/buildah/buildah_factory_.v b/lib/installers/virt/buildah/buildah_factory_.v index 4df1e278..a1efd243 100644 --- a/lib/installers/virt/buildah/buildah_factory_.v +++ b/lib/installers/virt/buildah/buildah_factory_.v @@ -1,79 +1,57 @@ + module buildah import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - buildah_global map[string]&BuildahInstaller - buildah_default string + buildah_global map[string]&BuildahInstaller + buildah_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&BuildahInstaller { - return &BuildahInstaller{} -} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// -fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } -} + + @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self BuildahInstaller) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self BuildahInstaller) build() ! { - switch(self.name) - build()! +pub fn destroy() ! { + destroy_()! } -pub fn (mut self BuildahInstaller) destroy() ! { - switch(self.name) - destroy()! +pub fn build() ! { + build_()! } -// switch instance to be used for buildah -pub fn switch(name string) { - buildah_default = name -} + + + + diff --git a/lib/installers/virt/cloudhypervisor/cloudhypervisor_actions.v b/lib/installers/virt/cloudhypervisor/cloudhypervisor_actions.v index f03dd8de..a09b5294 100644 --- a/lib/installers/virt/cloudhypervisor/cloudhypervisor_actions.v +++ b/lib/installers/virt/cloudhypervisor/cloudhypervisor_actions.v @@ -9,7 +9,7 @@ import freeflowuniverse.herolib.installers.ulist import os fn installed_() !bool { - res := os.execute('${osal.profile_path_source_and()} cloud-hypervisor --version') + res := os.execute('${osal.profile_path_source_and()!} cloud-hypervisor --version') if res.exit_code == 0 { r := res.output.split_into_lines().filter(it.contains('cloud-hypervisor')) if r.len != 1 { @@ -31,9 +31,9 @@ fn install_() ! { console.print_header('install cloudhypervisor') // mut installer := get()! mut url := '' - if osal.is_linux_arm() { + if core.is_linux_arm()! { url = 'https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/v${version0}/cloud-hypervisor-static-aarch64' - } else if osal.is_linux_intel() { + } else if core.is_linux_intel()! { url = 'https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/v${version0}/cloud-hypervisor-static' } else { return error('unsuported platform for cloudhypervisor') diff --git a/lib/installers/virt/cloudhypervisor/cloudhypervisor_factory_.v b/lib/installers/virt/cloudhypervisor/cloudhypervisor_factory_.v index d3931542..ada8913a 100644 --- a/lib/installers/virt/cloudhypervisor/cloudhypervisor_factory_.v +++ b/lib/installers/virt/cloudhypervisor/cloudhypervisor_factory_.v @@ -1,79 +1,57 @@ + module cloudhypervisor import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - cloudhypervisor_global map[string]&CloudHypervisor - cloudhypervisor_default string + cloudhypervisor_global map[string]&CloudHypervisor + cloudhypervisor_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&CloudHypervisor { - return &CloudHypervisor{} -} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// -fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } -} + + @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self CloudHypervisor) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self CloudHypervisor) build() ! { - switch(self.name) - build()! +pub fn destroy() ! { + destroy_()! } -pub fn (mut self CloudHypervisor) destroy() ! { - switch(self.name) - destroy()! +pub fn build() ! { + build_()! } -// switch instance to be used for cloudhypervisor -pub fn switch(name string) { - cloudhypervisor_default = name -} + + + + diff --git a/lib/installers/virt/docker/docker.v b/lib/installers/virt/docker/docker.v index fecc8b71..1f2ec28f 100644 --- a/lib/installers/virt/docker/docker.v +++ b/lib/installers/virt/docker/docker.v @@ -7,7 +7,7 @@ import freeflowuniverse.herolib.ui.console // install docker will return true if it was already installed pub fn install_() ! { console.print_header('package install install docker') - if osal.platform() != .ubuntu { + if core.platform()!= .ubuntu { return error('only support ubuntu for now') } diff --git a/lib/installers/virt/lima/lima.v b/lib/installers/virt/lima/lima.v index 66fc86a4..ecf59237 100644 --- a/lib/installers/virt/lima/lima.v +++ b/lib/installers/virt/lima/lima.v @@ -30,7 +30,7 @@ pub fn install_(args_ InstallArgs) ! { base.install()! - res := os.execute('${osal.profile_path_source_and()} lima -v') + res := os.execute('${osal.profile_path_source_and()!} lima -v') if res.exit_code == 0 { r := res.output.split_into_lines().filter(it.contains('limactl version')) if r.len != 1 { @@ -54,17 +54,17 @@ pub fn install_(args_ InstallArgs) ! { qemu.install()! mut url := '' mut dest_on_os := '${os.home_dir()}/hero' - if osal.is_linux_arm() { + if core.is_linux_arm()! { dest_on_os = '/usr/local' url = 'https://github.com/lima-vm/lima/releases/download/v${version}/lima-${version}-Linux-aarch64.tar.gz' - } else if osal.is_linux_intel() { + } else if core.is_linux_intel()! { dest_on_os = '/usr/local' url = 'https://github.com/lima-vm/lima/releases/download/v${version}/lima-${version}-Linux-x86_64.tar.gz' - } else if osal.is_osx() { + } else if core.is_osx()! { osx_install()! - // } else if osal.is_osx_arm() { + // } else if core.is_osx_arm()! { // url = 'https://github.com/lima-vm/lima/releases/download/v${version}/lima-${version}-Darwin-arm64.tar.gz' - // } else if osal.is_osx_intel() { + // } else if core.is_osx_intel()! { // url = 'https://github.com/lima-vm/lima/releases/download/v${version}/lima-${version}-Darwin-x86_64.tar.gz' } else { return error('unsported platform') diff --git a/lib/installers/virt/pacman/pacman_actions.v b/lib/installers/virt/pacman/pacman_actions.v index b6179b75..75f9fbb9 100644 --- a/lib/installers/virt/pacman/pacman_actions.v +++ b/lib/installers/virt/pacman/pacman_actions.v @@ -15,11 +15,11 @@ fn installed_() !bool { fn install_() ! { console.print_header('install pacman') - if osal.platform() == .arch { + if core.platform()! == .arch { return } - if osal.platform() != .ubuntu { + if core.platform()!= .ubuntu { return error('only ubuntu supported for this installer.') } diff --git a/lib/installers/virt/pacman/pacman_factory_.v b/lib/installers/virt/pacman/pacman_factory_.v index a9dbaaa1..d1bec936 100644 --- a/lib/installers/virt/pacman/pacman_factory_.v +++ b/lib/installers/virt/pacman/pacman_factory_.v @@ -1,74 +1,54 @@ + module pacman import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - pacman_global map[string]&PacmanInstaller - pacman_default string + pacman_global map[string]&PacmanInstaller + pacman_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&PacmanInstaller { - return &PacmanInstaller{} -} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// -fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } -} + + @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self PacmanInstaller) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self PacmanInstaller) destroy() ! { - switch(self.name) - destroy()! +pub fn destroy() ! { + destroy_()! } -// switch instance to be used for pacman -pub fn switch(name string) { - pacman_default = name -} + + + + + diff --git a/lib/installers/virt/podman/podman_actions.v b/lib/installers/virt/podman/podman_actions.v index 1d46732f..b12b0307 100644 --- a/lib/installers/virt/podman/podman_actions.v +++ b/lib/installers/virt/podman/podman_actions.v @@ -9,7 +9,7 @@ import os // checks if a certain version or above is installed fn installed_() !bool { - res := os.execute('${osal.profile_path_source_and()} podman -v') + res := os.execute('${osal.profile_path_source_and()!} podman -v') if res.exit_code != 0 { return false } @@ -30,10 +30,10 @@ fn install_() ! { destroy()! mut url := '' - if osal.platform() == .osx { + if core.platform()! == .osx { mut dest := '/tmp/podman.pkg' - if osal.cputype() == .arm { + if core.cputype()! == .arm { url = 'https://github.com/containers/podman/releases/download/v${version}/podman-installer-macos-arm64.pkg' } else { url = 'https://github.com/containers/podman/releases/download/v${version}/podman-installer-macos-amd64.pkg' @@ -52,9 +52,9 @@ fn install_() ! { ' osal.execute_interactive(cmd)! console.print_header(' - pkg installed.') - } else if osal.platform() == .ubuntu { + } else if core.platform()! == .ubuntu { // is the remote tool to connect to a remote podman - // if osal.cputype() == .arm { + // if core.cputype()! == .arm { // url = 'https://github.com/containers/podman/releases/download/v${version}/podman-remote-static-linux_arm64.tar.gz' // } else { // url = 'https://github.com/containers/podman/releases/download/v${version}/podman-remote-static-linux_amd64.tar.gz' @@ -78,7 +78,7 @@ fn build_() ! { // https://podman.io/docs/installation#building-from-source - if osal.platform() != .ubuntu && osal.platform() != .arch { + if core.platform()!= .ubuntu && core.platform()!= .arch { return error('only support ubuntu and arch for now') } mut g := golang.get()! diff --git a/lib/installers/virt/podman/podman_factory_.v b/lib/installers/virt/podman/podman_factory_.v index 76e29f06..64375306 100644 --- a/lib/installers/virt/podman/podman_factory_.v +++ b/lib/installers/virt/podman/podman_factory_.v @@ -1,79 +1,57 @@ + module podman import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - podman_global map[string]&PodmanInstaller - podman_default string + podman_global map[string]&PodmanInstaller + podman_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&PodmanInstaller { - return &PodmanInstaller{} -} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// -fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } -} + + @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self PodmanInstaller) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self PodmanInstaller) build() ! { - switch(self.name) - build()! +pub fn destroy() ! { + destroy_()! } -pub fn (mut self PodmanInstaller) destroy() ! { - switch(self.name) - destroy()! +pub fn build() ! { + build_()! } -// switch instance to be used for podman -pub fn switch(name string) { - podman_default = name -} + + + + diff --git a/lib/installers/virt/qemu/qemu_install.v b/lib/installers/virt/qemu/qemu_install.v index dd0001b6..d44020ec 100644 --- a/lib/installers/virt/qemu/qemu_install.v +++ b/lib/installers/virt/qemu/qemu_install.v @@ -44,7 +44,7 @@ pub fn install_(args_ InstallArgs) ! { console.print_header('install libvirt & qemu') base.install()! - if osal.platform() in [.arch, .ubuntu] { + if core.platform()! in [.arch, .ubuntu] { osal.package_install('qemu,libvirt,qemu-common,qemu-img,qemu-system-arm,qemu-system-x86,qemu-tools,libguestfs')! osal.exec(cmd: 'systemctl start libvirtd && systemctl enable libvirtd')! } else { diff --git a/lib/installers/virt/youki/youki_actions.v b/lib/installers/virt/youki/youki_actions.v index fa664754..8d31b664 100644 --- a/lib/installers/virt/youki/youki_actions.v +++ b/lib/installers/virt/youki/youki_actions.v @@ -14,7 +14,7 @@ import os // checks if a certain version or above is installed fn installed_() !bool { // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED - // res := os.execute('${osal.profile_path_source_and()} youki version') + // res := os.execute('${osal.profile_path_source_and()!} youki version') // if res.exit_code != 0 { // return false // } diff --git a/lib/installers/virt/youki/youki_factory_.v b/lib/installers/virt/youki/youki_factory_.v index e4ee87f9..4b7d23a0 100644 --- a/lib/installers/virt/youki/youki_factory_.v +++ b/lib/installers/virt/youki/youki_factory_.v @@ -1,79 +1,57 @@ + module youki import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - youki_global map[string]&YoukiInstaller - youki_default string + youki_global map[string]&YoukiInstaller + youki_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&YoukiInstaller { - return &YoukiInstaller{} -} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// -fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } -} + + @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self YoukiInstaller) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self YoukiInstaller) build() ! { - switch(self.name) - build()! +pub fn destroy() ! { + destroy_()! } -pub fn (mut self YoukiInstaller) destroy() ! { - switch(self.name) - destroy()! +pub fn build() ! { + build_()! } -// switch instance to be used for youki -pub fn switch(name string) { - youki_default = name -} + + + + diff --git a/lib/installers/web/caddy2/caddy_actions.v b/lib/installers/web/caddy2/caddy_actions.v index 68f76739..170dad5e 100644 --- a/lib/installers/web/caddy2/caddy_actions.v +++ b/lib/installers/web/caddy2/caddy_actions.v @@ -8,7 +8,7 @@ import os // checks if a certain version or above is installed fn installed_() !bool { // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED - // res := os.execute('${osal.profile_path_source_and()} caddy version') + // res := os.execute('${osal.profile_path_source_and()!} caddy version') // if res.exit_code != 0 { // return false // } @@ -28,13 +28,13 @@ fn install_() ! { mut cfg := get()! mut url := '' - if osal.is_linux_arm() { + if core.is_linux_arm()! { url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_linux_arm64.tar.gz' - } else if osal.is_linux_intel() { + } else if core.is_linux_intel()! { url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_linux_amd64.tar.gz' - } else if osal.is_osx_arm() { + } else if core.is_osx_arm()! { url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_mac_arm64.tar.gz' - } else if osal.is_osx_intel() { + } else if core.is_osx_intel()! { url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_mac_amd64.tar.gz' } else { return error('unsported platform') @@ -58,7 +58,7 @@ fn install_() ! { // Define the xcaddy command to build Caddy with plugins path := '/tmp/caddyserver/caddy' - cmd := 'source ${osal.profile_path()} && xcaddy build v${caddy_version} ${plugins_str} --output ${path}' + cmd := 'source ${osal.profile_path()!} && xcaddy build v${caddy_version} ${plugins_str} --output ${path}' osal.exec(cmd: cmd)! osal.cmd_add( cmdname: 'caddy' diff --git a/lib/installers/web/caddy2/caddy_factory_.v b/lib/installers/web/caddy2/caddy_factory_.v index 7136c405..1667a959 100644 --- a/lib/installers/web/caddy2/caddy_factory_.v +++ b/lib/installers/web/caddy2/caddy_factory_.v @@ -1,271 +1,255 @@ + module caddy import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.data.encoderhero + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - caddy_global map[string]&CaddyServer - caddy_default string + caddy_global map[string]&CaddyServer + caddy_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string + + + +//set the model in mem and the config on the filesystem +pub fn set(o CaddyServer)! { + mut o2:=obj_init(o)! + caddy_global[o.name] = &o2 + caddy_default = o.name } -fn args_get(args_ ArgsGet) ArgsGet { - mut model := args_ - if model.name == '' { - model.name = caddy_default - } - if model.name == '' { - model.name = 'default' - } - return model +//check we find the config on the filesystem +pub fn exists(args_ ArgsGet) bool { + mut model := args_get(args_) + mut context:=base.context() or { panic("bug") } + return context.hero_config_exists("caddy",model.name) } -pub fn get(args_ ArgsGet) !&CaddyServer { - mut model := args_get(args_) - if model.name !in caddy_global { - if model.name == 'default' { - if !config_exists(model) { - if default { - config_save(model)! - } - } - config_load(model)! - } - } - return caddy_global[model.name] or { - println(caddy_global) - panic('could not get config for caddy with name:${model.name}') - } +//load the config error if it doesn't exist +pub fn load(args_ ArgsGet) ! { + mut model := args_get(args_) + mut context:=base.context()! + mut heroscript := context.hero_config_get("caddy",model.name)! + play(heroscript:heroscript)! } -fn config_exists(args_ ArgsGet) bool { - mut model := args_get(args_) - mut context := base.context() or { panic('bug') } - return context.hero_config_exists('caddy', model.name) -} - -fn config_load(args_ ArgsGet) ! { - mut model := args_get(args_) - mut context := base.context()! - mut heroscript := context.hero_config_get('caddy', model.name)! - play(heroscript: heroscript)! -} - -fn config_save(args_ ArgsGet) ! { - mut model := args_get(args_) - mut context := base.context()! - context.hero_config_set('caddy', model.name, heroscript_default()!)! -} - -fn set(o CaddyServer) ! { - mut o2 := obj_init(o)! - caddy_global[o.name] = &o2 - caddy_default = o.name +//save the config to the filesystem in the context +pub fn save(o CaddyServer)! { + mut context:=base.context()! + heroscript := encoderhero.encode[CaddyServer](o)! + context.hero_config_set("caddy",model.name,heroscript)! } @[params] pub struct PlayArgs { pub mut: - heroscript string // if filled in then plbook will be made out of it - plbook ?playbook.PlayBook - reset bool + heroscript string //if filled in then plbook will be made out of it + plbook ?playbook.PlayBook + reset bool } pub fn play(args_ PlayArgs) ! { - mut model := args_ + + mut model:=args_ - if model.heroscript == '' { - model.heroscript = heroscript_default()! - } - mut plbook := model.plbook or { playbook.new(text: model.heroscript)! } + if model.heroscript == "" { + model.heroscript = heroscript_default()! + } + mut plbook := model.plbook or { + playbook.new(text: model.heroscript)! + } + + mut configure_actions := plbook.find(filter: 'caddy.configure')! + if configure_actions.len > 0 { + for config_action in configure_actions { + mut p := config_action.params + mycfg:=cfg_play(p)! + console.print_debug("install action caddy.configure\n${mycfg}") + set(mycfg)! + save(mycfg)! + } + } - mut install_actions := plbook.find(filter: 'caddy.configure')! - if install_actions.len > 0 { - for install_action in install_actions { - mut p := install_action.params - mycfg := cfg_play(p)! - console.print_debug('install action caddy.configure\n${mycfg}') - set(mycfg)! - } - } + mut other_actions := plbook.find(filter: 'caddy.')! + for other_action in other_actions { + if other_action.name in ["destroy","install","build"]{ + mut p := other_action.params + reset:=p.get_default_false("reset") + if other_action.name == "destroy" || reset{ + console.print_debug("install action caddy.destroy") + destroy_()! + } + if other_action.name == "install"{ + console.print_debug("install action caddy.install") + install_()! + } + } + if other_action.name in ["start","stop","restart"]{ + mut p := other_action.params + name := p.get('name')! + mut caddy_obj:=get(name:name)! + console.print_debug("action object:\n${caddy_obj}") + if other_action.name == "start"{ + console.print_debug("install action caddy.${other_action.name}") + caddy_obj.start()! + } - mut other_actions := plbook.find(filter: 'caddy.')! - for other_action in other_actions { - if other_action.name in ['destroy', 'install', 'build'] { - mut p := other_action.params - reset := p.get_default_false('reset') - if other_action.name == 'destroy' || reset { - console.print_debug('install action caddy.destroy') - destroy()! - } - if other_action.name == 'install' { - console.print_debug('install action caddy.install') - install()! - } - } - if other_action.name in ['start', 'stop', 'restart'] { - mut p := other_action.params - name := p.get('name')! - mut caddy_obj := get(name: name)! - console.print_debug('action object:\n${caddy_obj}') - if other_action.name == 'start' { - console.print_debug('install action caddy.${other_action.name}') - caddy_obj.start()! - } + if other_action.name == "stop"{ + console.print_debug("install action caddy.${other_action.name}") + caddy_obj.stop()! + } + if other_action.name == "restart"{ + console.print_debug("install action caddy.${other_action.name}") + caddy_obj.restart()! + } + } + } - if other_action.name == 'stop' { - console.print_debug('install action caddy.${other_action.name}') - caddy_obj.stop()! - } - if other_action.name == 'restart' { - console.print_debug('install action caddy.${other_action.name}') - caddy_obj.restart()! - } - } - } } + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// -fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } + +//load from disk and make sure is properly intialized +pub fn (mut self CaddyServer) reload() ! { + switch(self.name) + self=obj_init(self)! } -// load from disk and make sure is properly intialized -pub fn (mut self CaddyServer) reload() ! { - switch(self.name) - self = obj_init(self)! + +fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { + // unknown + // screen + // zinit + // tmux + // systemd + match cat{ + .zinit{ + console.print_debug("startupmanager: zinit") + return startupmanager.get(cat:.zinit)! + } + .systemd{ + console.print_debug("startupmanager: systemd") + return startupmanager.get(cat:.systemd)! + }else{ + console.print_debug("startupmanager: auto") + return startupmanager.get()! + } + } } pub fn (mut self CaddyServer) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('caddy start') + console.print_header('caddy start') - if !installed()! { - install()! - } + if ! installed_()!{ + install_()! + } - configure()! + configure()! - start_pre()! + start_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! - console.print_debug('starting caddy with ${zprocess.startuptype}...') + console.print_debug('starting caddy with ${zprocess.startuptype}...') - sm.new(zprocess)! + sm.new(zprocess)! - sm.start(zprocess.name)! - } + sm.start(zprocess.name)! + } - start_post()! + start_post()! + + for _ in 0 .. 50 { + if self.running()! { + return + } + time.sleep(100 * time.millisecond) + } + return error('caddy did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('caddy did not install properly.') } pub fn (mut self CaddyServer) install_start(model InstallArgs) ! { - switch(self.name) - self.install(model)! - self.start()! + switch(self.name) + self.install(model)! + self.start()! } pub fn (mut self CaddyServer) stop() ! { - switch(self.name) - stop_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - sm.stop(zprocess.name)! - } - stop_post()! + switch(self.name) + stop_pre()! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + sm.stop(zprocess.name)! + } + stop_post()! } pub fn (mut self CaddyServer) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self CaddyServer) running() !bool { - switch(self.name) + switch(self.name) - // walk over the generic processes, if not running return - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - r := sm.running(zprocess.name)! - if r == false { - return false - } - } - return running()! + //walk over the generic processes, if not running return + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + r:=sm.running(zprocess.name)! + if r==false{ + return false + } + } + return running()! } @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self CaddyServer) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self CaddyServer) build() ! { - switch(self.name) - build()! +pub fn destroy() ! { + destroy_()! } -pub fn (mut self CaddyServer) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! +pub fn build() ! { + build_()! } -// switch instance to be used for caddy -pub fn switch(name string) { - caddy_default = name -} + + + + diff --git a/lib/installers/web/caddy2/installer.v b/lib/installers/web/caddy2/installer.v index 0b7e1644..c32ac234 100644 --- a/lib/installers/web/caddy2/installer.v +++ b/lib/installers/web/caddy2/installer.v @@ -55,7 +55,7 @@ pub const version = '2.8.4' // } pub fn is_installed(version string) !bool { - res := os.execute('${osal.profile_path_source_and()} caddy version') + res := os.execute('${osal.profile_path_source_and()!} caddy version') if res.exit_code == 0 { mut r := res.output.split_into_lines().filter(it.trim_space().len > 0) if r.len > 1 { @@ -75,13 +75,13 @@ pub fn is_installed(version string) !bool { pub fn install_caddy_from_release() ! { version := '2.8.4' mut url := '' - if osal.is_linux_arm() { + if core.is_linux_arm()! { url = 'https://github.com/caddyserver/caddy/releases/download/v${version}/caddy_${version}_linux_arm64.tar.gz' - } else if osal.is_linux_intel() { + } else if core.is_linux_intel()! { url = 'https://github.com/caddyserver/caddy/releases/download/v${version}/caddy_${version}_linux_amd64.tar.gz' - } else if osal.is_osx_arm() { + } else if core.is_osx_arm()! { url = 'https://github.com/caddyserver/caddy/releases/download/v${version}/caddy_${version}_darwin_arm64.tar.gz' - } else if osal.is_osx_intel() { + } else if core.is_osx_intel()! { url = 'https://github.com/caddyserver/caddy/releases/download/v${version}/caddy_${version}_darwin_amd64.tar.gz' } else { return error('unsported platform') @@ -136,13 +136,13 @@ pub fn install_caddy_with_xcaddy(plugins []string) ! { console.print_header('Installing xcaddy') mut url := '' - if osal.is_linux_arm() { + if core.is_linux_arm()! { url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_linux_arm64.tar.gz' - } else if osal.is_linux_intel() { + } else if core.is_linux_intel()! { url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_linux_amd64.tar.gz' - } else if osal.is_osx_arm() { + } else if core.is_osx_arm()! { url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_mac_arm64.tar.gz' - } else if osal.is_osx_intel() { + } else if core.is_osx_intel()! { url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_mac_amd64.tar.gz' } else { return error('unsported platform') @@ -166,7 +166,7 @@ pub fn install_caddy_with_xcaddy(plugins []string) ! { // Define the xcaddy command to build Caddy with plugins path := '/tmp/caddyserver/caddy' - cmd := 'source ${osal.profile_path()} && xcaddy build v${caddy_version} ${plugins_str} --output ${path}' + cmd := 'source ${osal.profile_path()!} && xcaddy build v${caddy_version} ${plugins_str} --output ${path}' osal.exec(cmd: cmd)! osal.cmd_add( cmdname: 'caddy' diff --git a/lib/installers/web/caddy2/installers.v b/lib/installers/web/caddy2/installers.v index 42c25ff0..3c42e54c 100644 --- a/lib/installers/web/caddy2/installers.v +++ b/lib/installers/web/caddy2/installers.v @@ -5,13 +5,13 @@ import freeflowuniverse.herolib.ui.console pub fn install_caddy_from_release() ! { mut url := '' - if osal.is_linux_arm() { + if core.is_linux_arm()! { url = 'https://github.com/caddyserver/caddy/releases/download/v${version}/caddy_${version}_linux_arm64.tar.gz' - } else if osal.is_linux_intel() { + } else if core.is_linux_intel()! { url = 'https://github.com/caddyserver/caddy/releases/download/v${version}/caddy_${version}_linux_amd64.tar.gz' - } else if osal.is_osx_arm() { + } else if core.is_osx_arm()! { url = 'https://github.com/caddyserver/caddy/releases/download/v${version}/caddy_${version}_darwin_arm64.tar.gz' - } else if osal.is_osx_intel() { + } else if core.is_osx_intel()! { url = 'https://github.com/caddyserver/caddy/releases/download/v${version}/caddy_${version}_darwin_amd64.tar.gz' } else { return error('unsported platform') @@ -33,13 +33,13 @@ pub fn install_caddy_from_release() ! { pub fn install_caddy_with_xcaddy(plugins []string) ! { console.print_header('Installing xcaddy') mut url := '' - if osal.is_linux_arm() { + if core.is_linux_arm()! { url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_linux_arm64.tar.gz' - } else if osal.is_linux_intel() { + } else if core.is_linux_intel()! { url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_linux_amd64.tar.gz' - } else if osal.is_osx_arm() { + } else if core.is_osx_arm()! { url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_mac_arm64.tar.gz' - } else if osal.is_osx_intel() { + } else if core.is_osx_intel()! { url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_mac_amd64.tar.gz' } else { return error('unsported platform') @@ -63,7 +63,7 @@ pub fn install_caddy_with_xcaddy(plugins []string) ! { // Define the xcaddy command to build Caddy with plugins path := '/tmp/caddyserver/caddy' - cmd := 'source ${osal.profile_path()} && xcaddy build v${caddy_version} ${plugins_str} --output ${path}' + cmd := 'source ${osal.profile_path()!} && xcaddy build v${caddy_version} ${plugins_str} --output ${path}' osal.exec(cmd: cmd)! osal.cmd_add( cmdname: 'caddy' diff --git a/lib/installers/web/imagemagick/imagemagick_actions.v b/lib/installers/web/imagemagick/imagemagick_actions.v index dfbc0784..e1666bac 100644 --- a/lib/installers/web/imagemagick/imagemagick_actions.v +++ b/lib/installers/web/imagemagick/imagemagick_actions.v @@ -66,7 +66,7 @@ fn stop_post() ! { // checks if a certain version or above is installed fn installed_() !bool { // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED - // res := os.execute('${osal.profile_path_source_and()} imagemagick version') + // res := os.execute('${osal.profile_path_source_and()!} imagemagick version') // if res.exit_code != 0 { // return false // } @@ -98,13 +98,13 @@ fn install_() ! { console.print_header('install imagemagick') // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // mut url := '' - // if osal.is_linux_arm() { + // if core.is_linux_arm()! { // url = 'https://github.com/imagemagick-dev/imagemagick/releases/download/v${version}/imagemagick_${version}_linux_arm64.tar.gz' - // } else if osal.is_linux_intel() { + // } else if core.is_linux_intel()! { // url = 'https://github.com/imagemagick-dev/imagemagick/releases/download/v${version}/imagemagick_${version}_linux_amd64.tar.gz' - // } else if osal.is_osx_arm() { + // } else if core.is_osx_arm()! { // url = 'https://github.com/imagemagick-dev/imagemagick/releases/download/v${version}/imagemagick_${version}_darwin_arm64.tar.gz' - // } else if osal.is_osx_intel() { + // } else if core.is_osx_intel()! { // url = 'https://github.com/imagemagick-dev/imagemagick/releases/download/v${version}/imagemagick_${version}_darwin_amd64.tar.gz' // } else { // return error('unsported platform') @@ -129,7 +129,7 @@ fn build_() ! { // url := 'https://github.com/threefoldtech/imagemagick' // make sure we install base on the node - // if osal.platform() != .ubuntu { + // if core.platform()!= .ubuntu { // return error('only support ubuntu for now') // } // golang.install()! diff --git a/lib/installers/web/imagemagick/imagemagick_factory_.v b/lib/installers/web/imagemagick/imagemagick_factory_.v index a9d231fc..b5710430 100644 --- a/lib/installers/web/imagemagick/imagemagick_factory_.v +++ b/lib/installers/web/imagemagick/imagemagick_factory_.v @@ -1,153 +1,152 @@ + module imagemagick import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - imagemagick_global map[string]&ImageMagick - imagemagick_default string + imagemagick_global map[string]&ImageMagick + imagemagick_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&ImageMagick { - return &ImageMagick{} -} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// + + + fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } + // unknown + // screen + // zinit + // tmux + // systemd + match cat{ + .zinit{ + console.print_debug("startupmanager: zinit") + return startupmanager.get(cat:.zinit)! + } + .systemd{ + console.print_debug("startupmanager: systemd") + return startupmanager.get(cat:.systemd)! + }else{ + console.print_debug("startupmanager: auto") + return startupmanager.get()! + } + } } pub fn (mut self ImageMagick) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('imagemagick start') + console.print_header('imagemagick start') - if !installed()! { - install()! - } + if ! installed_()!{ + install_()! + } - configure()! + configure()! - start_pre()! + start_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! - console.print_debug('starting imagemagick with ${zprocess.startuptype}...') + console.print_debug('starting imagemagick with ${zprocess.startuptype}...') - sm.new(zprocess)! + sm.new(zprocess)! - sm.start(zprocess.name)! - } + sm.start(zprocess.name)! + } - start_post()! + start_post()! + + for _ in 0 .. 50 { + if self.running()! { + return + } + time.sleep(100 * time.millisecond) + } + return error('imagemagick did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('imagemagick did not install properly.') } pub fn (mut self ImageMagick) install_start(model InstallArgs) ! { - switch(self.name) - self.install(model)! - self.start()! + switch(self.name) + self.install(model)! + self.start()! } pub fn (mut self ImageMagick) stop() ! { - switch(self.name) - stop_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - sm.stop(zprocess.name)! - } - stop_post()! + switch(self.name) + stop_pre()! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + sm.stop(zprocess.name)! + } + stop_post()! } pub fn (mut self ImageMagick) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self ImageMagick) running() !bool { - switch(self.name) + switch(self.name) - // walk over the generic processes, if not running return - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - r := sm.running(zprocess.name)! - if r == false { - return false - } - } - return running()! + //walk over the generic processes, if not running return + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + r:=sm.running(zprocess.name)! + if r==false{ + return false + } + } + return running()! } @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self ImageMagick) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self ImageMagick) build() ! { - switch(self.name) - build()! +pub fn destroy() ! { + destroy_()! } -pub fn (mut self ImageMagick) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! +pub fn build() ! { + build_()! } -// switch instance to be used for imagemagick -pub fn switch(name string) { - imagemagick_default = name -} + + + + diff --git a/lib/installers/web/lighttpd/installer.v b/lib/installers/web/lighttpd/installer.v index 33b632a8..b92c84ea 100644 --- a/lib/installers/web/lighttpd/installer.v +++ b/lib/installers/web/lighttpd/installer.v @@ -19,7 +19,7 @@ pub fn installll(args InstallArgs) ! { return } - if !osal.is_linux() { + if !core.is_linux()! { return error('only support linux for now') } diff --git a/lib/installers/web/lighttpd/lighttpd_actions.v b/lib/installers/web/lighttpd/lighttpd_actions.v index b94e7c24..e392e733 100644 --- a/lib/installers/web/lighttpd/lighttpd_actions.v +++ b/lib/installers/web/lighttpd/lighttpd_actions.v @@ -66,7 +66,7 @@ fn stop_post() ! { // checks if a certain version or above is installed fn installed_() !bool { // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED - // res := os.execute('${osal.profile_path_source_and()} lighttpd version') + // res := os.execute('${osal.profile_path_source_and()!} lighttpd version') // if res.exit_code != 0 { // return false // } @@ -98,13 +98,13 @@ fn install_() ! { console.print_header('install lighttpd') // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // mut url := '' - // if osal.is_linux_arm() { + // if core.is_linux_arm()! { // url = 'https://github.com/lighttpd-dev/lighttpd/releases/download/v${version}/lighttpd_${version}_linux_arm64.tar.gz' - // } else if osal.is_linux_intel() { + // } else if core.is_linux_intel()! { // url = 'https://github.com/lighttpd-dev/lighttpd/releases/download/v${version}/lighttpd_${version}_linux_amd64.tar.gz' - // } else if osal.is_osx_arm() { + // } else if core.is_osx_arm()! { // url = 'https://github.com/lighttpd-dev/lighttpd/releases/download/v${version}/lighttpd_${version}_darwin_arm64.tar.gz' - // } else if osal.is_osx_intel() { + // } else if core.is_osx_intel()! { // url = 'https://github.com/lighttpd-dev/lighttpd/releases/download/v${version}/lighttpd_${version}_darwin_amd64.tar.gz' // } else { // return error('unsported platform') @@ -129,7 +129,7 @@ fn build_() ! { // url := 'https://github.com/threefoldtech/lighttpd' // make sure we install base on the node - // if osal.platform() != .ubuntu { + // if core.platform()!= .ubuntu { // return error('only support ubuntu for now') // } // golang.install()! diff --git a/lib/installers/web/lighttpd/lighttpd_factory_.v b/lib/installers/web/lighttpd/lighttpd_factory_.v index 36435ea4..7afb6431 100644 --- a/lib/installers/web/lighttpd/lighttpd_factory_.v +++ b/lib/installers/web/lighttpd/lighttpd_factory_.v @@ -1,153 +1,152 @@ + module lighttpd import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - lighttpd_global map[string]&LightHttpdInstaller - lighttpd_default string + lighttpd_global map[string]&LightHttpdInstaller + lighttpd_default string ) /////////FACTORY -@[params] -pub struct ArgsGet { -pub mut: - name string -} -pub fn get(args_ ArgsGet) !&LightHttpdInstaller { - return &LightHttpdInstaller{} -} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// + + + fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } + // unknown + // screen + // zinit + // tmux + // systemd + match cat{ + .zinit{ + console.print_debug("startupmanager: zinit") + return startupmanager.get(cat:.zinit)! + } + .systemd{ + console.print_debug("startupmanager: systemd") + return startupmanager.get(cat:.systemd)! + }else{ + console.print_debug("startupmanager: auto") + return startupmanager.get()! + } + } } pub fn (mut self LightHttpdInstaller) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('lighttpd start') + console.print_header('lighttpd start') - if !installed()! { - install()! - } + if ! installed_()!{ + install_()! + } - configure()! + configure()! - start_pre()! + start_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! - console.print_debug('starting lighttpd with ${zprocess.startuptype}...') + console.print_debug('starting lighttpd with ${zprocess.startuptype}...') - sm.new(zprocess)! + sm.new(zprocess)! - sm.start(zprocess.name)! - } + sm.start(zprocess.name)! + } - start_post()! + start_post()! + + for _ in 0 .. 50 { + if self.running()! { + return + } + time.sleep(100 * time.millisecond) + } + return error('lighttpd did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('lighttpd did not install properly.') } pub fn (mut self LightHttpdInstaller) install_start(model InstallArgs) ! { - switch(self.name) - self.install(model)! - self.start()! + switch(self.name) + self.install(model)! + self.start()! } pub fn (mut self LightHttpdInstaller) stop() ! { - switch(self.name) - stop_pre()! - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - sm.stop(zprocess.name)! - } - stop_post()! + switch(self.name) + stop_pre()! + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + sm.stop(zprocess.name)! + } + stop_post()! } pub fn (mut self LightHttpdInstaller) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self LightHttpdInstaller) running() !bool { - switch(self.name) + switch(self.name) - // walk over the generic processes, if not running return - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! - r := sm.running(zprocess.name)! - if r == false { - return false - } - } - return running()! + //walk over the generic processes, if not running return + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! + r:=sm.running(zprocess.name)! + if r==false{ + return false + } + } + return running()! } @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self LightHttpdInstaller) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +pub fn install(args InstallArgs) ! { + if args.reset { + destroy()! + } + if ! (installed_()!){ + install_()! + } } -pub fn (mut self LightHttpdInstaller) build() ! { - switch(self.name) - build()! +pub fn destroy() ! { + destroy_()! } -pub fn (mut self LightHttpdInstaller) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! +pub fn build() ! { + build_()! } -// switch instance to be used for lighttpd -pub fn switch(name string) { - lighttpd_default = name -} + + + + diff --git a/lib/installers/web/tailwind/tailwind_actions.v b/lib/installers/web/tailwind/tailwind_actions.v index e739969c..240f45d1 100644 --- a/lib/installers/web/tailwind/tailwind_actions.v +++ b/lib/installers/web/tailwind/tailwind_actions.v @@ -30,13 +30,13 @@ pub fn install_() ! { console.print_header('install tailwind') mut url := '' - if osal.is_linux_arm() { + if core.is_linux_arm()! { url = 'https://github.com/tailwindlabs/tailwindcss/releases/download/v${version}/tailwindcss-linux-arm64' - } else if osal.is_linux_intel() { + } else if core.is_linux_intel()! { url = 'https://github.com/tailwindlabs/tailwindcss/releases/download/v${version}/tailwindcss-linux-x64' - } else if osal.is_osx_arm() { + } else if core.is_osx_arm()! { url = 'https://github.com/tailwindlabs/tailwindcss/releases/download/v${version}/tailwindcss-macos-arm64' - } else if osal.is_osx_intel() { + } else if core.is_osx_intel()! { url = 'https://github.com/tailwindlabs/tailwindcss/releases/download/v${version}/tailwindcss-macos-x64' } else { return error('unsported platform') diff --git a/lib/installers/web/tailwind/tailwind_factory_.v b/lib/installers/web/tailwind/tailwind_factory_.v index 82892fa2..d8ae5442 100644 --- a/lib/installers/web/tailwind/tailwind_factory_.v +++ b/lib/installers/web/tailwind/tailwind_factory_.v @@ -1,74 +1,98 @@ + module tailwind import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - tailwind_global map[string]&Tailwind - tailwind_default string + tailwind_global map[string]&Tailwind + tailwind_default string ) /////////FACTORY + + @[params] -pub struct ArgsGet { +pub struct ArgsGet{ pub mut: - name string + name string } -pub fn get(args_ ArgsGet) !&Tailwind { - return &Tailwind{} +fn args_get (args_ ArgsGet) ArgsGet { + mut model:=args_ + if model.name == ""{ + model.name = tailwind_default + } + if model.name == ""{ + model.name = "default" + } + return model } +pub fn get(args_ ArgsGet) !&Tailwind { + mut args := args_get(args_) + if !(args.name in tailwind_global) { + if args.name=="default"{ + if ! config_exists(args){ + if default{ + mut context:=base.context() or { panic("bug") } + context.hero_config_set("tailwind",model.name,heroscript_default()!)! + } + } + load(args)! + } + } + return tailwind_global[args.name] or { + println(tailwind_global) + panic("could not get config for ${args.name} with name:${model.name}") + } +} + + + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// -fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } -} + + @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self Tailwind) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +//switch instance to be used for tailwind +pub fn switch(name string) { + tailwind_default = name } + +pub fn (mut self Tailwind) install(args InstallArgs) ! { + switch(self.name) + if args.reset { + destroy_()! + } + if ! (installed_()!){ + install_()! + } +} + + pub fn (mut self Tailwind) destroy() ! { - switch(self.name) - destroy()! + switch(self.name) + destroy_()! } -// switch instance to be used for tailwind -pub fn switch(name string) { - tailwind_default = name -} + + + diff --git a/lib/installers/web/zola/zola_actions.v b/lib/installers/web/zola/zola_actions.v index d521983a..c9dd2175 100644 --- a/lib/installers/web/zola/zola_actions.v +++ b/lib/installers/web/zola/zola_actions.v @@ -12,7 +12,7 @@ pub const version = '0.18.0' // checks if a certain version or above is installed fn installed_() !bool { - res := os.execute('${osal.profile_path_source_and()} zola -V') + res := os.execute('${osal.profile_path_source_and()!} zola -V') myversion := res.output.all_after(' ') if res.exit_code == 0 { v := texttools.version(myversion) @@ -34,11 +34,11 @@ fn install_() ! { tw.install()! mut url := '' - if osal.is_linux() { + if core.is_linux()! { url = 'https://github.com/getzola/zola/releases/download/v${version}/zola-v${version}-x86_64-unknown-linux-gnu.tar.gz' - } else if osal.is_osx_arm() { + } else if core.is_osx_arm()! { url = 'https://github.com/getzola/zola/releases/download/v${version}/zola-v${version}-aarch64-apple-darwin.tar.gz' - } else if osal.is_osx_intel() { + } else if core.is_osx_intel()! { url = 'https://github.com/getzola/zola/releases/download/v${version}/zola-v${version}-x86_64-apple-darwin.tar.gz' } else { return error('unsupported platform') diff --git a/lib/installers/web/zola/zola_factory_.v b/lib/installers/web/zola/zola_factory_.v index d0171fd7..c5b7c407 100644 --- a/lib/installers/web/zola/zola_factory_.v +++ b/lib/installers/web/zola/zola_factory_.v @@ -1,79 +1,102 @@ + module zola import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - zola_global map[string]&ZolaInstaller - zola_default string + zola_global map[string]&ZolaInstaller + zola_default string ) /////////FACTORY + + @[params] -pub struct ArgsGet { +pub struct ArgsGet{ pub mut: - name string + name string } -pub fn get(args_ ArgsGet) !&ZolaInstaller { - return &ZolaInstaller{} +fn args_get (args_ ArgsGet) ArgsGet { + mut model:=args_ + if model.name == ""{ + model.name = zola_default + } + if model.name == ""{ + model.name = "default" + } + return model } +pub fn get(args_ ArgsGet) !&ZolaInstaller { + mut args := args_get(args_) + if !(args.name in zola_global) { + if args.name=="default"{ + if ! config_exists(args){ + if default{ + mut context:=base.context() or { panic("bug") } + context.hero_config_set("zola",model.name,heroscript_default()!)! + } + } + load(args)! + } + } + return zola_global[args.name] or { + println(zola_global) + panic("could not get config for ${args.name} with name:${model.name}") + } +} + + + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// -fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { - // unknown - // screen - // zinit - // tmux - // systemd - match cat { - .zinit { - console.print_debug('startupmanager: zinit') - return startupmanager.get(cat: .zinit)! - } - .systemd { - console.print_debug('startupmanager: systemd') - return startupmanager.get(cat: .systemd)! - } - else { - console.print_debug('startupmanager: auto') - return startupmanager.get()! - } - } -} + + @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn (mut self ZolaInstaller) install(model InstallArgs) ! { - switch(self.name) - if model.reset || (!installed()!) { - install()! - } + +//switch instance to be used for zola +pub fn switch(name string) { + zola_default = name +} + + +pub fn (mut self ZolaInstaller) install(args InstallArgs) ! { + switch(self.name) + if args.reset { + destroy_()! + } + if ! (installed_()!){ + install_()! + } } pub fn (mut self ZolaInstaller) build() ! { - switch(self.name) - build()! + switch(self.name) + build_()! } pub fn (mut self ZolaInstaller) destroy() ! { - switch(self.name) - destroy()! + switch(self.name) + destroy_()! } -// switch instance to be used for zola -pub fn switch(name string) { - zola_default = name -} + + + diff --git a/lib/osal/cmds.v b/lib/osal/cmds.v index 3e63dca8..541c7bc6 100644 --- a/lib/osal/cmds.v +++ b/lib/osal/cmds.v @@ -2,6 +2,7 @@ module osal import os import freeflowuniverse.herolib.core.pathlib +import freeflowuniverse.herolib.core import freeflowuniverse.herolib.ui.console // import regex import freeflowuniverse.herolib.core.texttools @@ -73,7 +74,7 @@ pub fn profile_path_add_hero() !string { pub fn bin_path() !string { mut dest := '' - if is_osx() { + if core.is_osx()! { dest = '${os.home_dir()}/hero/bin' dir_ensure(dest)! } else { @@ -92,7 +93,7 @@ pub fn hero_path() !string { ///usr/local on linux, ${os.home_dir()}/hero on osx pub fn usr_local_path() !string { mut dest := '' - if is_osx() { + if core.is_osx()! { dest = '${os.home_dir()}/hero' dir_ensure(dest)! } else { @@ -102,11 +103,11 @@ pub fn usr_local_path() !string { } // return the source statement if the profile exists -pub fn profile_path_source() string { +pub fn profile_path_source()! string { if hostname() or { '' } == 'rescue' { return '' } - pp := profile_path() + pp := profile_path()! if os.exists(pp) { return 'source ${pp}' } @@ -115,11 +116,11 @@ pub fn profile_path_source() string { // return source $path && . // or empty if it doesn't exist -pub fn profile_path_source_and() string { +pub fn profile_path_source_and()! string { if hostname() or { '' } == 'rescue' { return '' } - pp := profile_path() + pp := profile_path()! if os.exists(pp) { return '. ${pp} &&' } @@ -276,7 +277,7 @@ pub fn profile_paths_all() ![]string { pub fn profile_paths_preferred() ![]string { mut toadd := []string{} - if is_osx() { + if core.is_osx()! { toadd << '${os.home_dir()}/.zprofile' toadd << '${os.home_dir()}/.zshrc' } else { @@ -295,8 +296,8 @@ pub fn profile_paths_preferred() ![]string { return profile_files2 } -pub fn profile_path() string { - if is_osx() { +pub fn profile_path()! string { + if core.is_osx()! { return '${os.home_dir()}/.zprofile' } else { return '${os.home_dir()}/.bash_profile' diff --git a/lib/osal/exec.v b/lib/osal/exec.v index 21d1a7f5..3c9efa21 100644 --- a/lib/osal/exec.v +++ b/lib/osal/exec.v @@ -449,7 +449,7 @@ pub fn cmd_exists(cmd string) bool { } pub fn cmd_exists_profile(cmd string) bool { - cmd1 := '${profile_path_source_and()} which ${cmd}' + cmd1 := '${profile_path_source_and() or {panic(err)}} which ${cmd}' res := os.execute(cmd1) if res.exit_code > 0 { return false diff --git a/lib/osal/file.v b/lib/osal/file.v index aa657a93..40e0f693 100644 --- a/lib/osal/file.v +++ b/lib/osal/file.v @@ -1,6 +1,7 @@ module osal import freeflowuniverse.herolib.core.texttools +import freeflowuniverse.herolib.core import freeflowuniverse.herolib.ui.console import os @@ -38,17 +39,25 @@ pub fn dir_reset(path string) ! { // can be \n or , separated pub fn rm(todelete_ string) ! { for mut item in texttools.to_array(todelete_) { - if item.trim_space() == '' { + if item.trim_space() == ''|| item.trim_space().starts_with("#"){ continue } + item = item.replace('~', os.home_dir()) console.print_debug(' - rm: ${item}') if item.starts_with('/') { if os.exists(item) { if os.is_dir(item) { - os.rmdir_all(item)! + //console.print_debug("rm deletedir: ${item}") + os.rmdir_all(core.sudo_path_check(item)!)! } else { - os.rm(item)! + //console.print_debug("rm delete file: ${item}") + if core.sudo_path_ok(item)!{ + os.rm(item)! + }else{ + + } + } } } else { diff --git a/lib/osal/net.v b/lib/osal/net.v index c21a4bda..14b1ebf6 100644 --- a/lib/osal/net.v +++ b/lib/osal/net.v @@ -3,6 +3,7 @@ module osal import net import time import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.core pub enum PingResult { ok @@ -23,7 +24,7 @@ pub mut: // address is e.g. 8.8.8.8 // ping means we check if the destination responds pub fn ping(args PingArgs) !PingResult { - platform_ := platform() + platform_ := core.platform()! mut cmd := 'ping' if args.address.contains(':') { cmd = 'ping6' diff --git a/lib/osal/package.v b/lib/osal/package.v index 7c40656b..55023d9e 100644 --- a/lib/osal/package.v +++ b/lib/osal/package.v @@ -2,11 +2,12 @@ module osal import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.core.texttools +import freeflowuniverse.herolib.core import os // update the package list pub fn package_refresh() ! { - platform_ := platform() + platform_ := core.platform()! if cmd_exists('nix-env') { // nix package manager is installed @@ -49,8 +50,8 @@ pub fn package_install(name_ string) ! { name := names.join(' ') console.print_header('package install: ${name}') - platform_ := platform() - cpu := cputype() + platform_ := core.platform()! + cpu := core.cputype()! if platform_ == .osx { if cpu == .arm { @@ -64,7 +65,7 @@ pub fn package_install(name_ string) ! { } } else if platform_ == .ubuntu { // Use sudo if required (based on user's permissions) - use_sudo := is_sudo_required() + use_sudo := core.sudo_required()! cmd := if use_sudo { 'sudo apt install -y ${name} -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --allow-downgrades --allow-remove-essential --allow-change-held-packages' @@ -76,7 +77,7 @@ pub fn package_install(name_ string) ! { } } else if platform_ == .alpine { // Use sudo if required - use_sudo := is_sudo_required() + use_sudo := core.sudo_required()! cmd := if use_sudo { 'sudo apk add ${name}' } else { @@ -87,7 +88,7 @@ pub fn package_install(name_ string) ! { } } else if platform_ == .arch { // Use sudo if required - use_sudo := is_sudo_required() + use_sudo := core.sudo_required()! cmd := if use_sudo { 'sudo pacman --noconfirm -Su ${name}' } else { @@ -101,23 +102,6 @@ pub fn package_install(name_ string) ! { } } -// Method to check if sudo is required (i.e., if the user is root or has sudo privileges) -fn is_sudo_required() bool { - // Check if the user is root - if os.getenv('USER') == 'root' { - return false - } - - platform_ := platform() - - if platform_ == .osx { - return false - } - - // Check if the user has sudo privileges (test with `sudo -v`) - sudo_check := os.execute('sudo -v') - return sudo_check.exit_code == 0 -} // remove a package using the right commands per platform pub fn package_remove(name_ string) ! { @@ -125,8 +109,8 @@ pub fn package_remove(name_ string) ! { name := names.join(' ') console.print_header('package remove: ${name}') - platform_ := platform() - cpu := cputype() + platform_ := core.platform()! + cpu := core.cputype()! // Debugging: print out platform and cpu type println('Platform: ${platform_}, CPU: ${cpu}') @@ -137,7 +121,7 @@ pub fn package_remove(name_ string) ! { } // Determine if sudo is required by checking if the user has sudo privileges - use_sudo := is_sudo_required() + use_sudo := core.sudo_required()! // Platform-specific package removal logic if platform_ == .osx { diff --git a/lib/osal/package_test.v b/lib/osal/package_test.v index bc03a606..966870ad 100644 --- a/lib/osal/package_test.v +++ b/lib/osal/package_test.v @@ -1,7 +1,8 @@ module osal +import freeflowuniverse.herolib.core fn test_package_management() { - platform_ := platform() + platform_ := core.platform()! if platform_ == .osx { // Check if brew is installed diff --git a/lib/osal/platform_test.v b/lib/osal/platform_test.v deleted file mode 100644 index 414735fc..00000000 --- a/lib/osal/platform_test.v +++ /dev/null @@ -1,9 +0,0 @@ -module osal - -fn test_platform() { - assert platform() != .unknown -} - -fn test_cputype() { - assert cputype() != .unknown -} diff --git a/lib/osal/readme.md b/lib/osal/readme.md index 985f3a60..a52e0641 100644 --- a/lib/osal/readme.md +++ b/lib/osal/readme.md @@ -18,28 +18,28 @@ A comprehensive operating system abstraction layer for V that provides platform- import freeflowuniverse.herolib.osal // Get platform type -platform := osal.platform() +platform := core.platform()! if platform == .osx { // macOS specific code } // Platform-specific checks -if osal.is_linux() { +if core.is_linux()! { // Linux specific code } -if osal.is_osx_arm() { +if core.is_osx_arm()! { // Apple Silicon specific code } // CPU architecture -cpu := osal.cputype() +cpu := core.cputype()! if cpu == .arm { // ARM specific code } // System information -hostname := osal.hostname()! -init_system := osal.initname()! // e.g., systemd, bash, zinit +hostname := core.hostname()!! +init_system := core.initname()! // e.g., systemd, bash, zinit ``` ## Process Execution diff --git a/lib/osal/screen/screen.v b/lib/osal/screen/screen.v index e163a6c7..f91e98ad 100644 --- a/lib/osal/screen/screen.v +++ b/lib/osal/screen/screen.v @@ -2,6 +2,7 @@ module screen import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.osal +import freeflowuniverse.herolib.core import os import time @@ -91,7 +92,7 @@ pub fn (mut self Screen) attach() ! { pub fn (mut self Screen) cmd_send(cmd string) ! { mut cmd2 := "screen -S ${self.name} -p 0 -X stuff \"${cmd} \n\" " - if osal.is_osx() { + if core.is_osx()! { cmd2 = "screen -S ${self.name} -p 0 -X stuff \"${cmd}\"\$'\n' " } res := os.execute(cmd2) diff --git a/lib/osal/ufw/ufw_list.v b/lib/osal/ufw/ufw_list.v index 8cac8f03..6d881517 100644 --- a/lib/osal/ufw/ufw_list.v +++ b/lib/osal/ufw/ufw_list.v @@ -4,7 +4,7 @@ import os pub fn ufw_status() !UFWStatus { // Run the UFW status command - result := os.execute('sudo ufw status') + result := os.execute('ufw status') if result.exit_code != 0 { return error('Error running UFW status: ${result.output}') } diff --git a/lib/osal/users.v b/lib/osal/users.v index 9f5b1bff..7d7e72cd 100644 --- a/lib/osal/users.v +++ b/lib/osal/users.v @@ -2,6 +2,7 @@ module osal import os import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.core @[params] pub struct UserArgs { @@ -33,7 +34,7 @@ pub fn user_add(args UserArgs) !int { return user_id_get(args.name)! } mut cmd := '' - platform_ := platform() + platform_ := core.platform()! if platform_ == .ubuntu { cmd = 'useradd -m ${args.name} ' } else { diff --git a/lib/osal/utils.v b/lib/osal/utils.v deleted file mode 100644 index ac58cf3c..00000000 --- a/lib/osal/utils.v +++ /dev/null @@ -1,41 +0,0 @@ -module osal - -import log - -__global ( - memdb shared map[string]string -) - -pub fn memdb_set(key string, val string) { - lock memdb { - memdb[key] = val - } -} - -pub fn memdb_get(key string) string { - lock memdb { - return memdb[key] or { return '' } - } - return '' -} - -pub fn memdb_exists(key string) bool { - if memdb_get(key).len > 0 { - return true - } - return false -} - -// Returns a logger object and allows you to specify via environment argument OSAL_LOG_LEVEL the debug level -pub fn get_logger() log.Log { - log_level := env_get_default('OSAL_LOG_LEVEL', 'info') - mut logger := &log.Log{} - logger.set_level(match log_level.to_lower() { - 'debug' { .debug } - 'info' { .info } - 'warn' { .warn } - 'error' { .error } - else { .info } - }) - return *logger -} diff --git a/lib/virt/docker/docker_engine.v b/lib/virt/docker/docker_engine.v index 523301d9..4f314654 100644 --- a/lib/virt/docker/docker_engine.v +++ b/lib/virt/docker/docker_engine.v @@ -4,6 +4,8 @@ import freeflowuniverse.herolib.osal { cputype, exec, platform } import freeflowuniverse.herolib.core.texttools import freeflowuniverse.herolib.virt.utils import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.core + // import freeflowuniverse.herolib.installers.swarm // https://docs.docker.com/reference/ @@ -36,9 +38,9 @@ pub fn (mut e DockerEngine) init() ! { exec(cmd: 'mkdir -p ${e.buildpath}', stdout: false)! } if e.platform == [] { - if platform() == .ubuntu && cputype() == .intel { + if core.platform()! == .ubuntu && cputype()! == .intel { e.platform = [.linux_amd64] - } else if platform() == .osx && cputype() == .arm { + } else if core.platform()! == .osx && cputype()! == .arm { e.platform = [.linux_arm64] } else { return error('only implemented ubuntu on amd and osx on arm for now for docker engine.') diff --git a/lib/virt/herocontainers/cengine.v b/lib/virt/herocontainers/cengine.v index 8a1193d6..a20b4af4 100644 --- a/lib/virt/herocontainers/cengine.v +++ b/lib/virt/herocontainers/cengine.v @@ -51,7 +51,7 @@ pub fn (mut e CEngine) reset_all() ! { exec(cmd: 'podman rmi -a -f', stdout: false)! e.builders_delete_all()! osal.done_reset()! - if osal.platform() == .arch { + if core.platform()! == .arch { exec(cmd: 'systemctl status podman.socket', stdout: false)! } e.load()! diff --git a/lib/virt/herocontainers/factory.v b/lib/virt/herocontainers/factory.v index 1d8988ab..7f7a2ebb 100644 --- a/lib/virt/herocontainers/factory.v +++ b/lib/virt/herocontainers/factory.v @@ -16,7 +16,7 @@ pub mut: pub fn new(args_ NewArgs) !CEngine { mut args := args_ - if !osal.is_linux() { + if !core.is_linux()! { return error('only linux supported as host for now') } diff --git a/lib/virt/hetzner/actions.v b/lib/virt/hetzner/actions.v index bd62e81c..e80c7fcf 100644 --- a/lib/virt/hetzner/actions.v +++ b/lib/virt/hetzner/actions.v @@ -226,7 +226,7 @@ pub fn (mut h HetznerManager) server_reset(args ServerRebootArgs) !ResetInfo { if serveractive { for { console.print_debug('wait for server ${serverinfo.server_name} to go down.') - if osal.ping(address: serverinfo.server_ip)! != .ok { + if osal.ping(address: serverinfo.server_ip)!= .ok { console.print_debug('server ${serverinfo.server_name} is now down, now waitig for reboot.') break }