Mirror list setup via a list but all are deadlinks so I need to make them.,
This commit is contained in:
parent
f0634e0b8d
commit
8cc6b4d580
1 changed files with 74 additions and 38 deletions
84
bur.v
84
bur.v
|
|
@ -12,6 +12,12 @@
|
||||||
import os
|
import os
|
||||||
import net.http
|
import net.http
|
||||||
|
|
||||||
|
const mirrors = [
|
||||||
|
'https://githubone/',
|
||||||
|
//'https://bur.curds.dev/mirrors/',
|
||||||
|
//'https://os.boreddev.nl/mirrors/'
|
||||||
|
]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
args := os.args
|
args := os.args
|
||||||
|
|
||||||
|
|
@ -40,6 +46,13 @@ fn main() {
|
||||||
}
|
}
|
||||||
upgrade_function(args[2])
|
upgrade_function(args[2])
|
||||||
}
|
}
|
||||||
|
'remove' {
|
||||||
|
if args.len < 3 {
|
||||||
|
println('error: please provide a package name')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
remove_function(args[2])
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
println('commands: bur [install|update|upgrade|remove]')
|
println('commands: bur [install|update|upgrade|remove]')
|
||||||
}
|
}
|
||||||
|
|
@ -47,16 +60,20 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn install_function(name string) {
|
fn install_function(name string) {
|
||||||
url := 'needtoadd' + name + '.c'
|
mut success := false
|
||||||
|
|
||||||
|
for mirror in mirrors {
|
||||||
|
url := mirror + name + '.c'
|
||||||
|
println('trying mirror: $mirror')
|
||||||
|
|
||||||
resp := http.get(url) or {
|
resp := http.get(url) or {
|
||||||
println('error couldnt connect to server sorry!!')
|
println('mirror down skipping...')
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.status_code != 200 {
|
if resp.status_code != 200 {
|
||||||
println('error package $name not found! 404')
|
println('not found on this mirror skipping...')
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
os.write_file('/tmp/$name.c', resp.body) or {
|
os.write_file('/tmp/$name.c', resp.body) or {
|
||||||
|
|
@ -64,6 +81,15 @@ fn install_function(name string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
success = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if !success {
|
||||||
|
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'
|
||||||
|
|
@ -80,33 +106,48 @@ fn install_function(name string) {
|
||||||
|
|
||||||
fn update_function() {
|
fn update_function() {
|
||||||
println('checking mirror for upds')
|
println('checking mirror for upds')
|
||||||
|
mut success := false
|
||||||
|
|
||||||
manifest_url := 'https://inserthis/manifest.txt'
|
for mirror in mirrors {
|
||||||
resp := http.get(manifest_url) or {
|
manifest_url := mirror + 'manifest.txt'
|
||||||
println('sorry could not reach the server')
|
resp := http.get(manifest_url) or { continue }
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.status_code != 200 {
|
if resp.status_code != 200 { continue }
|
||||||
println('error failed to fetch the package list')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
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/manifest.txt', resp.body) or {
|
||||||
println('failed to save manifest :(')
|
println('failed to save manifest :(')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
success = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if success {
|
||||||
println('done! packge list refreshed run bur upgrade [name] to see if it needs a upd')
|
println('done! packge list refreshed run bur upgrade [name] to see if it needs a upd')
|
||||||
|
} else {
|
||||||
|
println('error: could not update from any mirrors')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn upgrade_function(name string) {
|
fn upgrade_function(name string) {
|
||||||
hash_url := 'https://inserthis/' + name + '.hash'
|
mut remote_hash := ''
|
||||||
resp := http.get(hash_url) or {
|
mut success := false
|
||||||
println('error: could not check remote hash')
|
|
||||||
|
for mirror in mirrors {
|
||||||
|
hash_url := mirror + name + '.hash'
|
||||||
|
resp := http.get(hash_url) or { continue }
|
||||||
|
if resp.status_code != 200 { continue }
|
||||||
|
|
||||||
|
remote_hash = resp.body.trim_space()
|
||||||
|
success = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if !success {
|
||||||
|
println('error: could not check remote hash on any mirror')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
remote_hash := resp.body.trim_space()
|
|
||||||
|
|
||||||
hash_path := '/var/db/bur/' + name + '.hash'
|
hash_path := '/var/db/bur/' + name + '.hash'
|
||||||
if os.exists(hash_path) {
|
if os.exists(hash_path) {
|
||||||
|
|
@ -126,11 +167,6 @@ fn upgrade_function(name string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_function(name string) {
|
fn remove_function(name string) {
|
||||||
if name == '' {
|
|
||||||
println('hey say a package to remove!')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
println('removing $name play the bugle ;_;')
|
println('removing $name play the bugle ;_;')
|
||||||
|
|
||||||
executable_path := '/bin/$name.elf'
|
executable_path := '/bin/$name.elf'
|
||||||
|
|
@ -142,7 +178,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 { }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue