1
0
Fork 0

feat: check for mirrored packages

master
dump_stack() 2023-05-15 13:07:56 +00:00
parent e1ac75d0fa
commit d118ab03c3
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
2 changed files with 35 additions and 0 deletions

26
cache/cache.go vendored
View File

@ -6,6 +6,7 @@ package cache
import (
"fmt"
"net/http"
"net/url"
"os"
"os/exec"
@ -14,6 +15,7 @@ import (
"github.com/cavaliergopher/grab/v3"
"github.com/rs/zerolog/log"
"code.dumpstack.io/tools/out-of-tree/config"
"code.dumpstack.io/tools/out-of-tree/fs"
)
@ -88,3 +90,27 @@ func DownloadDebianCache(cachePath string) (err error) {
return os.Rename(resp.Filename, cachePath)
}
func PackageURL(dt config.DistroType, orig string) (found bool, fileurl string) {
if dt != config.Debian {
return
}
filename := filepath.Base(orig)
fileurl, err := url.JoinPath(URL, "packages/debian", filename)
if err != nil {
return
}
resp, err := http.Head(fileurl)
if err != nil {
return
}
if resp.StatusCode != http.StatusOK {
return
}
found = true
return
}

View File

@ -421,6 +421,15 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e
}
for _, pkg := range pkgs {
found, newurl := cache.PackageURL(
sk.DistroType,
pkg.Deb.URL,
)
if found {
log.Debug().Msgf("cached deb found %s", newurl)
pkg.Deb.URL = newurl
}
cmd += fmt.Sprintf(" && wget --no-check-certificate %s",
strings.Replace(pkg.Deb.URL, "https", "http", -1))
}