1
0

feat: download debian cache automatically

This commit is contained in:
dump_stack() 2023-05-13 11:04:35 +00:00
parent 59febd75b0
commit 1d22902eb0
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
2 changed files with 29 additions and 1 deletions

23
cache/cache.go vendored
View File

@ -10,6 +10,7 @@ import (
"net/url" "net/url"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"github.com/cavaliergopher/grab/v3" "github.com/cavaliergopher/grab/v3"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
@ -62,3 +63,25 @@ func DownloadQemuImage(path, file string) (err error) {
err = unpackTar(resp.Filename, path) err = unpackTar(resp.Filename, path)
return return
} }
func DownloadDebianCache(cachePath string) (err error) {
tmp, err := ioutil.TempDir(config.Dir("tmp"), "out-of-tree_")
if err != nil {
return
}
defer os.RemoveAll(tmp)
file := filepath.Base(cachePath)
fileurl, err := url.JoinPath(URL, file)
if err != nil {
return
}
resp, err := grab.Get(tmp, fileurl)
if err != nil {
return
}
return os.Rename(filepath.Join(tmp, resp.Filename), cachePath)
}

View File

@ -8,6 +8,7 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"code.dumpstack.io/tools/out-of-tree/cache"
"code.dumpstack.io/tools/out-of-tree/config" "code.dumpstack.io/tools/out-of-tree/config"
) )
@ -121,7 +122,6 @@ func kernelRelease(deb string) (r Release, err error) {
} }
var ( var (
CacheURL string
CachePath string CachePath string
RefetchDays int = 7 RefetchDays int = 7
) )
@ -130,6 +130,11 @@ func MatchImagePkg(km config.KernelMask) (pkgs []string, err error) {
if CachePath == "" { if CachePath == "" {
CachePath = config.File("debian.cache") CachePath = config.File("debian.cache")
log.Debug().Msgf("Use default kernels cache path: %s", CachePath) log.Debug().Msgf("Use default kernels cache path: %s", CachePath)
err = cache.DownloadDebianCache(CachePath)
if err != nil {
log.Debug().Msg("No remote cache, will take some time")
}
} else { } else {
log.Debug().Msgf("Debian kernels cache path: %s", CachePath) log.Debug().Msgf("Debian kernels cache path: %s", CachePath)
} }