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