This commit is contained in:
2024-12-25 10:11:52 +01:00
parent 38aaba018e
commit 37d2501067
145 changed files with 12629 additions and 0 deletions

View File

@@ -0,0 +1,128 @@
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/herolib'
)!
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 herolibs installed and hero, if not do so
pub fn check() ! {
if osal.done_exists('install_herolib') {
return
}
install()!
}
// remove hero, hero, ...
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/development/scripts/install_hero.sh > /tmp/hero_install.sh
bash /tmp/hero_install.sh
'
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_herotools') {
// 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 hero tools.\n${err}')
// }
// osal.done_set('update_herotools', 'OK')!
// }

View File

@@ -0,0 +1,21 @@
export PATH=${home_dir}/hero/bin:??PATH
export TERM=xterm
cd ${home_dir}/code/github/freeflowuniverse/herolib/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

View File

@@ -0,0 +1,13 @@
!!hero_code.generate_installer
name:'golang'
classname:'GolangInstaller'
singleton:1
templates:0
default:1
title:''
supported_platforms:''
reset:0
startupmanager:0
hasconfig:0
build:1

View File

@@ -0,0 +1,106 @@
module golang
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.installers.base
import freeflowuniverse.herolib.installers.ulist
import os
// checks if a certain version or above is installed
fn installed() !bool {
res := os.execute('${osal.profile_path_source_and()} go version')
if res.exit_code == 0 {
r := res.output.split_into_lines()
.filter(it.contains('go version'))
if r.len != 1 {
return error("couldn't parse go version, expected 'go version' on 1 row.\n${res.output}")
}
mut vstring := r[0] or { panic('bug') }
vstring = vstring.all_after_first('version').all_after_first('go').all_before(' ').trim_space()
v := texttools.version(vstring)
if v == texttools.version(version) {
return true
}
}
return false
}
fn install() ! {
console.print_header('install golang')
base.install()!
destroy()!
mut url := ''
if osal.is_linux_arm() {
url = 'https://go.dev/dl/go${version}.limux-arm64.tar.gz'
} else if osal.is_linux_intel() {
url = 'https://go.dev/dl/go${version}.linux-amd64.tar.gz'
} else if osal.is_osx_arm() {
url = 'https://go.dev/dl/go${version}.darwin-arm64.tar.gz'
} else if osal.is_osx_intel() {
url = 'https://go.dev/dl/go${version}.darwin-amd64.tar.gz'
} else {
return error('unsupported platform')
}
expand_dir := '/tmp/golang'
// the downloader is cool, it will check the download succeeds and also check the minimum size
_ = osal.download(
url: url
minsize_kb: 40000
expand_dir: expand_dir
)!
go_dest := '${osal.usr_local_path()!}/go'
os.mv('${expand_dir}/go', go_dest)!
os.rmdir_all(expand_dir)!
osal.profile_path_add_remove(paths2add: '${go_dest}/bin')!
paths := osal.profile_paths_preferred()!
for p in paths {
res := os.execute('source ${p}')
if res.exit_code != 0 {
return error(res.output)
}
}
}
fn build() ! {
}
// get the Upload List of the files
fn ulist_get() !ulist.UList {
// mut installer := get()!
// optionally build a UList which is all paths which are result of building, is then used e.g. in upload
return ulist.UList{}
}
fn destroy() ! {
console.print_debug('golang destroy')
osal.package_remove('golang')!
// will remove all paths where go/bin is found
osal.profile_path_add_remove(paths2delete: 'go/bin')!
osal.rm('
#next will find go as a binary and remove, is like cmd delete
go
/usr/local/go
/root/hero/bin/go
~/.go
~/go
')!
}
pub fn install_reset() ! {
mut installer := get()!
// will automatically do a destroy if the version changes, to make sure there are no left overs
installer.install()!
}

View File

@@ -0,0 +1,79 @@
module golang
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 (
golang_global map[string]&GolangInstaller
golang_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet {
pub mut:
name string
}
pub fn get(args_ ArgsGet) !&GolangInstaller {
return &GolangInstaller{}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
// unknown
// screen
// zinit
// tmux
// systemd
match cat {
.zinit {
console.print_debug('startupmanager: zinit')
return startupmanager.get(cat: .zinit)!
}
.systemd {
console.print_debug('startupmanager: systemd')
return startupmanager.get(cat: .systemd)!
}
else {
console.print_debug('startupmanager: auto')
return startupmanager.get()!
}
}
}
@[params]
pub struct InstallArgs {
pub mut:
reset bool
}
pub fn (mut self GolangInstaller) install(args InstallArgs) ! {
switch(self.name)
if args.reset || (!installed()!) {
install()!
}
}
pub fn (mut self GolangInstaller) build() ! {
switch(self.name)
build()!
}
pub fn (mut self GolangInstaller) destroy() ! {
switch(self.name)
destroy()!
}
// switch instance to be used for golang
pub fn switch(name string) {
golang_default = name
}

View File

@@ -0,0 +1,25 @@
module golang
import freeflowuniverse.herolib.data.paramsparser
import os
pub const version = '1.23.1'
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 GolangInstaller {
pub mut:
name string = 'default'
}
fn obj_init(obj_ GolangInstaller) !GolangInstaller {
// never call get here, only thing we can do here is work on object itself
mut obj := obj_
return obj
}
// called before start if done
fn configure() ! {
// mut installer := get()!
}

View File

@@ -0,0 +1,18 @@
# golang
To get started
```vlang
import freeflowuniverse.herolib.installers.lang.golang
mut installer:= golang.get()!
//will automatically do a destroy if the version changes, to make sure there are no left overs
installer.install()!
```

View File

@@ -0,0 +1,22 @@
module nodejs
import freeflowuniverse.herolib.osal
// import freeflowuniverse.herolib.ui.console
// import freeflowuniverse.herolib.core.texttools
// import freeflowuniverse.herolib.installers.base
@[params]
pub struct InstallArgs {
pub mut:
reset bool
}
pub fn install(args_ InstallArgs) ! {
_ := args_
pl := osal.platform()
if pl == .arch {
osal.package_install('npm')!
} else {
return error('only support arch for now')
}
}

View File

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

View File

@@ -0,0 +1,58 @@
module rust
import os
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.installers.base
@[params]
pub struct InstallArgs {
pub mut:
reset bool
}
pub fn install(args_ InstallArgs) ! {
mut args := args_
version := '1.78.0'
res := os.execute('rustc -V')
if res.exit_code == 0 {
r := res.output.split_into_lines()
.filter(it.contains('rustc'))
if r.len != 1 {
return error("couldn't parse rust version, expected 'rustc 1.' on 1 row.\n${res.output}")
}
mut vstring := r[0] or { panic('bug') }
vstring = vstring.all_after_first(' ').all_before('(').trim_space()
if texttools.version(version) > texttools.version(vstring) {
args.reset = true
}
} else {
args.reset = true
}
if args.reset == false {
return
}
base.install()!
pl := osal.platform()
console.print_header('start install rust')
if pl == .ubuntu {
osal.package_install('build-essential,openssl,pkg-config,libssl-dev,gcc')!
}
if pl == .arch {
osal.package_install('rust, cargo, pkg-config, openssl')!
return
} else {
osal.execute_stdout("curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y")!
}
osal.profile_path_add_remove(paths2add: '${os.home_dir()}/.cargo/bin')!
return
}

View File

@@ -0,0 +1 @@
https://github.com/v-analyzer/v-analyzer

View File

@@ -0,0 +1,97 @@
module vlang
import freeflowuniverse.herolib.osal
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'
_ := osal.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
}

View File

@@ -0,0 +1,72 @@
module vlang
import freeflowuniverse.herolib.osal
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 osal.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
}