This commit is contained in:
2025-02-08 14:11:51 +01:00
parent eb38bc5e60
commit 6e619622d2
23 changed files with 326 additions and 380 deletions

View File

@@ -1,12 +0,0 @@
!!hero_code.generate_installer
name:'buildah'
classname:'BuildahInstaller'
singleton:1
templates:0
default:1
title:''
supported_platforms:''
reset:0
startupmanager:0
hasconfig:0
build:0

View File

@@ -1,36 +0,0 @@
module buildah
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.installers.ulist
import freeflowuniverse.herolib.core
// checks if a certain version or above is installed
fn installed() !bool {
osal.execute_silent('buildah -v') or { return false }
return true
}
fn install() ! {
console.print_header('install buildah')
if core.platform()! != .ubuntu {
return error('Only ubuntu is supported for now')
}
cmd := 'sudo apt-get -y update && sudo apt-get -y install buildah'
osal.execute_stdout(cmd)!
console.print_header('Buildah Installed Successfuly')
}
// get the Upload List of the files
fn ulist_get() !ulist.UList {
// mut installer := get()!
// optionally build a UList which is all paths which are result of building, is then used e.g. in upload
return ulist.UList{}
}
fn destroy() ! {
osal.execute_stdout('sudo apt remove --purge -y buildah')!
}

View File

@@ -1,74 +0,0 @@
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
)
/////////FACTORY
@[params]
pub struct ArgsGet {
pub mut:
name string
}
pub fn get(args_ ArgsGet) !&BuildahInstaller {
return &BuildahInstaller{}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
// unknown
// screen
// zinit
// tmux
// systemd
match cat {
.zinit {
console.print_debug('startupmanager: zinit')
return startupmanager.get(cat: .zinit)!
}
.systemd {
console.print_debug('startupmanager: systemd')
return startupmanager.get(cat: .systemd)!
}
else {
console.print_debug('startupmanager: auto')
return startupmanager.get()!
}
}
}
@[params]
pub struct InstallArgs {
pub mut:
reset bool
}
pub fn (mut self BuildahInstaller) install(args InstallArgs) ! {
switch(self.name)
if args.reset || (!installed()!) {
install()!
}
}
pub fn (mut self BuildahInstaller) destroy() ! {
switch(self.name)
destroy()!
}
// switch instance to be used for buildah
pub fn switch(name string) {
buildah_default = name
}

View File

@@ -1,22 +0,0 @@
module buildah
const singleton = true
const default = true
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
@[heap]
pub struct BuildahInstaller {
pub mut:
name string = 'default'
}
fn obj_init(obj_ BuildahInstaller) !BuildahInstaller {
// never call get here, only thing we can do here is work on object itself
mut obj := obj_
return obj
}
// called before start if done
fn configure() ! {
// mut installer := get()!
}

View File

@@ -1,34 +0,0 @@
# buildah
To get started
```vlang
import freeflowuniverse.herolib.installers.something. buildah
mut installer:= buildah.get()!
installer.start()!
```
## example heroscript
```hero
!!buildah.install
homedir: '/home/user/buildah'
username: 'admin'
password: 'secretpassword'
title: 'Some Title'
host: 'localhost'
port: 8888
```

View File

