fixed installers

This commit is contained in:
2025-01-01 10:16:41 +01:00
parent e13931112d
commit cffd5e2f9c
76 changed files with 603 additions and 1731 deletions

View File

@@ -1,20 +1,27 @@
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run #!/usr/bin/env -S v -n -w -cg -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.data.dbfs
import freeflowuniverse.herolib.installers.lang.vlang import freeflowuniverse.herolib.installers.lang.rust
import freeflowuniverse.herolib.installers.db.redis as redis_installer import freeflowuniverse.herolib.installers.lang.python
import freeflowuniverse.herolib.installers.infra.coredns as coredns_installer import freeflowuniverse.herolib.installers.lang.nodejs
import freeflowuniverse.herolib.installers.sysadmintools.daguserver as dagu_installer import freeflowuniverse.herolib.installers.lang.golang
import freeflowuniverse.herolib.installers.sysadmintools.b2 as b2_installer
import freeflowuniverse.herolib.installers.net.mycelium as mycelium_installer
import freeflowuniverse.herolib.osal.screen // import freeflowuniverse.herolib.data.dbfs
// import freeflowuniverse.herolib.installers.lang.vlang
// import freeflowuniverse.herolib.installers.db.redis as redis_installer
// import freeflowuniverse.herolib.installers.infra.coredns as coredns_installer
// import freeflowuniverse.herolib.installers.sysadmintools.daguserver as dagu_installer
// import freeflowuniverse.herolib.installers.sysadmintools.b2 as b2_installer
// import freeflowuniverse.herolib.installers.net.mycelium as mycelium_installer
// import freeflowuniverse.herolib.osal.screen
// import freeflowuniverse.herolib.osal // import freeflowuniverse.herolib.osal
// redis_installer.new()! // redis_installer.new()!
// dagu_installer.install(passwd:"1234",secret:"1234",restart:true)! // dagu_installer.install(passwd:"1234",secret:"1234",restart:true)!
// coredns_installer.install()! // coredns_installer.install()!
mycelium_installer.install()! // mycelium_installer.install()!
// mycelium_installer.restart()! // mycelium_installer.restart()!
// mut screens:=screen.new()! // mut screens:=screen.new()!
@@ -22,6 +29,10 @@ mycelium_installer.install()!
// dagu_installer.check(secret:"1234")! // dagu_installer.check(secret:"1234")!
vlang.v_analyzer_install()! // vlang.v_analyzer_install()!
// b2_installer.install()! // b2_installer.install()!
// rust.install(reset:false)!
nodejs.install(reset:false)!

View File

