had to cleanup a lot in relation to optional returns

This commit is contained in:
2025-01-01 13:40:24 +01:00
parent cffd5e2f9c
commit 914e1f5073
135 changed files with 4165 additions and 3530 deletions

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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}")
}
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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()!

View File

@@ -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

View File

@@ -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

17
lib/core/interactive.v Normal file
View File

@@ -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
}

25
lib/core/memdb.v Normal file
View File

@@ -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
}

28
lib/core/memdb_test.v Normal file
View File

@@ -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
}

View File

@@ -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.")

9
lib/core/platform_test.v Normal file
View File

@@ -0,0 +1,9 @@
module core
fn test_platform()! {
assert platform()! != .unknown
}
fn test_cputype()! {
assert cputype()! != .unknown
}

85
lib/core/readme.md Normal file
View File

@@ -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)!
```

91
lib/core/sudo.v Normal file
View File

@@ -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
}

67
lib/core/sudo_test.v Normal file
View File

@@ -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}'
}

View File

@@ -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}'

View File

@@ -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, '')
}
}

View File

@@ -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

View File

@@ -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")!

View File

@@ -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}')

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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}'

View File

@@ -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')

View File

@@ -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()!

View File

@@ -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
}

View File

@@ -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()!

View File

@@ -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
}

View File

@@ -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')

View File

@@ -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

View File

@@ -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
// ")!
}

View File

@@ -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_()!
}

View File

@@ -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()!
}

View File

@@ -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')
}

View File

@@ -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
```

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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()!
}

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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

View File

@@ -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 {

View File

@@ -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

View File

@@ -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')!

View File

@@ -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) {

View File

@@ -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()!

View File

@@ -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
}

View File

@@ -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()

View File

@@ -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()!

View File

@@ -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
}

View File

@@ -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()!

View File

@@ -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
}

View File

@@ -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')

View File

@@ -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()!

View File

@@ -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
}

View File

@@ -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')

View File

@@ -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()!

View File

@@ -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
}

View File

@@ -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()!

View File

@@ -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
}

View File

@@ -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')

View File

@@ -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')

View File

@@ -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()!

View File

@@ -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
}

View File

@@ -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')

View File

@@ -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')

View File

@@ -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')

View File

@@ -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')

View File

@@ -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()!

View File

@@ -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
}

View File

@@ -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')

View File

@@ -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')

View File

@@ -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
}

View File

@@ -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()!

View File

@@ -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()!

View File

@@ -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
}

View File

@@ -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')

View File

@@ -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()!

View File

@@ -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()!

View File

@@ -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
}

View File

@@ -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

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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'
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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')

View File

@@ -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
}

View File

@@ -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')
}

View File

@@ -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')

View File

@@ -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.')
}

View File

@@ -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
}

View File

@@ -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()!

View File

@@ -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
}

Some files were not shown because too many files have changed in this diff Show More