feat: add wireguard installer

- Add a new wireguard installer to the installers.
This commit is contained in:
Mahmoud Emad
2025-02-12 11:23:36 +00:00
parent 3a337b7b0a
commit 582da6d7f0
10 changed files with 86 additions and 311 deletions

View File

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

View File

@@ -1,114 +0,0 @@
module wireguard_installer
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.core.pathlib
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 {
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()!} wireguard_installer version')
// if res.exit_code != 0 {
// return false
// }
// r := res.output.split_into_lines().filter(it.trim_space().len > 0)
// if r.len != 1 {
// return error("couldn't parse wireguard_installer version.\n${res.output}")
// }
// if texttools.version(version) == texttools.version(r[0]) {
// 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{}
}
//uploads to S3 server if configured
fn upload() ! {
// installers.upload(
// cmdname: 'wireguard_installer'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/wireguard_installer'
// )!
}
fn install() ! {
console.print_header('install wireguard_installer')
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := ''
// if core.is_linux_arm() {
// url = 'https://github.com/wireguard_installer-dev/wireguard_installer/releases/download/v${version}/wireguard_installer_${version}_linux_arm64.tar.gz'
// } else if core.is_linux_intel() {
// url = 'https://github.com/wireguard_installer-dev/wireguard_installer/releases/download/v${version}/wireguard_installer_${version}_linux_amd64.tar.gz'
// } else if core.is_osx_arm() {
// url = 'https://github.com/wireguard_installer-dev/wireguard_installer/releases/download/v${version}/wireguard_installer_${version}_darwin_arm64.tar.gz'
// } else if osal.is_osx_intel() {
// url = 'https://github.com/wireguard_installer-dev/wireguard_installer/releases/download/v${version}/wireguard_installer_${version}_darwin_amd64.tar.gz'
// } else {
// return error('unsported platform')
// }
// mut dest := osal.download(
// url: url
// minsize_kb: 9000
// expand_dir: '/tmp/wireguard_installer'
// )!
// //dest.moveup_single_subdir()!
// mut binpath := dest.file_get('wireguard_installer')!
// osal.cmd_add(
// cmdname: 'wireguard_installer'
// source: binpath.path
// )!
}
fn destroy() ! {
// 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
// ")!
}

View File

@@ -1,124 +0,0 @@
module wireguard_installer
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 (
wireguard_installer_global map[string]&WireGuard
wireguard_installer_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet{
pub mut:
name string
}
pub fn get(args_ ArgsGet) !&WireGuard {
return &WireGuard{}
}
@[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: 'wireguard_installer.')!
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 wireguard_installer.destroy")
destroy()!
}
if other_action.name == "install"{
console.print_debug("install action wireguard_installer.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()!
}
}
}
@[params]
pub struct InstallArgs{
pub mut:
reset bool
}
pub fn (mut self WireGuard) install(args InstallArgs) ! {
switch(self.name)
if args.reset || (!installed()!) {
install()!
}
}
pub fn (mut self WireGuard) destroy() ! {
switch(self.name)
destroy()!
}
//switch instance to be used for wireguard_installer
pub fn switch(name string) {
wireguard_installer_default = name
}
//helpers
@[params]
pub struct DefaultConfigArgs{
instance string = 'default'
}

View File

@@ -1,43 +0,0 @@
module wireguard_installer
import freeflowuniverse.herolib.data.paramsparser
import freeflowuniverse.herolib.data.encoderhero
import os
pub const version = '0.0.0'
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 WireGuard {
pub mut:
name string = 'default'
}
//your checking & initialization code if needed
fn obj_init(mycfg_ WireGuard)!WireGuard{
mut mycfg:=mycfg_
if mycfg.password == '' && mycfg.secret == '' {
return error('password or secret needs to be filled in for ${mycfg.name}')
}
return mycfg
}
//called before start if done
fn configure() ! {
//mut installer := get()!
}
/////////////NORMALLY NO NEED TO TOUCH
pub fn heroscript_dumps(obj WireGuard) !string {
return encoderhero.encode[WireGuard ](obj)!
}
pub fn heroscript_loads(heroscript string) !WireGuard {
mut obj := encoderhero.decode[WireGuard](heroscript)!
return obj
}

View File

@@ -1,23 +0,0 @@
module wireguard
pub const version = '1.14.3'
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 WireGuard {
pub mut:
name string = 'default'
}
fn obj_init(obj_ WireGuard) !WireGuard {
// 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,4 +1,4 @@
module wireguard
module wireguard_installer
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.installers.ulist
@@ -15,16 +15,15 @@ fn installed() !bool {
// 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 upload() ! {}
fn install() ! {
console.print_header('install wireguard')
cmd := match core.platform()! {
.ubuntu {
'sudo apt install -y wireguard'
@@ -38,6 +37,7 @@ fn install() ! {
}
osal.execute_stdout(cmd)!
console.print_header('wireguard is installed')
}
fn destroy() ! {
@@ -56,4 +56,5 @@ fn destroy() ! {
}
osal.execute_stdout(cmd)!
console.print_header('wireguard is uninstalled')
}

View File

@@ -1,11 +1,9 @@
module wireguard
module wireguard_installer
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 (
wireguard_installer_global map[string]&WireGuard
@@ -24,6 +22,36 @@ pub fn get(args_ ArgsGet) !&WireGuard {
return &WireGuard{}
}
@[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: 'wireguard_installer.')!
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 wireguard_installer.destroy')
destroy()!
}
if other_action.name == 'install' {
console.print_debug('install action wireguard_installer.install')
install()!
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -72,3 +100,10 @@ pub fn (mut self WireGuard) destroy() ! {
pub fn switch(name string) {
wireguard_installer_default = name
}
// helpers
@[params]
pub struct DefaultConfigArgs {
instance string = 'default'
}

View File

@@ -0,0 +1,36 @@
module wireguard_installer
import freeflowuniverse.herolib.data.encoderhero
pub const version = '1.14.3'
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 WireGuard {
pub mut:
name string = 'default'
}
// your checking & initialization code if needed
fn obj_init(mycfg_ WireGuard) !WireGuard {
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 WireGuard) !string {
return encoderhero.encode[WireGuard](obj)!
}
pub fn heroscript_loads(heroscript string) !WireGuard {
mut obj := encoderhero.decode[WireGuard](heroscript)!
return obj
}