From 79b61b87e1fba6553f6dec7e5b7924627bcff006 Mon Sep 17 00:00:00 2001 From: chersbobers Date: Wed, 13 May 2026 16:54:27 +1200 Subject: [PATCH] Moved to my personal forgejo. --- bur.v | 63 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/bur.v b/bur.v index 777d490..b59a03b 100644 --- a/bur.v +++ b/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 { } }