...
This commit is contained in:
11
libwip/installers/yggdrasil/.heroscript
Normal file
11
libwip/installers/yggdrasil/.heroscript
Normal file
@@ -0,0 +1,11 @@
|
||||
!!hero_code.generate_installer
|
||||
name: "yggdrasil"
|
||||
classname: "YggdrasilInstaller"
|
||||
hasconfig: false
|
||||
singleton: true
|
||||
default: true
|
||||
title: ""
|
||||
templates: false
|
||||
build: true
|
||||
startupmanager: true
|
||||
supported_platforms: ""
|
||||
40
libwip/installers/yggdrasil/readme.md
Normal file
40
libwip/installers/yggdrasil/readme.md
Normal file
@@ -0,0 +1,40 @@
|
||||
# yggdrasil
|
||||
|
||||
To get started
|
||||
|
||||
```v
|
||||
|
||||
|
||||
import incubaid.herolib.installers.something.yggdrasil as yggdrasil_installer
|
||||
|
||||
heroscript:="
|
||||
!!yggdrasil.configure name:'test'
|
||||
password: '1234'
|
||||
port: 7701
|
||||
|
||||
!!yggdrasil.start name:'test' reset:1
|
||||
"
|
||||
|
||||
yggdrasil_installer.play(heroscript=heroscript)!
|
||||
|
||||
//or we can call the default and do a start with reset
|
||||
//mut installer:= yggdrasil_installer.get()!
|
||||
//installer.start(reset:true)!
|
||||
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
## example heroscript
|
||||
|
||||
```hero
|
||||
!!yggdrasil.configure
|
||||
homedir: '/home/user/yggdrasil'
|
||||
username: 'admin'
|
||||
password: 'secretpassword'
|
||||
title: 'Some Title'
|
||||
host: 'localhost'
|
||||
port: 8888
|
||||
|
||||
```
|
||||
143
libwip/installers/yggdrasil/ygg.v
Normal file
143
libwip/installers/yggdrasil/ygg.v
Normal file
@@ -0,0 +1,143 @@
|
||||
module yggdrasil
|
||||
|
||||
import incubaid.herolib.osal.core as osal
|
||||
import incubaid.herolib.installers.lang.golang
|
||||
import incubaid.herolib.ui.console
|
||||
import incubaid.herolib.osal.screen
|
||||
import incubaid.herolib.ui
|
||||
import incubaid.herolib.develop.gittools
|
||||
import os
|
||||
import time
|
||||
|
||||
// install yggdrasil will return true if it was already installed
|
||||
pub fn install(args_ InstallArgs) ! {
|
||||
peers := '
|
||||
Peers:
|
||||
[
|
||||
tcp://45.138.172.192:5001
|
||||
tcp://94.130.203.208:5999
|
||||
tcp://185.69.166.140:9943
|
||||
tcp://185.69.166.141:9943
|
||||
tcp://185.69.167.141:9943
|
||||
tcp://185.69.167.142:9943
|
||||
tcp://185.206.122.31:9943
|
||||
tcp://185.206.122.32:9943
|
||||
tcp://185.206.122.131:9943
|
||||
tcp://185.206.122.132:9943
|
||||
tls://140.238.168.104:17121
|
||||
tls://s2.i2pd.xyz:39575
|
||||
tcp://62.210.85.80:39565
|
||||
]
|
||||
|
||||
'
|
||||
config_path := '/etc/yggdrasil.conf'
|
||||
mut args := args_
|
||||
|
||||
res := os.execute('${osal.profile_path_source_and()!} yggdrasil -version')
|
||||
if res.exit_code != 0 {
|
||||
args.reset = true
|
||||
}
|
||||
|
||||
if args.reset {
|
||||
golang.install()!
|
||||
console.print_header('install yggdrasil')
|
||||
mut gs := gittools.new(coderoot: '${os.home_dir()}/_code')!
|
||||
mut repo := gs.get_repo(
|
||||
url: 'https://github.com/yggdrasil-network/yggdrasil-go.git'
|
||||
reset: false
|
||||
)!
|
||||
|
||||
mut path := repo.path()
|
||||
|
||||
osal.exec(cmd: 'cd ${path} && PATH=\$PATH:/usr/local/go/bin ./build')!
|
||||
|
||||
osal.cmd_add(
|
||||
source: '${path}/yggdrasil'
|
||||
)!
|
||||
osal.cmd_add(
|
||||
source: '${path}/yggdrasilctl'
|
||||
)!
|
||||
|
||||
osal.cmd_add(
|
||||
source: '${path}/contrib/docker/entrypoint.sh'
|
||||
)!
|
||||
if !os.exists(config_path) {
|
||||
osal.exec(cmd: 'yggdrasil -genconf > /etc/yggdrasil.conf')!
|
||||
config := os.read_file(config_path)!
|
||||
config.replace('Peers: []', peers)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn restart() ! {
|
||||
name := 'yggdrasil'
|
||||
mut scr := screen.new(reset: false)!
|
||||
scr.kill(name)!
|
||||
start()!
|
||||
}
|
||||
|
||||
pub fn start() ! {
|
||||
// console.print_debug("start")
|
||||
|
||||
mut scr := screen.new(reset: false)!
|
||||
name := 'yggdrasil'
|
||||
|
||||
if scr.exists(name) {
|
||||
console.print_header('yggdrasil was already running')
|
||||
return
|
||||
}
|
||||
|
||||
mut s := scr.add(name: name, start: true)!
|
||||
|
||||
mut cmd2 := ''
|
||||
|
||||
if core.is_osx()! {
|
||||
cmd2 = 'sudo -s '
|
||||
}
|
||||
|
||||
cmd2 += 'yggdrasil --useconf < "/etc/yggdrasil.conf"'
|
||||
|
||||
s.cmd_send(cmd2)!
|
||||
|
||||
console.print_debug(s)
|
||||
|
||||
console.print_debug('send done')
|
||||
|
||||
if core.is_osx()! {
|
||||
mut myui := ui.new()!
|
||||
console.clear()
|
||||
|
||||
console.print_stderr("
|
||||
On the next screen you will be able to fill in your password.
|
||||
Once done and the server is started: do 'control a + control d'
|
||||
|
||||
")
|
||||
|
||||
_ = myui.ask_yesno(question: 'Please confirm you understand?')!
|
||||
|
||||
s.attach()! // to allow filling in passwd
|
||||
}
|
||||
|
||||
console.print_header('yggdrasil is running')
|
||||
|
||||
time.sleep(100 * time.millisecond)
|
||||
|
||||
if !running()! {
|
||||
return error('cound not start yggdrasil')
|
||||
}
|
||||
}
|
||||
|
||||
pub fn running_() !bool {
|
||||
mut scr := screen.new(reset: false)!
|
||||
name := 'yggdrasil'
|
||||
|
||||
if !scr.exists(name) {
|
||||
return false
|
||||
}
|
||||
|
||||
if !(osal.process_exists_byname('yggdrasil')!) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
187
libwip/installers/yggdrasil/yggdrasil_actions.v
Normal file
187
libwip/installers/yggdrasil/yggdrasil_actions.v
Normal file
@@ -0,0 +1,187 @@
|
||||
module yggdrasil
|
||||
|
||||
import incubaid.herolib.osal.core as osal
|
||||
import incubaid.herolib.ui.console
|
||||
import incubaid.herolib.core.texttools
|
||||
import incubaid.herolib.core.pathlib
|
||||
import incubaid.herolib.osal.systemd
|
||||
import incubaid.herolib.osal.startupmanager
|
||||
import incubaid.herolib.installers.ulist
|
||||
import incubaid.herolib.installers.lang.golang
|
||||
import incubaid.herolib.installers.lang.rust
|
||||
import incubaid.herolib.installers.lang.python
|
||||
import os
|
||||
|
||||
fn startupcmd() ![]startupmanager.ZProcessNewArgs {
|
||||
mut installer := get()!
|
||||
mut res := []startupmanager.ZProcessNewArgs{}
|
||||
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||
// res << startupmanager.ZProcessNewArgs{
|
||||
// name: 'yggdrasil'
|
||||
// cmd: 'yggdrasil server'
|
||||
// env: {
|
||||
// 'HOME': '/root'
|
||||
// }
|
||||
// }
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
fn running_() !bool {
|
||||
mut installer := get()!
|
||||
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||
// this checks health of yggdrasil
|
||||
// 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: 'yggdrasil', 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('yggdrasil 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
|
||||
|
||||
// checks if a certain version or above is installed
|
||||
fn installed_() !bool {
|
||||
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||
// res := os.execute('${osal.profile_path_source_and()!} yggdrasil 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 yggdrasil version.\n${res.output}")
|
||||
// }
|
||||
// if texttools.version(version) == texttools.version(r[0]) {
|
||||
// return true
|
||||
// }
|
||||
return false
|
||||
}
|
||||
|
||||
// get the Upload List of the files
|
||||
fn ulist_get() !ulist.UList {
|
||||
// optionally build a UList which is all paths which are result of building, is then used e.g. in upload
|
||||
return ulist.UList{}
|
||||
}
|
||||
|
||||
// uploads to S3 server if configured
|
||||
fn upload_() ! {
|
||||
// installers.upload(
|
||||
// cmdname: 'yggdrasil'
|
||||
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/yggdrasil'
|
||||
// )!
|
||||
}
|
||||
|
||||
fn install_() ! {
|
||||
console.print_header('install yggdrasil')
|
||||
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||
// mut url := ''
|
||||
// if core.is_linux_arm()! {
|
||||
// url = 'https://github.com/yggdrasil-dev/yggdrasil/releases/download/v${version}/yggdrasil_${version}_linux_arm64.tar.gz'
|
||||
// } else if core.is_linux_intel()! {
|
||||
// url = 'https://github.com/yggdrasil-dev/yggdrasil/releases/download/v${version}/yggdrasil_${version}_linux_amd64.tar.gz'
|
||||
// } else if core.is_osx_arm()! {
|
||||
// url = 'https://github.com/yggdrasil-dev/yggdrasil/releases/download/v${version}/yggdrasil_${version}_darwin_arm64.tar.gz'
|
||||
// } else if core.is_osx_intel()! {
|
||||
// url = 'https://github.com/yggdrasil-dev/yggdrasil/releases/download/v${version}/yggdrasil_${version}_darwin_amd64.tar.gz'
|
||||
// } else {
|
||||
// return error('unsported platform')
|
||||
// }
|
||||
|
||||
// mut dest := osal.download(
|
||||
// url: url
|
||||
// minsize_kb: 9000
|
||||
// expand_dir: '/tmp/yggdrasil'
|
||||
// )!
|
||||
|
||||
// //dest.moveup_single_subdir()!
|
||||
|
||||
// mut binpath := dest.file_get('yggdrasil')!
|
||||
// osal.cmd_add(
|
||||
// cmdname: 'yggdrasil'
|
||||
// source: binpath.path
|
||||
// )!
|
||||
}
|
||||
|
||||
fn build_() ! {
|
||||
// url := 'https://github.com/threefoldtech/yggdrasil'
|
||||
|
||||
// make sure we install base on the node
|
||||
// if core.platform()!= .ubuntu {
|
||||
// return error('only support ubuntu for now')
|
||||
// }
|
||||
// golang.install()!
|
||||
|
||||
// console.print_header('build yggdrasil')
|
||||
|
||||
// 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
|
||||
// ")!
|
||||
}
|
||||
205
libwip/installers/yggdrasil/yggdrasil_factory_.v
Normal file
205
libwip/installers/yggdrasil/yggdrasil_factory_.v
Normal file
@@ -0,0 +1,205 @@
|
||||
module yggdrasil
|
||||
|
||||
import incubaid.herolib.core.playbook { PlayBook }
|
||||
import incubaid.herolib.ui.console
|
||||
import json
|
||||
import incubaid.herolib.osal.startupmanager
|
||||
import time
|
||||
|
||||
__global (
|
||||
yggdrasil_global map[string]&YggdrasilInstaller
|
||||
yggdrasil_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
}
|
||||
|
||||
pub fn new(args ArgsGet) !&YggdrasilInstaller {
|
||||
return &YggdrasilInstaller{}
|
||||
}
|
||||
|
||||
pub fn get(args ArgsGet) !&YggdrasilInstaller {
|
||||
return new(args)!
|
||||
}
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
if !plbook.exists(filter: 'yggdrasil.') {
|
||||
return
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'yggdrasil.configure')!
|
||||
if install_actions.len > 0 {
|
||||
return error("can't configure yggdrasil, because no configuration allowed for this installer.")
|
||||
}
|
||||
mut other_actions := plbook.find(filter: 'yggdrasil.')!
|
||||
for mut other_action in other_actions {
|
||||
if other_action.name in ['destroy', 'install', 'build'] {
|
||||
mut p := other_action.params
|
||||
reset := p.get_default_false('reset')
|
||||
if other_action.name == 'destroy' || reset {
|
||||
console.print_debug('install action yggdrasil.destroy')
|
||||
destroy()!
|
||||
}
|
||||
if other_action.name == 'install' {
|
||||
console.print_debug('install action yggdrasil.install')
|
||||
install()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ['start', 'stop', 'restart'] {
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut yggdrasil_obj := get(name: name)!
|
||||
console.print_debug('action object:\n${yggdrasil_obj}')
|
||||
if other_action.name == 'start' {
|
||||
console.print_debug('install action yggdrasil.${other_action.name}')
|
||||
yggdrasil_obj.start()!
|
||||
}
|
||||
|
||||
if other_action.name == 'stop' {
|
||||
console.print_debug('install action yggdrasil.${other_action.name}')
|
||||
yggdrasil_obj.stop()!
|
||||
}
|
||||
if other_action.name == 'restart' {
|
||||
console.print_debug('install action yggdrasil.${other_action.name}')
|
||||
yggdrasil_obj.restart()!
|
||||
}
|
||||
}
|
||||
other_action.done = true
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
fn startupmanager_get(cat startupmanager.StartupManagerType) !startupmanager.StartupManager {
|
||||
// unknown
|
||||
// screen
|
||||
// zinit
|
||||
// tmux
|
||||
// systemd
|
||||
match cat {
|
||||
.screen {
|
||||
console.print_debug("installer: yggdrasil' startupmanager get screen")
|
||||
return startupmanager.get(.screen)!
|
||||
}
|
||||
.zinit {
|
||||
console.print_debug("installer: yggdrasil' startupmanager get zinit")
|
||||
return startupmanager.get(.zinit)!
|
||||
}
|
||||
.systemd {
|
||||
console.print_debug("installer: yggdrasil' startupmanager get systemd")
|
||||
return startupmanager.get(.systemd)!
|
||||
}
|
||||
else {
|
||||
console.print_debug("installer: yggdrasil' startupmanager get auto")
|
||||
return startupmanager.get(.auto)!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self YggdrasilInstaller) start() ! {
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
|
||||
console.print_header('installer: yggdrasil start')
|
||||
|
||||
if !installed()! {
|
||||
install()!
|
||||
}
|
||||
|
||||
configure()!
|
||||
|
||||
start_pre()!
|
||||
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
|
||||
console.print_debug('installer: yggdrasil starting 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('yggdrasil did not install properly.')
|
||||
}
|
||||
|
||||
pub fn (mut self YggdrasilInstaller) install_start(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
self.install(args)!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self YggdrasilInstaller) 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 YggdrasilInstaller) restart() ! {
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self YggdrasilInstaller) running() !bool {
|
||||
switch(self.name)
|
||||
|
||||
// walk over the generic processes, if not running return
|
||||
for zprocess in startupcmd()! {
|
||||
if zprocess.startuptype != .screen {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
r := sm.running(zprocess.name)!
|
||||
if r == false {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return running()!
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self YggdrasilInstaller) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self YggdrasilInstaller) build() ! {
|
||||
switch(self.name)
|
||||
build()!
|
||||
}
|
||||
|
||||
pub fn (mut self YggdrasilInstaller) destroy() ! {
|
||||
switch(self.name)
|
||||
self.stop() or {}
|
||||
destroy()!
|
||||
}
|
||||
|
||||
// switch instance to be used for yggdrasil
|
||||
pub fn switch(name string) {
|
||||
}
|
||||
27
libwip/installers/yggdrasil/yggdrasil_model.v
Normal file
27
libwip/installers/yggdrasil/yggdrasil_model.v
Normal file
@@ -0,0 +1,27 @@
|
||||
module yggdrasil
|
||||
|
||||
import incubaid.herolib.data.paramsparser
|
||||
import os
|
||||
|
||||
pub const version = '0.0.0'
|
||||
const singleton = true
|
||||
const default = true
|
||||
|
||||
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
|
||||
@[heap]
|
||||
pub struct YggdrasilInstaller {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
}
|
||||
|
||||
fn obj_init(obj_ YggdrasilInstaller) !YggdrasilInstaller {
|
||||
// never call get here, only thing we can do here is work on object itself
|
||||
mut obj := obj_
|
||||
panic('implement')
|
||||
return obj
|
||||
}
|
||||
|
||||
// called before start if done
|
||||
fn configure() ! {
|
||||
// mut installer := get()!
|
||||
}
|
||||
11
libwip/installers/zerofs/.heroscript
Normal file
11
libwip/installers/zerofs/.heroscript
Normal file
@@ -0,0 +1,11 @@
|
||||
!!hero_code.generate_installer
|
||||
name: "zerofs"
|
||||
classname: "ZeroFS"
|
||||
hasconfig: false
|
||||
singleton: true
|
||||
default: true
|
||||
title: ""
|
||||
templates: false
|
||||
build: true
|
||||
startupmanager: true
|
||||
supported_platforms: ""
|
||||
6
libwip/installers/zerofs/readme.md
Normal file
6
libwip/installers/zerofs/readme.md
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
# ZeroFS
|
||||
|
||||
more info see https://github.com/threefoldtech/rfs
|
||||
|
||||
//TODO: needs to be implemented
|
||||
31
libwip/installers/zerofs/rfs.v
Normal file
31
libwip/installers/zerofs/rfs.v
Normal file
@@ -0,0 +1,31 @@
|
||||
module zerofs
|
||||
|
||||
import incubaid.herolib.osal.core as osal
|
||||
import incubaid.herolib.installers.lang.rust
|
||||
import incubaid.herolib.develop.gittools
|
||||
// import incubaid.herolib.installers.zinit
|
||||
import incubaid.herolib.ui.console
|
||||
|
||||
// pub fn install_() ! {
|
||||
// rust.install()!
|
||||
// zinit.install()!
|
||||
// console.print_header('install rfs')
|
||||
// if !osal.done_exists('install_rfs') || !osal.cmd_exists('rfs') {
|
||||
// osal.package_install('musl-dev,musl-tools')!
|
||||
|
||||
// mut gs := gittools.new()!
|
||||
// mut repo := gs.get_repo(url: 'https://github.com/threefoldtech/rfs', reset: true)!
|
||||
// path := repo.path()
|
||||
// cmd := '
|
||||
// cd ${path}
|
||||
// rustup target add x86_64-unknown-linux-musl
|
||||
// cargo build --features build-binary --release --target=x86_64-unknown-linux-musl
|
||||
|
||||
// cp ~/code/github/threefoldtech/rfs/target/x86_64-unknown-linux-musl/release/rfs /usr/local/bin/
|
||||
// '
|
||||
// console.print_header('build rfs')
|
||||
// osal.execute_stdout(cmd)!
|
||||
// osal.done_set('install_rfs', 'OK')!
|
||||
// }
|
||||
// console.print_header('rfs already done')
|
||||
// }
|
||||
187
libwip/installers/zerofs/zerofs_actions.v
Normal file
187
libwip/installers/zerofs/zerofs_actions.v
Normal file
@@ -0,0 +1,187 @@
|
||||
module zerofs
|
||||
|
||||
import incubaid.herolib.osal.core as osal
|
||||
import incubaid.herolib.ui.console
|
||||
import incubaid.herolib.core.texttools
|
||||
import incubaid.herolib.core.pathlib
|
||||
import incubaid.herolib.osal.systemd
|
||||
import incubaid.herolib.osal.startupmanager
|
||||
import incubaid.herolib.installers.ulist
|
||||
import incubaid.herolib.installers.lang.golang
|
||||
import incubaid.herolib.installers.lang.rust
|
||||
import incubaid.herolib.installers.lang.python
|
||||
import os
|
||||
|
||||
fn startupcmd() ![]startupmanager.ZProcessNewArgs {
|
||||
mut installer := get()!
|
||||
mut res := []startupmanager.ZProcessNewArgs{}
|
||||
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||
// res << startupmanager.ZProcessNewArgs{
|
||||
// name: 'zerofs'
|
||||
// cmd: 'zerofs server'
|
||||
// env: {
|
||||
// 'HOME': '/root'
|
||||
// }
|
||||
// }
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
fn running_() !bool {
|
||||
mut installer := get()!
|
||||
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||
// this checks health of zerofs
|
||||
// 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: 'zerofs', 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('zerofs 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
|
||||
|
||||
// checks if a certain version or above is installed
|
||||
fn installed_() !bool {
|
||||
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||
// res := os.execute('${osal.profile_path_source_and()!} zerofs 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 zerofs version.\n${res.output}")
|
||||
// }
|
||||
// if texttools.version(version) == texttools.version(r[0]) {
|
||||
// return true
|
||||
// }
|
||||
return false
|
||||
}
|
||||
|
||||
// get the Upload List of the files
|
||||
fn ulist_get() !ulist.UList {
|
||||
// optionally build a UList which is all paths which are result of building, is then used e.g. in upload
|
||||
return ulist.UList{}
|
||||
}
|
||||
|
||||
// uploads to S3 server if configured
|
||||
fn upload_() ! {
|
||||
// installers.upload(
|
||||
// cmdname: 'zerofs'
|
||||
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/zerofs'
|
||||
// )!
|
||||
}
|
||||
|
||||
fn install_() ! {
|
||||
console.print_header('install zerofs')
|
||||
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||
// mut url := ''
|
||||
// if core.is_linux_arm()! {
|
||||
// url = 'https://github.com/zerofs-dev/zerofs/releases/download/v${version}/zerofs_${version}_linux_arm64.tar.gz'
|
||||
// } else if core.is_linux_intel()! {
|
||||
// url = 'https://github.com/zerofs-dev/zerofs/releases/download/v${version}/zerofs_${version}_linux_amd64.tar.gz'
|
||||
// } else if core.is_osx_arm()! {
|
||||
// url = 'https://github.com/zerofs-dev/zerofs/releases/download/v${version}/zerofs_${version}_darwin_arm64.tar.gz'
|
||||
// } else if core.is_osx_intel()! {
|
||||
// url = 'https://github.com/zerofs-dev/zerofs/releases/download/v${version}/zerofs_${version}_darwin_amd64.tar.gz'
|
||||
// } else {
|
||||
// return error('unsported platform')
|
||||
// }
|
||||
|
||||
// mut dest := osal.download(
|
||||
// url: url
|
||||
// minsize_kb: 9000
|
||||
// expand_dir: '/tmp/zerofs'
|
||||
// )!
|
||||
|
||||
// //dest.moveup_single_subdir()!
|
||||
|
||||
// mut binpath := dest.file_get('zerofs')!
|
||||
// osal.cmd_add(
|
||||
// cmdname: 'zerofs'
|
||||
// source: binpath.path
|
||||
// )!
|
||||
}
|
||||
|
||||
fn build_() ! {
|
||||
// url := 'https://github.com/threefoldtech/zerofs'
|
||||
|
||||
// make sure we install base on the node
|
||||
// if core.platform()!= .ubuntu {
|
||||
// return error('only support ubuntu for now')
|
||||
// }
|
||||
// golang.install()!
|
||||
|
||||
// console.print_header('build zerofs')
|
||||
|
||||
// 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
|
||||
// ")!
|
||||
}
|
||||
205
libwip/installers/zerofs/zerofs_factory_.v
Normal file
205
libwip/installers/zerofs/zerofs_factory_.v
Normal file
@@ -0,0 +1,205 @@
|
||||
module zerofs
|
||||
|
||||
import incubaid.herolib.core.playbook { PlayBook }
|
||||
import incubaid.herolib.ui.console
|
||||
import json
|
||||
import incubaid.herolib.osal.startupmanager
|
||||
import time
|
||||
|
||||
__global (
|
||||
zerofs_global map[string]&ZeroFS
|
||||
zerofs_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
}
|
||||
|
||||
pub fn new(args ArgsGet) !&ZeroFS {
|
||||
return &ZeroFS{}
|
||||
}
|
||||
|
||||
pub fn get(args ArgsGet) !&ZeroFS {
|
||||
return new(args)!
|
||||
}
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
if !plbook.exists(filter: 'zerofs.') {
|
||||
return
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'zerofs.configure')!
|
||||
if install_actions.len > 0 {
|
||||
return error("can't configure zerofs, because no configuration allowed for this installer.")
|
||||
}
|
||||
mut other_actions := plbook.find(filter: 'zerofs.')!
|
||||
for mut other_action in other_actions {
|
||||
if other_action.name in ['destroy', 'install', 'build'] {
|
||||
mut p := other_action.params
|
||||
reset := p.get_default_false('reset')
|
||||
if other_action.name == 'destroy' || reset {
|
||||
console.print_debug('install action zerofs.destroy')
|
||||
destroy()!
|
||||
}
|
||||
if other_action.name == 'install' {
|
||||
console.print_debug('install action zerofs.install')
|
||||
install()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ['start', 'stop', 'restart'] {
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut zerofs_obj := get(name: name)!
|
||||
console.print_debug('action object:\n${zerofs_obj}')
|
||||
if other_action.name == 'start' {
|
||||
console.print_debug('install action zerofs.${other_action.name}')
|
||||
zerofs_obj.start()!
|
||||
}
|
||||
|
||||
if other_action.name == 'stop' {
|
||||
console.print_debug('install action zerofs.${other_action.name}')
|
||||
zerofs_obj.stop()!
|
||||
}
|
||||
if other_action.name == 'restart' {
|
||||
console.print_debug('install action zerofs.${other_action.name}')
|
||||
zerofs_obj.restart()!
|
||||
}
|
||||
}
|
||||
other_action.done = true
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
fn startupmanager_get(cat startupmanager.StartupManagerType) !startupmanager.StartupManager {
|
||||
// unknown
|
||||
// screen
|
||||
// zinit
|
||||
// tmux
|
||||
// systemd
|
||||
match cat {
|
||||
.screen {
|
||||
console.print_debug("installer: zerofs' startupmanager get screen")
|
||||
return startupmanager.get(.screen)!
|
||||
}
|
||||
.zinit {
|
||||
console.print_debug("installer: zerofs' startupmanager get zinit")
|
||||
return startupmanager.get(.zinit)!
|
||||
}
|
||||
.systemd {
|
||||
console.print_debug("installer: zerofs' startupmanager get systemd")
|
||||
return startupmanager.get(.systemd)!
|
||||
}
|
||||
else {
|
||||
console.print_debug("installer: zerofs' startupmanager get auto")
|
||||
return startupmanager.get(.auto)!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self ZeroFS) start() ! {
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
|
||||
console.print_header('installer: zerofs start')
|
||||
|
||||
if !installed()! {
|
||||
install()!
|
||||
}
|
||||
|
||||
configure()!
|
||||
|
||||
start_pre()!
|
||||
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
|
||||
console.print_debug('installer: zerofs starting 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('zerofs did not install properly.')
|
||||
}
|
||||
|
||||
pub fn (mut self ZeroFS) install_start(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
self.install(args)!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self ZeroFS) 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 ZeroFS) restart() ! {
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self ZeroFS) running() !bool {
|
||||
switch(self.name)
|
||||
|
||||
// walk over the generic processes, if not running return
|
||||
for zprocess in startupcmd()! {
|
||||
if zprocess.startuptype != .screen {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
r := sm.running(zprocess.name)!
|
||||
if r == false {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return running()!
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self ZeroFS) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self ZeroFS) build() ! {
|
||||
switch(self.name)
|
||||
build()!
|
||||
}
|
||||
|
||||
pub fn (mut self ZeroFS) destroy() ! {
|
||||
switch(self.name)
|
||||
self.stop() or {}
|
||||
destroy()!
|
||||
}
|
||||
|
||||
// switch instance to be used for zerofs
|
||||
pub fn switch(name string) {
|
||||
}
|
||||
27
libwip/installers/zerofs/zerofs_model.v
Normal file
27
libwip/installers/zerofs/zerofs_model.v
Normal file
@@ -0,0 +1,27 @@
|
||||
module zerofs
|
||||
|
||||
import incubaid.herolib.data.paramsparser
|
||||
import os
|
||||
|
||||
pub const version = '0.0.0'
|
||||
const singleton = true
|
||||
const default = true
|
||||
|
||||
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
|
||||
@[heap]
|
||||
pub struct ZeroFS {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
}
|
||||
|
||||
fn obj_init(obj_ ZeroFS) !ZeroFS {
|
||||
// never call get here, only thing we can do here is work on object itself
|
||||
mut obj := obj_
|
||||
panic('implement')
|
||||
return obj
|
||||
}
|
||||
|
||||
// called before start if done
|
||||
fn configure() ! {
|
||||
// mut installer := get()!
|
||||
}
|
||||
Reference in New Issue
Block a user