feat: add screen installer

- Add a new screen installer to the project.
This commit is contained in:
Mahmoud Emad
2025-02-13 13:01:48 +00:00
parent 8abf113715
commit 9a4a39b19a
5 changed files with 81 additions and 77 deletions

View File

@@ -0,0 +1,8 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.installers.infra.screen as screen_installer
mut screen := screen_installer.get()!
screen.install()!
screen.destroy()!

View File

@@ -5,8 +5,6 @@ import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.installers.ulist
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('screen --version')
@@ -24,8 +22,7 @@ fn ulist_get() !ulist.UList {
}
// uploads to S3 server if configured
fn upload() ! {
}
fn upload() ! {}
fn install() ! {
console.print_header('install screen')

View File

@@ -1,124 +1,109 @@
module screen
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.data.paramsparser
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit
import time
__global (
screen_global map[string]&Screen
screen_default string
screen_global map[string]&Screen
screen_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet{
pub struct ArgsGet {
pub mut:
name string
name string
}
pub fn get(args_ ArgsGet) !&Screen {
return &Screen{}
pub fn get(args_ ArgsGet) !&Screen {
return &Screen{}
}
@[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 args := args_
mut args:=args_
mut plbook := args.plbook or {
playbook.new(text: args.heroscript)!
}
mut other_actions := plbook.find(filter: 'screen.')!
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 screen.destroy")
destroy()!
}
if other_action.name == "install"{
console.print_debug("install action screen.install")
install()!
}
}
}
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
mut other_actions := plbook.find(filter: 'screen.')!
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 screen.destroy')
destroy()!
}
if other_action.name == 'install' {
console.print_debug('install action screen.install')
install()!
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
// unknown
// screen
// zinit
// tmux
// systemd
match cat{
.zinit{
console.print_debug("startupmanager: zinit")
return startupmanager.get(cat:.zinit)!
}
.systemd{
console.print_debug("startupmanager: systemd")
return startupmanager.get(cat:.systemd)!
}else{
console.print_debug("startupmanager: auto")
return startupmanager.get()!
}
}
// 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 Screen) install(args InstallArgs) ! {
switch(self.name)
if args.reset || (!installed()!) {
install()!
}
switch(self.name)
if args.reset || (!installed()!) {
install()!
}
}
pub fn (mut self Screen) destroy() ! {
switch(self.name)
destroy()!
switch(self.name)
destroy()!
}
//switch instance to be used for screen
// switch instance to be used for screen
pub fn switch(name string) {
screen_default = name
screen_default = name
}
//helpers
// helpers
@[params]
pub struct DefaultConfigArgs{
instance string = 'default'
pub struct DefaultConfigArgs {
instance string = 'default'
}

View File

@@ -1,5 +1,7 @@
module screen
import freeflowuniverse.herolib.data.encoderhero
const singleton = false
const default = true
@@ -10,6 +12,7 @@ pub mut:
name string = 'default'
}
// your checking & initialization code if needed
fn obj_init(obj_ Screen) !Screen {
// never call get here, only thing we can do here is work on object itself
mut obj := obj_
@@ -20,3 +23,14 @@ fn obj_init(obj_ Screen) !Screen {
fn configure() ! {
// mut installer := get()!
}
/////////////NORMALLY NO NEED TO TOUCH
pub fn heroscript_dumps(obj Screen) !string {
return encoderhero.encode[Screen](obj)!
}
pub fn heroscript_loads(heroscript string) !Screen {
mut obj := encoderhero.decode[Screen](heroscript)!
return obj
}