postgresql & new docs

This commit is contained in:
2025-01-01 17:44:06 +01:00
parent b927fc5b5d
commit 36f41150c2
83 changed files with 3175 additions and 3768 deletions

View File

@@ -1,14 +1,12 @@
#!/usr/bin/env -S v -n -w -cg -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.installers.lang.rust
import freeflowuniverse.herolib.installers.lang.python
import freeflowuniverse.herolib.installers.lang.nodejs
import freeflowuniverse.herolib.installers.lang.golang
import freeflowuniverse.herolib.core
core.interactive_set()! //make sure the sudo works so we can do things even if it requires those rights
core.interactive_set()! // make sure the sudo works so we can do things even if it requires those rights
// import freeflowuniverse.herolib.data.dbfs
// import freeflowuniverse.herolib.installers.lang.vlang
@@ -39,4 +37,4 @@ core.interactive_set()! //make sure the sudo works so we can do things even if i
// rust.install(reset:false)!
// python.install(reset:false)!
// nodejs.install(reset:false)!
golang.install(reset:false)!
golang.install(reset: false)!

View File

@@ -1,4 +1,3 @@
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
struct DeploymentStateDB {
@@ -12,21 +11,21 @@ struct DeploymentState {
zdbs []ZDBDeployed
}
pub fn (mut db DeploymentStateDB) set(deployment_name string, key string, val string)! {
pub fn (mut db DeploymentStateDB) set(deployment_name string, key string, val string) ! {
// store e.g. \n separated list of all keys per deployment_name
// encrypt
db.data['${deployment_name}_${key}'] = val
}
pub fn (db DeploymentStateDB) get(deployment_name string, key string)!string {
pub fn (db DeploymentStateDB) get(deployment_name string, key string) !string {
return db.data['${deployment_name}_${key}'] or { return error('key not found') }
}
pub fn (mut db DeploymentStateDB) delete(deployment_name string, key string)! {
pub fn (mut db DeploymentStateDB) delete(deployment_name string, key string) ! {
db.data.delete('${deployment_name}_${key}')
}
pub fn (db DeploymentStateDB) keys(deployment_name string)![]string {
pub fn (db DeploymentStateDB) keys(deployment_name string) ![]string {
mut keys := []string{}
for k, _ in db.data {
if k.starts_with('${deployment_name}_') {
@@ -36,7 +35,7 @@ pub fn (db DeploymentStateDB) keys(deployment_name string)![]string {
return keys
}
pub fn (db DeploymentStateDB) load(deployment_name string)!DeploymentState {
pub fn (db DeploymentStateDB) load(deployment_name string) !DeploymentState {
mut state := DeploymentState{
name: deployment_name
}

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env -S v -gc none -no-retry-compilation -d use_openssl -enable-globals -cg run
//#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals -cg run
//#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals -cg run
import freeflowuniverse.herolib.threefold.gridproxy
import freeflowuniverse.herolib.threefold.tfgrid3deployer
import freeflowuniverse.herolib.installers.threefold.griddriver

View File

@@ -1,4 +1,3 @@
module mailclient
import freeflowuniverse.herolib.core.base
@@ -6,116 +5,102 @@ 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 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}")
}
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}')
}
}
//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
// 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
}
//check we find the config on the filesystem
// 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)
mut model := args_get(args_)
mut context := base.context() or { panic('bug') }
return context.hero_config_exists('mailclient', model.name)
}
//load the config error if it doesn't exist
// 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)!
mut model := args_get(args_)
mut context := base.context()!
mut heroscript := context.hero_config_get('mailclient', model.name)!
play(heroscript: heroscript)!
}
//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)!
// 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_
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)!
}
}
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)!
}
}
}

View File

@@ -1,4 +1,3 @@
module meilisearch
import freeflowuniverse.herolib.core.base
@@ -6,116 +5,102 @@ 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 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}")
}
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}')
}
}
//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
// 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
}
//check we find the config on the filesystem
// 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)
mut model := args_get(args_)
mut context := base.context() or { panic('bug') }
return context.hero_config_exists('meilisearch', model.name)
}
//load the config error if it doesn't exist
// 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)!
mut model := args_get(args_)
mut context := base.context()!
mut heroscript := context.hero_config_get('meilisearch', model.name)!
play(heroscript: heroscript)!
}
//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)!
// 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_
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)!
}
}
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)!
}
}
}

View File

@@ -1,4 +1,3 @@
module mycelium
import freeflowuniverse.herolib.core.base
@@ -6,79 +5,66 @@ 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
//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
// 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
}
//check we find the config on the filesystem
// 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)
mut model := args_get(args_)
mut context := base.context() or { panic('bug') }
return context.hero_config_exists('mycelium', model.name)
}
//load the config error if it doesn't exist
// 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)!
mut model := args_get(args_)
mut context := base.context()!
mut heroscript := context.hero_config_get('mycelium', model.name)!
play(heroscript: heroscript)!
}
//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)!
// 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_
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)!
}
}
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)!
}
}
}

View File

@@ -1,57 +1,48 @@
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 struct ArgsGet {
pub mut:
name string
name string
}
fn args_get (args_ ArgsGet) ArgsGet {
mut model:=args_
if model.name == ""{
model.name = openai_default
}
if model.name == ""{
model.name = "default"
}
return model
fn args_get(args_ ArgsGet) ArgsGet {
mut model := args_
if model.name == '' {
model.name = openai_default
}
if model.name == '' {
model.name = 'default'
}
return model
}
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}")
}
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,7 +1,7 @@
!!hero_code.generate_client
name: "postgresql_client"
classname: "PostgresClient"
hasconfig: false
singleton: true
hasconfig: true
singleton: false
default: true
title: ""

View File

@@ -1,4 +1,4 @@
module postgres
module postgresql_client
import freeflowuniverse.herolib.core.base
import db.pg
@@ -49,8 +49,8 @@ import freeflowuniverse.herolib.ui.console
// }
// }
struct LocalConfig {
name string
path string
passwd string
}
// struct LocalConfig {
// name string
// path string
// passwd string
// }

View File

