Update for pr

This commit is contained in:
chersbobers 2026-05-13 18:00:39 +12:00
parent 79b61b87e1
commit 25980ce565
2 changed files with 41 additions and 32 deletions

3
.gitignore vendored
View file

@ -1 +1,2 @@
*.exe
*.exe
bur.c

70
bur.v
View file

@ -12,10 +12,17 @@
import os
import net.http
struct PackageInfo {
name string
version string
}
struct Manifest {
packages []PackageInfo
}
const default_mirrors = [
'https://githubone/',
'https://bur.curds.dev/mirrors/',
'https://os.boreddev.nl/mirrors/'
'https://git.curds.dev/chersbobers/bur-packages/raw/branch/main/'
]
fn main() {
@ -33,6 +40,7 @@ fn main() {
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 {
@ -89,25 +97,27 @@ fn install_function(name string) {
active_mirrors := get_active_mirrors()
for mirror in active_mirrors {
url := mirror + name + '.c'
println('trying mirror: $mirror')
url := mirror + name + '/' + name + '.c'
println('trying mirror: ' + mirror)
resp := http.get(url) or {
println('mirror down skipping...')
println('mirror down skipping')
continue
}
if resp.status_code != 200 {
println('not found on this mirror skipping...')
println('not found on this mirror skipping')
continue
}
os.write_file('/tmp/$name.c', resp.body) or {
println('error failed writing to tmp ')
// Using concatenation to be safe for file paths
tmp_path := '/tmp/' + name + '.c'
os.write_file(tmp_path, resp.body) or {
println('error failed writing to tmp')
return
}
hash_resp := http.get(mirror + name + '.hash') or { continue }
hash_resp := http.get(mirror + name + '/' + name + '.hash') or { continue }
if hash_resp.status_code == 200 {
current_hash = hash_resp.body.trim_space()
}
@ -117,25 +127,25 @@ fn install_function(name string) {
}
if !success {
println('error: $name not found on any mirrors!')
println('error: ' + name + ' not found on any mirrors!')
return
}
println('boringly compiling $name')
println('boringly compiling ' + name)
compile_cmd := 'tcc /tmp/$name.c -o /bin/$name.elf'
compile_cmd := 'tcc /tmp/' + name + '.c -o /bin/' + name + '.elf'
res := os.execute(compile_cmd)
if res.exit_code == 0 {
println('boringly compiled $name.elf run $name in your terminal to run')
os.rm('/tmp/$name.c') or { }
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 { }
os.write_file('/var/db/bur/' + name + '.hash', current_hash) or { }
}
} else {
println('oh crud $name failed to compile!')
println('oh crud ' + name + ' failed to compile!')
println(res.output)
}
}
@ -146,14 +156,14 @@ fn update_function() {
active_mirrors := get_active_mirrors()
for mirror in active_mirrors {
manifest_url := mirror + 'manifest.txt'
manifest_url := mirror + 'packages.json'
resp := http.get(manifest_url) or { continue }
if resp.status_code != 200 { continue }
os.mkdir_all('/var/db/bur/') or { }
os.write_file('/var/db/bur/manifest.txt', resp.body) or {
println('failed to save manifest :(')
os.write_file('/var/db/bur/packages.json', resp.body) or {
println('failed to save packages to the json :(')
return
}
success = true
@ -173,7 +183,7 @@ fn upgrade_function(name string) {
active_mirrors := get_active_mirrors()
for mirror in active_mirrors {
hash_url := mirror + name + '.hash'
hash_url := mirror + name + '/' + name + '.hash'
resp := http.get(hash_url) or { continue }
if resp.status_code != 200 { continue }
@ -192,33 +202,31 @@ fn upgrade_function(name string) {
local_hash := os.read_file(hash_path) or { '' }.trim_space()
if local_hash == remote_hash {
println('$name is already the latest version.')
println(name + ' is already the latest version.')
return
}
}
println('new version of $name found! upgrading...')
println('new version of ' + name + ' found! upgrading...')
install_function(name)
}
fn remove_function(name string) {
println('removing $name play the bugle ;_;')
println('removing ' + name + ' play the bugle ;_;')
executable_path := '/bin/$name.elf'
executable_path := '/bin/' + name + '.elf'
if os.exists(executable_path) {
os.rm(executable_path) or {
println('oh crud could not remove the binary')
}
} else {
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) {
os.rm(hash_path) or { }
}
println('rip $name it has been removed')
}
// yello this is the bottom of the file
println('rip ' + name + ' it has been removed')
}