feat: Add screen installer
- Add a new installer for the `screen` utility. - This installer supports Ubuntu and macOS. - Includes functionality for installation, uninstallation, and status checking. - Fixed tests for osal.screen Co-authored-by: mahmmoud.hassanein <mahmmoud.hassanein@gmail.com>
This commit is contained in:
13
lib/installers/infra/screen/.heroscript
Normal file
13
lib/installers/infra/screen/.heroscript
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
!!hero_code.generate_installer
|
||||
name:'screen'
|
||||
classname:'Screen'
|
||||
singleton:0
|
||||
templates:0
|
||||
default:1
|
||||
title:''
|
||||
supported_platforms:''
|
||||
reset:0
|
||||
startupmanager:0
|
||||
hasconfig:0
|
||||
build:0
|
||||
44
lib/installers/infra/screen/readme.md
Normal file
44
lib/installers/infra/screen/readme.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# screen
|
||||
|
||||
|
||||
|
||||
To get started
|
||||
|
||||
```vlang
|
||||
|
||||
|
||||
import freeflowuniverse.herolib.installers.something.screen as screen_installer
|
||||
|
||||
heroscript:="
|
||||
!!screen.configure name:'test'
|
||||
password: '1234'
|
||||
port: 7701
|
||||
|
||||
!!screen.start name:'test' reset:1
|
||||
"
|
||||
|
||||
screen_installer.play(heroscript=heroscript)!
|
||||
|
||||
//or we can call the default and do a start with reset
|
||||
//mut installer:= screen_installer.get()!
|
||||
//installer.start(reset:true)!
|
||||
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
## example heroscript
|
||||
|
||||
```hero
|
||||
!!screen.configure
|
||||
homedir: '/home/user/screen'
|
||||
username: 'admin'
|
||||
password: 'secretpassword'
|
||||
title: 'Some Title'
|
||||
host: 'localhost'
|
||||
port: 8888
|
||||
|
||||
```
|
||||
|
||||
|
||||
63
lib/installers/infra/screen/screen_actions.v
Normal file
63
lib/installers/infra/screen/screen_actions.v
Normal file
@@ -0,0 +1,63 @@
|
||||
module screen
|
||||
|
||||
import freeflowuniverse.herolib.core
|
||||
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')
|
||||
if res.exit_code != 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// get the Upload List of the files
|
||||
fn ulist_get() !ulist.UList {
|
||||
// optionally build a UList which is all paths which are result of building, is then used e.g. in upload
|
||||
return ulist.UList{}
|
||||
}
|
||||
|
||||
// uploads to S3 server if configured
|
||||
fn upload() ! {
|
||||
}
|
||||
|
||||
fn install() ! {
|
||||
console.print_header('install screen')
|
||||
|
||||
if core.is_ubuntu()! {
|
||||
res := os.execute('sudo apt install screen -y')
|
||||
if res.exit_code != 0 {
|
||||
return error('failed to install screen: ${res.output}')
|
||||
}
|
||||
} else if core.is_osx()! {
|
||||
res := os.execute('sudo brew install screen')
|
||||
if res.exit_code != 0 {
|
||||
return error('failed to install screen: ${res.output}')
|
||||
}
|
||||
} else {
|
||||
return error('unsupported platform: ${core.platform()!}')
|
||||
}
|
||||
}
|
||||
|
||||
fn destroy() ! {
|
||||
console.print_header('uninstall screen')
|
||||
if core.is_ubuntu()! {
|
||||
res := os.execute('sudo apt remove screen -y')
|
||||
if res.exit_code != 0 {
|
||||
return error('failed to uninstall screen: ${res.output}')
|
||||
}
|
||||
} else if core.is_osx()! {
|
||||
res := os.execute('sudo brew uninstall screen')
|
||||
if res.exit_code != 0 {
|
||||
return error('failed to uninstall screen: ${res.output}')
|
||||
}
|
||||
} else {
|
||||
return error('unsupported platform: ${core.platform()!}')
|
||||
}
|
||||
}
|
||||
71
lib/installers/infra/screen/screen_factory_.v
Normal file
71
lib/installers/infra/screen/screen_factory_.v
Normal file
@@ -0,0 +1,71 @@
|
||||
module screen
|
||||
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
|
||||
__global (
|
||||
screen_global map[string]&Screen
|
||||
screen_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&Screen {
|
||||
return &Screen{}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////# 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 mut:
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self Screen) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self Screen) destroy() ! {
|
||||
switch(self.name)
|
||||
destroy()!
|
||||
}
|
||||
|
||||
// switch instance to be used for screen
|
||||
pub fn switch(name string) {
|
||||
screen_default = name
|
||||
}
|
||||
22
lib/installers/infra/screen/screen_model.v
Normal file
22
lib/installers/infra/screen/screen_model.v
Normal file
@@ -0,0 +1,22 @@
|
||||
module screen
|
||||
|
||||
const singleton = false
|
||||
const default = true
|
||||
|
||||
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
|
||||
@[heap]
|
||||
pub struct Screen {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
}
|
||||
|
||||
fn obj_init(obj_ Screen) !Screen {
|
||||
// never call get here, only thing we can do here is work on object itself
|
||||
mut obj := obj_
|
||||
return obj
|
||||
}
|
||||
|
||||
// called before start if done
|
||||
fn configure() ! {
|
||||
// mut installer := get()!
|
||||
}
|
||||
Reference in New Issue
Block a user