@@ -1,4 +1,4 @@
module postgres
module postgresql_client
import db.pg
import freeflowuniverse.herolib.core.texttools
@@ -6,26 +6,24 @@ import freeflowuniverse.herolib.osal
import os
import freeflowuniverse.herolib.ui.console
pub fn (mut self PostgresClient[Config]) check() ! {
mut db := self.db
pub fn (mut self PostgresClient) check() ! {
mut db := self.db()!
db.exec('SELECT version();') or { return error('can\t select version from database.\n${self}') }
}
pub fn (mut self PostgresClient[Config]) exec(c_ string) ![]pg.Row {
mut db := self.db
pub fn (mut self PostgresClient) exec(c_ string) ![]pg.Row {
mut db := self.db()!
mut c := c_
if !(c.trim_space().ends_with(';')) {
c += ';'
}
config := self.config()!
return db.exec(c) or {
return error('can\t execute query on ${config.host}:${config.dbname}.\n${c}\n${err}')
return error('can\t execute query on ${self.host}:${self.name}.\n${c}\n${err}')
}
}
pub fn (mut self PostgresClient[Config]) db_exists(name_ string) !bool {
mut db := self.db
pub fn (mut self PostgresClient) db_exists(name_ string) !bool {
mut db := self.db()!
r := db.exec("SELECT datname FROM pg_database WHERE datname='${name_}';")!
if r.len == 1 {
// console.print_header(' db exists: ${name_}')
@@ -37,36 +35,32 @@ pub fn (mut self PostgresClient[Config]) db_exists(name_ string) !bool {
return false
}
pub fn (mut self PostgresClient[Config]) db_create(name_ string) ! {
pub fn (mut self PostgresClient) db_create(name_ string) ! {
name := texttools.name_fix(name_)
mut db := self.db
db_exists := self.db_exists(name_)!
if !db_exists {
mut db := self.db()!
if !self.db_exists(name)! {
console.print_header(' db create: ${name}')
db.exec('CREATE DATABASE ${name};')!
}
db_exists2 := self.db_exists(name_)!
if !db_exists2 {
if !self.db_exists(name)! {
return error('Could not create db: ${name_}, could not find in DB.')
}
}
pub fn (mut self PostgresClient[Config]) db_delete(name_ string) ! {
mut db := self.db
pub fn (mut self PostgresClient) db_delete(name_ string) ! {
mut db := self.db()!
name := texttools.name_fix(name_)
self.check()!
db_exists := self.db_exists(name_)!
if db_exists {
if self.db_exists(name)! {
console.print_header(' db delete: ${name_}')
db.exec('DROP DATABASE ${name};')!
}
db_exists2 := self.db_exists(name_)!
if db_exists2 {
return error('Could not delete db: ${name_}, could not find in DB.')
if self.db_exists(name)! {
return error('Could not delete db: ${name_}, db was still there.')
}
}
pub fn (mut self PostgresClient[Config]) db_names() ![]string {
pub fn (mut self PostgresClient) db_names() ![]string {
mut res := []string{}
sqlstr := "SELECT datname FROM pg_database WHERE datistemplate = false and datname != 'postgres' and datname != 'root';"
for row in self.exec(sqlstr)! {
@@ -83,7 +77,7 @@ pub mut:
dest string
}
pub fn (mut self PostgresClient[Config]) backup(args BackupParams) ! {
pub fn (mut self PostgresClient) backup(args BackupParams) ! {
if args.dest == '' {
return error('specify the destination please')
}
@@ -96,10 +90,9 @@ pub fn (mut self PostgresClient[Config]) backup(args BackupParams) ! {
self.backup(dbname: dbname, dest: args.dest)!
}
} else {
config := self.config()!
cmd := '
export PGPASSWORD=\'${config.password}\'
pg_dump -h ${config.host} -p ${config.port} -U ${config.user} --dbname=${args.dbname} --format=c > "${args.dest}/${args.dbname}.bak"
export PGPASSWORD=\'${self.password}\'
pg_dump -h ${self.host} -p ${self.port} -U ${self.user} --dbname=${args.dbname} --format=c > "${args.dest}/${args.dbname}.bak"
' // console.print_debug(cmd)
osal.exec(cmd: cmd, stdout: true)!

View File

@@ -1,91 +0,0 @@
module postgres
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.ui
import freeflowuniverse.herolib.ui.console
@[params]
pub struct Config {
pub mut:
instance string = 'default'
user string = 'root'
port int = 5432
host string = 'localhost'
password string
dbname string = 'postgres'
heroscript string
reset bool
}
pub fn configure(instance string, cfg_ Config) !PostgresClient[Config] {
mut config := cfg_
mut server := PostgresClient[Config]{}
server.init('postgres', instance, .set, config)!
return get(instance)!
}
pub fn configure_interactive(args_ Config, mut session base.Session) ! {
mut args := args_
mut myui := ui.new()!
console.clear()
console.print_debug('\n## Configure Postgres Client')
console.print_debug('============================\n\n')
instance := myui.ask_question(
question: 'name for postgres client'
default: args.instance
)!
args.user = myui.ask_question(
question: 'user'
minlen: 3
default: args.user
)!
args.password = myui.ask_question(
question: 'password'
minlen: 3
default: args.password
)!
args.dbname = myui.ask_question(
question: 'dbname'
minlen: 3
default: args.dbname
)!
args.host = myui.ask_question(
question: 'host'
minlen: 3
default: args.host
)!
mut port := myui.ask_question(
question: 'port'
default: '${args.port}'
)!
args.port = port.int()
mut client := PostgresClient[Config]{}
client.init('postgres', instance, .set, args)!
}
// pub fn play_session(mut session base.Session) ! {
// for mut action in session.plbook.find(filter: 'postgresclient.define')! {
// mut p := action.params
// mut args := config()
// panic('implement')
// // args.instance = p.get_default('name','')!
// // if args.instance == ""{
// // args.instance = p.get_default('instance', 'default')!
// // }
// // args.mail_from = p.get('mail_from')!
// // args.smtp_addr = p.get('smtp_addr')!
// // args.smtp_login = p.get('smtp_login')!
// // args.smtp_passwd = p.get('smtp_passwd')!
// // args.smpt_port = p.get_int('smpt_port')!
// // mut c:=configurator(args.instance,session:session)!
// // c.set(args)!
// }
// }

View File

@@ -1,29 +0,0 @@
module postgres
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.ui as gui
import freeflowuniverse.herolib.ui.console
import db.pg
pub struct PostgresClient[T] {
base.BaseConfig[T]
pub mut:
db pg.DB
}
pub fn get(instance string) !PostgresClient[Config] {
mut self := PostgresClient[Config]{}
self.init('postgres', instance, .get)!
config := self.config()!
mut db := pg.connect(
host: config.host
user: config.user
port: config.port
password: config.password
dbname: config.dbname
)!
self.db = db
return self
}

View File

@@ -1,20 +1,107 @@
module postgresql_client
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core
import freeflowuniverse.herolib.data.encoderhero
__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
}
fn args_get(args_ ArgsGet) ArgsGet {
mut model := args_
if model.name == '' {
model.name = postgresql_client_default
}
if model.name == '' {
model.name = 'default'
}
return model
}
pub fn get(args_ ArgsGet) !&PostgresClient {
mut args := args_get(args_)
if args.name !in postgresql_client_global {
if args.name == 'default' {
if !exists(args)! {
if default {
mut context := base.context() or { panic('bug') }
context.hero_config_set('postgresql_client', args.name, heroscript_default()!)!
}
}
load(args)!
}
}
return postgresql_client_global[args.name] or {
println(postgresql_client_global)
panic('could not get config for ${args.name}.')
}
}
// set the model in mem and the config on the filesystem
pub fn set(o PostgresClient) ! {
mut o2 := obj_init(o)!
postgresql_client_global[o.name] = &o2
postgresql_client_default = o.name
}
// check we find the config on the filesystem
pub fn exists(args_ ArgsGet) !bool {
mut model := args_get(args_)
mut context := base.context()!
return context.hero_config_exists('postgresql_client', 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_client', model.name)!
play(heroscript: heroscript)!
}
// save the config to the filesystem in the context
pub fn save(o PostgresClient) ! {
mut context := base.context()!
heroscript := encoderhero.encode[PostgresClient](o)!
context.hero_config_set('postgresql_client', o.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
}
pub fn play(args_ PlayArgs) ! {
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: 'postgresql_client.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_client.configure\n${mycfg}')
set(mycfg)!
save(mycfg)!
}
}
}

View File

@@ -2,27 +2,71 @@ module postgresql_client
import freeflowuniverse.herolib.data.paramsparser
import os
import db.pg
pub const version = '0.0.0'
const singleton = true
const singleton = false
const default = true
pub fn heroscript_default() !string {
heroscript := "
!!postgresql_client.configure
name:'default'
user: 'root'
port: 5432
host: 'localhost'
password: ''
dbname: 'postgres'
"
return heroscript
}
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
@[heap]
pub struct PostgresClient {
mut:
db_ ?pg.DB
pub mut:
name string = 'default'
mail_from string
mail_password string @[secret]
mail_port int
mail_server string
mail_username string
name string = 'default'
user string = 'root'
port int = 5432
host string = 'localhost'
password string
dbname string = 'postgres'
}
fn cfg_play(p paramsparser.Params) !PostgresClient {
mut mycfg := PostgresClient{
name: p.get_default('name', 'default')!
user: p.get_default('user', 'root')!
port: p.get_int_default('port', 5432)!
host: p.get_default('host', 'localhost')!
password: p.get_default('password', '')!
dbname: p.get_default('dbname', 'postgres')!
}
set(mycfg)!
return mycfg
}
fn obj_init(obj_ PostgresClient) !PostgresClient {
// never call get here, only thing we can do here is work on object itself
mut obj := obj_
panic('implement')
return obj
}
fn (mut self PostgresClient) db() !pg.DB {
// console.print_debug(args)
mut db := self.db_ or {
mut db_ := pg.connect(
host: self.host
user: self.user
port: self.port
password: self.password
dbname: self.dbname
)!
db_
}
return db
}

View File

@@ -1,76 +1,113 @@
# postgres client
# PostgreSQL Client
## use hero to work with postgres
The PostgreSQL client provides a simple interface to interact with PostgreSQL databases through HeroScript.
```bash
## Configuration
Usage: hero postgres [flags] [commands]
The PostgreSQL client can be configured using HeroScript. Configuration settings are stored on the filesystem for future use.
manage postgresql
Flags:
-help Prints help information.
-man Prints the auto-generated manpage.
Commands:
exec execute a query
check check the postgresql connection
configure configure a postgresl connection.
backup backup
print print configure info.
list list databases
```
## configure
the postgres configuration is stored on the filesystem for further use, can be configured as follows
### Basic Configuration Example
```v
import freeflowuniverse.herolib.clients.postgres
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
postgres.configure(name:'default',
user :'root'
port : 5432
host : 'localhost'
password : 'ssss'
dbname :'postgres')!
import freeflowuniverse.herolib.core
import os
import freeflowuniverse.herolib.clients.postgresql_client
mut db:=postgres.get(name:'default')!
heroscript := "
!!postgresql_client.configure
name:'test'
user: 'root'
port: 5432
host: 'localhost'
password: '1234'
dbname: 'postgres'
"
// Process the heroscript
postgresql_client.play(heroscript:heroscript)!
// Get the configured client
mut db_client := postgresql_client.get(name:"test")!
println(db_client)
```
## configure through heroscript
### Configuration Parameters
| Parameter | Description | Default Value |
|-----------|-------------|---------------|
| name | Unique identifier for this configuration | 'default' |
| user | PostgreSQL user | 'root' |
| port | PostgreSQL server port | 5432 |
| host | PostgreSQL server host | 'localhost' |
| password | PostgreSQL user password | '' |
| dbname | Default database name | 'postgres' |
## Database Operations
### Check Connection
```v
import freeflowuniverse.herolib.clients.postgres
heroscript:='
!!postgresclient.define name:'default'
//TO IMPLEMENT
'
postgres.configure(heroscript:heroscript)!
//can also be done through get directly
mut cl:=postgres.get(reset:true,name:'default',heroscript:heroscript)
// Check if connection is working
db_client.check()!
```
## some postgresql cmds
### Database Management
```v
import freeflowuniverse.herolib.clients.postgres
// Check if database exists
exists := db_client.db_exists('mydb')!
mut cl:=postgres.get()! //will default get postgres client with name 'default'
// Create database
db_client.db_create('mydb')!
cl.db_exists("mydb")!
// Delete database
db_client.db_delete('mydb')!
// List all databases
db_names := db_client.db_names()!
```
## use the good module of v
### Query Execution
- [https://modules.vlang.io/db.pg.html#DB.exec](https://modules.vlang.io/db.pg.html#DB.exec)
```v
// Execute a query
rows := db_client.exec('SELECT * FROM mytable;')!
// Query without semicolon is automatically appended
rows := db_client.exec('SELECT * FROM mytable')!
```
## Backup Functionality
The client provides functionality to backup databases:
```v
// Backup a specific database
db_client.backup(dbname: 'mydb', dest: '/path/to/backup/dir')!
// Backup all databases
db_client.backup(dest: '/path/to/backup/dir')!
```
Backups are created in custom PostgreSQL format (.bak files) which can be restored using pg_restore.
## Default Configuration
If no configuration is provided, the client uses these default settings:
```v
heroscript := "
!!postgresql_client.configure
name:'default'
user: 'root'
port: 5432
host: 'localhost'
password: ''
dbname: 'postgres'
"
```
You can override these defaults by providing your own configuration using the HeroScript configure command.

View File

@@ -1,4 +1,3 @@
module rclone
import freeflowuniverse.herolib.core.base
@@ -6,79 +5,66 @@ 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
//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
// 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
}
//check we find the config on the filesystem
// 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)
mut model := args_get(args_)
mut context := base.context() or { panic('bug') }
return context.hero_config_exists('rclone', model.name)
}
//load the config error if it doesn't exist
// 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)!
mut model := args_get(args_)
mut context := base.context()!
mut heroscript := context.hero_config_get('rclone', model.name)!
play(heroscript: heroscript)!
}
//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)!
// 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_
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 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)!
}
}
}

View File

@@ -1,20 +1,12 @@
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

View File

@@ -1,20 +1,12 @@
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

View File

@@ -28,7 +28,7 @@ pub enum Cat {
installer
}
//creates the heroscript from the GenModel as part of GenerateArgs
// creates the heroscript from the GenModel as part of GenerateArgs
pub fn gen_model_set(args GenerateArgs) ! {
console.print_debug('Code generator set: ${args}')
model := args.model or { return error('model is none') }
@@ -41,7 +41,7 @@ pub fn gen_model_set(args GenerateArgs) ! {
pathlib.template_write(heroscript_templ, '${args.path}/.heroscript', true)!
}
//loads the heroscript and return the model
// loads the heroscript and return the model
pub fn gen_model_get(path string, create bool) !GenModel {
console.print_debug('play installer code for path: ${path}')

View File

@@ -46,10 +46,10 @@ pub fn get(args_ ArgsGet) !&${model.classname} {
mut args := args_get(args_)
if !(args.name in ${model.name}_global) {
if args.name=="default"{
if ! config_exists(args){
if ! exists!(args){
if default{
mut context:=base.context() or { panic("bug") }
context.hero_config_set("${model.name}",model.name,heroscript_default()!)!
context.hero_config_set("${model.name}",args.name,heroscript_default()!)!
}
}
load(args)!
@@ -57,7 +57,7 @@ pub fn get(args_ ArgsGet) !&${model.classname} {
}
return ${model.name}_global[args.name] or {
println(${model.name}_global)
panic("could not get config for ??{args.name} with name:??{model.name}")
panic("could not get config for ??{args.name}.")
}
}
@@ -73,9 +73,9 @@ pub fn set(o ${model.classname})! {
}
//check we find the config on the filesystem
pub fn exists(args_ ArgsGet) bool {
pub fn exists(args_ ArgsGet)!bool {
mut model := args_get(args_)
mut context:=base.context() or { panic("bug") }
mut context:=base.context()!
return context.hero_config_exists("${model.name}",model.name)
}
@@ -91,7 +91,7 @@ pub fn load(args_ ArgsGet) ! {
pub fn save(o ${model.classname})! {
mut context:=base.context()!
heroscript := encoderhero.encode[${model.classname}](o)!
context.hero_config_set("${model.name}",model.name,heroscript)!
context.hero_config_set("${model.name}",o.name,heroscript)!
}
^^[params]
@@ -272,7 +272,7 @@ pub fn (mut self ${model.classname}) restart() ! {
pub fn (mut self ${model.classname}) running() !bool {
switch(self.name)
//walk over the generic processes, if not running return
//walk over the generic processes, if not running_ return
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
r:=sm.running(zprocess.name)!
@@ -280,7 +280,7 @@ pub fn (mut self ${model.classname}) running() !bool {
return false
}
}
return running()!
return running_()!
}
@end

View File

@@ -112,7 +112,7 @@ pub mut:
}
@if model.hasconfig
fn cfg_play(p paramsparser.Params) ! {
fn cfg_play(p paramsparser.Params) !${model.classname} {
//THIS IS EXAMPLE CODE AND NEEDS TO BE CHANGED IN LINE WITH struct above
mut mycfg := ${model.classname}{
name: p.get_default('name', 'default')!
@@ -123,6 +123,7 @@ fn cfg_play(p paramsparser.Params) ! {
mail_username: p.get('mail_username')!
}
set(mycfg)!
return mycfg
}
@end

View File

@@ -2,16 +2,16 @@ module core
import base
//check if we are interactive in current context
pub fn interactive()!bool{
mut c:=base.context()!
if c.config.interactive{
// 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()!
pub fn interactive_set() ! {
mut c := base.context()!
c.config.interactive = true
}

View File

@@ -25,4 +25,3 @@ fn test_memdb_exists() {
memdb_set('empty_key', '')
assert memdb_exists('empty_key') == false
}

View File

@@ -5,7 +5,6 @@ import os
// import freeflowuniverse.herolib.ui.console
// Returns the enum value that matches the provided string for PlatformType
pub enum PlatformType {
unknown
osx
@@ -25,7 +24,6 @@ pub fn platform_enum_from_string(platform string) PlatformType {
}
}
// Returns the enum value that matches the provided string for CPUType
pub fn cputype_enum_from_string(cputype string) CPUType {
return match cputype.to_lower() {
@@ -54,7 +52,7 @@ pub fn cmd_exists(cmd string) bool {
return true
}
pub fn platform()! PlatformType {
pub fn platform() !PlatformType {
mut platform_ := PlatformType.unknown
platform_ = platform_enum_from_string(memdb_get('platformtype'))
if platform_ != PlatformType.unknown {
@@ -77,18 +75,18 @@ pub fn platform()! PlatformType {
return platform_
}
pub fn cputype()! CPUType {
pub fn cputype() !CPUType {
mut cputype_ := CPUType.unknown
cputype_ = cputype_enum_from_string(memdb_get('cputype'))
if cputype_ != CPUType.unknown {
return cputype_
}
res := os.execute('uname -m')
if res.exit_code >0{
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
@@ -110,37 +108,37 @@ pub fn cputype()! CPUType {
return cputype_
}
pub fn is_osx()! bool {
pub fn is_osx() !bool {
return platform()! == .osx
}
pub fn is_osx_arm()! bool {
pub fn is_osx_arm() !bool {
return platform()! == .osx && cputype()! == .arm
}
pub fn is_osx_intel()! bool {
pub fn is_osx_intel() !bool {
return platform()! == .osx && cputype()! == .intel
}
pub fn is_ubuntu()! bool {
pub fn is_ubuntu() !bool {
return platform()! == .ubuntu
}
pub fn is_linux()! bool {
pub fn is_linux() !bool {
return platform()! == .ubuntu || platform()! == .arch || platform()! == .suse
|| platform()! == .alpine
}
pub fn is_linux_arm()!bool {
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 {
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.")

View File

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

View File

@@ -50,6 +50,19 @@ And CPU architectures:
The core module provides essential functionality used by other Hero framework components. Key features include:
### Interactivity Check & Influence on delete
```
import freeflowuniverse.herolib.installers.lang.golang
import freeflowuniverse.herolib.core
core.interactive_set()! //make sure the sudo works so we can do things even if it requires those rights
//this will allow files which are in sudo area to still get them removed but its important interactive is set on the context.
golang.install(reset:false)!
```
### Platform Detection
```v
// Check platform type
@@ -74,13 +87,41 @@ value := core.memdb_get('key')
### Sudo Operations
The sudo operations module provides comprehensive permission management and command elevation handling:
```v
// Check sudo requirements
// Check if sudo is required for the current user
if core.sudo_required()! {
// Handle sudo requirements
// Returns false if user is root or on macOS
// Returns true if user has sudo privileges
}
// Verify path permissions
path := core.sudo_path_check('/protected/path', true)!
```
// Verify path permissions and accessibility
path := core.sudo_path_check('/path/to/check')! {
// Returns the path if accessible
// Errors if path requires sudo rights
}
// Check if a path is accessible without sudo
if core.sudo_path_ok('/usr/local/bin')! {
// Returns false for protected directories like:
// /usr/, /boot, /etc, /root/
// Returns true if path is accessible
}
// Check and modify commands that require sudo
cmd := core.sudo_cmd_check('ufw enable')! {
// Automatically adds 'sudo' prefix if:
// 1. Command requires elevated privileges
// 2. User doesn't have sudo rights
// 3. Running in interactive mode
}
// Check if current process has sudo rights
if core.sudo_rights_check()! {
// Returns true if:
// - Running as root user
// - Has necessary sudo privileges
}
```

View File

@@ -3,23 +3,23 @@ module core
import base
import os
//check path is accessible, e.g. do we need sudo and are we sudo
// 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)!{
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 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){
for item in ['/usr/', '/boot', '/etc', '/root/'] {
if path.starts_with(item) {
return false
}
}
@@ -27,23 +27,20 @@ pub fn sudo_path_ok(path string)!bool{
return true
}
//if we know cmd requires sudo rights
pub fn sudo_cmd(cmd string)!bool{
cmd2:=cmd.split(" ")[0]
if cmd2 in [
"ufw"
] {
// if we know cmd requires sudo rights
pub fn sudo_cmd(cmd string) !bool {
cmd2 := cmd.split(' ')[0]
if cmd2 == 'ufw' {
return true
}
//TODO: need many more checks
// 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 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()!{
if sudo_rights_check()! {
return cmd
}
@@ -54,29 +51,27 @@ pub fn sudo_cmd_check(cmd string)!string{
return cmd
}
if interactive()!{
return "sudo ${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 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
// 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 {
pub fn sudo_required() !bool {
// Check if the user is root
if sudo_rights_check()!{
if sudo_rights_check()! {
return false
}
platform_ := platform()!

View File

@@ -1,4 +1,5 @@
module core
import os
import base
@@ -9,7 +10,7 @@ fn init_context() ! {
c.save()!
}
fn test_sudo_required()! {
fn test_sudo_required() ! {
init_context()!
// Test if sudo requirement detection works
required := sudo_required()!
@@ -35,33 +36,30 @@ fn test_sudo_path_ok() {
fn test_sudo_path_protected() {
init_context()!
// Test path permission checks for protected paths
p := "/usr/local"
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()! {
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

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

@@ -55,7 +55,7 @@ pub fn redis_install(args_ RedisInstallArgs) ! {
}
fn configfilepath(args RedisInstallArgs) string {
if core.is_linux() or {panic(err)} {
if core.is_linux() or { panic(err) } {
return '/etc/redis/redis.conf'
} else {
return '${args.datadir}/redis.conf'

View File

@@ -1,301 +1,281 @@
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 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}")
}
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}')
}
}
//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
// 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
}
//check we find the config on the filesystem
// 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)
mut model := args_get(args_)
mut context := base.context() or { panic('bug') }
return context.hero_config_exists('meilisearchinstaller', model.name)
}
//load the config error if it doesn't exist
// 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)!
mut model := args_get(args_)
mut context := base.context()!
mut heroscript := context.hero_config_get('meilisearchinstaller', model.name)!
play(heroscript: heroscript)!
}
//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)!
// 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)!
}
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)!
}
}
if model.heroscript == '' {
model.heroscript = heroscript_default()!
}
mut plbook := model.plbook or { playbook.new(text: model.heroscript)! }
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 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)!
}
}
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()!
}
}
}
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()!
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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 MeilisearchServer) 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()!
}
}
// 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()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('meilisearchinstaller did not install properly.')
start_post()!
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
}
//switch instance to be used for meilisearchinstaller
// switch instance to be used for meilisearchinstaller
pub fn switch(name string) {
meilisearchinstaller_default = name
meilisearchinstaller_default = name
}
pub fn (mut self MeilisearchServer) install(args InstallArgs) ! {
switch(self.name)
if args.reset {
destroy_()!
}
if ! (installed_()!){
install_()!
}
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_()!
}

View File

@@ -1,252 +1,232 @@
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
//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
// 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
}
//check we find the config on the filesystem
// 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)
mut model := args_get(args_)
mut context := base.context() or { panic('bug') }
return context.hero_config_exists('postgresql', model.name)
}
//load the config error if it doesn't exist
// 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)!
mut model := args_get(args_)
mut context := base.context()!
mut heroscript := context.hero_config_get('postgresql', model.name)!
play(heroscript: heroscript)!
}
//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)!
// 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)!
}
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)!
}
}
if model.heroscript == '' {
model.heroscript = heroscript_default()!
}
mut plbook := model.plbook or { playbook.new(text: model.heroscript)! }
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 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)!
}
}
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()!
}
}
}
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()!
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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 Postgresql) 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()!
}
}
// 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()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('postgresql did not install properly.')
start_post()!
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 install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}

View File

@@ -1,152 +1,137 @@
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
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('zerodb did not install properly.')
start_post()!
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 install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

View File

@@ -1,152 +1,137 @@
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
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('zerofs did not install properly.')
start_post()!
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 install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

View File

@@ -6,198 +6,183 @@ 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'
// }
// }
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
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)!
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
// 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_pre() ! {
}
fn start_post()!{
fn start_post() ! {
}
fn stop_pre()!{
fn stop_pre() ! {
}
fn stop_post()!{
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
// 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
// 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{}
// 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
// uploads to S3 server if configured
fn upload_() ! {
// installers.upload(
// cmdname: 'gitea'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/gitea'
// )!
// 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')
// }
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'
// )!
// mut dest := osal.download(
// url: url
// minsize_kb: 9000
// expand_dir: '/tmp/gitea'
// )!
// //dest.moveup_single_subdir()!
// //dest.moveup_single_subdir()!
// mut binpath := dest.file_get('gitea')!
// osal.cmd_add(
// cmdname: 'gitea'
// source: binpath.path
// )!
// mut binpath := dest.file_get('gitea')!
// osal.cmd_add(
// cmdname: 'gitea'
// source: binpath.path
// )!
}
fn build_() ! {
//url := 'https://github.com/threefoldtech/gitea'
// 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()!
// 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')
// 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
// )!
// 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")!
// mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")!
// osal.process_kill_recursive(name:'zinit')!
// osal.cmd_delete('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
// ")!
// 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

@@ -1,152 +1,137 @@
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
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()!
}
}
// 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
}
switch(self.name)
if self.running()! {
return
}
console.print_header('gitea start')
console.print_header('gitea 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 gitea with ${zprocess.startuptype}...')
console.print_debug('starting gitea with ${zprocess.startuptype}...')
sm.new(zprocess)!
sm.new(zprocess)!
sm.start(zprocess.name)!
}
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.')
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()!
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()!
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()!
switch(self.name)
self.stop()!
self.start()!
}
pub fn (mut self GiteaInstaller) 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 install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

View File

@@ -1,4 +1,5 @@
module gitea
import freeflowuniverse.herolib.data.paramsparser
import os
@@ -6,24 +7,20 @@ 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
// 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'
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
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
// called before start if done
fn configure() ! {
//mut installer := get()!
// mut installer := get()!
}

View File

@@ -7,7 +7,7 @@ import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.ui.console
pub fn install_() ! {
if core.platform()!= .ubuntu || core.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 core.platform()!= .ubuntu || core.platform()!= .arch {
if core.platform() != .ubuntu || core.platform() != .arch {
return error('only support ubuntu and arch for now')
}

View File

@@ -1,297 +1,276 @@
module livekit
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 (
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
name string
}
fn args_get (args_ ArgsGet) ArgsGet {
mut model:=args_
if model.name == ""{
model.name = livekit_default
}
if model.name == ""{
model.name = "default"
}
return model
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 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}")
}
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}')
}
}
//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
// 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
}
//check we find the config on the filesystem
// 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)
mut model := args_get(args_)
mut context := base.context() or { panic('bug') }
return context.hero_config_exists('livekit', model.name)
}
//load the config error if it doesn't exist
// 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)!
mut model := args_get(args_)
mut context := base.context()!
mut heroscript := context.hero_config_get('livekit', model.name)!
play(heroscript: heroscript)!
}
//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)!
// 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:
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: '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)!
}
}
if model.heroscript == '' {
model.heroscript = heroscript_default()!
}
mut plbook := model.plbook or { playbook.new(text: model.heroscript)! }
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()!
}
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)!
}
}
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 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()!
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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()!
}
}
// 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')
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 livekit with ${zprocess.startuptype}...')
console.print_debug('starting livekit with ${zprocess.startuptype}...')
sm.new(zprocess)!
sm.new(zprocess)!
sm.start(zprocess.name)!
}
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.')
start_post()!
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(model InstallArgs) ! {
switch(self.name)
self.install(model)!
self.start()!
switch(self.name)
self.install(model)!
self.start()!
}
pub fn (mut self LivekitServer) 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 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)
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
}
//switch instance to be used for livekit
// switch instance to be used for livekit
pub fn switch(name string) {
livekit_default = name
livekit_default = name
}
pub fn (mut self LivekitServer) install(args InstallArgs) ! {
switch(self.name)
if args.reset {
destroy_()!
}
if ! (installed_()!){
install_()!
}
switch(self.name)
if args.reset {
destroy_()!
}
if !(installed_()!) {
install_()!
}
}
pub fn (mut self LivekitServer) destroy() ! {
switch(self.name)
self.stop() or {}
destroy_()!
switch(self.name)
self.stop() or {}
destroy_()!
}