@@ -3,6 +3,7 @@ module pacman
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core
import os
// checks if a certain version or above is installed
@@ -19,7 +20,7 @@ fn install_() ! {
return
}
if core.platform() != .ubuntu {
if core.platform()! != .ubuntu {
return error('only ubuntu supported for this installer.')
}

View File

@@ -1,87 +1,101 @@
module podman
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.core
import freeflowuniverse.herolib.installers.ulist
import os
// Check if Podman is installed
//////////////////// following actions are not specific to instance of the object
// checks if a certain version or above is installed
fn installed() !bool {
console.print_header('Checking if Podman is installed...')
result := os.execute('podman -v')
return result.exit_code == 0
res := os.execute('${osal.profile_path_source_and()!} podman -v')
if res.exit_code != 0 {
println(res)
return false
}
r := res.output.split_into_lines().filter(it.trim_space().len > 0)
if r.len != 1 {
return error("couldn't parse podman version.\n${res.output}")
}
if texttools.version(version) <= texttools.version(r[0].all_after("version")) {
return true
}
return false
}
//get the Upload List of the files
fn ulist_get() !ulist.UList {
//optionally build a UList which is all paths which are result of building, is then used e.g. in upload
return ulist.UList{}
}
fn upload() ! {
}
// Install Podman
fn install() ! {
if installed()! {
return error('Podman is already installed.')
}
console.print_header('install podman')
mut url := ''
if core.is_linux_arm()! || core.is_linux_intel()!{
osal.package_install("podman,buildah,crun,mmdebstrap")!
return
} else if core.is_linux_intel()! {
url = 'https://github.com/containers/podman/releases/download/v${version}/podman-installer-macos-arm64.pkg'
} else if core.is_osx_intel()! {
url = 'https://github.com/containers/podman/releases/download/v${version}/podman-installer-macos-amd64.pkg'
} else {
return error('unsported platform')
}
console.print_header('Installing Podman...')
platform := core.platform()!
command := get_platform_command(platform, 'install')!
execute_command(command, 'installing Podman')!
console.print_header('Podman installed successfully.')
mut dest := osal.download(
url: url
minsize_kb: 9000
expand_dir: '/tmp/podman'
)!
//dest.moveup_single_subdir()!
panic("implement")
}
// Remove Podman
fn destroy() ! {
if !installed()! {
return error('Podman is not installed.')
}
console.print_header('Removing Podman...')
platform := core.platform()!
command := get_platform_command(platform, 'remove')!
execute_command(command, 'removing Podman')!
console.print_header('Podman removed successfully.')
// mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")!
// osal.process_kill_recursive(name:'zinit')!
// osal.cmd_delete('zinit')!
osal.package_remove('
podman
conmon
buildah
skopeo
runc
')!
// //will remove all paths where go/bin is found
// osal.profile_path_add_remove(paths2delete:"go/bin")!
osal.rm("
podman
conmon
buildah
skopeo
runc
/var/lib/containers
/var/lib/podman
/var/lib/buildah
/tmp/podman
/tmp/conmon
")!
}
// Build Podman (install it)
fn build() ! {
install()!
}
// Get platform-specific commands for installing/removing Podman
fn get_platform_command(platform core.PlatformType, action string) !string {
return match platform {
.ubuntu {
if action == 'install' {
'sudo apt-get -y install podman'
} else if action == 'remove' {
'sudo apt-get -y remove podman'
} else {
return error('Invalid action: ${action}')
}
}
.arch {
if action == 'install' {
'sudo pacman -S --noconfirm podman'
} else if action == 'remove' {
'sudo pacman -R --noconfirm podman'
} else {
return error('Invalid action: ${action}')
}
}
.osx {
if action == 'install' {
'brew install podman'
} else if action == 'remove' {
'brew uninstall podman'
} else {
return error('Invalid action: ${action}')
}
}
else {
return error('Only Ubuntu, Arch, and macOS are supported.')
}
}
}
// Execute a shell command and handle errors
fn execute_command(command string, operation string) ! {
result := os.execute(command)
if result.exit_code != 0 {
return error('Failed ${operation}: ${result.output}')
}
}

View File

@@ -1,71 +1,124 @@
module podman
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 freeflowuniverse.herolib.ui.console
import time
__global (
podman_global map[string]&PodmanInstaller
podman_default string
podman_global map[string]&PodmanInstaller
podman_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet {
pub struct ArgsGet{
pub mut:
name string = 'default'
name string
}
pub fn get(args_ ArgsGet) !&PodmanInstaller {
return &PodmanInstaller{}
pub fn get(args_ ArgsGet) !&PodmanInstaller {
return &PodmanInstaller{}
}
@[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 args:=args_
mut plbook := args.plbook or {
playbook.new(text: args.heroscript)!
}
mut other_actions := plbook.find(filter: 'podman.')!
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 podman.destroy")
destroy()!
}
if other_action.name == "install"{
console.print_debug("install action podman.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 PodmanInstaller) install(args InstallArgs) ! {
switch(self.name)
if args.reset || !installed()! {
install()!
}
switch(self.name)
if args.reset || (!installed()!) {
install()!
}
}
pub fn (mut self PodmanInstaller) destroy() ! {
switch(self.name)
destroy()!
switch(self.name)
destroy()!
}
// switch instance to be used for podman
//switch instance to be used for podman
pub fn switch(name string) {
podman_default = name
podman_default = name
}
//helpers
@[params]
pub struct DefaultConfigArgs{
instance string = 'default'
}

View File

@@ -1,10 +1,40 @@
module podman
import freeflowuniverse.herolib.data.paramsparser
import freeflowuniverse.herolib.data.encoderhero
import os
pub const version = '4.9.3'
const singleton = true
const default = true
//THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
@[heap]
pub struct PodmanInstaller {
pub mut:
name string = 'default'
name string = 'default'
}
//your checking & initialization code if needed
fn obj_init(mycfg_ PodmanInstaller)!PodmanInstaller{
mut mycfg:=mycfg_
return mycfg
}
//called before start if done
fn configure() ! {
//mut installer := get()!
}
/////////////NORMALLY NO NEED TO TOUCH
pub fn heroscript_dumps(obj PodmanInstaller) !string {
return encoderhero.encode[PodmanInstaller ](obj)!
}
pub fn heroscript_loads(heroscript string) !PodmanInstaller {
mut obj := encoderhero.decode[PodmanInstaller](heroscript)!
return obj
}