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
112
bur.v
112
bur.v
|
|
@ -12,6 +12,12 @@
|
|||
import os
|
||||
import net.http
|
||||
|
||||
const mirrors = [
|
||||
'https://githubone/',
|
||||
//'https://bur.curds.dev/mirrors/',
|
||||
//'https://os.boreddev.nl/mirrors/'
|
||||
]
|
||||
|
||||
fn main() {
|
||||
args := os.args
|
||||
|
||||
|
|
@ -40,6 +46,13 @@ fn main() {
|
|||
}
|
||||
upgrade_function(args[2])
|
||||
}
|
||||
'remove' {
|
||||
if args.len < 3 {
|
||||
println('error: please provide a package name')
|
||||
return
|
||||
}
|
||||
remove_function(args[2])
|
||||
}
|
||||
else {
|
||||
println('commands: bur [install|update|upgrade|remove]')
|
||||
}
|
||||
|
|
@ -47,20 +60,33 @@ fn main() {
|
|||
}
|
||||
|
||||
fn install_function(name string) {
|
||||
url := 'needtoadd' + name + '.c'
|
||||
mut success := false
|
||||
|
||||
resp := http.get(url) or {
|
||||
println('error couldnt connect to server sorry!!')
|
||||
return
|
||||
for mirror in mirrors {
|
||||
url := mirror + name + '.c'
|
||||
println('trying mirror: $mirror')
|
||||
|
||||
resp := http.get(url) or {
|
||||
println('mirror down skipping...')
|
||||
continue
|
||||
}
|
||||
|
||||
if resp.status_code != 200 {
|
||||
println('not found on this mirror skipping...')
|
||||
continue
|
||||
}
|
||||
|
||||
os.write_file('/tmp/$name.c', resp.body) or {
|
||||
println('error failed writing to tmp ')
|
||||
return
|
||||
}
|
||||
|
||||
success = true
|
||||
break
|
||||
}
|
||||
|
||||
if resp.status_code != 200 {
|
||||
println('error package $name not found! 404')
|
||||
return
|
||||
}
|
||||
|
||||
os.write_file('/tmp/$name.c', resp.body) or {
|
||||
println('error failed writing to tmp ')
|
||||
if !success {
|
||||
println('error: $name not found on any mirrors!')
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -80,33 +106,48 @@ fn install_function(name string) {
|
|||
|
||||
fn update_function() {
|
||||
println('checking mirror for upds')
|
||||
mut success := false
|
||||
|
||||
manifest_url := 'https://inserthis/manifest.txt'
|
||||
resp := http.get(manifest_url) or {
|
||||
println('sorry could not reach the server')
|
||||
return
|
||||
}
|
||||
|
||||
if resp.status_code != 200 {
|
||||
println('error failed to fetch the package list')
|
||||
return
|
||||
for mirror in mirrors {
|
||||
manifest_url := mirror + 'manifest.txt'
|
||||
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 :(')
|
||||
return
|
||||
}
|
||||
success = true
|
||||
break
|
||||
}
|
||||
|
||||
os.mkdir_all('/var/db/bur/') or { }
|
||||
os.write_file('/var/db/bur/manifest.txt', resp.body) or {
|
||||
println('failed to save manifest :(')
|
||||
return
|
||||
if success {
|
||||
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')
|
||||
}
|
||||
println('done! packge list refreshed run bur upgrade [name] to see if it needs a upd')
|
||||
}
|
||||
|
||||
fn upgrade_function(name string) {
|
||||
hash_url := 'https://inserthis/' + name + '.hash'
|
||||
resp := http.get(hash_url) or {
|
||||
println('error: could not check remote hash')
|
||||
return
|
||||
mut remote_hash := ''
|
||||
mut success := false
|
||||
|
||||
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
|
||||
}
|
||||
remote_hash := resp.body.trim_space()
|
||||
|
||||
hash_path := '/var/db/bur/' + name + '.hash'
|
||||
if os.exists(hash_path) {
|
||||
|
|
@ -126,14 +167,9 @@ fn upgrade_function(name string) {
|
|||
}
|
||||
|
||||
fn remove_function(name string) {
|
||||
if name == '' {
|
||||
println('hey say a package to remove!')
|
||||
return
|
||||
}
|
||||
|
||||
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')
|
||||
|
|
@ -142,7 +178,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 { }
|
||||
}
|
||||
|
|
@ -150,4 +186,4 @@ fn remove_function(name string) {
|
|||
println('rip $name it has been removed')
|
||||
}
|
||||
|
||||
//yello this is the bottom of the file
|
||||
// yello this is the bottom of the file
|
||||
Loading…
Reference in a new issue