View File

@@ -11,7 +11,7 @@ import os
// checks if a certain version or above is installed
fn installed_() !bool {
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'))
@@ -34,7 +34,7 @@ fn installed_() !bool {
fn install_() ! {
console.print_header('install golang')
base.install()!
//destroy()!
// destroy()!
mut url := ''
if core.is_linux_arm()! {
@@ -93,4 +93,3 @@ fn destroy_() ! {
go
')!
}

View File

@@ -1,57 +1,42 @@
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
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
@[params]
pub struct InstallArgs{
pub struct InstallArgs {
pub mut:
reset bool
reset bool
}
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

View File

@@ -6,74 +6,64 @@ import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.installers.ulist
import freeflowuniverse.herolib.installers.base
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
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
}
//get the Upload List of the files
// 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{}
// 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
// uploads to S3 server if configured
fn upload_() ! {
}
fn install_() ! {
console.print_header('install nodejs')
osal.package_install('pnpm')!
console.print_header('install nodejs')
osal.package_install('pnpm')!
}
fn destroy_() ! {
// mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")!
// mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")!
// osal.process_kill_recursive(name:'zinit')!
// osal.cmd_delete('zinit')!
// osal.process_kill_recursive(name:'zinit')!
// osal.cmd_delete('zinit')!
osal.package_remove('
osal.package_remove('
pnpm
')!
// //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
// ")!
// //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

@@ -1,54 +1,38 @@
module nodejs
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 (
nodejs_global map[string]&NodeJS
nodejs_default string
nodejs_global map[string]&NodeJS
nodejs_default string
)
/////////FACTORY
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
@[params]
pub struct InstallArgs{
pub struct InstallArgs {
pub mut:
reset bool
reset bool
}
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}

View File

@@ -6,93 +6,83 @@ import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.core
import freeflowuniverse.herolib.installers.ulist
import freeflowuniverse.herolib.installers.base
import os
//////////////////// following actions are not specific to instance of the object
// 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
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
}
//get the Upload List of the files
// 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{}
// optionally build a UList which is all paths which are result of building, is then used e.g. in upload
return ulist.UList{}
}
fn upload_() ! {
}
fn install_() ! {
console.print_header('install python')
base.install()!
console.print_header('install python')
base.install()!
osal.package_install('python3')!
pl := core.platform()!
if pl == .arch {
osal.package_install('python-pipx,sqlite')!
} else if pl == .ubuntu {
osal.package_install('python-pipx,sqlite')!
} else if pl == .osx {
osal.package_install('pipx,sqlite')!
} else {
return error('only support osx, arch & ubuntu.')
}
osal.execute_silent("pipx install uv")!
osal.package_install('python3')!
pl := core.platform()!
if pl == .arch {
osal.package_install('python-pipx,sqlite')!
} else if pl == .ubuntu {
osal.package_install('python-pipx,sqlite')!
} else if pl == .osx {
osal.package_install('pipx,sqlite')!
} else {
return error('only support osx, arch & ubuntu.')
}
osal.execute_silent('pipx install uv')!
}
fn destroy_() ! {
panic('implement')
panic("implement")
// mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")!
// mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")!
// osal.process_kill_recursive(name:'zinit')!
// osal.cmd_delete('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
// ")!
// 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

@@ -1,54 +1,38 @@
module python
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 (
python_global map[string]&Python
python_default string
python_global map[string]&Python
python_default string
)
/////////FACTORY
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
@[params]
pub struct InstallArgs{
pub struct InstallArgs {
pub mut:
reset bool
reset bool
}
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}

View File

@@ -6,47 +6,43 @@ import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.core
import freeflowuniverse.herolib.installers.ulist
import freeflowuniverse.herolib.installers.base
import os
//////////////////// following actions are not specific to instance of the object
// checks if a certain version or above is installed
fn installed_() !bool {
res := os.execute('${osal.profile_path_source_and()!} rustc -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 rust version.\n${res.output}")
}
myversion := r[0].all_after_first("rustc").all_before("(")
if texttools.version(version) == texttools.version(myversion) {
return true
}
return false
res := os.execute('${osal.profile_path_source_and()!} rustc -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 rust version.\n${res.output}")
}
myversion := r[0].all_after_first('rustc').all_before('(')
if texttools.version(version) == texttools.version(myversion) {
return true
}
return false
}
//get the Upload List of the files
// 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{}
// 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
// uploads to S3 server if configured
fn upload_() ! {
// installers.upload(
// cmdname: 'rust'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/rust'
// )!
// installers.upload(
// cmdname: 'rust'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/rust'
// )!
}
fn install_() ! {
console.print_header('install rust')
console.print_header('install rust')
version := '1.83.0'
base.install()!
@@ -68,14 +64,13 @@ fn install_() ! {
return
}
fn destroy_() ! {
osal.package_remove('
osal.package_remove('
rust
')!
osal.exec(cmd:'
osal.exec(
cmd: '
#!/bin/bash
# Script to uninstall Rust and Rust-related files
@@ -103,13 +98,13 @@ fn destroy_() ! {
echo "Rust uninstallation process completed."
',debug:false)!
'
debug: false
)!
osal.rm("
osal.rm('
rustc
rustup
cargo
")!
')!
}

View File

@@ -1,54 +1,38 @@
module rust
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 (
rust_global map[string]&RustInstaller
rust_default string
rust_global map[string]&RustInstaller
rust_default string
)
/////////FACTORY
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
@[params]
pub struct InstallArgs{
pub struct InstallArgs {
pub mut:
reset bool
reset bool
}
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}

View File

@@ -1,4 +1,5 @@
module rust
import freeflowuniverse.herolib.data.paramsparser
import os
@@ -6,24 +7,20 @@ pub const version = '1.83.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
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
@[heap]
pub struct RustInstaller {
pub mut:
name string = 'default'
name string = 'default'
}
fn obj_init(obj_ RustInstaller)!RustInstaller{
//never call get here, only thing we can do here is work on object itself
mut obj:=obj_
return obj
fn obj_init(obj_ RustInstaller) !RustInstaller {
// 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
// called before start if done
fn configure() ! {
//mut installer := get()!
// mut installer := get()!
}

View File

@@ -1,152 +1,137 @@
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
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('mycelium did not install properly.')
start_post()!
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 install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

View File

@@ -1,152 +1,137 @@
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
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('yggdrasil did not install properly.')
start_post()!
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 install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

View File

@@ -1,152 +1,137 @@
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
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('actrunner did not install properly.')
start_post()!
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 install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

View File

@@ -1,152 +1,137 @@
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
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('b2 did not install properly.')
start_post()!
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 install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

View File

@@ -1,152 +1,137 @@
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
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('fungistor did not install properly.')
start_post()!
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 install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

View File

@@ -1,152 +1,137 @@
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
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('garage_s3 did not install properly.')
start_post()!
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 install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

View File

@@ -1,152 +1,137 @@
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
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('grafana did not install properly.')
start_post()!
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 install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

View File

@@ -1,152 +1,137 @@
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
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('prometheus did not install properly.')
start_post()!
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 install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

View File

@@ -1,182 +1,161 @@
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 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}")
}
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}')
}
}
//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
// 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
}
//check we find the config on the filesystem
// 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)
mut model := args_get(args_)
mut context := base.context() or { panic('bug') }
return context.hero_config_exists('rclone', model.name)
}
//load the config error if it doesn't exist
// 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)!
mut model := args_get(args_)
mut context := base.context()!
mut heroscript := context.hero_config_get('rclone', model.name)!
play(heroscript: heroscript)!
}
//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)!
// 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)!
}
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 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 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 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 ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
//load from disk and make sure is properly intialized
// load from disk and make sure is properly intialized
pub fn (mut self RClone) reload() ! {
switch(self.name)
self=obj_init(self)!
switch(self.name)
self = obj_init(self)!
}
@[params]
pub struct InstallArgs{
pub struct InstallArgs {
pub mut:
reset bool
reset bool
}
//switch instance to be used for rclone
// switch instance to be used for rclone
pub fn switch(name string) {
rclone_default = name
rclone_default = name
}
pub fn (mut self RClone) install(args InstallArgs) ! {
switch(self.name)
if args.reset {
destroy_()!
}
if ! (installed_()!){
install_()!
}
switch(self.name)
if args.reset {
destroy_()!
}
if !(installed_()!) {
install_()!
}
}
pub fn (mut self RClone) destroy() ! {
switch(self.name)
destroy_()!
switch(self.name)
destroy_()!
}

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 core.platform()!= .ubuntu {
if core.platform() != .ubuntu {
return error('only support ubuntu for now')
}
golang.install()!

View File

@@ -1,152 +1,137 @@
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
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('restic did not install properly.')
start_post()!
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 install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

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 core.platform()!= .ubuntu {
if core.platform() != .ubuntu {
return error('only support ubuntu for now')
}
rust.install()!

View File

@@ -1,152 +1,137 @@
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
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('s3 did not install properly.')
start_post()!
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 install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

View File

@@ -1,152 +1,137 @@
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
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('zinit did not install properly.')
start_post()!
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 install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

View File

@@ -1,57 +1,42 @@
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
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
@[params]
pub struct InstallArgs{
pub struct InstallArgs {
pub mut:
reset bool
reset bool
}
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

View File

@@ -1,57 +1,42 @@
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
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
@[params]
pub struct InstallArgs{
pub struct InstallArgs {
pub mut:
reset bool
reset bool
}
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

View File

@@ -1,57 +1,42 @@
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
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
@[params]
pub struct InstallArgs{
pub struct InstallArgs {
pub mut:
reset bool
reset bool
}
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

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 core.platform()!= .ubuntu {
if core.platform() != .ubuntu {
return error('only support ubuntu for now')
}

View File

@@ -19,7 +19,7 @@ fn install_() ! {
return
}
if core.platform()!= .ubuntu {
if core.platform() != .ubuntu {
return error('only ubuntu supported for this installer.')
}

View File

@@ -1,54 +1,38 @@
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
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
@[params]
pub struct InstallArgs{
pub struct InstallArgs {
pub mut:
reset bool
reset bool
}
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}

View File

@@ -78,7 +78,7 @@ fn build_() ! {
// https://podman.io/docs/installation#building-from-source
if core.platform()!= .ubuntu && core.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,57 +1,42 @@
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
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
@[params]
pub struct InstallArgs{
pub struct InstallArgs {
pub mut:
reset bool
reset bool
}
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

View File

@@ -1,57 +1,42 @@
module youki
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit
import time
__global (
youki_global map[string]&YoukiInstaller
youki_default string
youki_global map[string]&YoukiInstaller
youki_default string
)
/////////FACTORY
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
@[params]
pub struct InstallArgs{
pub struct InstallArgs {
pub mut:
reset bool
reset bool
}
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

View File

@@ -1,255 +1,236 @@
module caddy
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.data.encoderhero
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit
import time
__global (
caddy_global map[string]&CaddyServer
caddy_default string
caddy_global map[string]&CaddyServer
caddy_default string
)
/////////FACTORY
//set the model in mem and the config on the filesystem
pub fn set(o CaddyServer)! {
mut o2:=obj_init(o)!
caddy_global[o.name] = &o2
caddy_default = o.name
// set the model in mem and the config on the filesystem
pub fn set(o CaddyServer) ! {
mut o2 := obj_init(o)!
caddy_global[o.name] = &o2
caddy_default = o.name
}
//check we find the config on the filesystem
// check we find the config on the filesystem
pub fn exists(args_ ArgsGet) bool {
mut model := args_get(args_)
mut context:=base.context() or { panic("bug") }
return context.hero_config_exists("caddy",model.name)
mut model := args_get(args_)
mut context := base.context() or { panic('bug') }
return context.hero_config_exists('caddy', model.name)
}
//load the config error if it doesn't exist
// load the config error if it doesn't exist
pub fn load(args_ ArgsGet) ! {
mut model := args_get(args_)
mut context:=base.context()!
mut heroscript := context.hero_config_get("caddy",model.name)!
play(heroscript:heroscript)!
mut model := args_get(args_)
mut context := base.context()!
mut heroscript := context.hero_config_get('caddy', model.name)!
play(heroscript: heroscript)!
}
//save the config to the filesystem in the context
pub fn save(o CaddyServer)! {
mut context:=base.context()!
heroscript := encoderhero.encode[CaddyServer](o)!
context.hero_config_set("caddy",model.name,heroscript)!
// save the config to the filesystem in the context
pub fn save(o CaddyServer) ! {
mut context := base.context()!
heroscript := encoderhero.encode[CaddyServer](o)!
context.hero_config_set('caddy', model.name, heroscript)!
}
@[params]
pub struct PlayArgs {
pub mut:
heroscript string //if filled in then plbook will be made out of it
plbook ?playbook.PlayBook
reset bool
heroscript string // if filled in then plbook will be made out of it
plbook ?playbook.PlayBook
reset bool
}
pub fn play(args_ PlayArgs) ! {
mut model:=args_
mut model := args_
if model.heroscript == "" {
model.heroscript = heroscript_default()!
}
mut plbook := model.plbook or {
playbook.new(text: model.heroscript)!
}
mut configure_actions := plbook.find(filter: 'caddy.configure')!
if configure_actions.len > 0 {
for config_action in configure_actions {
mut p := config_action.params
mycfg:=cfg_play(p)!
console.print_debug("install action caddy.configure\n${mycfg}")
set(mycfg)!
save(mycfg)!
}
}
if model.heroscript == '' {
model.heroscript = heroscript_default()!
}
mut plbook := model.plbook or { playbook.new(text: model.heroscript)! }
mut other_actions := plbook.find(filter: 'caddy.')!
for other_action in other_actions {
if other_action.name in ["destroy","install","build"]{
mut p := other_action.params
reset:=p.get_default_false("reset")
if other_action.name == "destroy" || reset{
console.print_debug("install action caddy.destroy")
destroy_()!
}
if other_action.name == "install"{
console.print_debug("install action caddy.install")
install_()!
}
}
if other_action.name in ["start","stop","restart"]{
mut p := other_action.params
name := p.get('name')!
mut caddy_obj:=get(name:name)!
console.print_debug("action object:\n${caddy_obj}")
if other_action.name == "start"{
console.print_debug("install action caddy.${other_action.name}")
caddy_obj.start()!
}
mut configure_actions := plbook.find(filter: 'caddy.configure')!
if configure_actions.len > 0 {
for config_action in configure_actions {
mut p := config_action.params
mycfg := cfg_play(p)!
console.print_debug('install action caddy.configure\n${mycfg}')
set(mycfg)!
save(mycfg)!
}
}
if other_action.name == "stop"{
console.print_debug("install action caddy.${other_action.name}")
caddy_obj.stop()!
}
if other_action.name == "restart"{
console.print_debug("install action caddy.${other_action.name}")
caddy_obj.restart()!
}
}
}
mut other_actions := plbook.find(filter: 'caddy.')!
for other_action in other_actions {
if other_action.name in ['destroy', 'install', 'build'] {
mut p := other_action.params
reset := p.get_default_false('reset')
if other_action.name == 'destroy' || reset {
console.print_debug('install action caddy.destroy')
destroy_()!
}
if other_action.name == 'install' {
console.print_debug('install action caddy.install')
install_()!
}
}
if other_action.name in ['start', 'stop', 'restart'] {
mut p := other_action.params
name := p.get('name')!
mut caddy_obj := get(name: name)!
console.print_debug('action object:\n${caddy_obj}')
if other_action.name == 'start' {
console.print_debug('install action caddy.${other_action.name}')
caddy_obj.start()!
}
if other_action.name == 'stop' {
console.print_debug('install action caddy.${other_action.name}')
caddy_obj.stop()!
}
if other_action.name == 'restart' {
console.print_debug('install action caddy.${other_action.name}')
caddy_obj.restart()!
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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 CaddyServer) 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()!
}
}
// unknown
// screen
// zinit
// tmux
// systemd
match cat {
.zinit {
console.print_debug('startupmanager: zinit')
return startupmanager.get(cat: .zinit)!
}
.systemd {
console.print_debug('startupmanager: systemd')
return startupmanager.get(cat: .systemd)!
}
else {
console.print_debug('startupmanager: auto')
return startupmanager.get()!
}
}
}
pub fn (mut self CaddyServer) start() ! {
switch(self.name)
if self.running()!{
return
}
switch(self.name)
if self.running()! {
return
}
console.print_header('caddy start')
console.print_header('caddy start')
if ! installed_()!{
install_()!
}
if !installed_()! {
install_()!
}
configure()!
configure()!
start_pre()!
start_pre()!
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
console.print_debug('starting caddy with ${zprocess.startuptype}...')
console.print_debug('starting caddy with ${zprocess.startuptype}...')
sm.new(zprocess)!
sm.new(zprocess)!
sm.start(zprocess.name)!
}
sm.start(zprocess.name)!
}
start_post()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('caddy did not install properly.')
start_post()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('caddy did not install properly.')
}
pub fn (mut self CaddyServer) install_start(model InstallArgs) ! {
switch(self.name)
self.install(model)!
self.start()!
switch(self.name)
self.install(model)!
self.start()!
}
pub fn (mut self CaddyServer) stop() ! {
switch(self.name)
stop_pre()!
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
sm.stop(zprocess.name)!
}
stop_post()!
switch(self.name)
stop_pre()!
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
sm.stop(zprocess.name)!
}
stop_post()!
}
pub fn (mut self CaddyServer) restart() ! {
switch(self.name)
self.stop()!
self.start()!
switch(self.name)
self.stop()!
self.start()!
}
pub fn (mut self CaddyServer) running() !bool {
switch(self.name)
switch(self.name)
//walk over the generic processes, if not running return
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
r:=sm.running(zprocess.name)!
if r==false{
return false
}
}
return running()!
// walk over the generic processes, if not running return
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
r := sm.running(zprocess.name)!
if r == false {
return false
}
}
return running()!
}
@[params]
pub struct InstallArgs{
pub struct InstallArgs {
pub mut:
reset bool
reset bool
}
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

View File

@@ -1,152 +1,137 @@
module imagemagick
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit
import time
__global (
imagemagick_global map[string]&ImageMagick
imagemagick_default string
imagemagick_global map[string]&ImageMagick
imagemagick_default string
)
/////////FACTORY
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
// unknown
// screen
// zinit
// tmux
// systemd
match cat{
.zinit{
console.print_debug("startupmanager: zinit")
return startupmanager.get(cat:.zinit)!
}
.systemd{
console.print_debug("startupmanager: systemd")
return startupmanager.get(cat:.systemd)!
}else{
console.print_debug("startupmanager: auto")
return startupmanager.get()!
}
}
// unknown
// screen
// zinit
// tmux
// systemd
match cat {
.zinit {
console.print_debug('startupmanager: zinit')
return startupmanager.get(cat: .zinit)!
}
.systemd {
console.print_debug('startupmanager: systemd')
return startupmanager.get(cat: .systemd)!
}
else {
console.print_debug('startupmanager: auto')
return startupmanager.get()!
}
}
}
pub fn (mut self ImageMagick) start() ! {
switch(self.name)
if self.running()!{
return
}
switch(self.name)
if self.running()! {
return
}
console.print_header('imagemagick start')
console.print_header('imagemagick start')
if ! installed_()!{
install_()!
}
if !installed_()! {
install_()!
}
configure()!
configure()!
start_pre()!
start_pre()!
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
console.print_debug('starting imagemagick with ${zprocess.startuptype}...')
console.print_debug('starting imagemagick with ${zprocess.startuptype}...')
sm.new(zprocess)!
sm.new(zprocess)!
sm.start(zprocess.name)!
}
sm.start(zprocess.name)!
}
start_post()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('imagemagick did not install properly.')
start_post()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('imagemagick did not install properly.')
}
pub fn (mut self ImageMagick) install_start(model InstallArgs) ! {
switch(self.name)
self.install(model)!
self.start()!
switch(self.name)
self.install(model)!
self.start()!
}
pub fn (mut self ImageMagick) stop() ! {
switch(self.name)
stop_pre()!
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
sm.stop(zprocess.name)!
}
stop_post()!
switch(self.name)
stop_pre()!
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
sm.stop(zprocess.name)!
}
stop_post()!
}
pub fn (mut self ImageMagick) restart() ! {
switch(self.name)
self.stop()!
self.start()!
switch(self.name)
self.stop()!
self.start()!
}
pub fn (mut self ImageMagick) running() !bool {
switch(self.name)
switch(self.name)
//walk over the generic processes, if not running return
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
r:=sm.running(zprocess.name)!
if r==false{
return false
}
}
return running()!
// walk over the generic processes, if not running return
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
r := sm.running(zprocess.name)!
if r == false {
return false
}
}
return running()!
}
@[params]
pub struct InstallArgs{
pub struct InstallArgs {
pub mut:
reset bool
reset bool
}
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

View File

@@ -1,152 +1,137 @@
module lighttpd
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit
import time
__global (
lighttpd_global map[string]&LightHttpdInstaller
lighttpd_default string
lighttpd_global map[string]&LightHttpdInstaller
lighttpd_default string
)
/////////FACTORY
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
// unknown
// screen
// zinit
// tmux
// systemd
match cat{
.zinit{
console.print_debug("startupmanager: zinit")
return startupmanager.get(cat:.zinit)!
}
.systemd{
console.print_debug("startupmanager: systemd")
return startupmanager.get(cat:.systemd)!
}else{
console.print_debug("startupmanager: auto")
return startupmanager.get()!
}
}
// unknown
// screen
// zinit
// tmux
// systemd
match cat {
.zinit {
console.print_debug('startupmanager: zinit')
return startupmanager.get(cat: .zinit)!
}
.systemd {
console.print_debug('startupmanager: systemd')
return startupmanager.get(cat: .systemd)!
}
else {
console.print_debug('startupmanager: auto')
return startupmanager.get()!
}
}
}
pub fn (mut self LightHttpdInstaller) start() ! {
switch(self.name)
if self.running()!{
return
}
switch(self.name)
if self.running()! {
return
}
console.print_header('lighttpd start')
console.print_header('lighttpd start')
if ! installed_()!{
install_()!
}
if !installed_()! {
install_()!
}
configure()!
configure()!
start_pre()!
start_pre()!
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
console.print_debug('starting lighttpd with ${zprocess.startuptype}...')
console.print_debug('starting lighttpd with ${zprocess.startuptype}...')
sm.new(zprocess)!
sm.new(zprocess)!
sm.start(zprocess.name)!
}
sm.start(zprocess.name)!
}
start_post()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('lighttpd did not install properly.')
start_post()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('lighttpd did not install properly.')
}
pub fn (mut self LightHttpdInstaller) install_start(model InstallArgs) ! {
switch(self.name)
self.install(model)!
self.start()!
switch(self.name)
self.install(model)!
self.start()!
}
pub fn (mut self LightHttpdInstaller) stop() ! {
switch(self.name)
stop_pre()!
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
sm.stop(zprocess.name)!
}
stop_post()!
switch(self.name)
stop_pre()!
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
sm.stop(zprocess.name)!
}
stop_post()!
}
pub fn (mut self LightHttpdInstaller) restart() ! {
switch(self.name)
self.stop()!
self.start()!
switch(self.name)
self.stop()!
self.start()!
}
pub fn (mut self LightHttpdInstaller) running() !bool {
switch(self.name)
switch(self.name)
//walk over the generic processes, if not running return
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
r:=sm.running(zprocess.name)!
if r==false{
return false
}
}
return running()!
// walk over the generic processes, if not running return
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
r := sm.running(zprocess.name)!
if r == false {
return false
}
}
return running()!
}
@[params]
pub struct InstallArgs{
pub struct InstallArgs {
pub mut:
reset bool
reset bool
}
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
}
}
pub fn destroy() ! {
destroy_()!
destroy_()!
}
pub fn build() ! {
build_()!
build_()!
}