@@ -28,6 +28,7 @@ pub enum Cat {
installer installer
} }
//creates the heroscript from the GenModel as part of GenerateArgs
pub fn gen_model_set(args GenerateArgs) ! { pub fn gen_model_set(args GenerateArgs) ! {
console.print_debug('Code generator set: ${args}') console.print_debug('Code generator set: ${args}')
model := args.model or { return error('model is none') } model := args.model or { return error('model is none') }
@@ -40,6 +41,7 @@ pub fn gen_model_set(args GenerateArgs) ! {
pathlib.template_write(heroscript_templ, '${args.path}/.heroscript', true)! pathlib.template_write(heroscript_templ, '${args.path}/.heroscript', true)!
} }
//loads the heroscript and return the model
pub fn gen_model_get(path string, create bool) !GenModel { pub fn gen_model_get(path string, create bool) !GenModel {
console.print_debug('play installer code for path: ${path}') console.print_debug('play installer code for path: ${path}')

View File

@@ -4,6 +4,8 @@ import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.texttools import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.core.pathlib import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.installers.ulist
import freeflowuniverse.herolib.installers.base
@if model.startupmanager @if model.startupmanager
import freeflowuniverse.herolib.osal.systemd import freeflowuniverse.herolib.osal.systemd
@@ -11,7 +13,6 @@ import freeflowuniverse.herolib.osal.zinit
@end @end
@if model.build @if model.build
import freeflowuniverse.herolib.installers.ulist
import freeflowuniverse.herolib.installers.lang.golang import freeflowuniverse.herolib.installers.lang.golang
import freeflowuniverse.herolib.installers.lang.rust import freeflowuniverse.herolib.installers.lang.rust
import freeflowuniverse.herolib.installers.lang.python import freeflowuniverse.herolib.installers.lang.python
@@ -36,7 +37,7 @@ fn startupcmd () ![]zinit.ZProcessNewArgs{
} }
fn running() !bool { fn running_() !bool {
mut installer := get()! mut installer := get()!
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED //THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of ${model.name} // this checks health of ${model.name}
@@ -80,7 +81,7 @@ fn stop_post()!{
@if model.cat == .installer @if model.cat == .installer
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED //THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('??{osal.profile_path_source_and()} ${model.name} version') // res := os.execute('??{osal.profile_path_source_and()} ${model.name} version')
// if res.exit_code != 0 { // if res.exit_code != 0 {
@@ -103,7 +104,7 @@ fn ulist_get() !ulist.UList {
} }
//uploads to S3 server if configured //uploads to S3 server if configured
fn upload() ! { fn upload_() ! {
// installers.upload( // installers.upload(
// cmdname: '${model.name}' // cmdname: '${model.name}'
// source: '??{gitpath}/target/x86_64-unknown-linux-musl/release/${model.name}' // source: '??{gitpath}/target/x86_64-unknown-linux-musl/release/${model.name}'
@@ -111,7 +112,7 @@ fn upload() ! {
} }
fn install() ! { fn install_() ! {
console.print_header('install ${model.name}') console.print_header('install ${model.name}')
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED //THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := '' // mut url := ''
@@ -143,7 +144,7 @@ fn install() ! {
} }
@if model.build @if model.build
fn build() ! { fn build_() ! {
//url := 'https://github.com/threefoldtech/${model.name}' //url := 'https://github.com/threefoldtech/${model.name}'
// make sure we install base on the node // make sure we install base on the node
@@ -174,7 +175,7 @@ fn build() ! {
} }
@end @end
fn destroy() ! { fn destroy_() ! {
// mut systemdfactory := systemd.new()! // mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")! // systemdfactory.destroy("zinit")!

View File

@@ -21,13 +21,15 @@ __global (
/////////FACTORY /////////FACTORY
@if model.singleton == false
^^[params] ^^[params]
pub struct ArgsGet{ pub struct ArgsGet{
pub mut: pub mut:
name string name string
} }
@if model.hasconfig
fn args_get (args_ ArgsGet) ArgsGet { fn args_get (args_ ArgsGet) ArgsGet {
mut model:=args_ mut model:=args_
if model.name == ""{ if model.name == ""{
@@ -41,7 +43,7 @@ fn args_get (args_ ArgsGet) ArgsGet {
pub fn get(args_ ArgsGet) !&${model.classname} { pub fn get(args_ ArgsGet) !&${model.classname} {
mut args := args_get(args_) mut args := args_get(args_)
if !(args.name in ${args.name}_global) { if !(args.name in ${model.name}_global) {
if args.name=="default"{ if args.name=="default"{
if ! config_exists(args){ if ! config_exists(args){
if default{ if default{
@@ -52,36 +54,32 @@ pub fn get(args_ ArgsGet) !&${model.classname} {
load(args)! load(args)!
} }
} }
return ${args.name}_global[args.name] or { return ${model.name}_global[args.name] or {
println(${args.name}_global) println(${model.name}_global)
panic("could not get config for ${args.name} with name:??{model.name}") panic("could not get config for ??{args.name} with name:??{model.name}")
} }
} }
@else
pub fn get(args_ ArgsGet) !&${model.classname} {
return &${model.classname}{}
}
@end @end
@if model.hasconfig @if model.hasconfig
//set the model in mem and the config on the filesystem //set the model in mem and the config on the filesystem
fn set(o ${model.classname})! { pub fn set(o ${model.classname})! {
mut o2:=obj_init(o)! mut o2:=obj_init(o)!
${model.name}_global[o.name] = &o2 ${model.name}_global[o.name] = &o2
${model.name}_default = o.name ${model.name}_default = o.name
} }
//check we find the config on the filesystem //check we find the config on the filesystem
fn exists(args_ ArgsGet) bool { pub fn exists(args_ ArgsGet) bool {
mut model := args_get(args_) mut model := args_get(args_)
mut context:=base.context() or { panic("bug") } mut context:=base.context() or { panic("bug") }
return context.hero_config_exists("${model.name}",model.name) return context.hero_config_exists("${model.name}",model.name)
} }
//load the config error if it doesn't exist //load the config error if it doesn't exist
fn load(args_ ArgsGet) ! { pub fn load(args_ ArgsGet) ! {
mut model := args_get(args_) mut model := args_get(args_)
mut context:=base.context()! mut context:=base.context()!
mut heroscript := context.hero_config_get("${model.name}",model.name)! mut heroscript := context.hero_config_get("${model.name}",model.name)!
@@ -89,15 +87,12 @@ fn load(args_ ArgsGet) ! {
} }
//save the config to the filesystem in the context //save the config to the filesystem in the context
fn save(o ${model.classname})! { pub fn save(o ${model.classname})! {
mut model := args_get(args_)
mut context:=base.context()! mut context:=base.context()!
heroscript := encoderhero.encode[${model.classname}](o2)! heroscript := encoderhero.encode[${model.classname}](o)!
context.hero_config_set("${model.name}",model.name,heroscript)! context.hero_config_set("${model.name}",model.name,heroscript)!
} }
^^[params] ^^[params]
pub struct PlayArgs { pub struct PlayArgs {
pub mut: pub mut:
@@ -120,13 +115,14 @@ pub fn play(args_ PlayArgs) ! {
} }
@if model.hasconfig @if model.hasconfig
mut install_actions := plbook.find(filter: '${model.name}.configure')! mut configure_actions := plbook.find(filter: '${model.name}.configure')!
if install_actions.len > 0 { if configure_actions.len > 0 {
for install_action in install_actions { for config_action in configure_actions {
mut p := install_action.params mut p := config_action.params
mycfg:=cfg_play(p)! mycfg:=cfg_play(p)!
console.print_debug("install action ${model.name}.configure\n??{mycfg}") console.print_debug("install action ${model.name}.configure\n??{mycfg}")
set(mycfg)! set(mycfg)!
save(mycfg)!
} }
} }
@end @end
@@ -139,11 +135,11 @@ pub fn play(args_ PlayArgs) ! {
reset:=p.get_default_false("reset") reset:=p.get_default_false("reset")
if other_action.name == "destroy" || reset{ if other_action.name == "destroy" || reset{
console.print_debug("install action ${model.name}.destroy") console.print_debug("install action ${model.name}.destroy")
destroy()! destroy_()!
} }
if other_action.name == "install"{ if other_action.name == "install"{
console.print_debug("install action ${model.name}.install") console.print_debug("install action ${model.name}.install")
install()! install_()!
} }
} }
@if model.startupmanager @if model.startupmanager
@@ -180,6 +176,17 @@ pub fn play(args_ PlayArgs) ! {
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
@if model.hasconfig
//load from disk and make sure is properly intialized
pub fn (mut self ${model.classname}) reload() ! {
switch(self.name)
self=obj_init(self)!
}
@end
@if model.startupmanager
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager { fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
// unknown // unknown
// screen // screen
@@ -201,15 +208,6 @@ fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManag
} }
} }
@if model.hasconfig
//load from disk and make sure is properly intialized
pub fn (mut self ${model.classname}) reload() ! {
switch(self.name)
self=obj_init(self)!
}
@end
@if model.startupmanager
pub fn (mut self ${model.classname}) start() ! { pub fn (mut self ${model.classname}) start() ! {
switch(self.name) switch(self.name)
if self.running()!{ if self.running()!{
@@ -218,8 +216,8 @@ pub fn (mut self ${model.classname}) start() ! {
console.print_header('${model.name} start') console.print_header('${model.name} start')
if ! installed()!{ if ! installed_()!{
install()! install_()!
} }
configure()! configure()!
@@ -291,17 +289,50 @@ pub mut:
reset bool reset bool
} }
pub fn (mut self ${model.classname}) install(model InstallArgs) ! { @if model.singleton
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
}
pub fn destroy() ! {
destroy_()!
}
@if model.build
pub fn build() ! {
build_()!
}
@end
@else
//switch instance to be used for ${model.name}
pub fn switch(name string) {
${model.name}_default = name
}
pub fn (mut self ${model.classname}) install(args InstallArgs) ! {
switch(self.name) switch(self.name)
if model.reset || (!installed()!) { if args.reset {
install()! destroy_()!
}
if ! (installed_()!){
install_()!
} }
} }
@if model.build @if model.build
pub fn (mut self ${model.classname}) build() ! { pub fn (mut self ${model.classname}) build() ! {
switch(self.name) switch(self.name)
build()! build_()!
} }
@end @end
@@ -310,13 +341,11 @@ pub fn (mut self ${model.classname}) destroy() ! {
@if model.startupmanager @if model.startupmanager
self.stop() or {} self.stop() or {}
@end @end
destroy()! destroy_()!
} }
@end @end
@end
//switch instance to be used for ${model.name}
pub fn switch(name string) {
${model.name}_default = name
}

View File

@@ -1,74 +0,0 @@
module base
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.core.texttools
import os
const scriptspath = os.dir(@FILE) + '/../../../scripts'
fn script_write(mybase string, name string, cmd_ string) ! {
cmd := texttools.dedent(cmd_)
mut out := '${mybase}\n'
for line in cmd.split_into_lines() {
out += '${line}\n'
}
mut p := pathlib.get_file(path: '${scriptspath}/${name}.sh', create: true)!
p.write(out)!
os.chmod(p.path, 0o777)!
}
pub fn bash_installers_package() !string {
l := '
1_init.sh
2_myplatform.sh
3_gittools.sh
4_package.sh
5_exec.sh
6_reset.sh
7_zinit.sh
8_osupdate.sh
9_redis.sh
10_installer_v.sh
11_installer_herolib.sh
12_installer_hero.sh
13_s3.sh
20_installers.sh
'
mut out := ''
for mut name in l.split_into_lines() {
name = name.trim_space()
if name == '' {
continue
}
mut p := pathlib.get_file(path: '${scriptspath}/lib/${name}', create: false)!
c := p.read()!
out += c
}
script_write(out, 'baselib', '')!
script_write(out, 'installer', "
freeflow_dev_env_install
echo 'V & hero INSTALL OK'
")!
script_write(out, 'build_hero', "
hero_build
echo 'BUILD HERO OK'
")!
script_write(out, 'install_hero', "
hero_install
echo 'INSTALL HERO OK'
")!
script_write(out, 'githubactions', "
hero_build
hero_test
hero_upload
echo 'OK'
")!
mut p4 := pathlib.get_dir(path: '${scriptspath}', create: false)!
return p4.path
}

View File

@@ -1,22 +0,0 @@
#!/bin/bash
set -ux -o pipefail
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
if command_exists brew; then
# Uninstall Homebrew and all installed packages
echo "Uninstalling Homebrew and all packages..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"
# Verify removal and cleanup any remaining files
echo "Cleaning up remaining files and verifying removal..."
brew cleanup 2>/dev/null
sudo rm -rf /opt/homebrew
echo "Uninstallation process completed for brew."
fi

View File

@@ -1,48 +0,0 @@
#!/bin/bash
set -u -o pipefail
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Stop all running Docker containers and remove Docker images, containers, and volumes
if command_exists docker; then
echo "Removing all Docker containers, images, and volumes..."
docker stop $(docker ps -a -q) 2>/dev/null
docker rm $(docker ps -a -q) 2>/dev/null
docker rmi $(docker images -q) 2>/dev/null
docker volume rm $(docker volume ls -q) 2>/dev/null
docker system prune -a -f --volumes 2>/dev/null
osascript -e 'quit app "Docker"'
sudo rm -rf /Applications/Docker.app
rm -f ~/Library/Preferences/com.docker.docker.plist
rm -rf ~/Library/Saved\ Application\ State/com.electron.docker-frontend.savedState
rm -rf ~/Library/Containers/com.docker.docker
rm -rf ~/Library/Containers/com.docker.helper
rm -rf ~/Library/Application\ Support/Docker\ Desktop
rm -rf ~/.docker
else
echo "Docker is not installed. Skipping Docker cleanup."
fi
# Remove binaries from ~/hero/bin
echo "Removing binaries from ~/hero/bin..."
rm -f ~/hero/bin/lima*
rm -f ~/hero/bin/docker*
rm -f ~/hero/bin/herocontainers*
rm -f ~/hero/bin/kube*
# Remove Lima VMs
if command_exists limactl; then
echo "Removing Lima VMs..."
limactl stop $(limactl list --quiet) 2>/dev/null
limactl delete --force $(limactl list --quiet) 2>/dev/null
limactl list
rm -rf ~/.lima
else
echo "limactl is not installed. Skipping Lima VM removal."
fi
echo "Remove containers process completed."

View File

@@ -1,43 +0,0 @@
module base
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.ui.console
import os
const templatespath = os.dir(@FILE) + '/templates'
// install base will return true if it was already installed
pub fn osx_uninstall_containers() ! {
console.print_header('Uninstall Containers')
pl := osal.platform()
if pl != .osx {
return error('only support OSX')
}
containers_uninstall_file := $embed_file('templates/containers_uninstall.sh')
osal.exec(
cmd: containers_uninstall_file.to_string()
stdout: false
ignore_error: false
shell: true
) or { return error('cannot uninstall containers, something went wrong.\n${err}') }
// will never come here because of shell: true
console.print_header('Removed brew and docker ...')
}
// pub fn osx_uninstall_brew() ! {
// console.print_header('Uninstall Brew')
// pl := osal.platform()
// if pl != .osx {
// return error("only support OSX")
// }
// return error('cannot uninstall containers, something went wrong.\n${err}')
// brew_uninstall_file:=$embed_file('templates/brew_uninstall.sh')
// osal.exec(cmd: brew_uninstall_file.to_string(), stdout: true, ignore_error:false, shell: true
// ) or { return error('cannot uninstall brew, something went wrong.\n${err}') }
// //will never come here because of shell: true
// console.print_header('Removed brew and docker ...')
// }

View File

@@ -8,7 +8,7 @@ import freeflowuniverse.herolib.installers.ulist
// import freeflowuniverse.herolib.installers.lang.rust // import freeflowuniverse.herolib.installers.lang.rust
import os import os
fn installed() !bool { fn installed_() !bool {
res := os.execute('${osal.profile_path_source_and()} meilisearch -V') res := os.execute('${osal.profile_path_source_and()} meilisearch -V')
if res.exit_code != 0 { if res.exit_code != 0 {
return false return false
@@ -24,7 +24,7 @@ fn installed() !bool {
return true return true
} }
fn install() ! { fn install_() ! {
console.print_header('install meilisearch') console.print_header('install meilisearch')
mut url := '' mut url := ''
@@ -55,7 +55,7 @@ fn install() ! {
)! )!
} }
fn build() ! { fn build_() ! {
// mut installer := get()! // mut installer := get()!
// url := 'https://github.com/threefoldtech/meilisearch' // url := 'https://github.com/threefoldtech/meilisearch'
@@ -94,7 +94,7 @@ fn ulist_get() !ulist.UList {
} }
// uploads to S3 server if configured // uploads to S3 server if configured
fn upload() ! { fn upload_() ! {
// mut installer := get()! // mut installer := get()!
// installers.upload( // installers.upload(
// cmdname: 'meilisearch' // cmdname: 'meilisearch'
@@ -117,7 +117,7 @@ fn startupcmd() ![]zinit.ZProcessNewArgs {
return res return res
} }
fn running() !bool { fn running_() !bool {
mut installer := get()! mut installer := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of meilisearch // this checks health of meilisearch
@@ -151,7 +151,7 @@ fn stop_pre() ! {
fn stop_post() ! { fn stop_post() ! {
} }
fn destroy() ! { fn destroy_() ! {
// mut systemdfactory := systemd.new()! // mut systemdfactory := systemd.new()!
// systemdfactory.destroy("meilisearch")! // systemdfactory.destroy("meilisearch")!

View File

@@ -3,11 +3,11 @@ module postgresql
import freeflowuniverse.herolib.osal import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.osal.zinit import freeflowuniverse.herolib.osal.zinit
fn installed() !bool { fn installed_() !bool {
return true return true
} }
fn install() ! { fn install_() ! {
osal.execute_silent('podman pull docker.io/library/postgres:latest')! osal.execute_silent('podman pull docker.io/library/postgres:latest')!
} }
@@ -29,7 +29,7 @@ fn startupcmd() ![]zinit.ZProcessNewArgs {
return res return res
} }
fn running() !bool { fn running_() !bool {
mut mydb := get()! mut mydb := get()!
mydb.check() or { return false } mydb.check() or { return false }
return true return true
@@ -47,7 +47,7 @@ fn stop_pre() ! {
fn stop_post() ! { fn stop_post() ! {
} }
fn destroy() ! { fn destroy_() ! {
mut mydb := get()! mut mydb := get()!
mydb.destroy()! mydb.destroy()!

View File

@@ -6,7 +6,7 @@ import freeflowuniverse.herolib.installers.base
import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.ui.console
// install zdb will return true if it was already installed // install zdb will return true if it was already installed
pub fn build() ! { pub fn build_() ! {
base.install()! base.install()!
console.print_header('package_install install zdb') console.print_header('package_install install zdb')
if !osal.done_exists('install_zdb') && !osal.cmd_exists('zdb') { if !osal.done_exists('install_zdb') && !osal.cmd_exists('zdb') {

View File

@@ -24,7 +24,7 @@ pub mut:
rotateperiod int = 1200 // 20 min rotateperiod int = 1200 // 20 min
} }
pub fn install(args_ InstallArgs) ! { pub fn install_(args_ InstallArgs) ! {
mut args := args_ mut args := args_
version := '2.0.7' version := '2.0.7'

View File

@@ -27,7 +27,7 @@ fn startupcmd() ![]zinit.ZProcessNewArgs {
return res return res
} }
fn running() !bool { fn running_() !bool {
mut installer := get()! mut installer := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of zerodb // this checks health of zerodb
@@ -64,7 +64,7 @@ fn stop_post() ! {
//////////////////// following actions are not specific to instance of the object //////////////////// following actions are not specific to instance of the object
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} zerodb version') // res := os.execute('${osal.profile_path_source_and()} zerodb version')
// if res.exit_code != 0 { // if res.exit_code != 0 {
@@ -87,14 +87,14 @@ fn ulist_get() !ulist.UList {
} }
// uploads to S3 server if configured // uploads to S3 server if configured
fn upload() ! { fn upload_() ! {
// installers.upload( // installers.upload(
// cmdname: 'zerodb' // cmdname: 'zerodb'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/zerodb' // source: '${gitpath}/target/x86_64-unknown-linux-musl/release/zerodb'
// )! // )!
} }
fn install() ! { fn install_() ! {
console.print_header('install zerodb') console.print_header('install zerodb')
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := '' // mut url := ''
@@ -125,7 +125,7 @@ fn install() ! {
// )! // )!
} }
fn build() ! { fn build_() ! {
// url := 'https://github.com/threefoldtech/zerodb' // url := 'https://github.com/threefoldtech/zerodb'
// make sure we install base on the node // make sure we install base on the node
@@ -154,7 +154,7 @@ fn build() ! {
// )! // )!
} }
fn destroy() ! { fn destroy_() ! {
// mut systemdfactory := systemd.new()! // mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")! // systemdfactory.destroy("zinit")!

View File

@@ -6,7 +6,7 @@ import freeflowuniverse.herolib.develop.gittools
import freeflowuniverse.herolib.installers.zinit import freeflowuniverse.herolib.installers.zinit
import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.ui.console
pub fn install() ! { pub fn install_() ! {
rust.install()! rust.install()!
zinit.install()! zinit.install()!
console.print_header('install rfs') console.print_header('install rfs')

View File

@@ -27,7 +27,7 @@ fn startupcmd() ![]zinit.ZProcessNewArgs {
return res return res
} }
fn running() !bool { fn running_() !bool {
mut installer := get()! mut installer := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of zerofs // this checks health of zerofs
@@ -64,7 +64,7 @@ fn stop_post() ! {
//////////////////// following actions are not specific to instance of the object //////////////////// following actions are not specific to instance of the object
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} zerofs version') // res := os.execute('${osal.profile_path_source_and()} zerofs version')
// if res.exit_code != 0 { // if res.exit_code != 0 {
@@ -87,14 +87,14 @@ fn ulist_get() !ulist.UList {
} }
// uploads to S3 server if configured // uploads to S3 server if configured
fn upload() ! { fn upload_() ! {
// installers.upload( // installers.upload(
// cmdname: 'zerofs' // cmdname: 'zerofs'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/zerofs' // source: '${gitpath}/target/x86_64-unknown-linux-musl/release/zerofs'
// )! // )!
} }
fn install() ! { fn install_() ! {
console.print_header('install zerofs') console.print_header('install zerofs')
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := '' // mut url := ''
@@ -125,7 +125,7 @@ fn install() ! {
// )! // )!
} }
fn build() ! { fn build_() ! {
// url := 'https://github.com/threefoldtech/zerofs' // url := 'https://github.com/threefoldtech/zerofs'
// make sure we install base on the node // make sure we install base on the node
@@ -154,7 +154,7 @@ fn build() ! {
// )! // )!
} }
fn destroy() ! { fn destroy_() ! {
// mut systemdfactory := systemd.new()! // mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")! // systemdfactory.destroy("zinit")!

View File

@@ -23,7 +23,7 @@ pub mut:
example bool // if true we will install examples example bool // if true we will install examples
} }
pub fn install(args_ InstallArgs) ! { pub fn install_(args_ InstallArgs) ! {
mut args := args_ mut args := args_
version := '1.11.1' version := '1.11.1'

View File

@@ -6,7 +6,7 @@ import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.core.pathlib import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.ui.console
pub fn install() ! { pub fn install_() ! {
if osal.platform() != .ubuntu || osal.platform() != .arch { if osal.platform() != .ubuntu || osal.platform() != .arch {
return error('only support ubuntu and arch for now') return error('only support ubuntu and arch for now')
} }

View File

@@ -9,7 +9,7 @@ import json
import os import os
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
res := os.execute('${osal.profile_path_source_and()} livekit-server -v') res := os.execute('${osal.profile_path_source_and()} livekit-server -v')
if res.exit_code != 0 { if res.exit_code != 0 {
return false return false
@@ -25,7 +25,7 @@ fn installed() !bool {
return true return true
} }
fn install() ! { fn install_() ! {
console.print_header('install livekit') console.print_header('install livekit')
mut installer := get()! mut installer := get()!
osal.execute_silent(' osal.execute_silent('
@@ -45,7 +45,7 @@ fn startupcmd() ![]zinit.ZProcessNewArgs {
return res return res
} }
fn running() !bool { fn running_() !bool {
mut installer := get()! mut installer := get()!
myport := installer.nr * 2 + 7880 myport := installer.nr * 2 + 7880
@@ -90,7 +90,7 @@ fn stop_post() ! {
// Post-stop cleanup if needed // Post-stop cleanup if needed
} }
fn destroy() ! { fn destroy_() ! {
mut installer := get()! mut installer := get()!
os.rm(installer.configpath) or {} os.rm(installer.configpath) or {}
os.rm('livekit-server') or {} os.rm('livekit-server') or {}

View File

@@ -8,7 +8,7 @@ import freeflowuniverse.herolib.installers.ulist
import os import os
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
res := os.execute('${osal.profile_path_source_and()} go version') res := os.execute('${osal.profile_path_source_and()} go version')
if res.exit_code == 0 { if res.exit_code == 0 {
r := res.output.split_into_lines() r := res.output.split_into_lines()
@@ -29,7 +29,7 @@ fn installed() !bool {
return false return false
} }
fn install() ! { fn install_() ! {
console.print_header('install golang') console.print_header('install golang')
base.install()! base.install()!
//destroy()! //destroy()!
@@ -62,7 +62,7 @@ fn install() ! {
osal.profile_path_add_remove(paths2add: '${go_dest}/bin')! osal.profile_path_add_remove(paths2add: '${go_dest}/bin')!
} }
fn build() ! { fn build_() ! {
} }
// get the Upload List of the files // get the Upload List of the files
@@ -72,7 +72,7 @@ fn ulist_get() !ulist.UList {
return ulist.UList{} return ulist.UList{}
} }
fn destroy() ! { fn destroy_() ! {
console.print_debug('golang destroy') console.print_debug('golang destroy')
osal.package_remove('golang')! osal.package_remove('golang')!

View File

@@ -6,6 +6,6 @@
default: true default: true
title: "" title: ""
templates: false templates: false
build: true build: false
startupmanager: true startupmanager: false

View File

@@ -11,7 +11,7 @@ import freeflowuniverse.herolib.osal
// reset bool // reset bool
// } // }
// pub fn install(args_ InstallArgs) ! { // pub fn install_(args_ InstallArgs) ! {
// _ := args_ // _ := args_
// pl := osal.platform() // pl := osal.platform()
// if pl == .arch { // if pl == .arch {

View File

@@ -4,184 +4,64 @@ import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.texttools import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.core.pathlib import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.osal.systemd
import freeflowuniverse.herolib.osal.zinit
import freeflowuniverse.herolib.installers.ulist import freeflowuniverse.herolib.installers.ulist
import freeflowuniverse.herolib.installers.lang.golang import freeflowuniverse.herolib.installers.base
import freeflowuniverse.herolib.installers.lang.rust
import freeflowuniverse.herolib.installers.lang.python
import os import os
fn startupcmd() ![]zinit.ZProcessNewArgs {
mut installer := get()!
mut res := []zinit.ZProcessNewArgs{}
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res << zinit.ZProcessNewArgs{
// name: 'nodejs'
// cmd: 'nodejs server'
// env: {
// 'HOME': '/root'
// }
// }
return res
}
fn running() !bool {
mut installer := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of nodejs
// curl http://localhost:3333/api/v1/s --oauth2-bearer 1234 works
// url:='http://127.0.0.1:${cfg.port}/api/v1'
// mut conn := httpconnection.new(name: 'nodejs', url: url)!
// if cfg.secret.len > 0 {
// conn.default_header.add(.authorization, 'Bearer ${cfg.secret}')
// }
// conn.default_header.add(.content_type, 'application/json')
// console.print_debug("curl -X 'GET' '${url}'/tags --oauth2-bearer ${cfg.secret}")
// r := conn.get_json_dict(prefix: 'tags', debug: false) or {return false}
// println(r)
// if true{panic("ssss")}
// tags := r['Tags'] or { return false }
// console.print_debug(tags)
// console.print_debug('nodejs is answering.')
return false
}
fn start_pre() ! {
}
fn start_post() ! {
}
fn stop_pre() ! {
}
fn stop_post() ! {
}
//////////////////// following actions are not specific to instance of the object //////////////////// following actions are not specific to instance of the object
// checks if a certain version or above is installed fn installed_() !bool {
fn installed() !bool { return false
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} nodejs 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 nodejs version.\n${res.output}")
// }
// if texttools.version(version) == texttools.version(r[0]) {
// return true
// }
return false
} }
// get the Upload List of the files //get the Upload List of the files
fn ulist_get() !ulist.UList { 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 //optionally build a UList which is all paths which are result of building, is then used e.g. in upload
return ulist.UList{} return ulist.UList{}
} }
// uploads to S3 server if configured //uploads to S3 server if configured
fn upload() ! { fn upload_() ! {
// installers.upload(
// cmdname: 'nodejs'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/nodejs'
// )!
} }
fn install() ! { fn install_() ! {
console.print_header('install nodejs') console.print_header('install nodejs')
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED osal.package_install('pnpm')!
// mut url := ''
// if osal.is_linux_arm() {
// url = 'https://github.com/nodejs-dev/nodejs/releases/download/v${version}/nodejs_${version}_linux_arm64.tar.gz'
// } else if osal.is_linux_intel() {
// url = 'https://github.com/nodejs-dev/nodejs/releases/download/v${version}/nodejs_${version}_linux_amd64.tar.gz'
// } else if osal.is_osx_arm() {
// url = 'https://github.com/nodejs-dev/nodejs/releases/download/v${version}/nodejs_${version}_darwin_arm64.tar.gz'
// } else if osal.is_osx_intel() {
// url = 'https://github.com/nodejs-dev/nodejs/releases/download/v${version}/nodejs_${version}_darwin_amd64.tar.gz'
// } else {
// return error('unsported platform')
// }
// mut dest := osal.download(
// url: url
// minsize_kb: 9000
// expand_dir: '/tmp/nodejs'
// )!
// //dest.moveup_single_subdir()!
// mut binpath := dest.file_get('nodejs')!
// osal.cmd_add(
// cmdname: 'nodejs'
// source: binpath.path
// )!
} }
fn build() ! {
// url := 'https://github.com/threefoldtech/nodejs'
// make sure we install base on the node fn destroy_() ! {
// if osal.platform() != .ubuntu {
// return error('only support ubuntu for now')
// }
// golang.install()!
// console.print_header('build nodejs') // mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")!
// gitpath := gittools.get_repo(coderoot: '/tmp/builder', url: url, reset: true, pull: true)! // osal.process_kill_recursive(name:'zinit')!
// osal.cmd_delete('zinit')!
osal.package_remove('
pnpm
')!
// //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
// ")!
// cmd := '
// cd ${gitpath}
// source ~/.cargo/env
// exit 1 #todo
// '
// osal.execute_stdout(cmd)!
//
// //now copy to the default bin path
// mut binpath := dest.file_get('...')!
// adds it to path
// osal.cmd_add(
// cmdname: 'griddriver2'
// 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,153 +1,54 @@
module nodejs module nodejs
import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit import freeflowuniverse.herolib.osal.zinit
import time import time
__global ( __global (
nodejs_global map[string]&NodeJS nodejs_global map[string]&NodeJS
nodejs_default string nodejs_default string
) )
/////////FACTORY /////////FACTORY
@[params]
pub struct ArgsGet {
pub mut:
name string
}
pub fn get(args_ ArgsGet) !&NodeJS {
return &NodeJS{}
}
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////# 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()!
}
}
}
pub fn (mut self NodeJS) start() ! {
switch(self.name)
if self.running()! {
return
}
console.print_header('nodejs start')
if !installed()! {
install()!
}
configure()!
start_pre()!
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
console.print_debug('starting nodejs with ${zprocess.startuptype}...')
sm.new(zprocess)!
sm.start(zprocess.name)!
}
start_post()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('nodejs did not install properly.')
}
pub fn (mut self NodeJS) install_start(model InstallArgs) ! {
switch(self.name)
self.install(model)!
self.start()!
}
pub fn (mut self NodeJS) stop() ! {
switch(self.name)
stop_pre()!
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
sm.stop(zprocess.name)!
}
stop_post()!
}
pub fn (mut self NodeJS) restart() ! {
switch(self.name)
self.stop()!
self.start()!
}
pub fn (mut self NodeJS) running() !bool {
switch(self.name)
// walk over the generic processes, if not running return
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
r := sm.running(zprocess.name)!
if r == false {
return false
}
}
return running()!
}
@[params] @[params]
pub struct InstallArgs { pub struct InstallArgs{
pub mut: pub mut:
reset bool reset bool
} }
pub fn (mut self NodeJS) install(model InstallArgs) ! {
switch(self.name) pub fn install(args InstallArgs) ! {
if model.reset || (!installed()!) { if args.reset {
install()! destroy()!
} }
if ! (installed_()!){
install_()!
}
} }
pub fn (mut self NodeJS) build() ! { pub fn destroy() ! {
switch(self.name) destroy_()!
build()!
} }
pub fn (mut self NodeJS) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
}
// switch instance to be used for nodejs
pub fn switch(name string) {
nodejs_default = name
}

View File

@@ -6,6 +6,6 @@
default: true default: true
title: "" title: ""
templates: false templates: false
build: true build: false
startupmanager: true startupmanager: false

View File

@@ -1,33 +0,0 @@
module python
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.installers.base
import freeflowuniverse.herolib.ui.console
pub fn install() ! {
if !osal.done_exists('install_python')
&& (!osal.cmd_exists('python') && !osal.cmd_exists('python3')) {
base.install()!
console.print_header('package install python')
osal.package_install('python3')!
pl := osal.platform()
if pl == .arch {
osal.package_install('python-pipx,python-pip,sqlite')!
} else if pl == .ubuntu {
osal.package_install('python-pipx,python-pip,sqlite')!
} else {
return error('only support arch & ubuntu.')
}
}
// console.print_header('python already done')
}
pub fn check() ! {
// todo: do a monitoring check to see if it works
// cmd := '
// '
// r := osal.execute_silent(cmd)!
// console.print_debug(r)
}

View File

@@ -4,184 +4,84 @@ import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.texttools import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.core.pathlib import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.osal.systemd
import freeflowuniverse.herolib.osal.zinit
import freeflowuniverse.herolib.installers.ulist import freeflowuniverse.herolib.installers.ulist
import freeflowuniverse.herolib.installers.lang.golang import freeflowuniverse.herolib.installers.base
import freeflowuniverse.herolib.installers.lang.rust
import freeflowuniverse.herolib.installers.lang.python
import os import os
fn startupcmd() ![]zinit.ZProcessNewArgs {
mut installer := get()!
mut res := []zinit.ZProcessNewArgs{}
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res << zinit.ZProcessNewArgs{
// name: 'python'
// cmd: 'python server'
// env: {
// 'HOME': '/root'
// }
// }
return res
}
fn running() !bool {
mut installer := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of python
// curl http://localhost:3333/api/v1/s --oauth2-bearer 1234 works
// url:='http://127.0.0.1:${cfg.port}/api/v1'
// mut conn := httpconnection.new(name: 'python', url: url)!
// if cfg.secret.len > 0 {
// conn.default_header.add(.authorization, 'Bearer ${cfg.secret}')
// }
// conn.default_header.add(.content_type, 'application/json')
// console.print_debug("curl -X 'GET' '${url}'/tags --oauth2-bearer ${cfg.secret}")
// r := conn.get_json_dict(prefix: 'tags', debug: false) or {return false}
// println(r)
// if true{panic("ssss")}
// tags := r['Tags'] or { return false }
// console.print_debug(tags)
// console.print_debug('python is answering.')
return false
}
fn start_pre() ! {
}
fn start_post() ! {
}
fn stop_pre() ! {
}
fn stop_post() ! {
}
//////////////////// following actions are not specific to instance of the object //////////////////// following actions are not specific to instance of the object
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED return false
// res := os.execute('${osal.profile_path_source_and()} python 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 python version.\n${res.output}")
// }
// if texttools.version(version) == texttools.version(r[0]) {
// return true
// }
return false
} }
// get the Upload List of the files //get the Upload List of the files
fn ulist_get() !ulist.UList { 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 //optionally build a UList which is all paths which are result of building, is then used e.g. in upload
return ulist.UList{} return ulist.UList{}
} }
// uploads to S3 server if configured fn upload_() ! {
fn upload() ! {
// installers.upload(
// cmdname: 'python'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/python'
// )!
} }
fn install() ! { fn install_() ! {
console.print_header('install python') console.print_header('install python')
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED base.install()!
// mut url := ''
// if osal.is_linux_arm() {
// url = 'https://github.com/python-dev/python/releases/download/v${version}/python_${version}_linux_arm64.tar.gz'
// } else if osal.is_linux_intel() {
// url = 'https://github.com/python-dev/python/releases/download/v${version}/python_${version}_linux_amd64.tar.gz'
// } else if osal.is_osx_arm() {
// url = 'https://github.com/python-dev/python/releases/download/v${version}/python_${version}_darwin_arm64.tar.gz'
// } else if osal.is_osx_intel() {
// url = 'https://github.com/python-dev/python/releases/download/v${version}/python_${version}_darwin_amd64.tar.gz'
// } else {
// return error('unsported platform')
// }
// mut dest := osal.download( osal.package_install('python3')!
// url: url pl := osal.platform()
// minsize_kb: 9000 if pl == .arch {
// expand_dir: '/tmp/python' osal.package_install('python-pipx,sqlite')!
// )! } else if pl == .ubuntu {
osal.package_install('python-pipx,sqlite')!
} else if pl == .osx {
osal.package_install('pipx,sqlite')!
// //dest.moveup_single_subdir()! } else {
return error('only support osx, arch & ubuntu.')
// mut binpath := dest.file_get('python')! }
// osal.cmd_add( osal.execute_silent("pipx install uv")!
// cmdname: 'python'
// source: binpath.path
// )!
} }
fn build() ! {
// url := 'https://github.com/threefoldtech/python'
// make sure we install base on the node fn destroy_() ! {
// if osal.platform() != .ubuntu {
// return error('only support ubuntu for now')
// }
// golang.install()!
// console.print_header('build python') panic("implement")
// 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
// ")!
// gitpath := gittools.get_repo(coderoot: '/tmp/builder', url: url, reset: true, pull: true)!
// cmd := '
// cd ${gitpath}
// source ~/.cargo/env
// exit 1 #todo
// '
// osal.execute_stdout(cmd)!
//
// //now copy to the default bin path
// mut binpath := dest.file_get('...')!
// adds it to path
// osal.cmd_add(
// cmdname: 'griddriver2'
// 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,153 +1,54 @@
module python module python
import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit import freeflowuniverse.herolib.osal.zinit
import time import time
__global ( __global (
python_global map[string]&Python python_global map[string]&Python
python_default string python_default string
) )
/////////FACTORY /////////FACTORY
@[params]
pub struct ArgsGet {
pub mut:
name string
}
pub fn get(args_ ArgsGet) !&Python {
return &Python{}
}
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////# 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()!
}
}
}
pub fn (mut self Python) start() ! {
switch(self.name)
if self.running()! {
return
}
console.print_header('python start')
if !installed()! {
install()!
}
configure()!
start_pre()!
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
console.print_debug('starting python with ${zprocess.startuptype}...')
sm.new(zprocess)!
sm.start(zprocess.name)!
}
start_post()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('python did not install properly.')
}
pub fn (mut self Python) install_start(model InstallArgs) ! {
switch(self.name)
self.install(model)!
self.start()!
}
pub fn (mut self Python) stop() ! {
switch(self.name)
stop_pre()!
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
sm.stop(zprocess.name)!
}
stop_post()!
}
pub fn (mut self Python) restart() ! {
switch(self.name)
self.stop()!
self.start()!
}
pub fn (mut self Python) running() !bool {
switch(self.name)
// walk over the generic processes, if not running return
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
r := sm.running(zprocess.name)!
if r == false {
return false
}
}
return running()!
}
@[params] @[params]
pub struct InstallArgs { pub struct InstallArgs{
pub mut: pub mut:
reset bool reset bool
} }
pub fn (mut self Python) install(model InstallArgs) ! {
switch(self.name) pub fn install(args InstallArgs) ! {
if model.reset || (!installed()!) { if args.reset {
install()! destroy()!
} }
if ! (installed_()!){
install_()!
}
} }
pub fn (mut self Python) build() ! { pub fn destroy() ! {
switch(self.name) destroy_()!
build()!
} }
pub fn (mut self Python) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
}
// switch instance to be used for python
pub fn switch(name string) {
python_default = name
}

View File

@@ -6,6 +6,6 @@
default: true default: true
title: "" title: ""
templates: false templates: false
build: true build: false
startupmanager: true startupmanager: false

View File

@@ -4,126 +4,54 @@ import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.texttools import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.core.pathlib import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.osal.systemd
import freeflowuniverse.herolib.osal.zinit
import freeflowuniverse.herolib.installers.ulist import freeflowuniverse.herolib.installers.ulist
import freeflowuniverse.herolib.installers.lang.golang import freeflowuniverse.herolib.installers.base
import freeflowuniverse.herolib.installers.lang.rust
import freeflowuniverse.herolib.installers.lang.python
import os import os
fn startupcmd() ![]zinit.ZProcessNewArgs {
mut installer := get()!
mut res := []zinit.ZProcessNewArgs{}
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res << zinit.ZProcessNewArgs{
// name: 'rust'
// cmd: 'rust server'
// env: {
// 'HOME': '/root'
// }
// }
return res
}
fn running() !bool {
mut installer := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of rust
// curl http://localhost:3333/api/v1/s --oauth2-bearer 1234 works
// url:='http://127.0.0.1:${cfg.port}/api/v1'
// mut conn := httpconnection.new(name: 'rust', url: url)!
// if cfg.secret.len > 0 {
// conn.default_header.add(.authorization, 'Bearer ${cfg.secret}')
// }
// conn.default_header.add(.content_type, 'application/json')
// console.print_debug("curl -X 'GET' '${url}'/tags --oauth2-bearer ${cfg.secret}")
// r := conn.get_json_dict(prefix: 'tags', debug: false) or {return false}
// println(r)
// if true{panic("ssss")}
// tags := r['Tags'] or { return false }
// console.print_debug(tags)
// console.print_debug('rust is answering.')
return false
}
fn start_pre() ! {
}
fn start_post() ! {
}
fn stop_pre() ! {
}
fn stop_post() ! {
}
//////////////////// following actions are not specific to instance of the object //////////////////// following actions are not specific to instance of the object
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED res := os.execute('${osal.profile_path_source_and()} rustc -V')
// res := os.execute('${osal.profile_path_source_and()} rust version') if res.exit_code != 0 {
// if res.exit_code != 0 { return false
// return false }
// } r := res.output.split_into_lines().filter(it.trim_space().len > 0)
// r := res.output.split_into_lines().filter(it.trim_space().len > 0) if r.len != 1 {
// if r.len != 1 { return error("couldn't parse rust version.\n${res.output}")
// return error("couldn't parse rust version.\n${res.output}") }
// } myversion := r[0].all_after_first("rustc").all_before("(")
// if texttools.version(version) == texttools.version(r[0]) { if texttools.version(version) == texttools.version(myversion) {
// return true return true
// } }
return false return false
} }
// get the Upload List of the files //get the Upload List of the files
fn ulist_get() !ulist.UList { 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 //optionally build a UList which is all paths which are result of building, is then used e.g. in upload
return ulist.UList{} return ulist.UList{}
} }
// uploads to S3 server if configured //uploads to S3 server if configured
fn upload() ! { fn upload_() ! {
// installers.upload( // installers.upload(
// cmdname: 'rust' // cmdname: 'rust'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/rust' // source: '${gitpath}/target/x86_64-unknown-linux-musl/release/rust'
// )! // )!
} }
fn install() ! { fn install_() ! {
console.print_header('install rust') console.print_header('install rust')
mut args := args_ version := '1.83.0'
version := '1.78.0'
res := os.execute('rustc -V')
if res.exit_code == 0 {
r := res.output.split_into_lines()
.filter(it.contains('rustc'))
if r.len != 1 {
return error("couldn't parse rust version, expected 'rustc 1.' on 1 row.\n${res.output}")
}
mut vstring := r[0] or { panic('bug') }
vstring = vstring.all_after_first(' ').all_before('(').trim_space()
if texttools.version(version) > texttools.version(vstring) {
args.reset = true
}
} else {
args.reset = true
}
if args.reset == false {
return
}
base.install()! base.install()!
pl := osal.platform() pl := osal.platform()
console.print_header('start install rust')
if pl == .ubuntu { if pl == .ubuntu {
osal.package_install('build-essential,openssl,pkg-config,libssl-dev,gcc')! osal.package_install('build-essential,openssl,pkg-config,libssl-dev,gcc')!
@@ -140,63 +68,48 @@ fn install() ! {
return return
} }
fn build() ! {
// url := 'https://github.com/threefoldtech/rust'
// make sure we install base on the node fn destroy_() ! {
// if osal.platform() != .ubuntu {
// return error('only support ubuntu for now')
// }
// golang.install()!
// console.print_header('build rust') osal.package_remove('
rust
')!
// gitpath := gittools.get_repo(coderoot: '/tmp/builder', url: url, reset: true, pull: true)! osal.exec(cmd:'
#!/bin/bash
# Script to uninstall Rust and Rust-related files
# Use at your own risk. Make sure to backup your data if necessary.
echo "Starting Rust uninstallation process..."
# Step 1: Check if rustup is installed
if command -v rustup > /dev/null 2>&1; then
echo "Rustup found. Proceeding with uninstallation."
rustup self uninstall -y
else
echo "Rustup is not installed. Skipping rustup uninstallation."
fi
# Step 2: Remove cargo and rustc binaries
echo "Removing cargo and rustc binaries if they exist..."
rm -f ~/.cargo/bin/cargo
rm -f ~/.cargo/bin/rustc
# Step 3: Remove Rust-related directories
echo "Removing Rust-related directories..."
rm -rf ~/.cargo
rm -rf ~/.rustup
echo "Rust uninstallation process completed."
',debug:false)!
osal.rm("
rustc
rustup
cargo
")!
// cmd := '
// cd ${gitpath}
// source ~/.cargo/env
// exit 1 #todo
// '
// osal.execute_stdout(cmd)!
//
// //now copy to the default bin path
// mut binpath := dest.file_get('...')!
// adds it to path
// osal.cmd_add(
// cmdname: 'griddriver2'
// 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,153 +1,54 @@
module rust module rust
import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit import freeflowuniverse.herolib.osal.zinit
import time import time
__global ( __global (
rust_global map[string]&RustInstaller rust_global map[string]&RustInstaller
rust_default string rust_default string
) )
/////////FACTORY /////////FACTORY
@[params]
pub struct ArgsGet {
pub mut:
name string
}
pub fn get(args_ ArgsGet) !&RustInstaller {
return &RustInstaller{}
}
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////# 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()!
}
}
}
pub fn (mut self RustInstaller) start() ! {
switch(self.name)
if self.running()! {
return
}
console.print_header('rust start')
if !installed()! {
install()!
}
configure()!
start_pre()!
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
console.print_debug('starting rust with ${zprocess.startuptype}...')
sm.new(zprocess)!
sm.start(zprocess.name)!
}
start_post()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('rust did not install properly.')
}
pub fn (mut self RustInstaller) install_start(model InstallArgs) ! {
switch(self.name)
self.install(model)!
self.start()!
}
pub fn (mut self RustInstaller) stop() ! {
switch(self.name)
stop_pre()!
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
sm.stop(zprocess.name)!
}
stop_post()!
}
pub fn (mut self RustInstaller) restart() ! {
switch(self.name)
self.stop()!
self.start()!
}
pub fn (mut self RustInstaller) running() !bool {
switch(self.name)
// walk over the generic processes, if not running return
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
r := sm.running(zprocess.name)!
if r == false {
return false
}
}
return running()!
}
@[params] @[params]
pub struct InstallArgs { pub struct InstallArgs{
pub mut: pub mut:
reset bool reset bool
} }
pub fn (mut self RustInstaller) install(model InstallArgs) ! {
switch(self.name) pub fn install(args InstallArgs) ! {
if model.reset || (!installed()!) { if args.reset {
install()! destroy()!
} }
if ! (installed_()!){
install_()!
}
} }
pub fn (mut self RustInstaller) build() ! { pub fn destroy() ! {
switch(self.name) destroy_()!
build()!
} }
pub fn (mut self RustInstaller) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
}
// switch instance to be used for rust
pub fn switch(name string) {
rust_default = name
}

View File

@@ -1,27 +1,29 @@
module rust module rust
import freeflowuniverse.herolib.data.paramsparser import freeflowuniverse.herolib.data.paramsparser
import os import os
pub const version = '1.78.0' pub const version = '1.83.0'
const singleton = true const singleton = true
const default = true const default = true
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
//THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
@[heap] @[heap]
pub struct RustInstaller { pub struct RustInstaller {
pub mut: pub mut:
name string = 'default' name string = 'default'
} }
fn obj_init(obj_ RustInstaller) !RustInstaller {
// never call get here, only thing we can do here is work on object itself fn obj_init(obj_ RustInstaller)!RustInstaller{
mut obj := obj_ //never call get here, only thing we can do here is work on object itself
panic('implement') mut obj:=obj_
return obj return obj
} }
// called before start if done //called before start if done
fn configure() ! { fn configure() ! {
// mut installer := get()! //mut installer := get()!
} }

View File

@@ -177,7 +177,7 @@ pub fn check() bool {
} }
// install mycelium will return true if it was already installed // install mycelium will return true if it was already installed
pub fn build() ! { pub fn build_() ! {
rust.install()! rust.install()!
console.print_header('build mycelium') console.print_header('build mycelium')
if !osal.done_exists('build_mycelium') && !osal.cmd_exists('mycelium') { if !osal.done_exists('build_mycelium') && !osal.cmd_exists('mycelium') {

View File

@@ -27,7 +27,7 @@ fn startupcmd() ![]zinit.ZProcessNewArgs {
return res return res
} }
fn running() !bool { fn running_() !bool {
mut installer := get()! mut installer := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of mycelium // this checks health of mycelium
@@ -64,7 +64,7 @@ fn stop_post() ! {
//////////////////// following actions are not specific to instance of the object //////////////////// following actions are not specific to instance of the object
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} mycelium version') // res := os.execute('${osal.profile_path_source_and()} mycelium version')
// if res.exit_code != 0 { // if res.exit_code != 0 {
@@ -87,14 +87,14 @@ fn ulist_get() !ulist.UList {
} }
// uploads to S3 server if configured // uploads to S3 server if configured
fn upload() ! { fn upload_() ! {
// installers.upload( // installers.upload(
// cmdname: 'mycelium' // cmdname: 'mycelium'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/mycelium' // source: '${gitpath}/target/x86_64-unknown-linux-musl/release/mycelium'
// )! // )!
} }
fn install() ! { fn install_() ! {
console.print_header('install mycelium') console.print_header('install mycelium')
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := '' // mut url := ''
@@ -125,7 +125,7 @@ fn install() ! {
// )! // )!
} }
fn build() ! { fn build_() ! {
// url := 'https://github.com/threefoldtech/mycelium' // url := 'https://github.com/threefoldtech/mycelium'
// make sure we install base on the node // make sure we install base on the node
@@ -154,7 +154,7 @@ fn build() ! {
// )! // )!
} }
fn destroy() ! { fn destroy_() ! {
// mut systemdfactory := systemd.new()! // mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")! // systemdfactory.destroy("zinit")!

View File

@@ -127,7 +127,7 @@ pub fn start() ! {
} }
} }
pub fn running() !bool { pub fn running_() !bool {
mut scr := screen.new(reset: false)! mut scr := screen.new(reset: false)!
name := 'yggdrasil' name := 'yggdrasil'

View File

@@ -27,7 +27,7 @@ fn startupcmd() ![]zinit.ZProcessNewArgs {
return res return res
} }
fn running() !bool { fn running_() !bool {
mut installer := get()! mut installer := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of yggdrasil // this checks health of yggdrasil
@@ -64,7 +64,7 @@ fn stop_post() ! {
//////////////////// following actions are not specific to instance of the object //////////////////// following actions are not specific to instance of the object
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} yggdrasil version') // res := os.execute('${osal.profile_path_source_and()} yggdrasil version')
// if res.exit_code != 0 { // if res.exit_code != 0 {
@@ -87,14 +87,14 @@ fn ulist_get() !ulist.UList {
} }
// uploads to S3 server if configured // uploads to S3 server if configured
fn upload() ! { fn upload_() ! {
// installers.upload( // installers.upload(
// cmdname: 'yggdrasil' // cmdname: 'yggdrasil'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/yggdrasil' // source: '${gitpath}/target/x86_64-unknown-linux-musl/release/yggdrasil'
// )! // )!
} }
fn install() ! { fn install_() ! {
console.print_header('install yggdrasil') console.print_header('install yggdrasil')
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := '' // mut url := ''
@@ -125,7 +125,7 @@ fn install() ! {
// )! // )!
} }
fn build() ! { fn build_() ! {
// url := 'https://github.com/threefoldtech/yggdrasil' // url := 'https://github.com/threefoldtech/yggdrasil'
// make sure we install base on the node // make sure we install base on the node
@@ -154,7 +154,7 @@ fn build() ! {
// )! // )!
} }
fn destroy() ! { fn destroy_() ! {
// mut systemdfactory := systemd.new()! // mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")! // systemdfactory.destroy("zinit")!

View File

@@ -27,7 +27,7 @@ fn startupcmd() ![]zinit.ZProcessNewArgs {
return res return res
} }
fn running() !bool { fn running_() !bool {
mut installer := get()! mut installer := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of actrunner // this checks health of actrunner
@@ -64,7 +64,7 @@ fn stop_post() ! {
//////////////////// following actions are not specific to instance of the object //////////////////// following actions are not specific to instance of the object
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} actrunner version') // res := os.execute('${osal.profile_path_source_and()} actrunner version')
// if res.exit_code != 0 { // if res.exit_code != 0 {
@@ -87,14 +87,14 @@ fn ulist_get() !ulist.UList {
} }
// uploads to S3 server if configured // uploads to S3 server if configured
fn upload() ! { fn upload_() ! {
// installers.upload( // installers.upload(
// cmdname: 'actrunner' // cmdname: 'actrunner'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/actrunner' // source: '${gitpath}/target/x86_64-unknown-linux-musl/release/actrunner'
// )! // )!
} }
fn install() ! { fn install_() ! {
console.print_header('install actrunner') console.print_header('install actrunner')
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := '' // mut url := ''
@@ -125,7 +125,7 @@ fn install() ! {
// )! // )!
} }
fn build() ! { fn build_() ! {
// url := 'https://github.com/threefoldtech/actrunner' // url := 'https://github.com/threefoldtech/actrunner'
// make sure we install base on the node // make sure we install base on the node
@@ -154,7 +154,7 @@ fn build() ! {
// )! // )!
} }
fn destroy() ! { fn destroy_() ! {
// mut systemdfactory := systemd.new()! // mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")! // systemdfactory.destroy("zinit")!

View File

@@ -27,7 +27,7 @@ fn startupcmd() ![]zinit.ZProcessNewArgs {
return res return res
} }
fn running() !bool { fn running_() !bool {
mut installer := get()! mut installer := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of b2 // this checks health of b2
@@ -64,7 +64,7 @@ fn stop_post() ! {
//////////////////// following actions are not specific to instance of the object //////////////////// following actions are not specific to instance of the object
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} b2 version') // res := os.execute('${osal.profile_path_source_and()} b2 version')
// if res.exit_code != 0 { // if res.exit_code != 0 {
@@ -87,14 +87,14 @@ fn ulist_get() !ulist.UList {
} }
// uploads to S3 server if configured // uploads to S3 server if configured
fn upload() ! { fn upload_() ! {
// installers.upload( // installers.upload(
// cmdname: 'b2' // cmdname: 'b2'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/b2' // source: '${gitpath}/target/x86_64-unknown-linux-musl/release/b2'
// )! // )!
} }
fn install() ! { fn install_() ! {
console.print_header('install b2') console.print_header('install b2')
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := '' // mut url := ''
@@ -125,7 +125,7 @@ fn install() ! {
// )! // )!
} }
fn build() ! { fn build_() ! {
// url := 'https://github.com/threefoldtech/b2' // url := 'https://github.com/threefoldtech/b2'
// make sure we install base on the node // make sure we install base on the node
@@ -154,7 +154,7 @@ fn build() ! {
// )! // )!
} }
fn destroy() ! { fn destroy_() ! {
// mut systemdfactory := systemd.new()! // mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")! // systemdfactory.destroy("zinit")!

View File

@@ -27,7 +27,7 @@ fn startupcmd() ![]zinit.ZProcessNewArgs {
return res return res
} }
fn running() !bool { fn running_() !bool {
mut installer := get()! mut installer := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of fungistor // this checks health of fungistor
@@ -64,7 +64,7 @@ fn stop_post() ! {
//////////////////// following actions are not specific to instance of the object //////////////////// following actions are not specific to instance of the object
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} fungistor version') // res := os.execute('${osal.profile_path_source_and()} fungistor version')
// if res.exit_code != 0 { // if res.exit_code != 0 {
@@ -87,14 +87,14 @@ fn ulist_get() !ulist.UList {
} }
// uploads to S3 server if configured // uploads to S3 server if configured
fn upload() ! { fn upload_() ! {
// installers.upload( // installers.upload(
// cmdname: 'fungistor' // cmdname: 'fungistor'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/fungistor' // source: '${gitpath}/target/x86_64-unknown-linux-musl/release/fungistor'
// )! // )!
} }
fn install() ! { fn install_() ! {
console.print_header('install fungistor') console.print_header('install fungistor')
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := '' // mut url := ''
@@ -125,7 +125,7 @@ fn install() ! {
// )! // )!
} }
fn build() ! { fn build_() ! {
// url := 'https://github.com/threefoldtech/fungistor' // url := 'https://github.com/threefoldtech/fungistor'
// make sure we install base on the node // make sure we install base on the node
@@ -154,7 +154,7 @@ fn build() ! {
// )! // )!
} }
fn destroy() ! { fn destroy_() ! {
// mut systemdfactory := systemd.new()! // mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")! // systemdfactory.destroy("zinit")!

View File

@@ -27,7 +27,7 @@ fn startupcmd() ![]zinit.ZProcessNewArgs {
return res return res
} }
fn running() !bool { fn running_() !bool {
mut installer := get()! mut installer := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of garage_s3 // this checks health of garage_s3
@@ -64,7 +64,7 @@ fn stop_post() ! {
//////////////////// following actions are not specific to instance of the object //////////////////// following actions are not specific to instance of the object
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} garage_s3 version') // res := os.execute('${osal.profile_path_source_and()} garage_s3 version')
// if res.exit_code != 0 { // if res.exit_code != 0 {
@@ -87,14 +87,14 @@ fn ulist_get() !ulist.UList {
} }
// uploads to S3 server if configured // uploads to S3 server if configured
fn upload() ! { fn upload_() ! {
// installers.upload( // installers.upload(
// cmdname: 'garage_s3' // cmdname: 'garage_s3'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/garage_s3' // source: '${gitpath}/target/x86_64-unknown-linux-musl/release/garage_s3'
// )! // )!
} }
fn install() ! { fn install_() ! {
console.print_header('install garage_s3') console.print_header('install garage_s3')
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := '' // mut url := ''
@@ -125,7 +125,7 @@ fn install() ! {
// )! // )!
} }
fn build() ! { fn build_() ! {
// url := 'https://github.com/threefoldtech/garage_s3' // url := 'https://github.com/threefoldtech/garage_s3'
// make sure we install base on the node // make sure we install base on the node
@@ -154,7 +154,7 @@ fn build() ! {
// )! // )!
} }
fn destroy() ! { fn destroy_() ! {
// mut systemdfactory := systemd.new()! // mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")! // systemdfactory.destroy("zinit")!

View File

@@ -27,7 +27,7 @@ fn startupcmd() ![]zinit.ZProcessNewArgs {
return res return res
} }
fn running() !bool { fn running_() !bool {
mut installer := get()! mut installer := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of grafana // this checks health of grafana
@@ -64,7 +64,7 @@ fn stop_post() ! {
//////////////////// following actions are not specific to instance of the object //////////////////// following actions are not specific to instance of the object
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} grafana version') // res := os.execute('${osal.profile_path_source_and()} grafana version')
// if res.exit_code != 0 { // if res.exit_code != 0 {
@@ -87,14 +87,14 @@ fn ulist_get() !ulist.UList {
} }
// uploads to S3 server if configured // uploads to S3 server if configured
fn upload() ! { fn upload_() ! {
// installers.upload( // installers.upload(
// cmdname: 'grafana' // cmdname: 'grafana'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/grafana' // source: '${gitpath}/target/x86_64-unknown-linux-musl/release/grafana'
// )! // )!
} }
fn install() ! { fn install_() ! {
console.print_header('install grafana') console.print_header('install grafana')
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := '' // mut url := ''
@@ -125,7 +125,7 @@ fn install() ! {
// )! // )!
} }
fn build() ! { fn build_() ! {
// url := 'https://github.com/threefoldtech/grafana' // url := 'https://github.com/threefoldtech/grafana'
// make sure we install base on the node // make sure we install base on the node
@@ -154,7 +154,7 @@ fn build() ! {
// )! // )!
} }
fn destroy() ! { fn destroy_() ! {
// mut systemdfactory := systemd.new()! // mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")! // systemdfactory.destroy("zinit")!

View File

@@ -27,7 +27,7 @@ fn startupcmd() ![]zinit.ZProcessNewArgs {
return res return res
} }
fn running() !bool { fn running_() !bool {
mut installer := get()! mut installer := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of prometheus // this checks health of prometheus
@@ -64,7 +64,7 @@ fn stop_post() ! {
//////////////////// following actions are not specific to instance of the object //////////////////// following actions are not specific to instance of the object
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} prometheus version') // res := os.execute('${osal.profile_path_source_and()} prometheus version')
// if res.exit_code != 0 { // if res.exit_code != 0 {
@@ -87,14 +87,14 @@ fn ulist_get() !ulist.UList {
} }
// uploads to S3 server if configured // uploads to S3 server if configured
fn upload() ! { fn upload_() ! {
// installers.upload( // installers.upload(
// cmdname: 'prometheus' // cmdname: 'prometheus'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/prometheus' // source: '${gitpath}/target/x86_64-unknown-linux-musl/release/prometheus'
// )! // )!
} }
fn install() ! { fn install_() ! {
console.print_header('install prometheus') console.print_header('install prometheus')
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := '' // mut url := ''
@@ -125,7 +125,7 @@ fn install() ! {
// )! // )!
} }
fn build() ! { fn build_() ! {
// url := 'https://github.com/threefoldtech/prometheus' // url := 'https://github.com/threefoldtech/prometheus'
// make sure we install base on the node // make sure we install base on the node
@@ -154,7 +154,7 @@ fn build() ! {
// )! // )!
} }
fn destroy() ! { fn destroy_() ! {
// mut systemdfactory := systemd.new()! // mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")! // systemdfactory.destroy("zinit")!

View File

@@ -27,7 +27,7 @@ import time
// // port int = 8888 // // port int = 8888
// } // }
// pub fn install(args_ InstallArgs) ! { // pub fn install_(args_ InstallArgs) ! {
// install_prometheus(args_)! // install_prometheus(args_)!
// install_alertmanager(args_)! // install_alertmanager(args_)!
// install_node_exporter(args_)! // install_node_exporter(args_)!

View File

@@ -7,7 +7,7 @@ import freeflowuniverse.herolib.core.httpconnection
import os import os
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
res := os.execute('${osal.profile_path_source_and()} rclone version') res := os.execute('${osal.profile_path_source_and()} rclone version')
if res.exit_code != 0 { if res.exit_code != 0 {
return false return false
@@ -23,7 +23,7 @@ fn installed() !bool {
return true return true
} }
fn install() ! { fn install_() ! {
console.print_header('install rclone') console.print_header('install rclone')
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
mut url := '' mut url := ''
@@ -64,7 +64,7 @@ fn configure() ! {
// implement if steps need to be done for configuration // implement if steps need to be done for configuration
} }
fn destroy() ! { fn destroy_() ! {
} }
fn start_pre() ! { fn start_pre() ! {

View File

@@ -16,7 +16,7 @@ pub mut:
} }
// install restic will return true if it was already installed // install restic will return true if it was already installed
pub fn build(args BuildArgs) ! { pub fn build_(args BuildArgs) ! {
// make sure we install base on the node // make sure we install base on the node
if osal.platform() != .ubuntu { if osal.platform() != .ubuntu {
return error('only support ubuntu for now') return error('only support ubuntu for now')

View File

@@ -27,7 +27,7 @@ fn startupcmd() ![]zinit.ZProcessNewArgs {
return res return res
} }
fn running() !bool { fn running_() !bool {
mut installer := get()! mut installer := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of restic // this checks health of restic
@@ -64,7 +64,7 @@ fn stop_post() ! {
//////////////////// following actions are not specific to instance of the object //////////////////// following actions are not specific to instance of the object
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} restic version') // res := os.execute('${osal.profile_path_source_and()} restic version')
// if res.exit_code != 0 { // if res.exit_code != 0 {
@@ -87,14 +87,14 @@ fn ulist_get() !ulist.UList {
} }
// uploads to S3 server if configured // uploads to S3 server if configured
fn upload() ! { fn upload_() ! {
// installers.upload( // installers.upload(
// cmdname: 'restic' // cmdname: 'restic'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/restic' // source: '${gitpath}/target/x86_64-unknown-linux-musl/release/restic'
// )! // )!
} }
fn install() ! { fn install_() ! {
console.print_header('install restic') console.print_header('install restic')
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := '' // mut url := ''
@@ -125,7 +125,7 @@ fn install() ! {
// )! // )!
} }
fn build() ! { fn build_() ! {
// url := 'https://github.com/threefoldtech/restic' // url := 'https://github.com/threefoldtech/restic'
// make sure we install base on the node // make sure we install base on the node
@@ -154,7 +154,7 @@ fn build() ! {
// )! // )!
} }
fn destroy() ! { fn destroy_() ! {
// mut systemdfactory := systemd.new()! // mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")! // systemdfactory.destroy("zinit")!

View File

@@ -13,7 +13,7 @@ pub mut:
} }
// install s3cas will return true if it was already installed // install s3cas will return true if it was already installed
pub fn build(args BuildArgs) ! { pub fn build_(args BuildArgs) ! {
// make sure we install base on the node // make sure we install base on the node
if osal.platform() != .ubuntu { if osal.platform() != .ubuntu {
return error('only support ubuntu for now') return error('only support ubuntu for now')

View File

@@ -7,7 +7,7 @@ import freeflowuniverse.herolib.installers.rclone
import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.ui.console
// install s3 will return true if it was already installed // install s3 will return true if it was already installed
pub fn install() ! { pub fn install_() ! {
base.install()! base.install()!
zinitinstaller.install()! zinitinstaller.install()!
rclone.install()! rclone.install()!

View File

@@ -27,7 +27,7 @@ fn startupcmd() ![]zinit.ZProcessNewArgs {
return res return res
} }
fn running() !bool { fn running_() !bool {
mut installer := get()! mut installer := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of s3 // this checks health of s3
@@ -64,7 +64,7 @@ fn stop_post() ! {
//////////////////// following actions are not specific to instance of the object //////////////////// following actions are not specific to instance of the object
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} s3 version') // res := os.execute('${osal.profile_path_source_and()} s3 version')
// if res.exit_code != 0 { // if res.exit_code != 0 {
@@ -87,14 +87,14 @@ fn ulist_get() !ulist.UList {
} }
// uploads to S3 server if configured // uploads to S3 server if configured
fn upload() ! { fn upload_() ! {
// installers.upload( // installers.upload(
// cmdname: 's3' // cmdname: 's3'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/s3' // source: '${gitpath}/target/x86_64-unknown-linux-musl/release/s3'
// )! // )!
} }
fn install() ! { fn install_() ! {
console.print_header('install s3') console.print_header('install s3')
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := '' // mut url := ''
@@ -125,7 +125,7 @@ fn install() ! {
// )! // )!
} }
fn build() ! { fn build_() ! {
// url := 'https://github.com/threefoldtech/s3' // url := 'https://github.com/threefoldtech/s3'
// make sure we install base on the node // make sure we install base on the node
@@ -154,7 +154,7 @@ fn build() ! {
// )! // )!
} }
fn destroy() ! { fn destroy_() ! {
// mut systemdfactory := systemd.new()! // mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")! // systemdfactory.destroy("zinit")!

View File

@@ -11,7 +11,7 @@ import freeflowuniverse.herolib.osal.systemd
import os import os
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
cmd := 'zinit --version' cmd := 'zinit --version'
// console.print_debug(cmd) // console.print_debug(cmd)
res := os.execute(cmd) res := os.execute(cmd)
@@ -28,7 +28,7 @@ fn installed() !bool {
return false return false
} }
fn install() ! { fn install_() ! {
console.print_header('install zinit') console.print_header('install zinit')
if !osal.is_linux() { if !osal.is_linux() {
return error('only support linux for now') return error('only support linux for now')
@@ -52,7 +52,7 @@ fn install() ! {
console.print_header('install zinit done') console.print_header('install zinit done')
} }
fn build() ! { fn build_() ! {
if !osal.is_linux() { if !osal.is_linux() {
return error('only support linux for now') return error('only support linux for now')
} }
@@ -91,7 +91,7 @@ fn ulist_get() !ulist.UList {
} }
// uploads to S3 server if configured // uploads to S3 server if configured
fn upload() ! { fn upload_() ! {
} }
fn startupcmd() ![]ZProcessNewArgs { fn startupcmd() ![]ZProcessNewArgs {
@@ -106,7 +106,7 @@ fn startupcmd() ![]ZProcessNewArgs {
return res return res
} }
fn running() !bool { fn running_() !bool {
cmd := 'zinit list' cmd := 'zinit list'
return osal.execute_ok(cmd) return osal.execute_ok(cmd)
} }
@@ -123,7 +123,7 @@ fn stop_pre() ! {
fn stop_post() ! { fn stop_post() ! {
} }
fn destroy() ! { fn destroy_() ! {
mut systemdfactory := systemd.new()! mut systemdfactory := systemd.new()!
systemdfactory.destroy('zinit')! systemdfactory.destroy('zinit')!

View File

@@ -9,7 +9,7 @@ import freeflowuniverse.herolib.core.texttools
import os import os
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
res := os.execute('${osal.profile_path_source_and()} griddriver --version') res := os.execute('${osal.profile_path_source_and()} griddriver --version')
if res.exit_code != 0 { if res.exit_code != 0 {
return false return false
@@ -27,12 +27,12 @@ fn installed() !bool {
return true return true
} }
fn install() ! { fn install_() ! {
// console.print_header('install griddriver') // console.print_header('install griddriver')
build()! build()!
} }
fn build() ! { fn build_() ! {
console.print_header('build griddriver') console.print_header('build griddriver')
mut installer := golang.get()! mut installer := golang.get()!
installer.install()! installer.install()!
@@ -66,7 +66,7 @@ fn ulist_get() !ulist.UList {
} }
// uploads to S3 server if configured // uploads to S3 server if configured
fn upload() ! { fn upload_() ! {
// mut installer := get()! // mut installer := get()!
// installers.upload( // installers.upload(
// cmdname: 'griddriver' // cmdname: 'griddriver'
@@ -74,7 +74,7 @@ fn upload() ! {
// )! // )!
} }
fn destroy() ! { fn destroy_() ! {
// mut installer := get()! // mut installer := get()!
// cmd:=" // cmd:="
// systemctl disable griddriver_scheduler.service // systemctl disable griddriver_scheduler.service

View File

@@ -14,7 +14,7 @@ pub mut:
uninstall bool uninstall bool
} }
pub fn install(args_ InstallArgs) ! { pub fn install_(args_ InstallArgs) ! {
mut args := args_ mut args := args_
version := '0.14.0' version := '0.14.0'
@@ -38,7 +38,7 @@ pub fn install(args_ InstallArgs) ! {
} }
} }
pub fn build() ! { pub fn build_() ! {
mut g := golang.get()! mut g := golang.get()!
g.install()! g.install()!
console.print_header('build tfrobot') console.print_header('build tfrobot')

View File

@@ -11,7 +11,7 @@ pub mut:
reset bool reset bool
} }
pub fn upload(args_ UploadArgs) ! { pub fn upload_(args_ UploadArgs) ! {
//_ := args_ //_ := args_
panic('to implement') panic('to implement')
} }

View File

@@ -8,7 +8,7 @@ import freeflowuniverse.herolib.installers.lang.golang
import os import os
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
res := os.execute('${osal.profile_path_source_and()} buildah -v') res := os.execute('${osal.profile_path_source_and()} buildah -v')
if res.exit_code != 0 { if res.exit_code != 0 {
return false return false
@@ -24,12 +24,12 @@ fn installed() !bool {
return false return false
} }
fn install() ! { fn install_() ! {
console.print_header('install buildah') console.print_header('install buildah')
build()! build()!
} }
fn build() ! { fn build_() ! {
console.print_header('build buildah') console.print_header('build buildah')
osal.package_install('runc,bats,btrfs-progs,git,go-md2man,libapparmor-dev,libglib2.0-dev,libgpgme11-dev,libseccomp-dev,libselinux1-dev,make,skopeo,libbtrfs-dev')! osal.package_install('runc,bats,btrfs-progs,git,go-md2man,libapparmor-dev,libglib2.0-dev,libgpgme11-dev,libseccomp-dev,libselinux1-dev,make,skopeo,libbtrfs-dev')!
@@ -64,7 +64,7 @@ fn ulist_get() !ulist.UList {
return ulist.UList{} return ulist.UList{}
} }
fn destroy() ! { fn destroy_() ! {
osal.package_remove(' osal.package_remove('
buildah buildah
')! ')!

View File

@@ -8,7 +8,7 @@ import freeflowuniverse.herolib.installers.ulist
// import freeflowuniverse.herolib.installers.lang.rust // import freeflowuniverse.herolib.installers.lang.rust
import os import os
fn installed() !bool { fn installed_() !bool {
res := os.execute('${osal.profile_path_source_and()} cloud-hypervisor --version') res := os.execute('${osal.profile_path_source_and()} cloud-hypervisor --version')
if res.exit_code == 0 { if res.exit_code == 0 {
r := res.output.split_into_lines().filter(it.contains('cloud-hypervisor')) r := res.output.split_into_lines().filter(it.contains('cloud-hypervisor'))
@@ -27,7 +27,7 @@ fn installed() !bool {
return true return true
} }
fn install() ! { fn install_() ! {
console.print_header('install cloudhypervisor') console.print_header('install cloudhypervisor')
// mut installer := get()! // mut installer := get()!
mut url := '' mut url := ''
@@ -59,7 +59,7 @@ fn install() ! {
)! )!
} }
fn build() ! { fn build_() ! {
} }
// get the Upload List of the files // get the Upload List of the files
@@ -70,7 +70,7 @@ fn ulist_get() !ulist.UList {
} }
// uploads to S3 server if configured // uploads to S3 server if configured
fn upload() ! { fn upload_() ! {
// mut installer := get()! // mut installer := get()!
// installers.upload( // installers.upload(
// cmdname: 'cloudhypervisor' // cmdname: 'cloudhypervisor'
@@ -78,7 +78,7 @@ fn upload() ! {
// )! // )!
} }
fn destroy() ! { fn destroy_() ! {
osal.process_kill_recursive(name: 'cloud-hypervisor')! osal.process_kill_recursive(name: 'cloud-hypervisor')!
osal.package_remove(' osal.package_remove('

View File

@@ -5,7 +5,7 @@ import freeflowuniverse.herolib.installers.base
import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.ui.console
// install docker will return true if it was already installed // install docker will return true if it was already installed
pub fn install() ! { pub fn install_() ! {
console.print_header('package install install docker') console.print_header('package install install docker')
if osal.platform() != .ubuntu { if osal.platform() != .ubuntu {
return error('only support ubuntu for now') return error('only support ubuntu for now')

View File

@@ -14,7 +14,7 @@ pub mut:
uninstall bool uninstall bool
} }
pub fn install(args_ InstallArgs) ! { pub fn install_(args_ InstallArgs) ! {
mut args := args_ mut args := args_
version := '0.22.0' version := '0.22.0'

View File

@@ -6,13 +6,13 @@ import freeflowuniverse.herolib.ui.console
import os import os
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
return osal.done_exists('install_pacman') return osal.done_exists('install_pacman')
} }
// use https://archlinux.org/mirrorlist/ // use https://archlinux.org/mirrorlist/
fn install() ! { fn install_() ! {
console.print_header('install pacman') console.print_header('install pacman')
if osal.platform() == .arch { if osal.platform() == .arch {
@@ -83,7 +83,7 @@ fn install() ! {
console.print_header('install done') console.print_header('install done')
} }
fn destroy() ! { fn destroy_() ! {
osal.done_delete('install_pacman')! osal.done_delete('install_pacman')!
osal.package_remove(' osal.package_remove('

View File

@@ -8,7 +8,7 @@ import freeflowuniverse.herolib.installers.ulist
import os import os
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
res := os.execute('${osal.profile_path_source_and()} podman -v') res := os.execute('${osal.profile_path_source_and()} podman -v')
if res.exit_code != 0 { if res.exit_code != 0 {
return false return false
@@ -24,7 +24,7 @@ fn installed() !bool {
return false return false
} }
fn install() ! { fn install_() ! {
console.print_header('install podman') console.print_header('install podman')
destroy()! destroy()!
@@ -73,7 +73,7 @@ fn install() ! {
} }
} }
fn build() ! { fn build_() ! {
// mut installer := get()! // mut installer := get()!
// https://podman.io/docs/installation#building-from-source // https://podman.io/docs/installation#building-from-source
@@ -155,7 +155,7 @@ fn ulist_get() !ulist.UList {
return ulist.UList{} return ulist.UList{}
} }
fn destroy() ! { fn destroy_() ! {
osal.package_remove(' osal.package_remove('
podman podman
conmon conmon

View File

@@ -13,7 +13,7 @@ pub mut:
uninstall bool uninstall bool
} }
pub fn install(args_ InstallArgs) ! { pub fn install_(args_ InstallArgs) ! {
mut args := args_ mut args := args_
mut version := '10.0.0' mut version := '10.0.0'

View File

@@ -12,7 +12,7 @@ import freeflowuniverse.herolib.installers.lang.python
import os import os
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} youki version') // res := os.execute('${osal.profile_path_source_and()} youki version')
// if res.exit_code != 0 { // if res.exit_code != 0 {
@@ -28,13 +28,13 @@ fn installed() !bool {
return false return false
} }
fn install() ! { fn install_() ! {
console.print_header('install youki') console.print_header('install youki')
destroy()! destroy()!
build()! build()!
} }
fn build() ! { fn build_() ! {
// mut installer := get()! // mut installer := get()!
url := 'https://github.com/containers/youki' url := 'https://github.com/containers/youki'
@@ -73,7 +73,7 @@ fn ulist_get() !ulist.UList {
} }
// uploads to S3 server if configured // uploads to S3 server if configured
fn upload() ! { fn upload_() ! {
// mut installer := get()! // mut installer := get()!
// installers.upload( // installers.upload(
// cmdname: 'youki' // cmdname: 'youki'
@@ -81,7 +81,7 @@ fn upload() ! {
// )! // )!
} }
fn destroy() ! { fn destroy_() ! {
osal.package_remove(' osal.package_remove('
runc runc
')! ')!

View File

@@ -6,7 +6,7 @@ import freeflowuniverse.herolib.osal.zinit
import os import os
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} caddy version') // res := os.execute('${osal.profile_path_source_and()} caddy version')
// if res.exit_code != 0 { // if res.exit_code != 0 {
@@ -22,7 +22,7 @@ fn installed() !bool {
return true return true
} }
fn install() ! { fn install_() ! {
console.print_header('install caddy') console.print_header('install caddy')
mut cfg := get()! mut cfg := get()!
@@ -113,7 +113,7 @@ pub fn configure_examples(config WebConfig) ! {
configuration_set(content: config_file)! configuration_set(content: config_file)!
} }
fn running() !bool { fn running_() !bool {
mut cfg := get()! mut cfg := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
@@ -137,7 +137,7 @@ fn running() !bool {
return true return true
} }
fn destroy() ! { fn destroy_() ! {
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// cmd:=" // cmd:="
// systemctl disable caddy_scheduler.service // systemctl disable caddy_scheduler.service

View File

@@ -25,7 +25,7 @@ pub const version = '2.8.4'
// } // }
// // install caddy will return true if it was already installed // // install caddy will return true if it was already installed
// pub fn install(args_ InstallArgs) ! { // pub fn install_(args_ InstallArgs) ! {
// mut args := args_ // mut args := args_
// version := '2.8.4' // version := '2.8.4'

View File

@@ -8,7 +8,7 @@ import os
const installername = os.base(os.dir(@FILE)) const installername = os.base(os.dir(@FILE))
// install imagemagick will return true if it was already installed // install imagemagick will return true if it was already installed
pub fn install() ! { pub fn install_() ! {
console.print_header('install ${installername}') console.print_header('install ${installername}')
if !osal.done_exists('install_${installername}') { if !osal.done_exists('install_${installername}') {
osal.package_install('imagemagick')! osal.package_install('imagemagick')!

View File

@@ -27,7 +27,7 @@ fn startupcmd() ![]zinit.ZProcessNewArgs {
return res return res
} }
fn running() !bool { fn running_() !bool {
mut installer := get()! mut installer := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of imagemagick // this checks health of imagemagick
@@ -64,7 +64,7 @@ fn stop_post() ! {
//////////////////// following actions are not specific to instance of the object //////////////////// following actions are not specific to instance of the object
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} imagemagick version') // res := os.execute('${osal.profile_path_source_and()} imagemagick version')
// if res.exit_code != 0 { // if res.exit_code != 0 {
@@ -87,14 +87,14 @@ fn ulist_get() !ulist.UList {
} }
// uploads to S3 server if configured // uploads to S3 server if configured
fn upload() ! { fn upload_() ! {
// installers.upload( // installers.upload(
// cmdname: 'imagemagick' // cmdname: 'imagemagick'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/imagemagick' // source: '${gitpath}/target/x86_64-unknown-linux-musl/release/imagemagick'
// )! // )!
} }
fn install() ! { fn install_() ! {
console.print_header('install imagemagick') console.print_header('install imagemagick')
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := '' // mut url := ''
@@ -125,7 +125,7 @@ fn install() ! {
// )! // )!
} }
fn build() ! { fn build_() ! {
// url := 'https://github.com/threefoldtech/imagemagick' // url := 'https://github.com/threefoldtech/imagemagick'
// make sure we install base on the node // make sure we install base on the node
@@ -154,7 +154,7 @@ fn build() ! {
// )! // )!
} }
fn destroy() ! { fn destroy_() ! {
// mut systemdfactory := systemd.new()! // mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")! // systemdfactory.destroy("zinit")!

View File

@@ -27,7 +27,7 @@ fn startupcmd() ![]zinit.ZProcessNewArgs {
return res return res
} }
fn running() !bool { fn running_() !bool {
mut installer := get()! mut installer := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of lighttpd // this checks health of lighttpd
@@ -64,7 +64,7 @@ fn stop_post() ! {
//////////////////// following actions are not specific to instance of the object //////////////////// following actions are not specific to instance of the object
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} lighttpd version') // res := os.execute('${osal.profile_path_source_and()} lighttpd version')
// if res.exit_code != 0 { // if res.exit_code != 0 {
@@ -87,14 +87,14 @@ fn ulist_get() !ulist.UList {
} }
// uploads to S3 server if configured // uploads to S3 server if configured
fn upload() ! { fn upload_() ! {
// installers.upload( // installers.upload(
// cmdname: 'lighttpd' // cmdname: 'lighttpd'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/lighttpd' // source: '${gitpath}/target/x86_64-unknown-linux-musl/release/lighttpd'
// )! // )!
} }
fn install() ! { fn install_() ! {
console.print_header('install lighttpd') console.print_header('install lighttpd')
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := '' // mut url := ''
@@ -125,7 +125,7 @@ fn install() ! {
// )! // )!
} }
fn build() ! { fn build_() ! {
// url := 'https://github.com/threefoldtech/lighttpd' // url := 'https://github.com/threefoldtech/lighttpd'
// make sure we install base on the node // make sure we install base on the node
@@ -154,7 +154,7 @@ fn build() ! {
// )! // )!
} }
fn destroy() ! { fn destroy_() ! {
// mut systemdfactory := systemd.new()! // mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")! // systemdfactory.destroy("zinit")!

View File

@@ -9,7 +9,7 @@ import os
pub const version = '3.4.12' pub const version = '3.4.12'
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
res := os.execute('tailwind -h') res := os.execute('tailwind -h')
if res.exit_code == 0 { if res.exit_code == 0 {
r := res.output.split_into_lines().filter(it.contains('tailwindcss v')) r := res.output.split_into_lines().filter(it.contains('tailwindcss v'))
@@ -26,7 +26,7 @@ fn installed() !bool {
return false return false
} }
pub fn install() ! { pub fn install_() ! {
console.print_header('install tailwind') console.print_header('install tailwind')
mut url := '' mut url := ''
@@ -54,5 +54,5 @@ pub fn install() ! {
)! )!
} }
fn destroy() ! { fn destroy_() ! {
} }

View File

@@ -11,7 +11,7 @@ import os
pub const version = '0.18.0' pub const version = '0.18.0'
// checks if a certain version or above is installed // checks if a certain version or above is installed
fn installed() !bool { fn installed_() !bool {
res := os.execute('${osal.profile_path_source_and()} zola -V') res := os.execute('${osal.profile_path_source_and()} zola -V')
myversion := res.output.all_after(' ') myversion := res.output.all_after(' ')
if res.exit_code == 0 { if res.exit_code == 0 {
@@ -24,7 +24,7 @@ fn installed() !bool {
return false return false
} }
fn install() ! { fn install_() ! {
console.print_header('install zola') console.print_header('install zola')
// make sure we install base on the node // make sure we install base on the node
@@ -61,7 +61,7 @@ fn install() ! {
} }
// install zola will return true if it was already installed // install zola will return true if it was already installed
fn build() ! { fn build_() ! {
rust.install()! rust.install()!
console.print_header('install zola') console.print_header('install zola')
cmd := ' cmd := '
@@ -80,5 +80,5 @@ fn build() ! {
console.print_header('zola installed') console.print_header('zola installed')
} }
fn destroy() ! { fn destroy_() ! {
} }

View File

@@ -1,33 +0,0 @@
module python
// // remember the requirements list for all pips
// pub fn (mut py PythonEnv) freeze(name string) ! {
// console.print_debug('Freezing requirements for environment: ${py.name}')
// cmd := '
// cd ${py.path.path}
// source bin/activate
// python3 -m pip freeze
// '
// res := os.execute(cmd)
// if res.exit_code > 0 {
// console.print_stderr('Failed to freeze requirements: ${res}')
// return error('could not execute freeze.\n${res}\n${cmd}')
// }
// console.print_debug('Successfully froze requirements')
// }
// remember the requirements list for all pips
// pub fn (mut py PythonEnv) unfreeze(name string) ! {
// // requirements := py.db.get('freeze_${name}')!
// mut p := py.path.file_get_new('requirements.txt')!
// p.write(requirements)!
// cmd := '
// cd ${py.path.path}
// source bin/activate
// python3 -m pip install -r requirements.txt
// '
// res := os.execute(cmd)
// if res.exit_code > 0 {
// return error('could not execute unfreeze.\n${res}\n${cmd}')
// }
// }

View File

@@ -1,84 +0,0 @@
module python
import freeflowuniverse.herolib.osal
// import freeflowuniverse.herolib.data.dbfs
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.core.texttools
import os
import freeflowuniverse.herolib.ui.console
@[params]
pub struct PythonExecArgs {
pub mut:
cmd string @[required]
result_delimiter string = '==RESULT=='
ok_delimiter string = '==OK=='
python_script_name string // if used will put it in root of the sandbox under that name
stdout bool = true
}
pub fn (py PythonEnv) exec(args PythonExecArgs) !string {
mut cmd := texttools.dedent(args.cmd)
mut debug := false
if cmd.contains('DEBUG()') {
cmd = cmd.replace('DEBUG()', 'from IPython import embed; embed()')
debug = true
}
cmd += "\n\nprint(\"${args.ok_delimiter}\")\n"
mut scriptpath := ''
if args.python_script_name.len > 0 {
scriptpath = '${py.path.path}/${args.python_script_name}.py'
mut p := pathlib.get_file(path: scriptpath, create: true)!
p.write(cmd)!
} else {
scriptpath = pathlib.temp_write(text: cmd, ext: 'py') or {
return error('error: cannot write script to execute: ${err}')
}
}
console.print_debug(' - python script exec: ${scriptpath}')
os.chmod(scriptpath, 0o777)!
cmd2 := '
cd ${py.path.path}
source bin/activate
python3 ${scriptpath}
'
if args.stdout || debug {
console.print_debug(cmd2)
}
mut job := osal.Job{}
if debug {
osal.execute_interactive(cmd2)!
} else {
job = osal.exec(cmd: cmd2, stdout: args.stdout, raise_error: false)!
}
if job.exit_code > 0 {
// means error
mut msg := ' - error in execution of python script: ${scriptpath}\n'
msg += 'ERROR:\n'
msg += job.error.str()
return error(msg)
}
// console.print_debug(job)
mut o := []string{}
mut start := false
for l in job.output.split_into_lines() {
if l.trim_space().starts_with(args.result_delimiter) {
start = true
continue
}
if l.trim_space().starts_with(args.ok_delimiter) {
break
}
if start {
o << l
}
}
return o.join_lines()
}

View File

@@ -1,161 +0,0 @@
module python
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.installers.lang.python
import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.data.dbfs
import freeflowuniverse.herolib.ui.console
import os
pub struct PythonEnv {
pub mut:
name string
path pathlib.Path
db dbfs.DB
}
@[params]
pub struct PythonEnvArgs {
pub mut:
name string = 'default'
reset bool
}
pub fn new(args_ PythonEnvArgs) !PythonEnv {
console.print_debug('Creating new Python environment with name: ${args_.name}')
mut args := args_
name := texttools.name_fix(args.name)
pp := '${os.home_dir()}/hero/python/${name}'
console.print_debug('Python environment path: ${pp}')
mut c := base.context()!
mut py := PythonEnv{
name: name
path: pathlib.get_dir(path: pp, create: true)!
db: c.db_get('python_${args.name}')!
}
key_install := 'pips_${py.name}_install'
key_update := 'pips_${py.name}_update'
if !os.exists('${pp}/bin/activate') {
console.print_debug('Python environment directory does not exist, triggering reset')
args.reset = true
}
if args.reset {
console.print_debug('Resetting Python environment')
py.pips_done_reset()!
py.db.delete(key: key_install)!
py.db.delete(key: key_update)!
}
toinstall := !py.db.exists(key: key_install)!
if toinstall {
console.print_debug('Installing Python environment')
python.install()!
py.init_env()!
py.db.set(key: key_install, value: 'done')!
console.print_debug('Python environment setup complete')
}
toupdate := !py.db.exists(key: key_update)!
if toupdate {
console.print_debug('Updating Python environment')
py.update()!
py.db.set(key: key_update, value: 'done')!
console.print_debug('Python environment update complete')
}
return py
}
// comma separated list of packages to install
pub fn (py PythonEnv) init_env() ! {
console.print_green('Initializing Python virtual environment at: ${py.path.path}')
cmd := '
cd ${py.path.path}
python3 -m venv .
'
osal.exec(cmd: cmd)!
console.print_debug('Virtual environment initialization complete')
}
// comma separated list of packages to install
pub fn (py PythonEnv) update() ! {
console.print_green('Updating pip in Python environment: ${py.name}')
cmd := '
cd ${py.path.path}
source bin/activate
python3 -m pip install --upgrade pip
'
osal.exec(cmd: cmd)!
console.print_debug('Pip update complete')
}
// comma separated list of packages to install
pub fn (mut py PythonEnv) pip(packages string) ! {
mut to_install := []string{}
for i in packages.split(',') {
pip := i.trim_space()
if !py.pips_done_check(pip)! {
to_install << pip
console.print_debug('Package to install: ${pip}')
}
}
if to_install.len == 0 {
return
}
console.print_debug('Installing Python packages: ${packages}')
packages2 := to_install.join(' ')
cmd := '
cd ${py.path.path}
source bin/activate
pip3 install ${packages2} -q
'
osal.exec(cmd: cmd)!
// After successful installation, record the packages as done
for pip in to_install {
py.pips_done_add(pip)!
console.print_debug('Successfully installed package: ${pip}')
}
}
pub fn (mut py PythonEnv) pips_done_reset() ! {
console.print_debug('Resetting installed packages list for environment: ${py.name}')
py.db.delete(key: 'pips_${py.name}')!
}
pub fn (mut py PythonEnv) pips_done() ![]string {
// console.print_debug('Getting list of installed packages for environment: ${py.name}')
mut res := []string{}
pips := py.db.get(key: 'pips_${py.name}') or { '' }
for pip_ in pips.split_into_lines() {
pip := pip_.trim_space()
if pip !in res && pip.len > 0 {
res << pip
}
}
// console.print_debug('Found ${res.len} installed packages')
return res
}
pub fn (mut py PythonEnv) pips_done_add(name string) ! {
console.print_debug('Adding package ${name} to installed packages list')
mut pips := py.pips_done()!
if name in pips {
// console.print_debug('Package ${name} already marked as installed')
return
}
pips << name
out := pips.join_lines()
py.db.set(key: 'pips_${py.name}', value: out)!
console.print_debug('Successfully added package ${name} to installed list')
}
pub fn (mut py PythonEnv) pips_done_check(name string) !bool {
// console.print_debug('Checking if package ${name} is installed')
mut pips := py.pips_done()!
return name in pips
}

View File

@@ -1,7 +0,0 @@
module python
fn test_python() {
py := new() or { panic(err) }
py.update() or { panic(err) }
py.pip('ipython') or { panic(err) }
}

View File

@@ -1,96 +0,0 @@
## use virtual env
```v
import freeflowuniverse.herolib.lang.python
py:=python.new(name:'default')! //a python env with name default
py.update()!
py.pip("ipython")!
```
### to activate an environment and use the installed python
```bash
source ~/hero/python/default/bin/activate
```
### how to write python scripts to execute
```v
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.lang.python
import json
pub struct Person {
name string
age int
is_member bool
skills []string
}
mut py:=python.new(name:'test')! //a python env with name test
//py.update()!
py.pip("ipython")!
nrcount:=5
//this is used in the pythonexample
cmd:=$tmpl("pythonexample.py")
mut res:=""
for i in 0..5{
println(i)
res=py.exec(cmd:cmd)!
}
//res:=py.exec(cmd:cmd)!
person:=json.decode(Person,res)!
println(person)
```
example python script which is in the pythonscripts/ dir
```py
import json
for counter in range(1, @nrcount): # Loop from 1 to the specified param
print(f"done_{counter}")
# Define a simple Python structure (e.g., a dictionary)
example_struct = {
"name": "John Doe",
"age": @nrcount,
"is_member": True,
"skills": ["Python", "Data Analysis", "Machine Learning"]
}
# Convert the structure to a JSON string
json_string = json.dumps(example_struct, indent=4)
# Print the JSON string
print("==RESULT==")
print(json_string)
```
> see `herolib/examples/lang/python/pythonexample.vsh`
## remark
This is a slow way how to execute python, is about 2 per second on a fast machine, need to implement something where we keep the python in mem and reading from a queue e.g. redis this will go much faster, but ok for now.
see also examples dir, there is a working example

View File

@@ -1,14 +0,0 @@
module python
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.core.texttools
pub fn (py PythonEnv) shell(name_ string) ! {
_ := texttools.name_fix(name_)
cmd := '
cd ${py.path.path}
source bin/activate
'
osal.exec(cmd: cmd)!
}

View File

@@ -25,19 +25,25 @@ fn (err JobError) msg() string {
if err.error_type == .args { if err.error_type == .args {
return 'Error in arguments:\n${err.job.cmd}' return 'Error in arguments:\n${err.job.cmd}'
} }
if err.error_type == .timeout { mut msg := ""
return 'Execution failed timeout\n${err.job}' if err.job.cmd.ignore_error{
} return 'Ignore error for ${err.job.cmd.scriptpath}\n'
mut msg := 'Execution failed with code ${err.job.exit_code}\n' }else{
if err.job.cmd.scriptpath.len > 0 { if err.error_type == .timeout {
msg += '\nscript path:${err.job.cmd.scriptpath}' return 'Execution failed timeout\n${err.job}'
} }
if err.job.output.len > 0 { msg = 'Execution failed with code ${err.job.exit_code}\n'
msg += '\n\n## stdout:\n${err.job.output}' if err.job.cmd.scriptpath.len > 0 {
} msg += '\nscript path:${err.job.cmd.scriptpath}'
if err.job.error.len > 0 { }
msg += '\n\n## stderr:\n${err.job.error}' if err.job.output.len > 0 {
msg += '\n\n## stdout:\n${err.job.output}'
}
if err.job.error.len > 0 {
msg += '\n\n## stderr:\n${err.job.error}'
}
} }
return msg return msg
} }
@@ -143,7 +149,8 @@ pub mut:
// process os.Process // process os.Process
//``` //```
// return Job . // return Job .
pub fn exec(cmd Command) !Job { pub fn exec(cmd_ Command) !Job {
mut cmd:=cmd_
mut job := Job{ mut job := Job{
cmd: cmd cmd: cmd
} }
@@ -162,6 +169,9 @@ pub fn exec(cmd Command) !Job {
os.execvp(scriptpath, [])! os.execvp(scriptpath, [])!
return job return job
} }
if cmd.ignore_error{
cmd.retry=0
}
if !cmd.async { if !cmd.async {
job.execute_retry() or { job.execute_retry() or {
// println(err) // println(err)
@@ -177,7 +187,7 @@ pub fn (mut job Job) execute_retry() ! {
for x in 0 .. job.cmd.retry + 1 { for x in 0 .. job.cmd.retry + 1 {
job.execute() or { job.execute() or {
if x == job.cmd.retry { if x == job.cmd.retry {
// println(job) //println(job)
return err return err
} }
} }
@@ -197,25 +207,48 @@ pub fn (mut job Job) execute() ! {
job.start = time.now() job.start = time.now()
job.status = .running job.status = .running
job.cmd.scriptpath = cmd_to_script_path(job.cmd)! job.cmd.scriptpath = cmd_to_script_path(job.cmd)!
// console.print_debug(" - process execute ${process_args[0]}") if job.cmd.debug{
console.print_debug(job)
}
if job.cmd.debug{
console.print_debug(" - process execute ${job.cmd.scriptpath}")
}
mut p := os.new_process(job.cmd.scriptpath) mut p := os.new_process(job.cmd.scriptpath)
if job.cmd.work_folder.len > 0 { if job.cmd.work_folder.len > 0 {
p.set_work_folder(job.cmd.work_folder) p.set_work_folder(job.cmd.work_folder)
} }
if job.cmd.environment.len > 0 { if job.cmd.environment.len > 0 {
if job.cmd.debug{
console.print_debug(" - process setargs ${job.cmd.environment}")
}
p.set_environment(job.cmd.environment) p.set_environment(job.cmd.environment)
} }
p.set_redirect_stdio() p.set_redirect_stdio()
// console.print_debug("process setargs ${process_args[1..process_args.len]}")
// p.set_args(process_args[1..process_args.len]) // p.set_args(process_args[1..process_args.len])
if job.cmd.stdout { if job.cmd.stdout {
console.print_debug('') console.print_debug('')
} }
p.run() p.run()
job.process = p job.process = p
//initial check, no point reading the output if we can't get the process starting
// NOT OK TO DO BECAUSE IF PROCESS FINISHED WITHOUT ISSUE THEN NOT OK
// if ! p.is_alive() {
// if job.cmd.debug{
// console.print_debug(p)
// console.print_stderr(' ########## Process could not get started, result code is: ${p.code}')
// }
// job.exit_code = p.code
// job.status = .error_exec
// job.cmd.scriptkeep = true
// job.close()!
// return
// }
job.wait()! job.wait()!
} }
@@ -226,10 +259,9 @@ pub fn (mut job Job) execute() ! {
// wait till the job finishes or goes in error // wait till the job finishes or goes in error
pub fn (mut job Job) wait() ! { pub fn (mut job Job) wait() ! {
// if job.status != .running && job.status != .init { if job.status != .running && job.status != .init {
// return error('can only wait for running job') return error('can only wait for running job')
// } }
for { for {
job.process()! job.process()!
// console.print_debug(result) // console.print_debug(result)
@@ -252,14 +284,15 @@ pub fn (mut job Job) process() ! {
} }
mut p := job.process or { return error('there is not process on job') } mut p := job.process or { return error('there is not process on job') }
// mut result := job.read()! // mut result := job.read()
job.read()!
if p.is_alive() { if p.is_alive() {
job.read()! job.read()!
// result=job.read()! // result=job.read()!
if time.now().unix() > job.start.unix() + job.cmd.timeout * 1000 { if time.now().unix() > job.start.unix() + job.cmd.timeout * 1000 {
// console.print_stderr("TIMEOUT TIMEOUT TIMEOUT TIMEOUT") // console.print_stderr("TIMEOUT TIMEOUT TIMEOUT TIMEOUT")
if job.cmd.debug{
console.print_stderr("***TIMEOUT TIMEOUT TIMEOUT TIMEOUT***")
}
p.signal_pgkill() p.signal_pgkill()
p.close() p.close()
job.exit_code = 9999 job.exit_code = 9999
@@ -273,13 +306,16 @@ pub fn (mut job Job) process() ! {
} }
} }
} else { } else {
// console.print_stderr(" - process stopped") if ! job.cmd.ignore_error && job.cmd.debug{
console.print_stderr(" - process stopped (don't know if error)")
}
job.read()! job.read()!
job.read()! job.read()!
job.status = .done job.status = .done
// result.done = true
if p.code > 0 { if p.code > 0 {
// console.print_stderr(' ########## Process CODE IS > 0') if job.cmd.debug{
console.print_stderr(' ########## Process result code is > 0: ${p.code}')
}
job.exit_code = p.code job.exit_code = p.code
job.status = .error_exec job.status = .error_exec
job.cmd.scriptkeep = true job.cmd.scriptkeep = true
@@ -356,12 +392,15 @@ pub fn (mut job Job) close() ! {
// console.print_debug(job.cmd.scriptpath) // console.print_debug(job.cmd.scriptpath)
os.rm(job.cmd.scriptpath)! os.rm(job.cmd.scriptpath)!
} }
if job.cmd.ignore_error == false && job.cmd.scriptkeep == false && os.exists(job.cmd.scriptpath) { if (job.cmd.ignore_error || job.cmd.scriptkeep == false) && os.exists(job.cmd.scriptpath) {
os.rm(job.cmd.scriptpath)! os.rm(job.cmd.scriptpath)!
} }
// job.status = .done
if job.cmd.raise_error && job.exit_code > 0 { if job.cmd.ignore_error{
job.status = .done
return
}
if job.cmd.raise_error && job.exit_code > 0 {
return JobError{ return JobError{
job: job job: job
error_type: .exec error_type: .exec

View File

@@ -8,6 +8,7 @@ import freeflowuniverse.herolib.core.pathlib
pub fn cmd_to_script_path(cmd Command) !string { pub fn cmd_to_script_path(cmd Command) !string {
// all will be done over filessytem now // all will be done over filessytem now
mut cmdcontent := texttools.dedent(cmd.cmd) mut cmdcontent := texttools.dedent(cmd.cmd)
cmdcontent = cmdcontent.trim_space()
if !cmdcontent.ends_with('\n') { if !cmdcontent.ends_with('\n') {
cmdcontent += '\n' cmdcontent += '\n'
} }

View File

@@ -108,6 +108,12 @@ fn is_sudo_required() bool {
return false return false
} }
platform_ := platform()
if platform_ == .osx {
return false
}
// Check if the user has sudo privileges (test with `sudo -v`) // Check if the user has sudo privileges (test with `sudo -v`)
sudo_check := os.execute('sudo -v') sudo_check := os.execute('sudo -v')
return sudo_check.exit_code == 0 return sudo_check.exit_code == 0
@@ -136,9 +142,9 @@ pub fn package_remove(name_ string) ! {
// Platform-specific package removal logic // Platform-specific package removal logic
if platform_ == .osx { if platform_ == .osx {
if cpu == .arm { if cpu == .arm {
exec(cmd: 'arch --arm64 brew uninstall ${name}', ignore_error: false)! exec(cmd: 'arch --arm64 brew uninstall ${name}', ignore_error: true)!
} else { } else {
exec(cmd: 'brew uninstall ${name}', ignore_error: false)! exec(cmd: 'brew uninstall ${name}', ignore_error: true)!
} }
} else if platform_ == .ubuntu { } else if platform_ == .ubuntu {
// Use sudo if required // Use sudo if required
@@ -148,7 +154,7 @@ pub fn package_remove(name_ string) ! {
'apt remove -y ${name} --allow-change-held-packages' 'apt remove -y ${name} --allow-change-held-packages'
} }
exec(cmd: cmd, ignore_error: false)! exec(cmd: cmd, ignore_error: false)!
exec(cmd: 'sudo apt autoremove -y', ignore_error: false)! exec(cmd: 'sudo apt autoremove -y', ignore_error: true)!
} else if platform_ == .alpine { } else if platform_ == .alpine {
// Use sudo if required // Use sudo if required
cmd := if use_sudo { 'sudo apk del ${name}' } else { 'apk del ${name}' } cmd := if use_sudo { 'sudo apk del ${name}' } else { 'apk del ${name}' }
@@ -160,7 +166,7 @@ pub fn package_remove(name_ string) ! {
} else { } else {
'pacman --noconfirm -R ${name}' 'pacman --noconfirm -R ${name}'
} }
exec(cmd: cmd, ignore_error: false)! exec(cmd: cmd, ignore_error: true)!
} else { } else {
return error('Only ubuntu, alpine, and osx supported for now') return error('Only ubuntu, alpine, and osx supported for now')
} }