refactor: improve Podman installer
- Refactor Podman installer to use a more robust approach - Improve error handling and clarify the installation/removal - Update example usage to reflect changes Co-authored-by: supermario <mariobassem12@gmail.com>
This commit is contained in:
@@ -4,8 +4,8 @@ import freeflowuniverse.herolib.installers.virt.podman as podman_installer
|
||||
|
||||
mut podman := podman_installer.get()!
|
||||
|
||||
if podman.installed() {
|
||||
podman.destroy()!
|
||||
} else {
|
||||
podman.install()!
|
||||
}
|
||||
// To install
|
||||
podman.install()!
|
||||
|
||||
// To remove
|
||||
podman.destroy()!
|
||||
|
||||
@@ -12,17 +12,8 @@ fn installed_() !bool {
|
||||
|
||||
fn install_() ! {
|
||||
console.print_header('install postgresql')
|
||||
|
||||
if core.platform()! != .ubuntu || core.platform()! != .arch {
|
||||
return error('only support ubuntu and arch for now')
|
||||
}
|
||||
|
||||
if osal.done_exists('podman') {
|
||||
console.print_header('podman binary already installed')
|
||||
return
|
||||
}
|
||||
|
||||
podman_installer.install()!
|
||||
mut podman := podman_installer.get()!
|
||||
podman.install()!
|
||||
osal.execute_silent('podman pull docker.io/library/postgres:latest')!
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import freeflowuniverse.herolib.core
|
||||
import os
|
||||
|
||||
// Check if Podman is installed
|
||||
fn installed() bool {
|
||||
fn installed() !bool {
|
||||
console.print_header('Checking if Podman is installed...')
|
||||
result := os.execute('podman -v')
|
||||
return result.exit_code == 0
|
||||
@@ -13,7 +13,7 @@ fn installed() bool {
|
||||
|
||||
// Install Podman
|
||||
fn install() ! {
|
||||
if installed() {
|
||||
if installed()! {
|
||||
return error('Podman is already installed.')
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ fn install() ! {
|
||||
|
||||
// Remove Podman
|
||||
fn destroy() ! {
|
||||
if !installed() {
|
||||
if !installed()! {
|
||||
return error('Podman is not installed.')
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
module podman
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
@@ -22,6 +24,32 @@ pub fn get(args_ ArgsGet) !&PodmanInstaller {
|
||||
return &PodmanInstaller{}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////# 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:
|
||||
@@ -30,17 +58,9 @@ pub mut:
|
||||
|
||||
pub fn (mut self PodmanInstaller) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset || !installed()! {
|
||||
install()!
|
||||
}
|
||||
|
||||
pub fn (mut self PodmanInstaller) installed(args InstallArgs) bool {
|
||||
switch(self.name)
|
||||
return installed()
|
||||
}
|
||||
|
||||
pub fn (mut self PodmanInstaller) build() ! {
|
||||
switch(self.name)
|
||||
build()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self PodmanInstaller) destroy() ! {
|
||||
|
||||
@@ -12,9 +12,9 @@ import freeflowuniverse.herolib.installers.virt.podman as podman_installer
|
||||
|
||||
mut podman := podman_installer.get()!
|
||||
|
||||
if podman.installed() {
|
||||
podman.destroy()!
|
||||
} else {
|
||||
podman.install()!
|
||||
}
|
||||
// To install
|
||||
podman.install()!
|
||||
|
||||
// To remove
|
||||
podman.destroy()!
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user