View File

@@ -1,98 +1,81 @@
module tailwind
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit
import time
__global (
tailwind_global map[string]&Tailwind
tailwind_default string
tailwind_global map[string]&Tailwind
tailwind_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet{
pub struct ArgsGet {
pub mut:
name string
name string
}
fn args_get (args_ ArgsGet) ArgsGet {
mut model:=args_
if model.name == ""{
model.name = tailwind_default
}
if model.name == ""{
model.name = "default"
}
return model
fn args_get(args_ ArgsGet) ArgsGet {
mut model := args_
if model.name == '' {
model.name = tailwind_default
}
if model.name == '' {
model.name = 'default'
}
return model
}
pub fn get(args_ ArgsGet) !&Tailwind {
mut args := args_get(args_)
if !(args.name in tailwind_global) {
if args.name=="default"{
if ! config_exists(args){
if default{
mut context:=base.context() or { panic("bug") }
context.hero_config_set("tailwind",model.name,heroscript_default()!)!
}
}
load(args)!
}
}
return tailwind_global[args.name] or {
println(tailwind_global)
panic("could not get config for ${args.name} with name:${model.name}")
}
pub fn get(args_ ArgsGet) !&Tailwind {
mut args := args_get(args_)
if args.name !in tailwind_global {
if args.name == 'default' {
if !config_exists(args) {
if default {
mut context := base.context() or { panic('bug') }
context.hero_config_set('tailwind', model.name, heroscript_default()!)!
}
}
load(args)!
}
}
return tailwind_global[args.name] or {
println(tailwind_global)
panic('could not get config for ${args.name} with name:${model.name}')
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
@[params]
pub struct InstallArgs{
pub struct InstallArgs {
pub mut:
reset bool
reset bool
}
//switch instance to be used for tailwind
// switch instance to be used for tailwind
pub fn switch(name string) {
tailwind_default = name
tailwind_default = name
}
pub fn (mut self Tailwind) install(args InstallArgs) ! {
switch(self.name)
if args.reset {
destroy_()!
}
if ! (installed_()!){
install_()!
}
switch(self.name)
if args.reset {
destroy_()!
}
if !(installed_()!) {
install_()!
}
}
pub fn (mut self Tailwind) destroy() ! {
switch(self.name)
destroy_()!
switch(self.name)
destroy_()!
}

View File

@@ -1,102 +1,86 @@
module zola
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit
import time
__global (
zola_global map[string]&ZolaInstaller
zola_default string
zola_global map[string]&ZolaInstaller
zola_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet{
pub struct ArgsGet {
pub mut:
name string
name string
}
fn args_get (args_ ArgsGet) ArgsGet {
mut model:=args_
if model.name == ""{
model.name = zola_default
}
if model.name == ""{
model.name = "default"
}
return model
fn args_get(args_ ArgsGet) ArgsGet {
mut model := args_
if model.name == '' {
model.name = zola_default
}
if model.name == '' {
model.name = 'default'
}
return model
}
pub fn get(args_ ArgsGet) !&ZolaInstaller {
mut args := args_get(args_)
if !(args.name in zola_global) {
if args.name=="default"{
if ! config_exists(args){
if default{
mut context:=base.context() or { panic("bug") }
context.hero_config_set("zola",model.name,heroscript_default()!)!
}
}
load(args)!
}
}
return zola_global[args.name] or {
println(zola_global)
panic("could not get config for ${args.name} with name:${model.name}")
}
pub fn get(args_ ArgsGet) !&ZolaInstaller {
mut args := args_get(args_)
if args.name !in zola_global {
if args.name == 'default' {
if !config_exists(args) {
if default {
mut context := base.context() or { panic('bug') }
context.hero_config_set('zola', model.name, heroscript_default()!)!
}
}
load(args)!
}
}
return zola_global[args.name] or {
println(zola_global)
panic('could not get config for ${args.name} with name:${model.name}')
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
@[params]
pub struct InstallArgs{
pub struct InstallArgs {
pub mut:
reset bool
reset bool
}
//switch instance to be used for zola
// switch instance to be used for zola
pub fn switch(name string) {
zola_default = name
zola_default = name
}
pub fn (mut self ZolaInstaller) install(args InstallArgs) ! {
switch(self.name)
if args.reset {
destroy_()!
}
if ! (installed_()!){
install_()!
}
switch(self.name)
if args.reset {
destroy_()!
}
if !(installed_()!) {
install_()!
}
}
pub fn (mut self ZolaInstaller) build() ! {
switch(self.name)
build_()!
switch(self.name)
build_()!
}
pub fn (mut self ZolaInstaller) destroy() ! {
switch(self.name)
destroy_()!
switch(self.name)
destroy_()!
}

View File

@@ -103,7 +103,7 @@ pub fn usr_local_path() !string {
}
// return the source statement if the profile exists
pub fn profile_path_source()! string {
pub fn profile_path_source() !string {
if hostname() or { '' } == 'rescue' {
return ''
}
@@ -116,7 +116,7 @@ pub fn profile_path_source()! string {
// return source $path && .
// or empty if it doesn't exist
pub fn profile_path_source_and()! string {
pub fn profile_path_source_and() !string {
if hostname() or { '' } == 'rescue' {
return ''
}
@@ -245,16 +245,15 @@ pub fn cmd_delete(cmd string) ! {
res := cmd_path(cmd2) or { '' }
if res.len > 0 {
if os.exists(res) {
if core.sudo_path_ok(res)!{
if core.sudo_path_ok(res)! {
os.rm(res)!
}else{
if core.interactive()!{
execute_silent("sudo rm -rf ${res}")!
}else{
} else {
if core.interactive()! {
execute_silent('sudo rm -rf ${res}')!
} else {
return error("can't remove ${res} as sudo because non interactive as part of cmd delete.")
}
}
}
}
}
@@ -305,7 +304,7 @@ pub fn profile_paths_preferred() ![]string {
return profile_files2
}
pub fn profile_path()! string {
pub fn profile_path() !string {
if core.is_osx()! {
return '${os.home_dir()}/.zprofile'
} else {

View File

@@ -25,10 +25,10 @@ fn (err JobError) msg() string {
if err.error_type == .args {
return 'Error in arguments:\n${err.job.cmd}'
}
mut msg := ""
if err.job.cmd.ignore_error{
mut msg := ''
if err.job.cmd.ignore_error {
return 'Ignore error for ${err.job.cmd.scriptpath}\n'
}else{
} else {
if err.error_type == .timeout {
return 'Execution failed timeout\n${err.job}'
}
@@ -150,7 +150,7 @@ pub mut:
//```
// return Job .
pub fn exec(cmd_ Command) !Job {
mut cmd:=cmd_
mut cmd := cmd_
mut job := Job{
cmd: cmd
}
@@ -169,8 +169,8 @@ pub fn exec(cmd_ Command) !Job {
os.execvp(scriptpath, [])!
return job
}
if cmd.ignore_error{
cmd.retry=0
if cmd.ignore_error {
cmd.retry = 0
}
if !cmd.async {
job.execute_retry() or {
@@ -187,7 +187,7 @@ pub fn (mut job Job) execute_retry() ! {
for x in 0 .. job.cmd.retry + 1 {
job.execute() or {
if x == job.cmd.retry {
//println(job)
// println(job)
return err
}
}
@@ -207,25 +207,24 @@ pub fn (mut job Job) execute() ! {
job.start = time.now()
job.status = .running
job.cmd.scriptpath = cmd_to_script_path(job.cmd)!
if job.cmd.debug{
if job.cmd.debug {
console.print_debug(job)
}
if job.cmd.debug{
console.print_debug(" - process execute ${job.cmd.scriptpath}")
}
if job.cmd.debug {
console.print_debug(' - process execute ${job.cmd.scriptpath}')
}
mut p := os.new_process(job.cmd.scriptpath)
if job.cmd.work_folder.len > 0 {
p.set_work_folder(job.cmd.work_folder)
}
if job.cmd.environment.len > 0 {
if job.cmd.debug{
console.print_debug(" - process setargs ${job.cmd.environment}")
}
if job.cmd.debug {
console.print_debug(' - process setargs ${job.cmd.environment}')
}
p.set_environment(job.cmd.environment)
}
p.set_redirect_stdio()
@@ -236,7 +235,7 @@ pub fn (mut job Job) execute() ! {
p.run()
job.process = p
//initial check, no point reading the output if we can't get the process starting
// initial check, no point reading the output if we can't get the process starting
// NOT OK TO DO BECAUSE IF PROCESS FINISHED WITHOUT ISSUE THEN NOT OK
// if ! p.is_alive() {
// if job.cmd.debug{
@@ -290,8 +289,8 @@ pub fn (mut job Job) process() ! {
// result=job.read()!
if time.now().unix() > job.start.unix() + job.cmd.timeout * 1000 {
// console.print_stderr("TIMEOUT TIMEOUT TIMEOUT TIMEOUT")
if job.cmd.debug{
console.print_stderr("***TIMEOUT TIMEOUT TIMEOUT TIMEOUT***")
if job.cmd.debug {
console.print_stderr('***TIMEOUT TIMEOUT TIMEOUT TIMEOUT***')
}
p.signal_pgkill()
p.close()
@@ -306,14 +305,14 @@ pub fn (mut job Job) process() ! {
}
}
} else {
if ! job.cmd.ignore_error && job.cmd.debug{
if !job.cmd.ignore_error && job.cmd.debug {
console.print_stderr(" - process stopped (don't know if error)")
}
job.read()!
job.read()!
job.status = .done
if p.code > 0 {
if job.cmd.debug{
if job.cmd.debug {
console.print_stderr(' ########## Process result code is > 0: ${p.code}')
}
job.exit_code = p.code
@@ -396,11 +395,11 @@ pub fn (mut job Job) close() ! {
os.rm(job.cmd.scriptpath)!
}
if job.cmd.ignore_error{
if job.cmd.ignore_error {
job.status = .done
return
}
if job.cmd.raise_error && job.exit_code > 0 {
if job.cmd.raise_error && job.exit_code > 0 {
return JobError{
job: job
error_type: .exec
@@ -449,7 +448,7 @@ pub fn cmd_exists(cmd string) bool {
}
pub fn cmd_exists_profile(cmd string) bool {
cmd1 := '${profile_path_source_and() or {panic(err)}} which ${cmd}'
cmd1 := '${profile_path_source_and() or { panic(err) }} which ${cmd}'
res := os.execute(cmd1)
if res.exit_code > 0 {
return false

View File

@@ -39,42 +39,39 @@ pub fn dir_reset(path string) ! {
// can be \n or , separated
pub fn rm(todelete_ string) ! {
for mut item in texttools.to_array(todelete_) {
if item.trim_space() == ''|| item.trim_space().starts_with("#"){
if item.trim_space() == '' || item.trim_space().starts_with('#') {
continue
}
if item.len <2{
return error("not allowed to remove anything with less than 2 chars. ${item}")
if item.len < 2 {
return error('not allowed to remove anything with less than 2 chars. ${item}')
}
item = item.replace('~', os.home_dir())
console.print_debug(' - rm: ${item}')
if item.starts_with('/') {
if os.exists(item) {
if os.is_dir(item) {
if core.sudo_path_ok(item)!{
//console.print_debug("rm deletedir: ${item}")
if core.sudo_path_ok(item)! {
// console.print_debug("rm deletedir: ${item}")
os.rmdir_all(item)!
}else{
if core.interactive()!{
execute_silent("sudo rm -rf ${item}")!
}else{
} else {
if core.interactive()! {
execute_silent('sudo rm -rf ${item}')!
} else {
return error("can't remove ${item} as sudo because non interactive")
}
}
} else {
//console.print_debug("rm delete file: ${item}")
if core.sudo_path_ok(item)!{
// console.print_debug("rm delete file: ${item}")
if core.sudo_path_ok(item)! {
os.rm(item)!
}else{
if core.interactive()!{
execute_silent("sudo rm -f ${item}")!
}else{
} else {
if core.interactive()! {
execute_silent('sudo rm -f ${item}')!
} else {
return error("can't remove ${item} as sudo because non interactive")
}
}
}
}
}
} else {

View File

@@ -102,7 +102,6 @@ pub fn package_install(name_ string) ! {
}
}
// remove a package using the right commands per platform
pub fn package_remove(name_ string) ! {
names := texttools.to_array(name_)

View File

@@ -1,4 +1,5 @@
module osal
import freeflowuniverse.herolib.core
fn test_package_management() {

View File

@@ -1,6 +1,6 @@
module docker
import freeflowuniverse.herolib.osal {exec}
import freeflowuniverse.herolib.osal { exec }
import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.virt.utils
import freeflowuniverse.herolib.core

View File

@@ -226,7 +226,7 @@ pub fn (mut h HetznerManager) server_reset(args ServerRebootArgs) !ResetInfo {
if serveractive {
for {
console.print_debug('wait for server ${serverinfo.server_name} to go down.')
if osal.ping(address: serverinfo.server_ip)!= .ok {
if osal.ping(address: serverinfo.server_ip) != .ok {
console.print_debug('server ${serverinfo.server_name} is now down, now waitig for reboot.')
break
}