had to cleanup a lot in relation to optional returns
This commit is contained in:
@@ -8,7 +8,7 @@ import os
|
||||
// checks if a certain version or above is installed
|
||||
fn installed_() !bool {
|
||||
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||
// res := os.execute('${osal.profile_path_source_and()} caddy version')
|
||||
// res := os.execute('${osal.profile_path_source_and()!} caddy version')
|
||||
// if res.exit_code != 0 {
|
||||
// return false
|
||||
// }
|
||||
@@ -28,13 +28,13 @@ fn install_() ! {
|
||||
mut cfg := get()!
|
||||
|
||||
mut url := ''
|
||||
if osal.is_linux_arm() {
|
||||
if core.is_linux_arm()! {
|
||||
url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_linux_arm64.tar.gz'
|
||||
} else if osal.is_linux_intel() {
|
||||
} else if core.is_linux_intel()! {
|
||||
url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_linux_amd64.tar.gz'
|
||||
} else if osal.is_osx_arm() {
|
||||
} else if core.is_osx_arm()! {
|
||||
url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_mac_arm64.tar.gz'
|
||||
} else if osal.is_osx_intel() {
|
||||
} else if core.is_osx_intel()! {
|
||||
url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_mac_amd64.tar.gz'
|
||||
} else {
|
||||
return error('unsported platform')
|
||||
@@ -58,7 +58,7 @@ fn install_() ! {
|
||||
|
||||
// Define the xcaddy command to build Caddy with plugins
|
||||
path := '/tmp/caddyserver/caddy'
|
||||
cmd := 'source ${osal.profile_path()} && xcaddy build v${caddy_version} ${plugins_str} --output ${path}'
|
||||
cmd := 'source ${osal.profile_path()!} && xcaddy build v${caddy_version} ${plugins_str} --output ${path}'
|
||||
osal.exec(cmd: cmd)!
|
||||
osal.cmd_add(
|
||||
cmdname: 'caddy'
|
||||
|
||||
@@ -1,271 +1,255 @@
|
||||
|
||||
module caddy
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.data.encoderhero
|
||||
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import time
|
||||
|
||||
__global (
|
||||
caddy_global map[string]&CaddyServer
|
||||
caddy_default string
|
||||
caddy_global map[string]&CaddyServer
|
||||
caddy_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string
|
||||
|
||||
|
||||
|
||||
//set the model in mem and the config on the filesystem
|
||||
pub fn set(o CaddyServer)! {
|
||||
mut o2:=obj_init(o)!
|
||||
caddy_global[o.name] = &o2
|
||||
caddy_default = o.name
|
||||
}
|
||||
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut model := args_
|
||||
if model.name == '' {
|
||||
model.name = caddy_default
|
||||
}
|
||||
if model.name == '' {
|
||||
model.name = 'default'
|
||||
}
|
||||
return model
|
||||
//check we find the config on the filesystem
|
||||
pub fn exists(args_ ArgsGet) bool {
|
||||
mut model := args_get(args_)
|
||||
mut context:=base.context() or { panic("bug") }
|
||||
return context.hero_config_exists("caddy",model.name)
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&CaddyServer {
|
||||
mut model := args_get(args_)
|
||||
if model.name !in caddy_global {
|
||||
if model.name == 'default' {
|
||||
if !config_exists(model) {
|
||||
if default {
|
||||
config_save(model)!
|
||||
}
|
||||
}
|
||||
config_load(model)!
|
||||
}
|
||||
}
|
||||
return caddy_global[model.name] or {
|
||||
println(caddy_global)
|
||||
panic('could not get config for caddy with name:${model.name}')
|
||||
}
|
||||
//load the config error if it doesn't exist
|
||||
pub fn load(args_ ArgsGet) ! {
|
||||
mut model := args_get(args_)
|
||||
mut context:=base.context()!
|
||||
mut heroscript := context.hero_config_get("caddy",model.name)!
|
||||
play(heroscript:heroscript)!
|
||||
}
|
||||
|
||||
fn config_exists(args_ ArgsGet) bool {
|
||||
mut model := args_get(args_)
|
||||
mut context := base.context() or { panic('bug') }
|
||||
return context.hero_config_exists('caddy', model.name)
|
||||
}
|
||||
|
||||
fn config_load(args_ ArgsGet) ! {
|
||||
mut model := args_get(args_)
|
||||
mut context := base.context()!
|
||||
mut heroscript := context.hero_config_get('caddy', model.name)!
|
||||
play(heroscript: heroscript)!
|
||||
}
|
||||
|
||||
fn config_save(args_ ArgsGet) ! {
|
||||
mut model := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_set('caddy', model.name, heroscript_default()!)!
|
||||
}
|
||||
|
||||
fn set(o CaddyServer) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
caddy_global[o.name] = &o2
|
||||
caddy_default = o.name
|
||||
//save the config to the filesystem in the context
|
||||
pub fn save(o CaddyServer)! {
|
||||
mut context:=base.context()!
|
||||
heroscript := encoderhero.encode[CaddyServer](o)!
|
||||
context.hero_config_set("caddy",model.name,heroscript)!
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct PlayArgs {
|
||||
pub mut:
|
||||
heroscript string // if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
heroscript string //if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn play(args_ PlayArgs) ! {
|
||||
mut model := args_
|
||||
|
||||
mut model:=args_
|
||||
|
||||
if model.heroscript == '' {
|
||||
model.heroscript = heroscript_default()!
|
||||
}
|
||||
mut plbook := model.plbook or { playbook.new(text: model.heroscript)! }
|
||||
if model.heroscript == "" {
|
||||
model.heroscript = heroscript_default()!
|
||||
}
|
||||
mut plbook := model.plbook or {
|
||||
playbook.new(text: model.heroscript)!
|
||||
}
|
||||
|
||||
mut configure_actions := plbook.find(filter: 'caddy.configure')!
|
||||
if configure_actions.len > 0 {
|
||||
for config_action in configure_actions {
|
||||
mut p := config_action.params
|
||||
mycfg:=cfg_play(p)!
|
||||
console.print_debug("install action caddy.configure\n${mycfg}")
|
||||
set(mycfg)!
|
||||
save(mycfg)!
|
||||
}
|
||||
}
|
||||
|
||||
mut install_actions := plbook.find(filter: 'caddy.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
mut p := install_action.params
|
||||
mycfg := cfg_play(p)!
|
||||
console.print_debug('install action caddy.configure\n${mycfg}')
|
||||
set(mycfg)!
|
||||
}
|
||||
}
|
||||
mut other_actions := plbook.find(filter: 'caddy.')!
|
||||
for other_action in other_actions {
|
||||
if other_action.name in ["destroy","install","build"]{
|
||||
mut p := other_action.params
|
||||
reset:=p.get_default_false("reset")
|
||||
if other_action.name == "destroy" || reset{
|
||||
console.print_debug("install action caddy.destroy")
|
||||
destroy_()!
|
||||
}
|
||||
if other_action.name == "install"{
|
||||
console.print_debug("install action caddy.install")
|
||||
install_()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ["start","stop","restart"]{
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut caddy_obj:=get(name:name)!
|
||||
console.print_debug("action object:\n${caddy_obj}")
|
||||
if other_action.name == "start"{
|
||||
console.print_debug("install action caddy.${other_action.name}")
|
||||
caddy_obj.start()!
|
||||
}
|
||||
|
||||
mut other_actions := plbook.find(filter: 'caddy.')!
|
||||
for other_action in other_actions {
|
||||
if other_action.name in ['destroy', 'install', 'build'] {
|
||||
mut p := other_action.params
|
||||
reset := p.get_default_false('reset')
|
||||
if other_action.name == 'destroy' || reset {
|
||||
console.print_debug('install action caddy.destroy')
|
||||
destroy()!
|
||||
}
|
||||
if other_action.name == 'install' {
|
||||
console.print_debug('install action caddy.install')
|
||||
install()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ['start', 'stop', 'restart'] {
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut caddy_obj := get(name: name)!
|
||||
console.print_debug('action object:\n${caddy_obj}')
|
||||
if other_action.name == 'start' {
|
||||
console.print_debug('install action caddy.${other_action.name}')
|
||||
caddy_obj.start()!
|
||||
}
|
||||
if other_action.name == "stop"{
|
||||
console.print_debug("install action caddy.${other_action.name}")
|
||||
caddy_obj.stop()!
|
||||
}
|
||||
if other_action.name == "restart"{
|
||||
console.print_debug("install action caddy.${other_action.name}")
|
||||
caddy_obj.restart()!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if other_action.name == 'stop' {
|
||||
console.print_debug('install action caddy.${other_action.name}')
|
||||
caddy_obj.stop()!
|
||||
}
|
||||
if other_action.name == 'restart' {
|
||||
console.print_debug('install action caddy.${other_action.name}')
|
||||
caddy_obj.restart()!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||
// unknown
|
||||
// screen
|
||||
// zinit
|
||||
// tmux
|
||||
// systemd
|
||||
match cat {
|
||||
.zinit {
|
||||
console.print_debug('startupmanager: zinit')
|
||||
return startupmanager.get(cat: .zinit)!
|
||||
}
|
||||
.systemd {
|
||||
console.print_debug('startupmanager: systemd')
|
||||
return startupmanager.get(cat: .systemd)!
|
||||
}
|
||||
else {
|
||||
console.print_debug('startupmanager: auto')
|
||||
return startupmanager.get()!
|
||||
}
|
||||
}
|
||||
|
||||
//load from disk and make sure is properly intialized
|
||||
pub fn (mut self CaddyServer) reload() ! {
|
||||
switch(self.name)
|
||||
self=obj_init(self)!
|
||||
}
|
||||
|
||||
// load from disk and make sure is properly intialized
|
||||
pub fn (mut self CaddyServer) reload() ! {
|
||||
switch(self.name)
|
||||
self = obj_init(self)!
|
||||
|
||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||
// unknown
|
||||
// screen
|
||||
// zinit
|
||||
// tmux
|
||||
// systemd
|
||||
match cat{
|
||||
.zinit{
|
||||
console.print_debug("startupmanager: zinit")
|
||||
return startupmanager.get(cat:.zinit)!
|
||||
}
|
||||
.systemd{
|
||||
console.print_debug("startupmanager: systemd")
|
||||
return startupmanager.get(cat:.systemd)!
|
||||
}else{
|
||||
console.print_debug("startupmanager: auto")
|
||||
return startupmanager.get()!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self CaddyServer) start() ! {
|
||||
switch(self.name)
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
switch(self.name)
|
||||
if self.running()!{
|
||||
return
|
||||
}
|
||||
|
||||
console.print_header('caddy start')
|
||||
console.print_header('caddy start')
|
||||
|
||||
if !installed()! {
|
||||
install()!
|
||||
}
|
||||
if ! installed_()!{
|
||||
install_()!
|
||||
}
|
||||
|
||||
configure()!
|
||||
configure()!
|
||||
|
||||
start_pre()!
|
||||
start_pre()!
|
||||
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
for zprocess in startupcmd()!{
|
||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||
|
||||
console.print_debug('starting caddy with ${zprocess.startuptype}...')
|
||||
console.print_debug('starting caddy with ${zprocess.startuptype}...')
|
||||
|
||||
sm.new(zprocess)!
|
||||
sm.new(zprocess)!
|
||||
|
||||
sm.start(zprocess.name)!
|
||||
}
|
||||
sm.start(zprocess.name)!
|
||||
}
|
||||
|
||||
start_post()!
|
||||
start_post()!
|
||||
|
||||
for _ in 0 .. 50 {
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
time.sleep(100 * time.millisecond)
|
||||
}
|
||||
return error('caddy did not install properly.')
|
||||
|
||||
for _ in 0 .. 50 {
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
time.sleep(100 * time.millisecond)
|
||||
}
|
||||
return error('caddy did not install properly.')
|
||||
}
|
||||
|
||||
pub fn (mut self CaddyServer) install_start(model InstallArgs) ! {
|
||||
switch(self.name)
|
||||
self.install(model)!
|
||||
self.start()!
|
||||
switch(self.name)
|
||||
self.install(model)!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self CaddyServer) stop() ! {
|
||||
switch(self.name)
|
||||
stop_pre()!
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
sm.stop(zprocess.name)!
|
||||
}
|
||||
stop_post()!
|
||||
switch(self.name)
|
||||
stop_pre()!
|
||||
for zprocess in startupcmd()!{
|
||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||
sm.stop(zprocess.name)!
|
||||
}
|
||||
stop_post()!
|
||||
}
|
||||
|
||||
pub fn (mut self CaddyServer) restart() ! {
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self CaddyServer) running() !bool {
|
||||
switch(self.name)
|
||||
switch(self.name)
|
||||
|
||||
// walk over the generic processes, if not running return
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
r := sm.running(zprocess.name)!
|
||||
if r == false {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return running()!
|
||||
//walk over the generic processes, if not running return
|
||||
for zprocess in startupcmd()!{
|
||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||
r:=sm.running(zprocess.name)!
|
||||
if r==false{
|
||||
return false
|
||||
}
|
||||
}
|
||||
return running()!
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub struct InstallArgs{
|
||||
pub mut:
|
||||
reset bool
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self CaddyServer) install(model InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if model.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
|
||||
pub fn install(args InstallArgs) ! {
|
||||
if args.reset {
|
||||
destroy()!
|
||||
}
|
||||
if ! (installed_()!){
|
||||
install_()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self CaddyServer) build() ! {
|
||||
switch(self.name)
|
||||
build()!
|
||||
pub fn destroy() ! {
|
||||
destroy_()!
|
||||
}
|
||||
|
||||
pub fn (mut self CaddyServer) destroy() ! {
|
||||
switch(self.name)
|
||||
self.stop() or {}
|
||||
destroy()!
|
||||
pub fn build() ! {
|
||||
build_()!
|
||||
}
|
||||
|
||||
// switch instance to be used for caddy
|
||||
pub fn switch(name string) {
|
||||
caddy_default = name
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ pub const version = '2.8.4'
|
||||
// }
|
||||
|
||||
pub fn is_installed(version string) !bool {
|
||||
res := os.execute('${osal.profile_path_source_and()} caddy version')
|
||||
res := os.execute('${osal.profile_path_source_and()!} caddy version')
|
||||
if res.exit_code == 0 {
|
||||
mut r := res.output.split_into_lines().filter(it.trim_space().len > 0)
|
||||
if r.len > 1 {
|
||||
@@ -75,13 +75,13 @@ pub fn is_installed(version string) !bool {
|
||||
pub fn install_caddy_from_release() ! {
|
||||
version := '2.8.4'
|
||||
mut url := ''
|
||||
if osal.is_linux_arm() {
|
||||
if core.is_linux_arm()! {
|
||||
url = 'https://github.com/caddyserver/caddy/releases/download/v${version}/caddy_${version}_linux_arm64.tar.gz'
|
||||
} else if osal.is_linux_intel() {
|
||||
} else if core.is_linux_intel()! {
|
||||
url = 'https://github.com/caddyserver/caddy/releases/download/v${version}/caddy_${version}_linux_amd64.tar.gz'
|
||||
} else if osal.is_osx_arm() {
|
||||
} else if core.is_osx_arm()! {
|
||||
url = 'https://github.com/caddyserver/caddy/releases/download/v${version}/caddy_${version}_darwin_arm64.tar.gz'
|
||||
} else if osal.is_osx_intel() {
|
||||
} else if core.is_osx_intel()! {
|
||||
url = 'https://github.com/caddyserver/caddy/releases/download/v${version}/caddy_${version}_darwin_amd64.tar.gz'
|
||||
} else {
|
||||
return error('unsported platform')
|
||||
@@ -136,13 +136,13 @@ pub fn install_caddy_with_xcaddy(plugins []string) ! {
|
||||
|
||||
console.print_header('Installing xcaddy')
|
||||
mut url := ''
|
||||
if osal.is_linux_arm() {
|
||||
if core.is_linux_arm()! {
|
||||
url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_linux_arm64.tar.gz'
|
||||
} else if osal.is_linux_intel() {
|
||||
} else if core.is_linux_intel()! {
|
||||
url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_linux_amd64.tar.gz'
|
||||
} else if osal.is_osx_arm() {
|
||||
} else if core.is_osx_arm()! {
|
||||
url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_mac_arm64.tar.gz'
|
||||
} else if osal.is_osx_intel() {
|
||||
} else if core.is_osx_intel()! {
|
||||
url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_mac_amd64.tar.gz'
|
||||
} else {
|
||||
return error('unsported platform')
|
||||
@@ -166,7 +166,7 @@ pub fn install_caddy_with_xcaddy(plugins []string) ! {
|
||||
|
||||
// Define the xcaddy command to build Caddy with plugins
|
||||
path := '/tmp/caddyserver/caddy'
|
||||
cmd := 'source ${osal.profile_path()} && xcaddy build v${caddy_version} ${plugins_str} --output ${path}'
|
||||
cmd := 'source ${osal.profile_path()!} && xcaddy build v${caddy_version} ${plugins_str} --output ${path}'
|
||||
osal.exec(cmd: cmd)!
|
||||
osal.cmd_add(
|
||||
cmdname: 'caddy'
|
||||
|
||||
@@ -5,13 +5,13 @@ import freeflowuniverse.herolib.ui.console
|
||||
|
||||
pub fn install_caddy_from_release() ! {
|
||||
mut url := ''
|
||||
if osal.is_linux_arm() {
|
||||
if core.is_linux_arm()! {
|
||||
url = 'https://github.com/caddyserver/caddy/releases/download/v${version}/caddy_${version}_linux_arm64.tar.gz'
|
||||
} else if osal.is_linux_intel() {
|
||||
} else if core.is_linux_intel()! {
|
||||
url = 'https://github.com/caddyserver/caddy/releases/download/v${version}/caddy_${version}_linux_amd64.tar.gz'
|
||||
} else if osal.is_osx_arm() {
|
||||
} else if core.is_osx_arm()! {
|
||||
url = 'https://github.com/caddyserver/caddy/releases/download/v${version}/caddy_${version}_darwin_arm64.tar.gz'
|
||||
} else if osal.is_osx_intel() {
|
||||
} else if core.is_osx_intel()! {
|
||||
url = 'https://github.com/caddyserver/caddy/releases/download/v${version}/caddy_${version}_darwin_amd64.tar.gz'
|
||||
} else {
|
||||
return error('unsported platform')
|
||||
@@ -33,13 +33,13 @@ pub fn install_caddy_from_release() ! {
|
||||
pub fn install_caddy_with_xcaddy(plugins []string) ! {
|
||||
console.print_header('Installing xcaddy')
|
||||
mut url := ''
|
||||
if osal.is_linux_arm() {
|
||||
if core.is_linux_arm()! {
|
||||
url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_linux_arm64.tar.gz'
|
||||
} else if osal.is_linux_intel() {
|
||||
} else if core.is_linux_intel()! {
|
||||
url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_linux_amd64.tar.gz'
|
||||
} else if osal.is_osx_arm() {
|
||||
} else if core.is_osx_arm()! {
|
||||
url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_mac_arm64.tar.gz'
|
||||
} else if osal.is_osx_intel() {
|
||||
} else if core.is_osx_intel()! {
|
||||
url = 'https://github.com/caddyserver/xcaddy/releases/download/v${xcaddy_version}/xcaddy_${xcaddy_version}_mac_amd64.tar.gz'
|
||||
} else {
|
||||
return error('unsported platform')
|
||||
@@ -63,7 +63,7 @@ pub fn install_caddy_with_xcaddy(plugins []string) ! {
|
||||
|
||||
// Define the xcaddy command to build Caddy with plugins
|
||||
path := '/tmp/caddyserver/caddy'
|
||||
cmd := 'source ${osal.profile_path()} && xcaddy build v${caddy_version} ${plugins_str} --output ${path}'
|
||||
cmd := 'source ${osal.profile_path()!} && xcaddy build v${caddy_version} ${plugins_str} --output ${path}'
|
||||
osal.exec(cmd: cmd)!
|
||||
osal.cmd_add(
|
||||
cmdname: 'caddy'
|
||||
|
||||
@@ -66,7 +66,7 @@ fn stop_post() ! {
|
||||
// checks if a certain version or above is installed
|
||||
fn installed_() !bool {
|
||||
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||
// res := os.execute('${osal.profile_path_source_and()} imagemagick version')
|
||||
// res := os.execute('${osal.profile_path_source_and()!} imagemagick version')
|
||||
// if res.exit_code != 0 {
|
||||
// return false
|
||||
// }
|
||||
@@ -98,13 +98,13 @@ fn install_() ! {
|
||||
console.print_header('install imagemagick')
|
||||
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||
// mut url := ''
|
||||
// if osal.is_linux_arm() {
|
||||
// if core.is_linux_arm()! {
|
||||
// url = 'https://github.com/imagemagick-dev/imagemagick/releases/download/v${version}/imagemagick_${version}_linux_arm64.tar.gz'
|
||||
// } else if osal.is_linux_intel() {
|
||||
// } else if core.is_linux_intel()! {
|
||||
// url = 'https://github.com/imagemagick-dev/imagemagick/releases/download/v${version}/imagemagick_${version}_linux_amd64.tar.gz'
|
||||
// } else if osal.is_osx_arm() {
|
||||
// } else if core.is_osx_arm()! {
|
||||
// url = 'https://github.com/imagemagick-dev/imagemagick/releases/download/v${version}/imagemagick_${version}_darwin_arm64.tar.gz'
|
||||
// } else if osal.is_osx_intel() {
|
||||
// } else if core.is_osx_intel()! {
|
||||
// url = 'https://github.com/imagemagick-dev/imagemagick/releases/download/v${version}/imagemagick_${version}_darwin_amd64.tar.gz'
|
||||
// } else {
|
||||
// return error('unsported platform')
|
||||
@@ -129,7 +129,7 @@ fn build_() ! {
|
||||
// url := 'https://github.com/threefoldtech/imagemagick'
|
||||
|
||||
// make sure we install base on the node
|
||||
// if osal.platform() != .ubuntu {
|
||||
// if core.platform()!= .ubuntu {
|
||||
// return error('only support ubuntu for now')
|
||||
// }
|
||||
// golang.install()!
|
||||
|
||||
@@ -1,153 +1,152 @@
|
||||
|
||||
module imagemagick
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import time
|
||||
|
||||
__global (
|
||||
imagemagick_global map[string]&ImageMagick
|
||||
imagemagick_default string
|
||||
imagemagick_global map[string]&ImageMagick
|
||||
imagemagick_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&ImageMagick {
|
||||
return &ImageMagick{}
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||
// unknown
|
||||
// screen
|
||||
// zinit
|
||||
// tmux
|
||||
// systemd
|
||||
match cat {
|
||||
.zinit {
|
||||
console.print_debug('startupmanager: zinit')
|
||||
return startupmanager.get(cat: .zinit)!
|
||||
}
|
||||
.systemd {
|
||||
console.print_debug('startupmanager: systemd')
|
||||
return startupmanager.get(cat: .systemd)!
|
||||
}
|
||||
else {
|
||||
console.print_debug('startupmanager: auto')
|
||||
return startupmanager.get()!
|
||||
}
|
||||
}
|
||||
// unknown
|
||||
// screen
|
||||
// zinit
|
||||
// tmux
|
||||
// systemd
|
||||
match cat{
|
||||
.zinit{
|
||||
console.print_debug("startupmanager: zinit")
|
||||
return startupmanager.get(cat:.zinit)!
|
||||
}
|
||||
.systemd{
|
||||
console.print_debug("startupmanager: systemd")
|
||||
return startupmanager.get(cat:.systemd)!
|
||||
}else{
|
||||
console.print_debug("startupmanager: auto")
|
||||
return startupmanager.get()!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self ImageMagick) start() ! {
|
||||
switch(self.name)
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
switch(self.name)
|
||||
if self.running()!{
|
||||
return
|
||||
}
|
||||
|
||||
console.print_header('imagemagick start')
|
||||
console.print_header('imagemagick start')
|
||||
|
||||
if !installed()! {
|
||||
install()!
|
||||
}
|
||||
if ! installed_()!{
|
||||
install_()!
|
||||
}
|
||||
|
||||
configure()!
|
||||
configure()!
|
||||
|
||||
start_pre()!
|
||||
start_pre()!
|
||||
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
for zprocess in startupcmd()!{
|
||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||
|
||||
console.print_debug('starting imagemagick with ${zprocess.startuptype}...')
|
||||
console.print_debug('starting imagemagick with ${zprocess.startuptype}...')
|
||||
|
||||
sm.new(zprocess)!
|
||||
sm.new(zprocess)!
|
||||
|
||||
sm.start(zprocess.name)!
|
||||
}
|
||||
sm.start(zprocess.name)!
|
||||
}
|
||||
|
||||
start_post()!
|
||||
start_post()!
|
||||
|
||||
for _ in 0 .. 50 {
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
time.sleep(100 * time.millisecond)
|
||||
}
|
||||
return error('imagemagick did not install properly.')
|
||||
|
||||
for _ in 0 .. 50 {
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
time.sleep(100 * time.millisecond)
|
||||
}
|
||||
return error('imagemagick did not install properly.')
|
||||
}
|
||||
|
||||
pub fn (mut self ImageMagick) install_start(model InstallArgs) ! {
|
||||
switch(self.name)
|
||||
self.install(model)!
|
||||
self.start()!
|
||||
switch(self.name)
|
||||
self.install(model)!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self ImageMagick) stop() ! {
|
||||
switch(self.name)
|
||||
stop_pre()!
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
sm.stop(zprocess.name)!
|
||||
}
|
||||
stop_post()!
|
||||
switch(self.name)
|
||||
stop_pre()!
|
||||
for zprocess in startupcmd()!{
|
||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||
sm.stop(zprocess.name)!
|
||||
}
|
||||
stop_post()!
|
||||
}
|
||||
|
||||
pub fn (mut self ImageMagick) restart() ! {
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self ImageMagick) running() !bool {
|
||||
switch(self.name)
|
||||
switch(self.name)
|
||||
|
||||
// walk over the generic processes, if not running return
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
r := sm.running(zprocess.name)!
|
||||
if r == false {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return running()!
|
||||
//walk over the generic processes, if not running return
|
||||
for zprocess in startupcmd()!{
|
||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||
r:=sm.running(zprocess.name)!
|
||||
if r==false{
|
||||
return false
|
||||
}
|
||||
}
|
||||
return running()!
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub struct InstallArgs{
|
||||
pub mut:
|
||||
reset bool
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self ImageMagick) install(model InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if model.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
|
||||
pub fn install(args InstallArgs) ! {
|
||||
if args.reset {
|
||||
destroy()!
|
||||
}
|
||||
if ! (installed_()!){
|
||||
install_()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self ImageMagick) build() ! {
|
||||
switch(self.name)
|
||||
build()!
|
||||
pub fn destroy() ! {
|
||||
destroy_()!
|
||||
}
|
||||
|
||||
pub fn (mut self ImageMagick) destroy() ! {
|
||||
switch(self.name)
|
||||
self.stop() or {}
|
||||
destroy()!
|
||||
pub fn build() ! {
|
||||
build_()!
|
||||
}
|
||||
|
||||
// switch instance to be used for imagemagick
|
||||
pub fn switch(name string) {
|
||||
imagemagick_default = name
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ pub fn installll(args InstallArgs) ! {
|
||||
return
|
||||
}
|
||||
|
||||
if !osal.is_linux() {
|
||||
if !core.is_linux()! {
|
||||
return error('only support linux for now')
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ fn stop_post() ! {
|
||||
// checks if a certain version or above is installed
|
||||
fn installed_() !bool {
|
||||
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||
// res := os.execute('${osal.profile_path_source_and()} lighttpd version')
|
||||
// res := os.execute('${osal.profile_path_source_and()!} lighttpd version')
|
||||
// if res.exit_code != 0 {
|
||||
// return false
|
||||
// }
|
||||
@@ -98,13 +98,13 @@ fn install_() ! {
|
||||
console.print_header('install lighttpd')
|
||||
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||
// mut url := ''
|
||||
// if osal.is_linux_arm() {
|
||||
// if core.is_linux_arm()! {
|
||||
// url = 'https://github.com/lighttpd-dev/lighttpd/releases/download/v${version}/lighttpd_${version}_linux_arm64.tar.gz'
|
||||
// } else if osal.is_linux_intel() {
|
||||
// } else if core.is_linux_intel()! {
|
||||
// url = 'https://github.com/lighttpd-dev/lighttpd/releases/download/v${version}/lighttpd_${version}_linux_amd64.tar.gz'
|
||||
// } else if osal.is_osx_arm() {
|
||||
// } else if core.is_osx_arm()! {
|
||||
// url = 'https://github.com/lighttpd-dev/lighttpd/releases/download/v${version}/lighttpd_${version}_darwin_arm64.tar.gz'
|
||||
// } else if osal.is_osx_intel() {
|
||||
// } else if core.is_osx_intel()! {
|
||||
// url = 'https://github.com/lighttpd-dev/lighttpd/releases/download/v${version}/lighttpd_${version}_darwin_amd64.tar.gz'
|
||||
// } else {
|
||||
// return error('unsported platform')
|
||||
@@ -129,7 +129,7 @@ fn build_() ! {
|
||||
// url := 'https://github.com/threefoldtech/lighttpd'
|
||||
|
||||
// make sure we install base on the node
|
||||
// if osal.platform() != .ubuntu {
|
||||
// if core.platform()!= .ubuntu {
|
||||
// return error('only support ubuntu for now')
|
||||
// }
|
||||
// golang.install()!
|
||||
|
||||
@@ -1,153 +1,152 @@
|
||||
|
||||
module lighttpd
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import time
|
||||
|
||||
__global (
|
||||
lighttpd_global map[string]&LightHttpdInstaller
|
||||
lighttpd_default string
|
||||
lighttpd_global map[string]&LightHttpdInstaller
|
||||
lighttpd_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&LightHttpdInstaller {
|
||||
return &LightHttpdInstaller{}
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||
// unknown
|
||||
// screen
|
||||
// zinit
|
||||
// tmux
|
||||
// systemd
|
||||
match cat {
|
||||
.zinit {
|
||||
console.print_debug('startupmanager: zinit')
|
||||
return startupmanager.get(cat: .zinit)!
|
||||
}
|
||||
.systemd {
|
||||
console.print_debug('startupmanager: systemd')
|
||||
return startupmanager.get(cat: .systemd)!
|
||||
}
|
||||
else {
|
||||
console.print_debug('startupmanager: auto')
|
||||
return startupmanager.get()!
|
||||
}
|
||||
}
|
||||
// unknown
|
||||
// screen
|
||||
// zinit
|
||||
// tmux
|
||||
// systemd
|
||||
match cat{
|
||||
.zinit{
|
||||
console.print_debug("startupmanager: zinit")
|
||||
return startupmanager.get(cat:.zinit)!
|
||||
}
|
||||
.systemd{
|
||||
console.print_debug("startupmanager: systemd")
|
||||
return startupmanager.get(cat:.systemd)!
|
||||
}else{
|
||||
console.print_debug("startupmanager: auto")
|
||||
return startupmanager.get()!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self LightHttpdInstaller) start() ! {
|
||||
switch(self.name)
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
switch(self.name)
|
||||
if self.running()!{
|
||||
return
|
||||
}
|
||||
|
||||
console.print_header('lighttpd start')
|
||||
console.print_header('lighttpd start')
|
||||
|
||||
if !installed()! {
|
||||
install()!
|
||||
}
|
||||
if ! installed_()!{
|
||||
install_()!
|
||||
}
|
||||
|
||||
configure()!
|
||||
configure()!
|
||||
|
||||
start_pre()!
|
||||
start_pre()!
|
||||
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
for zprocess in startupcmd()!{
|
||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||
|
||||
console.print_debug('starting lighttpd with ${zprocess.startuptype}...')
|
||||
console.print_debug('starting lighttpd with ${zprocess.startuptype}...')
|
||||
|
||||
sm.new(zprocess)!
|
||||
sm.new(zprocess)!
|
||||
|
||||
sm.start(zprocess.name)!
|
||||
}
|
||||
sm.start(zprocess.name)!
|
||||
}
|
||||
|
||||
start_post()!
|
||||
start_post()!
|
||||
|
||||
for _ in 0 .. 50 {
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
time.sleep(100 * time.millisecond)
|
||||
}
|
||||
return error('lighttpd did not install properly.')
|
||||
|
||||
for _ in 0 .. 50 {
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
time.sleep(100 * time.millisecond)
|
||||
}
|
||||
return error('lighttpd did not install properly.')
|
||||
}
|
||||
|
||||
pub fn (mut self LightHttpdInstaller) install_start(model InstallArgs) ! {
|
||||
switch(self.name)
|
||||
self.install(model)!
|
||||
self.start()!
|
||||
switch(self.name)
|
||||
self.install(model)!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self LightHttpdInstaller) stop() ! {
|
||||
switch(self.name)
|
||||
stop_pre()!
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
sm.stop(zprocess.name)!
|
||||
}
|
||||
stop_post()!
|
||||
switch(self.name)
|
||||
stop_pre()!
|
||||
for zprocess in startupcmd()!{
|
||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||
sm.stop(zprocess.name)!
|
||||
}
|
||||
stop_post()!
|
||||
}
|
||||
|
||||
pub fn (mut self LightHttpdInstaller) restart() ! {
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self LightHttpdInstaller) running() !bool {
|
||||
switch(self.name)
|
||||
switch(self.name)
|
||||
|
||||
// walk over the generic processes, if not running return
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
r := sm.running(zprocess.name)!
|
||||
if r == false {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return running()!
|
||||
//walk over the generic processes, if not running return
|
||||
for zprocess in startupcmd()!{
|
||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||
r:=sm.running(zprocess.name)!
|
||||
if r==false{
|
||||
return false
|
||||
}
|
||||
}
|
||||
return running()!
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub struct InstallArgs{
|
||||
pub mut:
|
||||
reset bool
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self LightHttpdInstaller) install(model InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if model.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
|
||||
pub fn install(args InstallArgs) ! {
|
||||
if args.reset {
|
||||
destroy()!
|
||||
}
|
||||
if ! (installed_()!){
|
||||
install_()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self LightHttpdInstaller) build() ! {
|
||||
switch(self.name)
|
||||
build()!
|
||||
pub fn destroy() ! {
|
||||
destroy_()!
|
||||
}
|
||||
|
||||
pub fn (mut self LightHttpdInstaller) destroy() ! {
|
||||
switch(self.name)
|
||||
self.stop() or {}
|
||||
destroy()!
|
||||
pub fn build() ! {
|
||||
build_()!
|
||||
}
|
||||
|
||||
// switch instance to be used for lighttpd
|
||||
pub fn switch(name string) {
|
||||
lighttpd_default = name
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -30,13 +30,13 @@ pub fn install_() ! {
|
||||
console.print_header('install tailwind')
|
||||
|
||||
mut url := ''
|
||||
if osal.is_linux_arm() {
|
||||
if core.is_linux_arm()! {
|
||||
url = 'https://github.com/tailwindlabs/tailwindcss/releases/download/v${version}/tailwindcss-linux-arm64'
|
||||
} else if osal.is_linux_intel() {
|
||||
} else if core.is_linux_intel()! {
|
||||
url = 'https://github.com/tailwindlabs/tailwindcss/releases/download/v${version}/tailwindcss-linux-x64'
|
||||
} else if osal.is_osx_arm() {
|
||||
} else if core.is_osx_arm()! {
|
||||
url = 'https://github.com/tailwindlabs/tailwindcss/releases/download/v${version}/tailwindcss-macos-arm64'
|
||||
} else if osal.is_osx_intel() {
|
||||
} else if core.is_osx_intel()! {
|
||||
url = 'https://github.com/tailwindlabs/tailwindcss/releases/download/v${version}/tailwindcss-macos-x64'
|
||||
} else {
|
||||
return error('unsported platform')
|
||||
|
||||
@@ -1,74 +1,98 @@
|
||||
|
||||
module tailwind
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import time
|
||||
|
||||
__global (
|
||||
tailwind_global map[string]&Tailwind
|
||||
tailwind_default string
|
||||
tailwind_global map[string]&Tailwind
|
||||
tailwind_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub struct ArgsGet{
|
||||
pub mut:
|
||||
name string
|
||||
name string
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&Tailwind {
|
||||
return &Tailwind{}
|
||||
fn args_get (args_ ArgsGet) ArgsGet {
|
||||
mut model:=args_
|
||||
if model.name == ""{
|
||||
model.name = tailwind_default
|
||||
}
|
||||
if model.name == ""{
|
||||
model.name = "default"
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&Tailwind {
|
||||
mut args := args_get(args_)
|
||||
if !(args.name in tailwind_global) {
|
||||
if args.name=="default"{
|
||||
if ! config_exists(args){
|
||||
if default{
|
||||
mut context:=base.context() or { panic("bug") }
|
||||
context.hero_config_set("tailwind",model.name,heroscript_default()!)!
|
||||
}
|
||||
}
|
||||
load(args)!
|
||||
}
|
||||
}
|
||||
return tailwind_global[args.name] or {
|
||||
println(tailwind_global)
|
||||
panic("could not get config for ${args.name} with name:${model.name}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||
// unknown
|
||||
// screen
|
||||
// zinit
|
||||
// tmux
|
||||
// systemd
|
||||
match cat {
|
||||
.zinit {
|
||||
console.print_debug('startupmanager: zinit')
|
||||
return startupmanager.get(cat: .zinit)!
|
||||
}
|
||||
.systemd {
|
||||
console.print_debug('startupmanager: systemd')
|
||||
return startupmanager.get(cat: .systemd)!
|
||||
}
|
||||
else {
|
||||
console.print_debug('startupmanager: auto')
|
||||
return startupmanager.get()!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub struct InstallArgs{
|
||||
pub mut:
|
||||
reset bool
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self Tailwind) install(model InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if model.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
|
||||
//switch instance to be used for tailwind
|
||||
pub fn switch(name string) {
|
||||
tailwind_default = name
|
||||
}
|
||||
|
||||
|
||||
pub fn (mut self Tailwind) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset {
|
||||
destroy_()!
|
||||
}
|
||||
if ! (installed_()!){
|
||||
install_()!
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn (mut self Tailwind) destroy() ! {
|
||||
switch(self.name)
|
||||
destroy()!
|
||||
switch(self.name)
|
||||
destroy_()!
|
||||
}
|
||||
|
||||
// switch instance to be used for tailwind
|
||||
pub fn switch(name string) {
|
||||
tailwind_default = name
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ pub const version = '0.18.0'
|
||||
|
||||
// checks if a certain version or above is installed
|
||||
fn installed_() !bool {
|
||||
res := os.execute('${osal.profile_path_source_and()} zola -V')
|
||||
res := os.execute('${osal.profile_path_source_and()!} zola -V')
|
||||
myversion := res.output.all_after(' ')
|
||||
if res.exit_code == 0 {
|
||||
v := texttools.version(myversion)
|
||||
@@ -34,11 +34,11 @@ fn install_() ! {
|
||||
tw.install()!
|
||||
|
||||
mut url := ''
|
||||
if osal.is_linux() {
|
||||
if core.is_linux()! {
|
||||
url = 'https://github.com/getzola/zola/releases/download/v${version}/zola-v${version}-x86_64-unknown-linux-gnu.tar.gz'
|
||||
} else if osal.is_osx_arm() {
|
||||
} else if core.is_osx_arm()! {
|
||||
url = 'https://github.com/getzola/zola/releases/download/v${version}/zola-v${version}-aarch64-apple-darwin.tar.gz'
|
||||
} else if osal.is_osx_intel() {
|
||||
} else if core.is_osx_intel()! {
|
||||
url = 'https://github.com/getzola/zola/releases/download/v${version}/zola-v${version}-x86_64-apple-darwin.tar.gz'
|
||||
} else {
|
||||
return error('unsupported platform')
|
||||
|
||||
@@ -1,79 +1,102 @@
|
||||
|
||||
module zola
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import time
|
||||
|
||||
__global (
|
||||
zola_global map[string]&ZolaInstaller
|
||||
zola_default string
|
||||
zola_global map[string]&ZolaInstaller
|
||||
zola_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub struct ArgsGet{
|
||||
pub mut:
|
||||
name string
|
||||
name string
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&ZolaInstaller {
|
||||
return &ZolaInstaller{}
|
||||
fn args_get (args_ ArgsGet) ArgsGet {
|
||||
mut model:=args_
|
||||
if model.name == ""{
|
||||
model.name = zola_default
|
||||
}
|
||||
if model.name == ""{
|
||||
model.name = "default"
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&ZolaInstaller {
|
||||
mut args := args_get(args_)
|
||||
if !(args.name in zola_global) {
|
||||
if args.name=="default"{
|
||||
if ! config_exists(args){
|
||||
if default{
|
||||
mut context:=base.context() or { panic("bug") }
|
||||
context.hero_config_set("zola",model.name,heroscript_default()!)!
|
||||
}
|
||||
}
|
||||
load(args)!
|
||||
}
|
||||
}
|
||||
return zola_global[args.name] or {
|
||||
println(zola_global)
|
||||
panic("could not get config for ${args.name} with name:${model.name}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||
// unknown
|
||||
// screen
|
||||
// zinit
|
||||
// tmux
|
||||
// systemd
|
||||
match cat {
|
||||
.zinit {
|
||||
console.print_debug('startupmanager: zinit')
|
||||
return startupmanager.get(cat: .zinit)!
|
||||
}
|
||||
.systemd {
|
||||
console.print_debug('startupmanager: systemd')
|
||||
return startupmanager.get(cat: .systemd)!
|
||||
}
|
||||
else {
|
||||
console.print_debug('startupmanager: auto')
|
||||
return startupmanager.get()!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub struct InstallArgs{
|
||||
pub mut:
|
||||
reset bool
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self ZolaInstaller) install(model InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if model.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
|
||||
//switch instance to be used for zola
|
||||
pub fn switch(name string) {
|
||||
zola_default = name
|
||||
}
|
||||
|
||||
|
||||
pub fn (mut self ZolaInstaller) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset {
|
||||
destroy_()!
|
||||
}
|
||||
if ! (installed_()!){
|
||||
install_()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self ZolaInstaller) build() ! {
|
||||
switch(self.name)
|
||||
build()!
|
||||
switch(self.name)
|
||||
build_()!
|
||||
}
|
||||
|
||||
pub fn (mut self ZolaInstaller) destroy() ! {
|
||||
switch(self.name)
|
||||
destroy()!
|
||||
switch(self.name)
|
||||
destroy_()!
|
||||
}
|
||||
|
||||
// switch instance to be used for zola
|
||||
pub fn switch(name string) {
|
||||
zola_default = name
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user