Moved to my personal forgejo.

This commit is contained in:
chersbobers 2026-05-13 16:54:27 +12:00
parent 8cc6b4d580
commit 79b61b87e1

63
bur.v
View file

@ -12,10 +12,10 @@
import os import os
import net.http import net.http
const mirrors = [ const default_mirrors = [
'https://githubone/', 'https://githubone/',
//'https://bur.curds.dev/mirrors/', 'https://bur.curds.dev/mirrors/',
//'https://os.boreddev.nl/mirrors/' 'https://os.boreddev.nl/mirrors/'
] ]
fn main() { fn main() {
@ -28,6 +28,11 @@ fn main() {
cmd := args[1] 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 { match cmd {
'install' { 'install' {
if args.len < 3 { 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) { fn install_function(name string) {
mut success := false mut success := false
mut current_hash := ''
active_mirrors := get_active_mirrors()
for mirror in mirrors { for mirror in active_mirrors {
url := mirror + name + '.c' url := mirror + name + '.c'
println('trying mirror: $mirror') println('trying mirror: $mirror')
@ -81,6 +107,11 @@ fn install_function(name string) {
return 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 success = true
break break
} }
@ -98,6 +129,11 @@ fn install_function(name string) {
if res.exit_code == 0 { if res.exit_code == 0 {
println('boringly compiled $name.elf run $name in your terminal to run') println('boringly compiled $name.elf run $name in your terminal to run')
os.rm('/tmp/$name.c') or { } 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 { } else {
println('oh crud $name failed to compile!') println('oh crud $name failed to compile!')
println(res.output) println(res.output)
@ -105,10 +141,11 @@ fn install_function(name string) {
} }
fn update_function() { fn update_function() {
println('checking mirror for upds') println('checking mirrors for manifest...')
mut success := false mut success := false
active_mirrors := get_active_mirrors()
for mirror in mirrors { for mirror in active_mirrors {
manifest_url := mirror + 'manifest.txt' manifest_url := mirror + 'manifest.txt'
resp := http.get(manifest_url) or { continue } resp := http.get(manifest_url) or { continue }
@ -124,7 +161,7 @@ fn update_function() {
} }
if success { 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 { } else {
println('error: could not update from any mirrors') println('error: could not update from any mirrors')
} }
@ -133,8 +170,9 @@ fn update_function() {
fn upgrade_function(name string) { fn upgrade_function(name string) {
mut remote_hash := '' mut remote_hash := ''
mut success := false mut success := false
active_mirrors := get_active_mirrors()
for mirror in mirrors { for mirror in active_mirrors {
hash_url := mirror + name + '.hash' hash_url := mirror + name + '.hash'
resp := http.get(hash_url) or { continue } resp := http.get(hash_url) or { continue }
if resp.status_code != 200 { 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() local_hash := os.read_file(hash_path) or { '' }.trim_space()
if local_hash == remote_hash { if local_hash == remote_hash {
println('$name is latest version not upgrading') println('$name is already the latest version.')
return return
} }
} }
println('new version of $name found upgrading now') println('new version of $name found! upgrading...')
install_function(name) install_function(name)
os.mkdir_all('/var/db/bur/') or { }
os.write_file(hash_path, remote_hash) or { }
} }
fn remove_function(name string) { fn remove_function(name string) {
@ -178,7 +213,7 @@ fn remove_function(name string) {
println('HEY $name.elf was not found in /bin/!') 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) { if os.exists(hash_path) {
os.rm(hash_path) or { } os.rm(hash_path) or { }
} }