WIP: Building hero
- The work is still in progress Co-authored-by: supermario <mariobassem12@gmail.com>
This commit is contained in:
120
lib/installers/develapps/chrome/chrome.v
Normal file
120
lib/installers/develapps/chrome/chrome.v
Normal file
@@ -0,0 +1,120 @@
|
||||
module chrome
|
||||
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.core
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import os
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
uninstall bool
|
||||
}
|
||||
|
||||
pub fn install(args_ InstallArgs) ! {
|
||||
mut args := args_
|
||||
// base.install()!
|
||||
if args.reset || args.uninstall {
|
||||
console.print_header('uninstall chrome')
|
||||
uninstall()!
|
||||
console.print_debug(' - ok')
|
||||
if args.uninstall {
|
||||
return
|
||||
}
|
||||
}
|
||||
console.print_header('package_install install chrome')
|
||||
if !args.reset && osal.done_exists('install_chrome') && exists()! {
|
||||
console.print_debug(' - already installed')
|
||||
return
|
||||
}
|
||||
mut url := ''
|
||||
platform := core.platform()!
|
||||
if platform in [.alpine, .arch, .ubuntu] {
|
||||
// url = 'https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmg'
|
||||
panic('not implemented yet')
|
||||
} else if platform == .osx {
|
||||
url = 'https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmg'
|
||||
}
|
||||
console.print_debug(' download ${url}')
|
||||
_ = osal.download(
|
||||
url: url
|
||||
minsize_kb: 5000
|
||||
reset: args.reset
|
||||
dest: '/tmp/googlechrome.dmg'
|
||||
)!
|
||||
|
||||
cmd := "
|
||||
hdiutil attach /tmp/googlechrome.dmg
|
||||
echo ' - copy chrome into app folder'
|
||||
echo ' - will now copy all files to Application folder, this can take a while'
|
||||
cp -r /Volumes/Google\\ Chrome/Google\\ Chrome.app /Applications/
|
||||
sleep 30
|
||||
echo ' - copy done'
|
||||
hdiutil detach /Volumes/Google\\ Chrome/
|
||||
rm -f /tmp/googlechrome.dmg
|
||||
"
|
||||
osal.exec(cmd: cmd)!
|
||||
console.print_debug(' - copy done to Application folder.')
|
||||
|
||||
if exists()! {
|
||||
console.print_debug(' - exists check ok.')
|
||||
}
|
||||
|
||||
osal.done_set('install_chrome', 'OK')!
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct ExtensionsInstallArgs {
|
||||
pub mut:
|
||||
extensions string
|
||||
default bool = true
|
||||
}
|
||||
|
||||
pub fn exists() !bool {
|
||||
cmd := 'mdfind "kMDItemKind == \'Application\'" | grep "Google Chrome"'
|
||||
res := os.execute(cmd)
|
||||
if res.exit_code > 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
pub fn install_path() !string {
|
||||
cmd := 'mdfind "kMDItemKind == \'Application\'" | grep "Google Chrome"'
|
||||
res := os.execute(cmd)
|
||||
if res.exit_code > 0 {
|
||||
return error("can't find install path")
|
||||
}
|
||||
return res.output.trim_space()
|
||||
}
|
||||
|
||||
pub fn uninstall() ! {
|
||||
cmd := '
|
||||
# Quit Google Chrome
|
||||
osascript -e \'quit app "Google Chrome"\'
|
||||
|
||||
# Wait a bit to ensure Chrome has completely quit
|
||||
sleep 2
|
||||
|
||||
# Remove the Google Chrome Application
|
||||
rm -rf "/Applications/Google Chrome.app"
|
||||
|
||||
# Remove Chrome’s Application Support Data
|
||||
rm -rf ~/Library/Application\\ Support/Google/Chrome
|
||||
|
||||
# Remove Chrome\'s Caches
|
||||
rm -rf ~/Library/Caches/Google/Chrome
|
||||
|
||||
# Delete Chrome Preferences
|
||||
rm -rf ~/Library/Preferences/com.google.Chrome.plist
|
||||
|
||||
# Clear Chrome Saved Application State
|
||||
rm -rf ~/Library/Saved\\ Application\\ State/com.google.Chrome.savedState
|
||||
|
||||
'
|
||||
osal.exec(cmd: cmd)!
|
||||
}
|
||||
|
||||
// # Optional: Empty the Trash
|
||||
// osascript -e 'tell app "Finder" to empty'
|
||||
132
lib/installers/develapps/vscode/vscode.v
Normal file
132
lib/installers/develapps/vscode/vscode.v
Normal file
@@ -0,0 +1,132 @@
|
||||
module vscode
|
||||
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.core
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import os
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn install(args_ InstallArgs) ! {
|
||||
mut args := args_
|
||||
// base.install()!
|
||||
console.print_header('install vscode')
|
||||
if !args.reset && osal.done_exists('install_vscode') && osal.cmd_exists('code') {
|
||||
console.print_debug(' - already installed')
|
||||
return
|
||||
}
|
||||
mut url := ''
|
||||
platform := core.platform()!
|
||||
if platform in [.alpine, .arch, .ubuntu] {
|
||||
if core.cputype()! == .arm {
|
||||
url = 'https://code.visualstudio.com/sha/download?build=stable&os=cli-alpine-arm64'
|
||||
} else {
|
||||
url = 'https://code.visualstudio.com/sha/download?build=stable&os=cli-alpine-x64'
|
||||
}
|
||||
} else if platform == .osx {
|
||||
if core.cputype()! == .arm {
|
||||
url = 'https://code.visualstudio.com/sha/download?build=stable&os=cli-darwin-arm64'
|
||||
} else {
|
||||
url = 'https://code.visualstudio.com/sha/download?build=stable&os=cli-darwin-x64'
|
||||
}
|
||||
}
|
||||
console.print_debug(' download ${url}')
|
||||
_ = osal.download(
|
||||
url: url
|
||||
minsize_kb: 5000
|
||||
reset: args.reset
|
||||
dest: '/tmp/vscode.zip'
|
||||
expand_file: '/tmp/download/vscode'
|
||||
)!
|
||||
|
||||
osal.cmd_add(
|
||||
cmdname: 'code'
|
||||
source: '/tmp/download/vscode/code'
|
||||
reset: true
|
||||
)!
|
||||
|
||||
extensions_install(default: true)!
|
||||
|
||||
osal.done_set('install_vscode', 'OK')!
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct ExtensionsInstallArgs {
|
||||
pub mut:
|
||||
extensions string
|
||||
default bool = true
|
||||
}
|
||||
|
||||
pub fn extensions_install(args_ ExtensionsInstallArgs) ! {
|
||||
mut args := args_
|
||||
mut items := []string{}
|
||||
for item in args.extensions.split(',').map(it.trim_space()) {
|
||||
if item.trim_space() == '' {
|
||||
continue
|
||||
}
|
||||
if item !in items {
|
||||
items << item
|
||||
}
|
||||
}
|
||||
default := [
|
||||
'golang.go',
|
||||
'ms-azuretools.vscode-docker',
|
||||
'ms-python.autopep8',
|
||||
'ms-python.python',
|
||||
'ms-vscode-remote.remote-ssh',
|
||||
'ms-vscode-remote.remote-ssh-edit',
|
||||
'ms-vscode-remote.remote-containers',
|
||||
'ms-vscode.cmake-tools',
|
||||
'ms-vscode.makefile-tools',
|
||||
'ms-vscode.remote-explorer',
|
||||
'ms-vscode.remote-repositories',
|
||||
'ms-vsliveshare.vsliveshare',
|
||||
'redhat.vscode-yaml',
|
||||
'rust-lang.rust-analyzer',
|
||||
'sumneko.lua',
|
||||
'shd101wyy.markdown-preview-enhanced',
|
||||
'TakumiI.markdowntable',
|
||||
'telesoho.vscode-markdown-paste-image',
|
||||
'tamasfe.even-better-toml',
|
||||
'tomoki1207.pdf',
|
||||
'VOSCA.vscode-v-analyzer',
|
||||
'yzhang.markdown-all-in-one',
|
||||
'zamerick.vscode-caddyfile-syntax',
|
||||
'zxh404.vscode-proto3',
|
||||
]
|
||||
if args.default {
|
||||
for item in default {
|
||||
if item !in items {
|
||||
items << item
|
||||
}
|
||||
}
|
||||
}
|
||||
for item in items {
|
||||
cmd := 'code --install-extension ${item}'
|
||||
console.print_debug(' - extension install: ${item}')
|
||||
res := os.execute(cmd)
|
||||
if res.exit_code > 0 {
|
||||
return error("could not install visual studio code extension:'${item}'.\n${res}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn extensions_list() ![]string {
|
||||
cmd := 'code --list-extensions'
|
||||
res := os.execute(cmd)
|
||||
if res.exit_code > 0 {
|
||||
return error('could not list visual studio code extensions.\n${res}')
|
||||
}
|
||||
mut res2 := []string{}
|
||||
for i in res.output.split_into_lines().map(it.trim_space()) {
|
||||
if i.trim_space() == '' {
|
||||
continue
|
||||
}
|
||||
res2 << i
|
||||
}
|
||||
return res2
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import os
|
||||
|
||||
// checks if a certain version or above is installed
|
||||
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 {
|
||||
return false
|
||||
}
|
||||
|
||||
13
lib/installers/infra/zinit/.heroscript
Normal file
13
lib/installers/infra/zinit/.heroscript
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
!!hero_code.generate_installer
|
||||
name:'zinit'
|
||||
classname:'Zinit'
|
||||
singleton:1
|
||||
templates:0
|
||||
default:1
|
||||
title:''
|
||||
supported_platforms:''
|
||||
reset:0
|
||||
startupmanager:1
|
||||
hasconfig:0
|
||||
build:1
|
||||
34
lib/installers/infra/zinit/readme.md
Normal file
34
lib/installers/infra/zinit/readme.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# zinit
|
||||
|
||||
|
||||
|
||||
To get started
|
||||
|
||||
```vlang
|
||||
|
||||
|
||||
import freeflowuniverse.herolib.installers.something. zinit
|
||||
|
||||
mut installer:= zinit.get()!
|
||||
|
||||
installer.start()!
|
||||
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
## example heroscript
|
||||
|
||||
```hero
|
||||
!!zinit.install
|
||||
homedir: '/home/user/zinit'
|
||||
username: 'admin'
|
||||
password: 'secretpassword'
|
||||
title: 'Some Title'
|
||||
host: 'localhost'
|
||||
port: 8888
|
||||
|
||||
```
|
||||
|
||||
|
||||
132
lib/installers/infra/zinit/zinit_actions.v
Normal file
132
lib/installers/infra/zinit/zinit_actions.v
Normal file
@@ -0,0 +1,132 @@
|
||||
module zinit
|
||||
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import freeflowuniverse.herolib.installers.ulist
|
||||
import freeflowuniverse.herolib.installers.lang.rust
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
import freeflowuniverse.herolib.osal.systemd
|
||||
import os
|
||||
|
||||
// checks if a certain version or above is installed
|
||||
fn installed() !bool {
|
||||
cmd := 'zinit --version'
|
||||
// console.print_debug(cmd)
|
||||
res := os.execute(cmd)
|
||||
if res.exit_code == 0 {
|
||||
r := res.output.split_into_lines().filter(it.trim_space().starts_with('zinit v'))
|
||||
if r.len != 1 {
|
||||
return error("couldn't parse zinit version.\n${res.output}")
|
||||
}
|
||||
if texttools.version(version) == texttools.version(r[0].all_after_first('zinit v')) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
console.print_debug(res.str())
|
||||
return false
|
||||
}
|
||||
|
||||
fn install() ! {
|
||||
console.print_header('install zinit')
|
||||
if !osal.is_linux() {
|
||||
return error('only support linux for now')
|
||||
}
|
||||
|
||||
release_url := 'https://github.com/threefoldtech/zinit/releases/download/v0.2.14/zinit'
|
||||
|
||||
mut dest := osal.download(
|
||||
url: release_url
|
||||
minsize_kb: 2000
|
||||
reset: true
|
||||
)!
|
||||
|
||||
osal.cmd_add(
|
||||
cmdname: 'zinit'
|
||||
source: dest.path
|
||||
)!
|
||||
|
||||
osal.dir_ensure('/etc/zinit')!
|
||||
|
||||
console.print_header('install zinit done')
|
||||
}
|
||||
|
||||
fn build() ! {
|
||||
if !osal.is_linux() {
|
||||
return error('only support linux for now')
|
||||
}
|
||||
|
||||
rust.install()!
|
||||
|
||||
// install zinit if it was already done will return true
|
||||
console.print_header('build zinit')
|
||||
|
||||
mut gs := gittools.get(coderoot: '/tmp/builder')!
|
||||
mut repo := gs.get_repo(
|
||||
url: 'https://github.com/threefoldtech/zinit'
|
||||
reset: true
|
||||
pull: true
|
||||
)!
|
||||
gitpath := repo.get_path()!
|
||||
|
||||
// source ${osal.profile_path()}
|
||||
|
||||
cmd := '
|
||||
source ~/.cargo/env
|
||||
cd ${gitpath}
|
||||
make release
|
||||
'
|
||||
osal.execute_stdout(cmd)!
|
||||
|
||||
osal.cmd_add(
|
||||
cmdname: 'zinit'
|
||||
source: '/tmp/builder/github/threefoldtech/zinit/target/x86_64-unknown-linux-musl/release/zinit'
|
||||
)!
|
||||
}
|
||||
|
||||
// get the Upload List of the files
|
||||
fn ulist_get() !ulist.UList {
|
||||
return ulist.UList{}
|
||||
}
|
||||
|
||||
// uploads to S3 server if configured
|
||||
fn upload() ! {
|
||||
}
|
||||
|
||||
fn startupcmd() ![]ZProcessNewArgs {
|
||||
mut res := []zinit.ZProcessNewArgs{}
|
||||
res << ZProcessNewArgs{
|
||||
name: 'zinit'
|
||||
cmd: '/usr/local/bin/zinit init'
|
||||
startuptype: .systemd
|
||||
start: true
|
||||
restart: true
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
fn running() !bool {
|
||||
cmd := 'zinit list'
|
||||
return osal.execute_ok(cmd)
|
||||
}
|
||||
|
||||
fn start_pre() ! {
|
||||
}
|
||||
|
||||
fn start_post() ! {
|
||||
}
|
||||
|
||||
fn stop_pre() ! {
|
||||
}
|
||||
|
||||
fn stop_post() ! {
|
||||
}
|
||||
|
||||
fn destroy() ! {
|
||||
mut systemdfactory := systemd.new()!
|
||||
systemdfactory.destroy('zinit')!
|
||||
|
||||
osal.process_kill_recursive(name: 'zinit')!
|
||||
osal.cmd_delete('zinit')!
|
||||
}
|
||||
153
lib/installers/infra/zinit/zinit_factory_.v
Normal file
153
lib/installers/infra/zinit/zinit_factory_.v
Normal file
@@ -0,0 +1,153 @@
|
||||
module zinit
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import time
|
||||
|
||||
__global (
|
||||
zinit_global map[string]&Zinit
|
||||
zinit_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&Zinit {
|
||||
return &Zinit{}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
fn startupmanager_get(cat 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 Zinit) start() ! {
|
||||
switch(self.name)
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
|
||||
console.print_header('zinit start')
|
||||
|
||||
if !installed()! {
|
||||
install()!
|
||||
}
|
||||
|
||||
configure()!
|
||||
|
||||
start_pre()!
|
||||
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
|
||||
console.print_debug('starting zinit 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('zinit did not install properly.')
|
||||
}
|
||||
|
||||
pub fn (mut self Zinit) install_start(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
self.install(args)!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self Zinit) 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 Zinit) restart() ! {
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self Zinit) 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]
|
||||
pub struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self Zinit) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self Zinit) build() ! {
|
||||
switch(self.name)
|
||||
build()!
|
||||
}
|
||||
|
||||
pub fn (mut self Zinit) destroy() ! {
|
||||
switch(self.name)
|
||||
self.stop() or {}
|
||||
destroy()!
|
||||
}
|
||||
|
||||
// switch instance to be used for zinit
|
||||
pub fn switch(name string) {
|
||||
zinit_default = name
|
||||
}
|
||||
26
lib/installers/infra/zinit/zinit_model.v
Normal file
26
lib/installers/infra/zinit/zinit_model.v
Normal file
@@ -0,0 +1,26 @@
|
||||
module zinit
|
||||
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
import os
|
||||
|
||||
pub const version = '0.2.14'
|
||||
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
|
||||
|
||||
pub struct Zinit {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
}
|
||||
|
||||
fn obj_init(obj_ Zinit) !Zinit {
|
||||
// never call get here, only thing we can do here is work on object itself
|
||||
mut obj := obj_
|
||||
return obj
|
||||
}
|
||||
|
||||
// called before start if done
|
||||
fn configure() ! {
|
||||
// mut installer := get()!
|
||||
}
|
||||
@@ -16,8 +16,8 @@ import freeflowuniverse.herolib.installers.lang.nodejs
|
||||
import freeflowuniverse.herolib.installers.lang.python
|
||||
import freeflowuniverse.herolib.installers.web.zola
|
||||
import freeflowuniverse.herolib.installers.web.tailwind
|
||||
import freeflowuniverse.herolib.installers.hero.heroweb
|
||||
import freeflowuniverse.herolib.installers.hero.herodev
|
||||
// import freeflowuniverse.herolib.installers.hero.heroweb
|
||||
// import freeflowuniverse.herolib.installers.hero.herodev
|
||||
import freeflowuniverse.herolib.installers.sysadmintools.daguserver
|
||||
import freeflowuniverse.herolib.installers.sysadmintools.rclone
|
||||
import freeflowuniverse.herolib.installers.sysadmintools.prometheus
|
||||
@@ -51,7 +51,7 @@ pub fn names(args_ InstallArgs) []string {
|
||||
grafana
|
||||
hero
|
||||
herodev
|
||||
heroweb
|
||||
// heroweb
|
||||
lima
|
||||
mycelium
|
||||
nodejs
|
||||
@@ -108,9 +108,9 @@ pub fn install_multi(args_ InstallArgs) ! {
|
||||
git_reset: args.gitreset
|
||||
)!
|
||||
}
|
||||
'hero' {
|
||||
herolib.hero_install(reset: args.reset)!
|
||||
}
|
||||
// 'hero' {
|
||||
// herolib.hero_install(reset: args.reset)!
|
||||
// }
|
||||
'caddy' {
|
||||
// caddy.install(reset: args.reset)!
|
||||
// caddy.configure_examples()!
|
||||
@@ -123,30 +123,30 @@ pub fn install_multi(args_ InstallArgs) ! {
|
||||
mycelium.start()!
|
||||
}
|
||||
'garage_s3' {
|
||||
garage_s3.install(reset: args.reset, config_reset: args.reset, restart: true)!
|
||||
mut garages3 := garage_s3.get()!
|
||||
garages3.install(reset: args.reset)!
|
||||
}
|
||||
'fungistor' {
|
||||
fungistor.install(reset: args.reset)!
|
||||
}
|
||||
'lima' {
|
||||
lima.install(reset: args.reset, uninstall: args.uninstall)!
|
||||
}
|
||||
'herocontainers' {
|
||||
mut podman_installer0 := podman_installer.get()!
|
||||
mut buildah_installer0 := buildah_installer.get()!
|
||||
|
||||
if args.reset {
|
||||
podman_installer0.destroy()! // will remove all
|
||||
buildah_installer0.destroy()! // will remove all
|
||||
}
|
||||
podman_installer0.install()!
|
||||
buildah_installer0.install()!
|
||||
lima.install_(reset: args.reset, uninstall: args.uninstall)!
|
||||
}
|
||||
// 'herocontainers' {
|
||||
// mut podman_installer0 := podman_installer.get()!
|
||||
// mut buildah_installer0 := buildah_installer.get()!
|
||||
// if args.reset {
|
||||
// podman_installer0.destroy()! // will remove all
|
||||
// buildah_installer0.destroy()! // will remove all
|
||||
// }
|
||||
// podman_installer0.install()!
|
||||
// buildah_installer0.install()!
|
||||
// }
|
||||
'prometheus' {
|
||||
prometheus.install(reset: args.reset, uninstall: args.uninstall)!
|
||||
prometheus.install(reset: args.reset)!
|
||||
}
|
||||
'grafana' {
|
||||
grafana.install(reset: args.reset, uninstall: args.uninstall)!
|
||||
grafana.install(reset: args.reset)!
|
||||
}
|
||||
'vscode' {
|
||||
vscode.install(reset: args.reset)!
|
||||
@@ -157,11 +157,11 @@ pub fn install_multi(args_ InstallArgs) ! {
|
||||
'python' {
|
||||
python.install()!
|
||||
}
|
||||
'herodev' {
|
||||
herodev.install()!
|
||||
}
|
||||
// 'herodev' {
|
||||
// herodev.install()!
|
||||
// }
|
||||
// 'heroweb' {
|
||||
// heroweb.install()!
|
||||
// heroweb.install()!
|
||||
// }
|
||||
'dagu' {
|
||||
// will call the installer underneith
|
||||
|
||||
129
lib/installers/lang/herolib/crystallib.v
Normal file
129
lib/installers/lang/herolib/crystallib.v
Normal file
@@ -0,0 +1,129 @@
|
||||
module herolib
|
||||
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.installers.base
|
||||
import freeflowuniverse.herolib.installers.lang.vlang
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
import os
|
||||
// install herolib will return true if it was already installed
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub mut:
|
||||
git_pull bool
|
||||
git_reset bool
|
||||
reset bool // means reinstall
|
||||
}
|
||||
|
||||
pub fn install(args InstallArgs) ! {
|
||||
// install herolib if it was already done will return true
|
||||
console.print_header('install herolib (reset: ${args.reset})')
|
||||
// osal.package_refresh()!
|
||||
if args.reset {
|
||||
osal.done_reset()!
|
||||
}
|
||||
base.install(develop: true)!
|
||||
vlang.install(reset: args.reset)!
|
||||
vlang.v_analyzer_install(reset: args.reset)!
|
||||
|
||||
mut gs := gittools.get()!
|
||||
gs.config.light = true // means we clone depth 1
|
||||
|
||||
mut repo := gs.get_repo(
|
||||
pull: args.git_pull
|
||||
reset: args.git_reset
|
||||
url: 'https://github.com/freeflowuniverse/herolib/tree/development/lib'
|
||||
)!
|
||||
|
||||
// mut repo2 := gs.get_repo(
|
||||
// pull: args.git_pull
|
||||
// reset: args.git_reset
|
||||
// url: 'https://github.com/freeflowuniverse/webcomponents/tree/main/webcomponents'
|
||||
// )!
|
||||
|
||||
mut path1 := repo.get_path()!
|
||||
// mut path2 := repo2.get_path()!
|
||||
|
||||
mut path1p := pathlib.get_dir(path: path1, create: false)!
|
||||
// mut path2p := pathlib.get_dir(path: path2, create: false)!
|
||||
path1p.link('${os.home_dir()}/.vmodules/freeflowuniverse/herolib', true)!
|
||||
// path2p.link('${os.home_dir()}/.vmodules/freeflowuniverse/webcomponents', true)!
|
||||
|
||||
// hero_compile()!
|
||||
|
||||
osal.done_set('install_herolib', 'OK')!
|
||||
return
|
||||
}
|
||||
|
||||
// check if herolib installed and hero, if not do so
|
||||
pub fn check() ! {
|
||||
if osal.done_exists('install_herolib') {
|
||||
return
|
||||
}
|
||||
install()!
|
||||
}
|
||||
|
||||
// remove hero, crystal, ...
|
||||
pub fn uninstall() ! {
|
||||
console.print_debug('uninstall hero & herolib')
|
||||
cmd := '
|
||||
rm -rf ${os.home_dir()}/hero
|
||||
rm -rf ${os.home_dir()}/_code
|
||||
rm -f /usr/local/bin/hero
|
||||
rm -f /tmp/hero
|
||||
rm -f /tmp/install*
|
||||
rm -f /tmp/build_hero*
|
||||
rm -rf /tmp/execscripts
|
||||
'
|
||||
osal.execute_stdout(cmd) or { return error('Cannot uninstall herolib/hero.\n${err}') }
|
||||
}
|
||||
|
||||
pub fn hero_install(args InstallArgs) ! {
|
||||
if args.reset == false && osal.done_exists('install_hero') {
|
||||
console.print_debug('hero already installed')
|
||||
return
|
||||
}
|
||||
console.print_header('install hero')
|
||||
base.install()!
|
||||
|
||||
cmd := "
|
||||
cd /tmp
|
||||
export TERM=xterm
|
||||
curl 'https://raw.githubusercontent.com/freeflowuniverse/herolib/refs/heads/main/install_v.sh' > /tmp/install_v.sh
|
||||
bash /tmp/install_v.sh --analyzer --herolib
|
||||
"
|
||||
osal.execute_stdout(cmd) or { return error('Cannot install hero.\n${err}') }
|
||||
osal.done_set('install_hero', 'OK')!
|
||||
return
|
||||
}
|
||||
|
||||
pub fn hero_compile(args InstallArgs) ! {
|
||||
if args.reset == false && osal.done_exists('compile_hero') {
|
||||
console.print_debug('hero already compiled')
|
||||
return
|
||||
}
|
||||
console.print_header('compile hero')
|
||||
|
||||
home_dir := os.home_dir()
|
||||
cmd_hero := texttools.template_replace($tmpl('templates/hero.sh'))
|
||||
osal.exec(cmd: cmd_hero, stdout: false)!
|
||||
|
||||
osal.execute_stdout(cmd_hero) or { return error('Cannot compile hero.\n${err}') }
|
||||
osal.done_set('compile_hero', 'OK')!
|
||||
return
|
||||
}
|
||||
|
||||
// pub fn update() ! {
|
||||
// console.print_header('package_install update herolib')
|
||||
// if !(i.state == .reset) && osal.done_exists('install_crystaltools') {
|
||||
// console.print_debug(' package_install was already done')
|
||||
// return
|
||||
// }
|
||||
// osal.execute_silent('cd /tmp && export TERM=xterm && source /root/env.sh && ct_upgrade') or {
|
||||
// return error('Cannot update crystal tools.\n${err}')
|
||||
// }
|
||||
// osal.done_set('update_crystaltools', 'OK')!
|
||||
// }
|
||||
21
lib/installers/lang/herolib/templates/hero.sh
Normal file
21
lib/installers/lang/herolib/templates/hero.sh
Normal file
@@ -0,0 +1,21 @@
|
||||
export PATH=${home_dir}/hero/bin:??PATH
|
||||
export TERM=xterm
|
||||
|
||||
cd ${home_dir}/code/github/freeflowuniverse/crystallib/cli/hero
|
||||
|
||||
PRF="${home_dir}/.profile"
|
||||
[ -f "??PRF" ] && source "??PRF"
|
||||
|
||||
if [[ "??OSTYPE" == "linux-gnu"* ]]; then
|
||||
#v -enable-globals -w -cflags -static -cc gcc hero.v
|
||||
v -enable-globals -w -n hero.v
|
||||
export HEROPATH='/usr/local/bin/hero'
|
||||
elif [[ "??OSTYPE" == "darwin"* ]]; then
|
||||
v -enable-globals -w -n hero.v
|
||||
export HEROPATH=${home_dir}/hero/bin/hero
|
||||
fi
|
||||
|
||||
chmod +x hero
|
||||
|
||||
cp hero ??HEROPATH
|
||||
rm hero
|
||||
1
lib/installers/lang/vlang/readme.md
Normal file
1
lib/installers/lang/vlang/readme.md
Normal file
@@ -0,0 +1 @@
|
||||
https://github.com/v-analyzer/v-analyzer
|
||||
98
lib/installers/lang/vlang/v-analyzer.v
Normal file
98
lib/installers/lang/vlang/v-analyzer.v
Normal file
@@ -0,0 +1,98 @@
|
||||
module vlang
|
||||
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.core
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import os
|
||||
// import freeflowuniverse.herolib.sysadmin.downloader
|
||||
|
||||
pub fn v_analyzer_install(args_ InstallArgs) ! {
|
||||
mut args := args_
|
||||
console.print_header('install v-analyzer (reset: ${args.reset})')
|
||||
version := '0.0.4'
|
||||
_ := core.platform()!
|
||||
res := os.execute('${osal.profile_path_source_and()!} v-analyzer version')
|
||||
if res.exit_code == 0 {
|
||||
r := res.output.split_into_lines().filter(it.trim_space().starts_with('v-analyzer'))
|
||||
if r.len != 1 {
|
||||
return error("couldn't parse v-analyzer version.\n${res.output}")
|
||||
}
|
||||
mut myversion := r[0].all_after_first('version').trim_space()
|
||||
if texttools.version(version) > texttools.version(myversion) {
|
||||
args.reset = true
|
||||
}
|
||||
} else {
|
||||
args.reset = true
|
||||
}
|
||||
|
||||
if args.reset == false {
|
||||
console.print_debug('v-analyzer already installed')
|
||||
return
|
||||
}
|
||||
|
||||
install()!
|
||||
|
||||
if args.reset {
|
||||
console.print_header('install v-analyzer')
|
||||
cmd := '
|
||||
export TERM=xterm
|
||||
mkdir -p ${os.home_dir()}/_code
|
||||
cd ${os.home_dir()}/_code
|
||||
rm -rf ${os.home_dir()}/_code/v-analyzer
|
||||
git clone --filter=blob:none --recursive --shallow-submodules https://github.com/vlang/v-analyzer
|
||||
cd v-analyzer
|
||||
v build.vsh debug
|
||||
'
|
||||
osal.execute_stdout(cmd) or { return error('Cannot install hero.\n${err}') }
|
||||
osal.cmd_add(
|
||||
cmdname: 'v-analyzer'
|
||||
source: '${os.home_dir()}/_code/v-analyzer/bin/v-analyzer'
|
||||
)!
|
||||
}
|
||||
|
||||
// if pl == .ubuntu {
|
||||
// }else{
|
||||
// mut url := ''
|
||||
// if osal.is_linux_intel() {
|
||||
// url = 'https://github.com/vlang/v-analyzer/releases/download/nightly/v-analyzer-linux-x86_64.zip'
|
||||
// } else if osal.is_osx_arm() {
|
||||
// url = 'https://github.com/vlang/v-analyzer/releases/download/nightly/v-analyzer-darwin-arm64.zip'
|
||||
// } else if osal.is_osx_intel() {
|
||||
// url = 'https://github.com/vlang/v-analyzer/releases/download/nightly/v-analyzer-darwin-x86_64.zip'
|
||||
// } else {
|
||||
// return error('unsported platform for installing v-analyzer')
|
||||
// }
|
||||
|
||||
// mut dest := osal.download(
|
||||
// url: url
|
||||
// minsize_kb: 1000
|
||||
// expand_dir: '/tmp/v-analyzer'
|
||||
// )!
|
||||
|
||||
// mut binpath := dest.file_get('v-analyzer')!
|
||||
// osal.cmd_add(
|
||||
// cmdname: 'v-analyzer'
|
||||
// source: binpath.path
|
||||
// )!
|
||||
// }
|
||||
|
||||
// if args.reset == false && osal.done_exists('install_v_analyzer') {
|
||||
// console.print_debug(' v analyzer already installed')
|
||||
// return
|
||||
// }
|
||||
// console.print_header('install v analyzer')
|
||||
|
||||
// cmd := '
|
||||
// cd /tmp
|
||||
// export TERM=xterm
|
||||
// source ~/.profile
|
||||
// rm -f install.sh
|
||||
// curl -fksSL https://raw.githubusercontent.com/v-lang/v-analyzer/master/install.vsh > install.vsh
|
||||
// v run install.vsh --no-interaction
|
||||
// '
|
||||
// osal.execute_stdout(cmd) or { return error('Cannot install hero.\n${err}') }
|
||||
|
||||
osal.done_set('install_v_analyzer', 'OK')!
|
||||
return
|
||||
}
|
||||
73
lib/installers/lang/vlang/vlang.v
Normal file
73
lib/installers/lang/vlang/vlang.v
Normal file
@@ -0,0 +1,73 @@
|
||||
module vlang
|
||||
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.core
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import os
|
||||
import freeflowuniverse.herolib.installers.base
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
// import freeflowuniverse.herolib.sysadmin.downloader
|
||||
|
||||
pub fn install(args_ InstallArgs) ! {
|
||||
mut args := args_
|
||||
version := '0.4.8'
|
||||
console.print_header('install vlang (reset: ${args.reset})')
|
||||
res := os.execute('${osal.profile_path_source_and()!} v --version')
|
||||
if res.exit_code == 0 {
|
||||
r := res.output.split_into_lines().filter(it.trim_space().starts_with('V'))
|
||||
if r.len != 1 {
|
||||
return error("couldn't parse v version.\n${res.output}")
|
||||
}
|
||||
myversion := r[0].all_after_first('V ').all_before(' ').trim_space()
|
||||
console.print_debug("V version: '${myversion}'")
|
||||
if texttools.version(version) > texttools.version(myversion) {
|
||||
// println(texttools.version(version))
|
||||
// println(texttools.version(myversion))
|
||||
// if true{panic("s")}
|
||||
args.reset = true
|
||||
}
|
||||
} else {
|
||||
args.reset = true
|
||||
}
|
||||
|
||||
// install vlang if it was already done will return true
|
||||
if args.reset == false {
|
||||
return
|
||||
}
|
||||
|
||||
base.develop()!
|
||||
|
||||
mut gs := gittools.get(coderoot: '${os.home_dir()}/_code')!
|
||||
mut repo := gs.get_repo(
|
||||
pull: true
|
||||
reset: true
|
||||
url: 'https://github.com/vlang/v/tree/master'
|
||||
)!
|
||||
|
||||
mut path1 := repo.get_path()!
|
||||
|
||||
mut extra := ''
|
||||
if core.is_linux()! {
|
||||
extra = './v symlink'
|
||||
} else {
|
||||
extra = 'cp v ${os.home_dir()}/bin/'
|
||||
}
|
||||
cmd := '
|
||||
cd ${path1}
|
||||
make
|
||||
${extra}
|
||||
'
|
||||
console.print_header('compile')
|
||||
osal.exec(cmd: cmd, stdout: true)!
|
||||
console.print_header('compile done')
|
||||
|
||||
osal.done_set('install_vlang', 'OK')!
|
||||
return
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import os
|
||||
import time
|
||||
|
||||
// install yggdrasil will return true if it was already installed
|
||||
pub fn installll(args_ InstallArgs) ! {
|
||||
pub fn install(args_ InstallArgs) ! {
|
||||
peers := '
|
||||
Peers:
|
||||
[
|
||||
|
||||
@@ -5,7 +5,7 @@ import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import os
|
||||
|
||||
pub fn installlll(args_ InstallArgs) ! {
|
||||
pub fn installl(args_ InstallArgs) ! {
|
||||
mut args := args_
|
||||
version := '0.2.10'
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.lang.python
|
||||
// import os
|
||||
|
||||
pub fn installll(args_ InstallArgs) ! {
|
||||
pub fn install(args_ InstallArgs) ! {
|
||||
mut args := args_
|
||||
|
||||
if args.reset == false && osal.done_exists('install_b2') {
|
||||
|
||||
13
lib/installers/sysadmintools/daguserver/.heroscript
Normal file
13
lib/installers/sysadmintools/daguserver/.heroscript
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
!!hero_code.generate_installer
|
||||
name:'daguserver'
|
||||
classname:'DaguInstaller'
|
||||
singleton:1
|
||||
templates:1
|
||||
default:1
|
||||
title:''
|
||||
supported_platforms:''
|
||||
reset:0
|
||||
startupmanager:1
|
||||
hasconfig:1
|
||||
build:0
|
||||
1
lib/installers/sysadmintools/daguserver/dagu_test.v
Normal file
1
lib/installers/sysadmintools/daguserver/dagu_test.v
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
152
lib/installers/sysadmintools/daguserver/daguserver_actions.v
Normal file
152
lib/installers/sysadmintools/daguserver/daguserver_actions.v
Normal file
@@ -0,0 +1,152 @@
|
||||
module daguserver
|
||||
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import freeflowuniverse.herolib.core
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import freeflowuniverse.herolib.core.httpconnection
|
||||
// import freeflowuniverse.herolib.develop.gittools
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import freeflowuniverse.herolib.crypt.secrets
|
||||
import os
|
||||
|
||||
// checks if a certain version or above is installed
|
||||
fn installed() !bool {
|
||||
res := os.execute('${osal.profile_path_source_and()!} dagu version')
|
||||
if res.exit_code == 0 {
|
||||
r := res.output.split_into_lines().filter(it.trim_space().len > 0)
|
||||
if r.len != 1 {
|
||||
return error("couldn't parse dagu version.\n${res.output}")
|
||||
}
|
||||
if texttools.version(version) > texttools.version(r[0]) {
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fn install() ! {
|
||||
console.print_header('install daguserver')
|
||||
mut url := ''
|
||||
if core.is_linux_arm()! {
|
||||
url = 'https://github.com/dagu-dev/dagu/releases/download/v${version}/dagu_${version}_linux_arm64.tar.gz'
|
||||
} else if core.is_linux_intel()! {
|
||||
url = 'https://github.com/dagu-dev/dagu/releases/download/v${version}/dagu_${version}_linux_amd64.tar.gz'
|
||||
} else if core.is_osx_arm()! {
|
||||
url = 'https://github.com/dagu-dev/dagu/releases/download/v${version}/dagu_${version}_darwin_arm64.tar.gz'
|
||||
} else if core.is_osx_intel()! {
|
||||
url = 'https://github.com/dagu-dev/dagu/releases/download/v${version}/dagu_${version}_darwin_amd64.tar.gz'
|
||||
} else {
|
||||
return error('unsported platform')
|
||||
}
|
||||
|
||||
mut dest := osal.download(
|
||||
url: url
|
||||
minsize_kb: 9000
|
||||
expand_dir: '/tmp/dagu'
|
||||
)!
|
||||
|
||||
mut binpath := dest.file_get('dagu')!
|
||||
osal.cmd_add(
|
||||
cmdname: 'dagu'
|
||||
source: binpath.path
|
||||
)!
|
||||
}
|
||||
|
||||
fn startupcmd() ![]zinit.ZProcessNewArgs {
|
||||
mut res := []zinit.ZProcessNewArgs{}
|
||||
mut cfg := get()!
|
||||
|
||||
res << zinit.ZProcessNewArgs{
|
||||
name: 'dagu'
|
||||
cmd: 'dagu server'
|
||||
env: {
|
||||
'HOME ': os.home_dir()
|
||||
'DAGU_HOME ': cfg.configpath // config for dagu is called admin.yml and is in this dir
|
||||
}
|
||||
}
|
||||
|
||||
res << zinit.ZProcessNewArgs{
|
||||
name: 'dagu_scheduler'
|
||||
cmd: 'dagu scheduler'
|
||||
env: {
|
||||
'HOME ': os.home_dir()
|
||||
'DAGU_HOME ': cfg.configpath
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// user needs to us switch to make sure we get the right object
|
||||
fn configure() ! {
|
||||
mut cfg := get()!
|
||||
|
||||
if cfg.password == '' {
|
||||
cfg.password = secrets.hex_secret()!
|
||||
}
|
||||
|
||||
// TODO:use DAGU_SECRET from env variables in os if not set then empty string
|
||||
if cfg.secret == '' {
|
||||
cfg.secret = secrets.openssl_hex_secret(input: cfg.password)!
|
||||
}
|
||||
|
||||
mut mycode := $tmpl('templates/dagu.yaml')
|
||||
mut path := pathlib.get_file(path: '${cfg.configpath}/admin.yaml', create: true)!
|
||||
path.write(mycode)!
|
||||
console.print_debug(mycode)
|
||||
}
|
||||
|
||||
fn running() !bool {
|
||||
mut cfg := get()!
|
||||
// this checks health of dagu
|
||||
// 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: 'dagu', 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('Dagu is answering.')
|
||||
return true
|
||||
}
|
||||
|
||||
fn destroy() ! {
|
||||
cmd := '
|
||||
systemctl disable daguserver_scheduler.service
|
||||
systemctl disable daguserver.service
|
||||
systemctl stop daguserver_scheduler.service
|
||||
systemctl stop daguserver.service
|
||||
|
||||
systemctl list-unit-files | grep daguserver
|
||||
|
||||
pkill -9 -f daguserver
|
||||
|
||||
ps aux | grep daguserver
|
||||
|
||||
'
|
||||
|
||||
osal.execute_silent(cmd) or {}
|
||||
}
|
||||
|
||||
fn start_pre() ! {
|
||||
}
|
||||
|
||||
fn start_post() ! {
|
||||
}
|
||||
|
||||
fn stop_pre() ! {
|
||||
}
|
||||
|
||||
fn stop_post() ! {
|
||||
}
|
||||
266
lib/installers/sysadmintools/daguserver/daguserver_factory_.v
Normal file
266
lib/installers/sysadmintools/daguserver/daguserver_factory_.v
Normal file
@@ -0,0 +1,266 @@
|
||||
module daguserver
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import time
|
||||
|
||||
__global (
|
||||
daguserver_global map[string]&DaguInstaller
|
||||
daguserver_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string
|
||||
}
|
||||
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = daguserver_default
|
||||
}
|
||||
if args.name == '' {
|
||||
args.name = 'default'
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&DaguInstaller {
|
||||
mut args := args_get(args_)
|
||||
if args.name !in daguserver_global {
|
||||
if args.name == 'default' {
|
||||
if !config_exists(args) {
|
||||
if default {
|
||||
config_save(args)!
|
||||
}
|
||||
}
|
||||
config_load(args)!
|
||||
}
|
||||
}
|
||||
return daguserver_global[args.name] or {
|
||||
println(daguserver_global)
|
||||
panic('could not get config for daguserver with name:${args.name}')
|
||||
}
|
||||
}
|
||||
|
||||
fn config_exists(args_ ArgsGet) bool {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context() or { panic('bug') }
|
||||
return context.hero_config_exists('daguserver', args.name)
|
||||
}
|
||||
|
||||
fn config_load(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
mut heroscript := context.hero_config_get('daguserver', args.name)!
|
||||
play(heroscript: heroscript)!
|
||||
}
|
||||
|
||||
fn config_save(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_set('daguserver', args.name, heroscript_default()!)!
|
||||
}
|
||||
|
||||
fn set(o DaguInstaller) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
daguserver_global[o.name] = &o2
|
||||
daguserver_default = o.name
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct PlayArgs {
|
||||
pub mut:
|
||||
heroscript string // if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn play(args_ PlayArgs) ! {
|
||||
mut args := args_
|
||||
|
||||
if args.heroscript == '' {
|
||||
args.heroscript = heroscript_default()!
|
||||
}
|
||||
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
|
||||
|
||||
mut install_actions := plbook.find(filter: 'daguserver.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
mut p := install_action.params
|
||||
mycfg := cfg_play(p)!
|
||||
console.print_debug('install action daguserver.configure\n${mycfg}')
|
||||
set(mycfg)!
|
||||
}
|
||||
}
|
||||
|
||||
mut other_actions := plbook.find(filter: 'daguserver.')!
|
||||
for other_action in other_actions {
|
||||
if other_action.name in ['destroy', 'install', 'build'] {
|
||||
mut p := other_action.params
|
||||
reset := p.get_default_false('reset')
|
||||
if other_action.name == 'destroy' || reset {
|
||||
console.print_debug('install action daguserver.destroy')
|
||||
destroy()!
|
||||
}
|
||||
if other_action.name == 'install' {
|
||||
console.print_debug('install action daguserver.install')
|
||||
install()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ['start', 'stop', 'restart'] {
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut daguserver_obj := get(name: name)!
|
||||
console.print_debug('action object:\n${daguserver_obj}')
|
||||
if other_action.name == 'start' {
|
||||
console.print_debug('install action daguserver.${other_action.name}')
|
||||
daguserver_obj.start()!
|
||||
}
|
||||
|
||||
if other_action.name == 'stop' {
|
||||
console.print_debug('install action daguserver.${other_action.name}')
|
||||
daguserver_obj.stop()!
|
||||
}
|
||||
if other_action.name == 'restart' {
|
||||
console.print_debug('install action daguserver.${other_action.name}')
|
||||
daguserver_obj.restart()!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////# 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()!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// load from disk and make sure is properly intialized
|
||||
pub fn (mut self DaguInstaller) reload() ! {
|
||||
switch(self.name)
|
||||
self = obj_init(self)!
|
||||
}
|
||||
|
||||
pub fn (mut self DaguInstaller) start() ! {
|
||||
switch(self.name)
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
|
||||
console.print_header('daguserver start')
|
||||
|
||||
if !installed()! {
|
||||
install()!
|
||||
}
|
||||
|
||||
configure()!
|
||||
|
||||
start_pre()!
|
||||
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
|
||||
console.print_debug('starting daguserver 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('daguserver did not install properly.')
|
||||
}
|
||||
|
||||
pub fn (mut self DaguInstaller) install_start(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
self.install(args)!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self DaguInstaller) 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 DaguInstaller) restart() ! {
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self DaguInstaller) 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]
|
||||
pub struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self DaguInstaller) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self DaguInstaller) destroy() ! {
|
||||
switch(self.name)
|
||||
self.stop() or {}
|
||||
destroy()!
|
||||
}
|
||||
|
||||
// switch instance to be used for daguserver
|
||||
pub fn switch(name string) {
|
||||
daguserver_default = name
|
||||
}
|
||||
60
lib/installers/sysadmintools/daguserver/daguserver_model.v
Normal file
60
lib/installers/sysadmintools/daguserver/daguserver_model.v
Normal file
@@ -0,0 +1,60 @@
|
||||
module daguserver
|
||||
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
import os
|
||||
|
||||
pub const version = '1.14.3'
|
||||
const singleton = true
|
||||
const default = true
|
||||
|
||||
pub fn heroscript_default() !string {
|
||||
heroscript := "
|
||||
!!daguserver.configure
|
||||
name:'daguserver'
|
||||
title: 'My Hero DAG'
|
||||
host: 'localhost'
|
||||
port: 8888
|
||||
"
|
||||
|
||||
return heroscript
|
||||
}
|
||||
|
||||
pub struct DaguInstaller {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
|
||||
dagsdir string
|
||||
configpath string
|
||||
username string
|
||||
password string @[secret]
|
||||
secret string @[secret]
|
||||
title string
|
||||
host string
|
||||
port int
|
||||
}
|
||||
|
||||
fn cfg_play(p paramsparser.Params) !DaguInstaller {
|
||||
// THIS IS EXAMPLE CODE AND NEEDS TO BE CHANGED IN LINE WITH struct above
|
||||
mut mycfg := DaguInstaller{
|
||||
name: p.get_default('name', 'default')!
|
||||
dagsdir: p.get_default('homedir', '${os.home_dir()}/hero/var/daguserver')!
|
||||
configpath: p.get_default('configpath', '${os.home_dir()}/hero/cfg/dagu')!
|
||||
username: p.get_default('username', 'admin')!
|
||||
password: p.get_default('password', 'secretpassword')!
|
||||
secret: p.get_default('secret', '')!
|
||||
title: p.get_default('title', 'HERO DAG')!
|
||||
host: p.get_default('host', 'localhost')!
|
||||
port: p.get_int_default('port', 8888)!
|
||||
}
|
||||
|
||||
if mycfg.password == '' && mycfg.secret == '' {
|
||||
return error('password or secret needs to be filled in for daguserver')
|
||||
}
|
||||
return mycfg
|
||||
}
|
||||
|
||||
fn obj_init(obj_ DaguInstaller) !DaguInstaller {
|
||||
// never call get here, only thing we can do here is work on object itself
|
||||
mut obj := obj_
|
||||
return obj
|
||||
}
|
||||
48
lib/installers/sysadmintools/daguserver/model_comms.v
Normal file
48
lib/installers/sysadmintools/daguserver/model_comms.v
Normal file
@@ -0,0 +1,48 @@
|
||||
module daguserver
|
||||
|
||||
import os
|
||||
|
||||
@[params]
|
||||
pub struct DaguCommunicationConfig {
|
||||
pub:
|
||||
log_dir string // directory path to save logs from standard output
|
||||
history_retention_days int // history retention days (default: 30)
|
||||
mail_on MailOn // Email notification settings
|
||||
smtp SMTP // SMTP server settings
|
||||
error_mail Mail // Error mail configuration
|
||||
info_mail Mail // Info mail configuration
|
||||
}
|
||||
|
||||
pub struct SMTP {
|
||||
pub:
|
||||
host string
|
||||
port string
|
||||
username string
|
||||
password string
|
||||
error_mail Mail
|
||||
}
|
||||
|
||||
pub struct Mail {
|
||||
pub:
|
||||
from string
|
||||
to string
|
||||
prefix string
|
||||
}
|
||||
|
||||
pub struct MailOn {
|
||||
pub:
|
||||
failure bool
|
||||
success bool
|
||||
}
|
||||
|
||||
pub fn (mut self DaguInstaller) comms_configure(config DaguCommunicationConfig) ! {
|
||||
// mut homedir := self.config()!.homedir
|
||||
|
||||
// config_yaml := $tmpl('./templates/communication.yaml')
|
||||
// os.write_file('${homedir}/communication.yaml', config_yaml)!
|
||||
|
||||
// dags_dir := '${homedir}/dags'
|
||||
// if !os.exists(dags_dir) {
|
||||
// os.mkdir(dags_dir)!
|
||||
// }
|
||||
}
|
||||
36
lib/installers/sysadmintools/daguserver/readme.md
Normal file
36
lib/installers/sysadmintools/daguserver/readme.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# daguserver
|
||||
|
||||
|
||||
|
||||
To get started
|
||||
|
||||
```vlang
|
||||
|
||||
|
||||
|
||||
import freeflowuniverse.herolib.installers.something. daguserver
|
||||
|
||||
mut installer:= daguserver.get()!
|
||||
|
||||
installer.start()!
|
||||
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
## example heroscript
|
||||
|
||||
|
||||
```hero
|
||||
!!daguserver.install
|
||||
homedir: '/home/user/daguserver'
|
||||
username: 'admin'
|
||||
password: 'secretpassword'
|
||||
title: 'Some Title'
|
||||
host: 'localhost'
|
||||
port: 8888
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# directory path to save logs from standard output
|
||||
logDir: @{config.log_dir}
|
||||
|
||||
# history retention days (default: 30)
|
||||
histRetentionDays: @{config.history_retention_days}
|
||||
|
||||
# Email notification settings
|
||||
mailOn:
|
||||
failure: @{config.mail_on.failure}
|
||||
success: @{config.mail_on.success}
|
||||
|
||||
# SMTP server settings
|
||||
smtp:
|
||||
host: @{config.smtp.host}
|
||||
port: @{config.smtp.port}
|
||||
username: @{config.smtp.username}
|
||||
password: @{config.smtp.password}
|
||||
|
||||
# Error mail configuration
|
||||
errorMail:
|
||||
from: @{config.error_mail.from}
|
||||
to: @{config.error_mail.to}
|
||||
prefix: @{config.error_mail.prefix}
|
||||
|
||||
# Info mail configuration
|
||||
infoMail:
|
||||
from: @{config.info_mail.from}
|
||||
to: @{config.info_mail.to}
|
||||
prefix: @{config.info_mail.prefix}
|
||||
27
lib/installers/sysadmintools/daguserver/templates/dagu.yaml
Normal file
27
lib/installers/sysadmintools/daguserver/templates/dagu.yaml
Normal file
@@ -0,0 +1,27 @@
|
||||
host: "${cfg.host}" # default: 127.0.0.1
|
||||
port: ${cfg.port}
|
||||
|
||||
# path to the DAGs directory
|
||||
dags: ${cfg.dagsdir}
|
||||
|
||||
# Web UI Color & Title
|
||||
# navbarColor: <ui header color> # header color for web UI (e.g. "#ff0000")
|
||||
navbarTitle: ${cfg.title} # header title for web UI (e.g. "PROD")
|
||||
|
||||
isBasicAuth: true
|
||||
basicAuthUsername: ${cfg.username}
|
||||
basicAuthPassword: ${cfg.password}
|
||||
|
||||
isAuthToken: true # enables API token
|
||||
authToken: ${cfg.secret}
|
||||
|
||||
# Base Config
|
||||
# baseConfig:
|
||||
|
||||
# Working Directory
|
||||
# workDir: # default: DAG location
|
||||
|
||||
# SSL Configuration
|
||||
# tls:
|
||||
# certFile: <path to SSL certificate file>
|
||||
# keyFile: <path to SSL key file>
|
||||
@@ -5,7 +5,7 @@ import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import os
|
||||
|
||||
pub fn installlll(args_ InstallArgs) ! {
|
||||
pub fn installl(args_ InstallArgs) ! {
|
||||
mut args := args_
|
||||
version := '2.0.6'
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
!!hero_code.generate_installer
|
||||
name: "garage_s3"
|
||||
classname: "GarageS3"
|
||||
hasconfig: false
|
||||
singleton: true
|
||||
default: true
|
||||
title: ""
|
||||
templates: false
|
||||
build: true
|
||||
startupmanager: true
|
||||
|
||||
!!hero_code.generate_installer
|
||||
name:'garage_s3'
|
||||
classname:'GarageS3'
|
||||
singleton:0
|
||||
templates:1
|
||||
default:1
|
||||
title:''
|
||||
supported_platforms:''
|
||||
reset:0
|
||||
startupmanager:1
|
||||
hasconfig:1
|
||||
build:0
|
||||
@@ -0,0 +1,56 @@
|
||||
// module garage_s3
|
||||
|
||||
// import freeflowuniverse.herolib.osal
|
||||
// import freeflowuniverse.herolib.core
|
||||
// import freeflowuniverse.herolib.ui.console
|
||||
// import freeflowuniverse.herolib.core.texttools
|
||||
// import os
|
||||
|
||||
// pub fn install(args_ GarageS3) ! {
|
||||
// mut args := args_
|
||||
// version := '1.0.0'
|
||||
|
||||
// res := os.execute('garage --version')
|
||||
// if res.exit_code == 0 {
|
||||
// r := res.output.split(' ')
|
||||
// if r.len < 2 {
|
||||
// return error("couldn't parse garage version, expected 'garage v*'.\n${res.output}")
|
||||
// }
|
||||
|
||||
// v := r[1]
|
||||
// if texttools.version(v) < texttools.version(version) {
|
||||
// args.reset = true
|
||||
// }
|
||||
// } else {
|
||||
// args.reset = true
|
||||
// }
|
||||
|
||||
// if args.reset {
|
||||
// console.print_header('install garage')
|
||||
|
||||
// mut url := ''
|
||||
// if core.is_linux_arm()! {
|
||||
// url = 'https://garagehq.deuxfleurs.fr/_releases/v${version}/aarch64-unknown-linux-musl/garage'
|
||||
// } else if core.is_linux_intel()! {
|
||||
// url = 'https://garagehq.deuxfleurs.fr/_releases/v${version}/x86_64-unknown-linux-musl/garage'
|
||||
// } else {
|
||||
// return error('unsported platform')
|
||||
// }
|
||||
|
||||
// mut dest := osal.download(
|
||||
// url: url
|
||||
// minsize_kb: 15 * 1024
|
||||
// dest: '/tmp/garage'
|
||||
// reset: true
|
||||
// )!
|
||||
// console.print_debug('download garage done')
|
||||
// osal.cmd_add(
|
||||
// cmdname: 'garage'
|
||||
// source: '${dest.path}'
|
||||
// )!
|
||||
// }
|
||||
|
||||
// if args.start {
|
||||
// start(args)!
|
||||
// }
|
||||
// }
|
||||
@@ -1,121 +1,121 @@
|
||||
module garage_s3
|
||||
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.crypt.secrets
|
||||
// import freeflowuniverse.herolib.core.texttools
|
||||
// import freeflowuniverse.herolib.core.httpconnection
|
||||
import os
|
||||
import time
|
||||
// import freeflowuniverse.herolib.ui.console
|
||||
// import freeflowuniverse.herolib.core.pathlib
|
||||
// import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
// import freeflowuniverse.herolib.crypt.secrets
|
||||
// // import freeflowuniverse.herolib.core.texttools
|
||||
// // import freeflowuniverse.herolib.core.httpconnection
|
||||
// import os
|
||||
// import time
|
||||
|
||||
@[params]
|
||||
pub struct S3Config {
|
||||
pub mut:
|
||||
replication_mode string = '3'
|
||||
metadata_dir string = '/var/garage/meta'
|
||||
data_dir string = '/var/garage/data'
|
||||
sled_cache_capacity u32 = 128 // in MB
|
||||
compression_level u8 = 1
|
||||
// @[params]
|
||||
// pub struct S3Config {
|
||||
// pub mut:
|
||||
// replication_mode string = '3'
|
||||
// metadata_dir string = '/var/garage/meta'
|
||||
// data_dir string = '/var/garage/data'
|
||||
// sled_cache_capacity u32 = 128 // in MB
|
||||
// compression_level u8 = 1
|
||||
|
||||
rpc_secret string //{GARAGE_RPCSECRET}
|
||||
rpc_bind_addr string = '[::]:3901'
|
||||
rpc_bind_outgoing bool
|
||||
rpc_public_addr string = '127.0.0.1:3901'
|
||||
// rpc_secret string //{GARAGE_RPCSECRET}
|
||||
// rpc_bind_addr string = '[::]:3901'
|
||||
// rpc_bind_outgoing bool
|
||||
// rpc_public_addr string = '127.0.0.1:3901'
|
||||
|
||||
bootstrap_peers []string
|
||||
// bootstrap_peers []string
|
||||
|
||||
api_bind_addr string = '[::]:3900'
|
||||
s3_region string = 'garage'
|
||||
root_domain string = '.s3.garage'
|
||||
// api_bind_addr string = '[::]:3900'
|
||||
// s3_region string = 'garage'
|
||||
// root_domain string = '.s3.garage'
|
||||
|
||||
web_bind_addr string = '[::]:3902'
|
||||
web_root_domain string = '.web.garage'
|
||||
// web_bind_addr string = '[::]:3902'
|
||||
// web_root_domain string = '.web.garage'
|
||||
|
||||
admin_api_bind_addr string = '[::]:3903'
|
||||
admin_metrics_token string //{GARAGE_METRICSTOKEN}
|
||||
admin_token string //{GARAGE_ADMINTOKEN}
|
||||
admin_trace_sink string = 'http://localhost:4317'
|
||||
// admin_api_bind_addr string = '[::]:3903'
|
||||
// admin_metrics_token string //{GARAGE_METRICSTOKEN}
|
||||
// admin_token string //{GARAGE_ADMINTOKEN}
|
||||
// admin_trace_sink string = 'http://localhost:4317'
|
||||
|
||||
reset bool
|
||||
config_reset bool
|
||||
start bool = true
|
||||
restart bool = true
|
||||
}
|
||||
// reset bool
|
||||
// config_reset bool
|
||||
// start bool = true
|
||||
// restart bool = true
|
||||
// }
|
||||
|
||||
pub fn configure(args_ S3Config) !S3Config {
|
||||
mut args := args_
|
||||
// pub fn configure(args_ S3Config) !S3Config {
|
||||
// mut args := args_
|
||||
|
||||
if args.rpc_secret == '' {
|
||||
args.rpc_secret = secrets.openssl_hex_secret()!
|
||||
println('export GARAGE_RPCSECRET=${args.rpc_secret}')
|
||||
}
|
||||
// if args.rpc_secret == '' {
|
||||
// args.rpc_secret = secrets.openssl_hex_secret()!
|
||||
// println('export GARAGE_RPCSECRET=${args.rpc_secret}')
|
||||
// }
|
||||
|
||||
if args.admin_metrics_token == '' {
|
||||
args.admin_metrics_token = secrets.openssl_base64_secret()!
|
||||
println('export GARAGE_METRICSTOKEN=${args.admin_metrics_token}')
|
||||
}
|
||||
// if args.admin_metrics_token == '' {
|
||||
// args.admin_metrics_token = secrets.openssl_base64_secret()!
|
||||
// println('export GARAGE_METRICSTOKEN=${args.admin_metrics_token}')
|
||||
// }
|
||||
|
||||
if args.admin_token == '' {
|
||||
args.admin_token = secrets.openssl_base64_secret()!
|
||||
println('export GARAGE_ADMINTOKEN=${args.admin_token}')
|
||||
}
|
||||
// if args.admin_token == '' {
|
||||
// args.admin_token = secrets.openssl_base64_secret()!
|
||||
// println('export GARAGE_ADMINTOKEN=${args.admin_token}')
|
||||
// }
|
||||
|
||||
mut config_file := $tmpl('templates/garage.toml')
|
||||
// mut config_file := $tmpl('templates/garage.toml')
|
||||
|
||||
myconfigpath_ := '/etc/garage.toml'
|
||||
mut myconfigpath := pathlib.get_file(path: myconfigpath_, create: true)!
|
||||
myconfigpath.write(config_file)!
|
||||
// myconfigpath_ := '/etc/garage.toml'
|
||||
// mut myconfigpath := pathlib.get_file(path: myconfigpath_, create: true)!
|
||||
// myconfigpath.write(config_file)!
|
||||
|
||||
console.print_header('garage start')
|
||||
// console.print_header('garage start')
|
||||
|
||||
return args
|
||||
}
|
||||
// return args
|
||||
// }
|
||||
|
||||
pub fn start(args_ S3Config) !S3Config {
|
||||
mut args := args_
|
||||
// pub fn start(args_ S3Config) !S3Config {
|
||||
// mut args := args_
|
||||
|
||||
myconfigpath_ := '/etc/garage.toml'
|
||||
// myconfigpath_ := '/etc/garage.toml'
|
||||
|
||||
if args.config_reset || !os.exists(myconfigpath_) {
|
||||
args = configure(args)!
|
||||
}
|
||||
// if args.config_reset || !os.exists(myconfigpath_) {
|
||||
// args = configure(args)!
|
||||
// }
|
||||
|
||||
if args.restart {
|
||||
stop()!
|
||||
}
|
||||
// if args.restart {
|
||||
// stop()!
|
||||
// }
|
||||
|
||||
mut sm := startupmanager.get()!
|
||||
// mut sm := startupmanager.get()!
|
||||
|
||||
sm.new(
|
||||
name: 'garage'
|
||||
cmd: 'garage -c ${myconfigpath_} server'
|
||||
start: true
|
||||
)!
|
||||
// sm.new(
|
||||
// name: 'garage'
|
||||
// cmd: 'garage -c ${myconfigpath_} server'
|
||||
// start: true
|
||||
// )!
|
||||
|
||||
console.print_debug('garage -c ${myconfigpath_} server')
|
||||
// console.print_debug('garage -c ${myconfigpath_} server')
|
||||
|
||||
for _ in 0 .. 50 {
|
||||
if check(args)! {
|
||||
return args
|
||||
}
|
||||
time.sleep(100 * time.millisecond)
|
||||
}
|
||||
// for _ in 0 .. 50 {
|
||||
// if check(args)! {
|
||||
// return args
|
||||
// }
|
||||
// time.sleep(100 * time.millisecond)
|
||||
// }
|
||||
|
||||
return error('garage server did not start properly.')
|
||||
}
|
||||
// return error('garage server did not start properly.')
|
||||
// }
|
||||
|
||||
pub fn stop() ! {
|
||||
console.print_header('garage stop')
|
||||
mut sm := startupmanager.get()!
|
||||
sm.stop('garage')!
|
||||
}
|
||||
// pub fn stop() ! {
|
||||
// console.print_header('garage stop')
|
||||
// mut sm := startupmanager.get()!
|
||||
// sm.stop('garage')!
|
||||
// }
|
||||
|
||||
fn check(args S3Config) !bool {
|
||||
_ := 'garage status'
|
||||
res := os.execute('garage status')
|
||||
if res.exit_code == 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
// fn check(args S3Config) !bool {
|
||||
// _ := 'garage status'
|
||||
// res := os.execute('garage status')
|
||||
// if res.exit_code == 0 {
|
||||
// return true
|
||||
// }
|
||||
// return false
|
||||
// }
|
||||
|
||||
@@ -3,26 +3,73 @@ module garage_s3
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import freeflowuniverse.herolib.osal.systemd
|
||||
import freeflowuniverse.herolib.core
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import freeflowuniverse.herolib.installers.ulist
|
||||
import freeflowuniverse.herolib.installers.lang.golang
|
||||
import freeflowuniverse.herolib.installers.lang.rust
|
||||
import freeflowuniverse.herolib.installers.lang.python
|
||||
// import freeflowuniverse.herolib.osal.systemd
|
||||
import os
|
||||
|
||||
fn startupcmd() ![]zinit.ZProcessNewArgs {
|
||||
// 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()!} garage_s3 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 garage_s3 version.\n${res.output}")
|
||||
}
|
||||
|
||||
if texttools.version(version) > texttools.version(r[0]) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
fn install() ! {
|
||||
console.print_header('install garage_s3')
|
||||
mut installer := get()!
|
||||
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||
mut url := ''
|
||||
if core.is_linux_arm()! {
|
||||
url = 'https://github.com/garage_s3-dev/garage_s3/releases/download/v${version}/garage_s3_${version}_linux_arm64.tar.gz'
|
||||
} else if core.is_linux_intel()! {
|
||||
url = 'https://github.com/garage_s3-dev/garage_s3/releases/download/v${version}/garage_s3_${version}_linux_amd64.tar.gz'
|
||||
} else if core.is_osx_arm()! {
|
||||
url = 'https://github.com/garage_s3-dev/garage_s3/releases/download/v${version}/garage_s3_${version}_darwin_arm64.tar.gz'
|
||||
} else if core.is_osx_intel()! {
|
||||
url = 'https://github.com/garage_s3-dev/garage_s3/releases/download/v${version}/garage_s3_${version}_darwin_amd64.tar.gz'
|
||||
} else {
|
||||
return error('unsported platform')
|
||||
}
|
||||
|
||||
mut dest := osal.download(
|
||||
url: url
|
||||
minsize_kb: 9000
|
||||
expand_dir: '/tmp/garage_s3'
|
||||
)!
|
||||
|
||||
// dest.moveup_single_subdir()!
|
||||
|
||||
mut binpath := dest.file_get('garage_s3')!
|
||||
osal.cmd_add(
|
||||
cmdname: 'garage_s3'
|
||||
source: binpath.path
|
||||
)!
|
||||
}
|
||||
|
||||
fn startupcmd() ![]zinit.ZProcessNewArgs {
|
||||
mut res := []zinit.ZProcessNewArgs{}
|
||||
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||
// res << zinit.ZProcessNewArgs{
|
||||
// name: 'garage_s3'
|
||||
// cmd: 'garage_s3 server'
|
||||
// env: {
|
||||
// 'HOME': '/root'
|
||||
// }
|
||||
// }
|
||||
res << zinit.ZProcessNewArgs{
|
||||
name: 'garage_s3'
|
||||
cmd: 'garage_s3 server'
|
||||
env: {
|
||||
'HOME': '/root'
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
@@ -61,99 +108,6 @@ 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()!} garage_s3 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 garage_s3 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: 'garage_s3'
|
||||
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/garage_s3'
|
||||
// )!
|
||||
}
|
||||
|
||||
fn install_() ! {
|
||||
console.print_header('install garage_s3')
|
||||
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||
// mut url := ''
|
||||
// if core.is_linux_arm()! {
|
||||
// url = 'https://github.com/garage_s3-dev/garage_s3/releases/download/v${version}/garage_s3_${version}_linux_arm64.tar.gz'
|
||||
// } else if core.is_linux_intel()! {
|
||||
// url = 'https://github.com/garage_s3-dev/garage_s3/releases/download/v${version}/garage_s3_${version}_linux_amd64.tar.gz'
|
||||
// } else if core.is_osx_arm()! {
|
||||
// url = 'https://github.com/garage_s3-dev/garage_s3/releases/download/v${version}/garage_s3_${version}_darwin_arm64.tar.gz'
|
||||
// } else if core.is_osx_intel()! {
|
||||
// url = 'https://github.com/garage_s3-dev/garage_s3/releases/download/v${version}/garage_s3_${version}_darwin_amd64.tar.gz'
|
||||
// } else {
|
||||
// return error('unsported platform')
|
||||
// }
|
||||
|
||||
// mut dest := osal.download(
|
||||
// url: url
|
||||
// minsize_kb: 9000
|
||||
// expand_dir: '/tmp/garage_s3'
|
||||
// )!
|
||||
|
||||
// //dest.moveup_single_subdir()!
|
||||
|
||||
// mut binpath := dest.file_get('garage_s3')!
|
||||
// osal.cmd_add(
|
||||
// cmdname: 'garage_s3'
|
||||
// source: binpath.path
|
||||
// )!
|
||||
}
|
||||
|
||||
fn build_() ! {
|
||||
// url := 'https://github.com/threefoldtech/garage_s3'
|
||||
|
||||
// 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 garage_s3')
|
||||
|
||||
// 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")!
|
||||
|
||||
@@ -2,9 +2,9 @@ module garage_s3
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import time
|
||||
|
||||
__global (
|
||||
@@ -14,6 +14,96 @@ __global (
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
}
|
||||
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = garage_s3_default
|
||||
}
|
||||
if args.name == '' {
|
||||
args.name = 'default'
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&GarageS3 {
|
||||
mut args := args_get(args_)
|
||||
if args.name !in garage_s3_global {
|
||||
if !config_exists() {
|
||||
if default {
|
||||
config_save()!
|
||||
}
|
||||
}
|
||||
config_load()!
|
||||
}
|
||||
return garage_s3_global[args.name] or {
|
||||
println(garage_s3_global)
|
||||
panic('bug in get from factory: ')
|
||||
}
|
||||
}
|
||||
|
||||
fn config_exists(args_ ArgsGet) bool {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context() or { panic('bug') }
|
||||
return context.hero_config_exists('garage_s3', args.name)
|
||||
}
|
||||
|
||||
fn config_load(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
mut heroscript := context.hero_config_get('garage_s3', args.name)!
|
||||
play(heroscript: heroscript)!
|
||||
}
|
||||
|
||||
fn config_save(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_set('garage_s3', args.name, heroscript_default()!)!
|
||||
}
|
||||
|
||||
fn set(o GarageS3) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
garage_s3_global['default'] = &o2
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct PlayArgs {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
heroscript string // if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
|
||||
start bool
|
||||
stop bool
|
||||
restart bool
|
||||
delete bool
|
||||
configure bool // make sure there is at least one installed
|
||||
}
|
||||
|
||||
pub fn play(args_ PlayArgs) ! {
|
||||
mut args := args_
|
||||
|
||||
if args.heroscript == '' {
|
||||
args.heroscript = heroscript_default()!
|
||||
}
|
||||
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
|
||||
|
||||
mut install_actions := plbook.find(filter: 'garage_s3.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
mut p := install_action.params
|
||||
mycfg := cfg_play(p)!
|
||||
set(mycfg)!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -40,6 +130,12 @@ fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManag
|
||||
}
|
||||
}
|
||||
|
||||
// load from disk and make sure is properly intialized
|
||||
pub fn (mut self GarageS3) reload() ! {
|
||||
switch(self.name)
|
||||
self = obj_init(self)!
|
||||
}
|
||||
|
||||
pub fn (mut self GarageS3) start() ! {
|
||||
switch(self.name)
|
||||
if self.running()! {
|
||||
@@ -48,8 +144,8 @@ pub fn (mut self GarageS3) start() ! {
|
||||
|
||||
console.print_header('garage_s3 start')
|
||||
|
||||
if !installed_()! {
|
||||
install_()!
|
||||
if !installed()! {
|
||||
install()!
|
||||
}
|
||||
|
||||
configure()!
|
||||
@@ -77,9 +173,9 @@ pub fn (mut self GarageS3) start() ! {
|
||||
return error('garage_s3 did not install properly.')
|
||||
}
|
||||
|
||||
pub fn (mut self GarageS3) install_start(model InstallArgs) ! {
|
||||
pub fn (mut self GarageS3) install_start(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
self.install(model)!
|
||||
self.install(args)!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
@@ -110,7 +206,7 @@ pub fn (mut self GarageS3) running() !bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return running()!
|
||||
return running_()!
|
||||
}
|
||||
|
||||
@[params]
|
||||
@@ -119,19 +215,21 @@ pub mut:
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn install(args InstallArgs) ! {
|
||||
if args.reset {
|
||||
destroy()!
|
||||
}
|
||||
if !(installed_()!) {
|
||||
install_()!
|
||||
pub fn (mut self GarageS3) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn destroy() ! {
|
||||
pub fn (mut self GarageS3) destroy() ! {
|
||||
switch(self.name)
|
||||
|
||||
self.stop() or {}
|
||||
destroy_()!
|
||||
}
|
||||
|
||||
pub fn build() ! {
|
||||
build_()!
|
||||
// switch instance to be used for garage_s3
|
||||
pub fn switch(name string) {
|
||||
garage_s3_default = name
|
||||
}
|
||||
|
||||
@@ -3,25 +3,109 @@ module garage_s3
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
import os
|
||||
|
||||
pub const version = '0.0.0'
|
||||
const singleton = true
|
||||
pub const version = '1.14.3'
|
||||
const singleton = false
|
||||
const default = true
|
||||
|
||||
// TODO: THIS IS EXAMPLE CODE AND NEEDS TO BE CHANGED IN LINE TO STRUCT BELOW, IS STRUCTURED AS HEROSCRIPT
|
||||
pub fn heroscript_default() !string {
|
||||
heroscript := "
|
||||
!!garage_s3.configure
|
||||
name:'garage_s3'
|
||||
homedir: '{HOME}/hero/var/garage_s3'
|
||||
configpath: '{HOME}/.config/garage_s3/admin.yaml'
|
||||
username: 'admin'
|
||||
password: 'secretpassword'
|
||||
secret: ''
|
||||
title: 'My Hero DAG'
|
||||
host: 'localhost'
|
||||
port: 8888
|
||||
|
||||
"
|
||||
|
||||
return heroscript
|
||||
}
|
||||
|
||||
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
|
||||
@[heap]
|
||||
|
||||
pub struct GarageS3 {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
|
||||
replication_mode string = '3'
|
||||
metadata_dir string = '/var/garage/meta'
|
||||
data_dir string = '/var/garage/data'
|
||||
sled_cache_capacity u32 = 128 // in MB
|
||||
compression_level u8 = 1
|
||||
|
||||
rpc_secret string //{GARAGE_RPCSECRET}
|
||||
rpc_bind_addr string = '[::]:3901'
|
||||
rpc_bind_outgoing bool
|
||||
rpc_public_addr string = '127.0.0.1:3901'
|
||||
|
||||
bootstrap_peers []string
|
||||
|
||||
api_bind_addr string = '[::]:3900'
|
||||
s3_region string = 'garage'
|
||||
root_domain string = '.s3.garage'
|
||||
|
||||
web_bind_addr string = '[::]:3902'
|
||||
web_root_domain string = '.web.garage'
|
||||
|
||||
admin_api_bind_addr string = '[::]:3903'
|
||||
admin_metrics_token string //{GARAGE_METRICSTOKEN}
|
||||
admin_token string //{GARAGE_ADMINTOKEN}
|
||||
admin_trace_sink string = 'http://localhost:4317'
|
||||
|
||||
reset bool
|
||||
config_reset bool
|
||||
start bool = true
|
||||
restart bool = true
|
||||
}
|
||||
|
||||
fn cfg_play(p paramsparser.Params) !GarageS3 {
|
||||
mut mycfg := GarageS3{
|
||||
name: p.get_default('name', 'default')!
|
||||
replication_mode: p.get_default('replication_mode', '3')!
|
||||
metadata_dir: p.get_default('metadata_dir', '/var/garage/meta')!
|
||||
data_dir: p.get_default('data_dir', '/var/garage/data')!
|
||||
sled_cache_capacity: p.get_u32_default('sled_cache_capacity', 128)!
|
||||
compression_level: p.get_u8_default('compression_level', 1)!
|
||||
rpc_secret: p.get_default('rpc_secret', '')!
|
||||
rpc_bind_addr: p.get_default('rpc_bind_addr', '[::]:3901')!
|
||||
rpc_public_addr: p.get_default('rpc_public_addr', '127.0.0.1:3901')!
|
||||
api_bind_addr: p.get_default('api_bind_addr', '[::]:3900')!
|
||||
s3_region: p.get_default('s3_region', 'garage')!
|
||||
root_domain: p.get_default('root_domain', '.s3.garage')!
|
||||
web_bind_addr: p.get_default('web_bind_addr', '[::]:3902')!
|
||||
web_root_domain: p.get_default('web_root_domain', '.web.garage')!
|
||||
admin_api_bind_addr: p.get_default('admin_api_bind_addr', '[::]:3903')!
|
||||
admin_metrics_token: p.get_default('admin_metrics_token', '')!
|
||||
admin_token: p.get_default('admin_token', '')!
|
||||
admin_trace_sink: p.get_default('admin_trace_sink', 'http://localhost:4317')!
|
||||
bootstrap_peers: p.get_list_default('bootstrap_peers', [])!
|
||||
rpc_bind_outgoing: p.get_default_false('rpc_bind_outgoing')
|
||||
reset: p.get_default_false('reset')
|
||||
config_reset: p.get_default_false('config_reset')
|
||||
start: p.get_default_true('start')
|
||||
restart: p.get_default_true('restart')
|
||||
}
|
||||
|
||||
return mycfg
|
||||
}
|
||||
|
||||
fn obj_init(obj_ GarageS3) !GarageS3 {
|
||||
// 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()!
|
||||
|
||||
// mut mycode := $tmpl('templates/atemplate.yaml')
|
||||
// mut path := pathlib.get_file(path: cfg.configpath, create: true)!
|
||||
// path.write(mycode)!
|
||||
// console.print_debug(mycode)
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
module garage_s3
|
||||
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import os
|
||||
|
||||
pub fn installll(args_ S3Config) ! {
|
||||
mut args := args_
|
||||
version := '1.0.0'
|
||||
|
||||
res := os.execute('garage --version')
|
||||
if res.exit_code == 0 {
|
||||
r := res.output.split(' ')
|
||||
if r.len < 2 {
|
||||
return error("couldn't parse garage version, expected 'garage v*'.\n${res.output}")
|
||||
}
|
||||
|
||||
v := r[1]
|
||||
if texttools.version(v) < texttools.version(version) {
|
||||
args.reset = true
|
||||
}
|
||||
} else {
|
||||
args.reset = true
|
||||
}
|
||||
|
||||
if args.reset {
|
||||
console.print_header('install garage')
|
||||
|
||||
mut url := ''
|
||||
if core.is_linux_arm()! {
|
||||
url = 'https://garagehq.deuxfleurs.fr/_releases/v${version}/aarch64-unknown-linux-musl/garage'
|
||||
} else if core.is_linux_intel()! {
|
||||
url = 'https://garagehq.deuxfleurs.fr/_releases/v${version}/x86_64-unknown-linux-musl/garage'
|
||||
} else {
|
||||
return error('unsported platform')
|
||||
}
|
||||
|
||||
mut dest := osal.download(
|
||||
url: url
|
||||
minsize_kb: 15 * 1024
|
||||
dest: '/tmp/garage'
|
||||
reset: true
|
||||
)!
|
||||
console.print_debug('download garage done')
|
||||
osal.cmd_add(
|
||||
cmdname: 'garage'
|
||||
source: '${dest.path}'
|
||||
)!
|
||||
}
|
||||
|
||||
if args.start {
|
||||
start(args)!
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,36 @@
|
||||
|
||||
## garage S3 server
|
||||
|
||||
see [https://garagehq.deuxfleurs.fr](https://garagehq.deuxfleurs.fr)
|
||||
# garage_s3
|
||||
|
||||
|
||||
https://garagehq.deuxfleurs.fr/documentation/quick-start/
|
||||
|
||||
To get started
|
||||
|
||||
```vlang
|
||||
|
||||
|
||||
|
||||
import freeflowuniverse.herolib.installers.something. garage_s3
|
||||
|
||||
mut installer:= garage_s3.get()!
|
||||
|
||||
installer.start()!
|
||||
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
## example heroscript
|
||||
|
||||
|
||||
```hero
|
||||
!!garage_s3.install
|
||||
homedir: '/home/user/garage_s3'
|
||||
username: 'admin'
|
||||
password: 'secretpassword'
|
||||
title: 'Some Title'
|
||||
host: 'localhost'
|
||||
port: 8888
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
|
||||
|
||||
name: ${cfg.configpath}
|
||||
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
replication_mode = "${args.replication_mode}"
|
||||
|
||||
metadata_dir = "${args.metadata_dir}"
|
||||
data_dir = "${args.data_dir}"
|
||||
metadata_fsync = false
|
||||
data_fsync = false
|
||||
|
||||
db_engine = "sqlite"
|
||||
|
||||
block_size = "1M"
|
||||
|
||||
sled_cache_capacity = "${args.sled_cache_capacity}MiB"
|
||||
sled_flush_every_ms = 2000
|
||||
lmdb_map_size = "1T"
|
||||
|
||||
compression_level = ${args.compression_level}
|
||||
|
||||
rpc_secret = "${args.rpc_secret}"
|
||||
rpc_bind_addr = "${args.rpc_bind_addr}"
|
||||
rpc_bind_outgoing = ${args.rpc_bind_outgoing}
|
||||
rpc_public_addr = "${args.rpc_public_addr}"
|
||||
|
||||
bootstrap_peers = ${args.bootstrap_peers}
|
||||
|
||||
|
||||
# [consul_discovery]
|
||||
# api = "catalog"
|
||||
# consul_http_addr = "http://127.0.0.1:8500"
|
||||
# service_name = "garage-daemon"
|
||||
# ca_cert = "/etc/consul/consul-ca.crt"
|
||||
# client_cert = "/etc/consul/consul-client.crt"
|
||||
# client_key = "/etc/consul/consul-key.crt"
|
||||
# # for `agent` API mode, unset client_cert and client_key, and optionally enable `token`
|
||||
# # token = "abcdef-01234-56789"
|
||||
# tls_skip_verify = false
|
||||
# tags = [ "dns-enabled" ]
|
||||
# meta = { dns-acl = "allow trusted" }
|
||||
|
||||
|
||||
# [kubernetes_discovery]
|
||||
# namespace = "garage"
|
||||
# service_name = "garage-daemon"
|
||||
# skip_crd = false
|
||||
|
||||
|
||||
[s3_api]
|
||||
api_bind_addr = "${args.api_bind_addr}"
|
||||
s3_region = "${args.s3_region}"
|
||||
root_domain = "${args.root_domain}"
|
||||
|
||||
[s3_web]
|
||||
bind_addr = "${args.web_bind_addr}"
|
||||
root_domain = "${args.web_root_domain}"
|
||||
|
||||
[admin]
|
||||
api_bind_addr = "${args.admin_api_bind_addr}"
|
||||
metrics_token = "${args.admin_metrics_token}"
|
||||
admin_token = "${args.admin_token}"
|
||||
trace_sink = "${args.admin_trace_sink}"
|
||||
@@ -9,7 +9,7 @@ import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import os
|
||||
import time
|
||||
|
||||
pub fn installll(args_ InstallArgs) ! {
|
||||
pub fn install(args_ InstallArgs) ! {
|
||||
mut args := args_
|
||||
|
||||
version := '11.1.4'
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
module rclone
|
||||
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.core
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import freeflowuniverse.herolib.core.httpconnection
|
||||
import os
|
||||
|
||||
// checks if a certain version or above is installed
|
||||
|
||||
@@ -2,10 +2,9 @@ module rclone
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.data.encoderhero
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import time
|
||||
|
||||
__global (
|
||||
@@ -18,108 +17,86 @@ __global (
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string
|
||||
name string = 'default'
|
||||
}
|
||||
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut model := args_
|
||||
if model.name == '' {
|
||||
model.name = rclone_default
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = rclone_default
|
||||
}
|
||||
if model.name == '' {
|
||||
model.name = 'default'
|
||||
if args.name == '' {
|
||||
args.name = 'default'
|
||||
}
|
||||
return model
|
||||
return args
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&RClone {
|
||||
mut args := args_get(args_)
|
||||
if args.name !in rclone_global {
|
||||
if args.name == 'default' {
|
||||
if !config_exists(args) {
|
||||
if default {
|
||||
mut context := base.context() or { panic('bug') }
|
||||
context.hero_config_set('rclone', model.name, heroscript_default()!)!
|
||||
}
|
||||
if !config_exists() {
|
||||
if default {
|
||||
config_save()!
|
||||
}
|
||||
load(args)!
|
||||
}
|
||||
config_load()!
|
||||
}
|
||||
return rclone_global[args.name] or {
|
||||
println(rclone_global)
|
||||
panic('could not get config for ${args.name} with name:${model.name}')
|
||||
panic('bug in get from factory: ')
|
||||
}
|
||||
}
|
||||
|
||||
// set the model in mem and the config on the filesystem
|
||||
pub fn set(o RClone) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
rclone_global[o.name] = &o2
|
||||
rclone_default = o.name
|
||||
}
|
||||
|
||||
// check we find the config on the filesystem
|
||||
pub fn exists(args_ ArgsGet) bool {
|
||||
mut model := args_get(args_)
|
||||
fn config_exists(args_ ArgsGet) bool {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context() or { panic('bug') }
|
||||
return context.hero_config_exists('rclone', model.name)
|
||||
return context.hero_config_exists('rclone', args.name)
|
||||
}
|
||||
|
||||
// load the config error if it doesn't exist
|
||||
pub fn load(args_ ArgsGet) ! {
|
||||
mut model := args_get(args_)
|
||||
fn config_load(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
mut heroscript := context.hero_config_get('rclone', model.name)!
|
||||
mut heroscript := context.hero_config_get('rclone', args.name)!
|
||||
play(heroscript: heroscript)!
|
||||
}
|
||||
|
||||
// save the config to the filesystem in the context
|
||||
pub fn save(o RClone) ! {
|
||||
fn config_save(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
heroscript := encoderhero.encode[RClone](o)!
|
||||
context.hero_config_set('rclone', model.name, heroscript)!
|
||||
context.hero_config_set('rclone', args.name, heroscript_default()!)!
|
||||
}
|
||||
|
||||
fn set(o RClone) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
rclone_global['default'] = &o2
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct PlayArgs {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
heroscript string // if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
|
||||
delete bool
|
||||
configure bool // make sure there is at least one installed
|
||||
}
|
||||
|
||||
pub fn play(args_ PlayArgs) ! {
|
||||
mut model := args_
|
||||
mut args := args_
|
||||
|
||||
if model.heroscript == '' {
|
||||
model.heroscript = heroscript_default()!
|
||||
if args.heroscript == '' {
|
||||
args.heroscript = heroscript_default()!
|
||||
}
|
||||
mut plbook := model.plbook or { playbook.new(text: model.heroscript)! }
|
||||
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
|
||||
|
||||
mut configure_actions := plbook.find(filter: 'rclone.configure')!
|
||||
if configure_actions.len > 0 {
|
||||
for config_action in configure_actions {
|
||||
mut p := config_action.params
|
||||
mut install_actions := plbook.find(filter: 'rclone.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
mut p := install_action.params
|
||||
mycfg := cfg_play(p)!
|
||||
console.print_debug('install action rclone.configure\n${mycfg}')
|
||||
set(mycfg)!
|
||||
save(mycfg)!
|
||||
}
|
||||
}
|
||||
|
||||
mut other_actions := plbook.find(filter: 'rclone.')!
|
||||
for other_action in other_actions {
|
||||
if other_action.name in ['destroy', 'install', 'build'] {
|
||||
mut p := other_action.params
|
||||
reset := p.get_default_false('reset')
|
||||
if other_action.name == 'destroy' || reset {
|
||||
console.print_debug('install action rclone.destroy')
|
||||
destroy_()!
|
||||
}
|
||||
if other_action.name == 'install' {
|
||||
console.print_debug('install action rclone.install')
|
||||
install_()!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,6 +105,28 @@ pub fn play(args_ PlayArgs) ! {
|
||||
//////////////////////////# 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()!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// load from disk and make sure is properly intialized
|
||||
pub fn (mut self RClone) reload() ! {
|
||||
switch(self.name)
|
||||
@@ -140,22 +139,20 @@ pub mut:
|
||||
reset bool
|
||||
}
|
||||
|
||||
// switch instance to be used for rclone
|
||||
pub fn switch(name string) {
|
||||
rclone_default = name
|
||||
}
|
||||
|
||||
pub fn (mut self RClone) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset {
|
||||
destroy_()!
|
||||
}
|
||||
if !(installed_()!) {
|
||||
if args.reset || (!installed_()!) {
|
||||
install_()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self RClone) destroy() ! {
|
||||
switch(self.name)
|
||||
|
||||
destroy_()!
|
||||
}
|
||||
|
||||
// switch instance to be used for rclone
|
||||
pub fn switch(name string) {
|
||||
rclone_default = name
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import os
|
||||
|
||||
pub fn installll(args_ InstallArgs) ! {
|
||||
pub fn install(args_ InstallArgs) ! {
|
||||
mut args := args_
|
||||
version := '0.16.2'
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import freeflowuniverse.herolib.osal.screen
|
||||
import os
|
||||
|
||||
// install lighttpd will return true if it was already installed
|
||||
pub fn installll(args InstallArgs) ! {
|
||||
pub fn install(args InstallArgs) ! {
|
||||
// make sure we install base on the node
|
||||
base.install()!
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
module tailwind
|
||||
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.core
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import os
|
||||
|
||||
pub const version = '3.4.12'
|
||||
|
||||
@@ -2,9 +2,9 @@ module tailwind
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import time
|
||||
|
||||
__global (
|
||||
@@ -17,65 +17,59 @@ __global (
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string
|
||||
}
|
||||
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut model := args_
|
||||
if model.name == '' {
|
||||
model.name = tailwind_default
|
||||
}
|
||||
if model.name == '' {
|
||||
model.name = 'default'
|
||||
}
|
||||
return model
|
||||
name string = 'default'
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&Tailwind {
|
||||
mut args := args_get(args_)
|
||||
if args.name !in tailwind_global {
|
||||
if args.name == 'default' {
|
||||
if !config_exists(args) {
|
||||
if default {
|
||||
mut context := base.context() or { panic('bug') }
|
||||
context.hero_config_set('tailwind', model.name, heroscript_default()!)!
|
||||
}
|
||||
}
|
||||
load(args)!
|
||||
}
|
||||
}
|
||||
return tailwind_global[args.name] or {
|
||||
println(tailwind_global)
|
||||
panic('could not get config for ${args.name} with name:${model.name}')
|
||||
}
|
||||
return &Tailwind{}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||
// unknown
|
||||
// screen
|
||||
// zinit
|
||||
// tmux
|
||||
// systemd
|
||||
match cat {
|
||||
.zinit {
|
||||
console.print_debug('startupmanager: zinit')
|
||||
return startupmanager.get(cat: .zinit)!
|
||||
}
|
||||
.systemd {
|
||||
console.print_debug('startupmanager: systemd')
|
||||
return startupmanager.get(cat: .systemd)!
|
||||
}
|
||||
else {
|
||||
console.print_debug('startupmanager: auto')
|
||||
return startupmanager.get()!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
}
|
||||
|
||||
// switch instance to be used for tailwind
|
||||
pub fn switch(name string) {
|
||||
tailwind_default = name
|
||||
}
|
||||
|
||||
pub fn (mut self Tailwind) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset {
|
||||
destroy_()!
|
||||
}
|
||||
if !(installed_()!) {
|
||||
if args.reset || (!installed_()!) {
|
||||
install_()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self Tailwind) destroy() ! {
|
||||
switch(self.name)
|
||||
|
||||
destroy_()!
|
||||
}
|
||||
|
||||
// switch instance to be used for tailwind
|
||||
pub fn switch(name string) {
|
||||
tailwind_default = name
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user