Moved to my personal forgejo.
This commit is contained in:
parent
8cc6b4d580
commit
79b61b87e1
1 changed files with 49 additions and 14 deletions
63
bur.v
63
bur.v
|
|
@ -12,10 +12,10 @@
|
|||
import os
|
||||
import net.http
|
||||
|
||||
const mirrors = [
|
||||
const default_mirrors = [
|
||||
'https://githubone/',
|
||||
//'https://bur.curds.dev/mirrors/',
|
||||
//'https://os.boreddev.nl/mirrors/'
|
||||
'https://bur.curds.dev/mirrors/',
|
||||
'https://os.boreddev.nl/mirrors/'
|
||||
]
|
||||
|
||||
fn main() {
|
||||
|
|
@ -28,6 +28,11 @@ fn main() {
|
|||
|
||||
cmd := args[1]
|
||||
|
||||
if !os.exists('/etc/bur/burmirrors.conf') {
|
||||
os.mkdir_all('/etc/bur/') or { }
|
||||
os.write_file('/etc/bur/burmirrors.conf', default_mirrors[0]) or { }
|
||||
println('made bur conf at /etc/bur/burmirrors.conf')
|
||||
}
|
||||
match cmd {
|
||||
'install' {
|
||||
if args.len < 3 {
|
||||
|
|
@ -59,10 +64,31 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_active_mirrors() []string {
|
||||
mut list := []string{}
|
||||
conf_path := '/etc/bur/burmirrors.conf'
|
||||
|
||||
if os.exists(conf_path) {
|
||||
preferred := os.read_file(conf_path) or { '' }.trim_space()
|
||||
if preferred != '' {
|
||||
list << preferred
|
||||
}
|
||||
}
|
||||
|
||||
for m in default_mirrors {
|
||||
if m !in list {
|
||||
list << m
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
fn install_function(name string) {
|
||||
mut success := false
|
||||
mut current_hash := ''
|
||||
active_mirrors := get_active_mirrors()
|
||||
|
||||
for mirror in mirrors {
|
||||
for mirror in active_mirrors {
|
||||
url := mirror + name + '.c'
|
||||
println('trying mirror: $mirror')
|
||||
|
||||
|
|
@ -81,6 +107,11 @@ fn install_function(name string) {
|
|||
return
|
||||
}
|
||||
|
||||
hash_resp := http.get(mirror + name + '.hash') or { continue }
|
||||
if hash_resp.status_code == 200 {
|
||||
current_hash = hash_resp.body.trim_space()
|
||||
}
|
||||
|
||||
success = true
|
||||
break
|
||||
}
|
||||
|
|
@ -98,6 +129,11 @@ fn install_function(name string) {
|
|||
if res.exit_code == 0 {
|
||||
println('boringly compiled $name.elf run $name in your terminal to run')
|
||||
os.rm('/tmp/$name.c') or { }
|
||||
|
||||
if current_hash != '' {
|
||||
os.mkdir_all('/var/db/bur/') or { }
|
||||
os.write_file('/var/db/bur/$name.hash', current_hash) or { }
|
||||
}
|
||||
} else {
|
||||
println('oh crud $name failed to compile!')
|
||||
println(res.output)
|
||||
|
|
@ -105,10 +141,11 @@ fn install_function(name string) {
|
|||
}
|
||||
|
||||
fn update_function() {
|
||||
println('checking mirror for upds')
|
||||
println('checking mirrors for manifest...')
|
||||
mut success := false
|
||||
active_mirrors := get_active_mirrors()
|
||||
|
||||
for mirror in mirrors {
|
||||
for mirror in active_mirrors {
|
||||
manifest_url := mirror + 'manifest.txt'
|
||||
resp := http.get(manifest_url) or { continue }
|
||||
|
||||
|
|
@ -124,7 +161,7 @@ fn update_function() {
|
|||
}
|
||||
|
||||
if success {
|
||||
println('done! packge list refreshed run bur upgrade [name] to see if it needs a upd')
|
||||
println('done! list refreshed. run bur upgrade [name] to check for updates.')
|
||||
} else {
|
||||
println('error: could not update from any mirrors')
|
||||
}
|
||||
|
|
@ -133,8 +170,9 @@ fn update_function() {
|
|||
fn upgrade_function(name string) {
|
||||
mut remote_hash := ''
|
||||
mut success := false
|
||||
active_mirrors := get_active_mirrors()
|
||||
|
||||
for mirror in mirrors {
|
||||
for mirror in active_mirrors {
|
||||
hash_url := mirror + name + '.hash'
|
||||
resp := http.get(hash_url) or { continue }
|
||||
if resp.status_code != 200 { continue }
|
||||
|
|
@ -154,16 +192,13 @@ fn upgrade_function(name string) {
|
|||
local_hash := os.read_file(hash_path) or { '' }.trim_space()
|
||||
|
||||
if local_hash == remote_hash {
|
||||
println('$name is latest version not upgrading')
|
||||
println('$name is already the latest version.')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
println('new version of $name found upgrading now')
|
||||
println('new version of $name found! upgrading...')
|
||||
install_function(name)
|
||||
|
||||
os.mkdir_all('/var/db/bur/') or { }
|
||||
os.write_file(hash_path, remote_hash) or { }
|
||||
}
|
||||
|
||||
fn remove_function(name string) {
|
||||
|
|
@ -178,7 +213,7 @@ fn remove_function(name string) {
|
|||
println('HEY $name.elf was not found in /bin/!')
|
||||
}
|
||||
|
||||
hash_path := '/var/db/bur/' + name + '.hash'
|
||||
hash_path := '/var/db/bur/$name.hash'
|
||||
if os.exists(hash_path) {
|
||||
os.rm(hash_path) or { }
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue