2023-05-11 22:17:46 +00:00
|
|
|
package debian
|
|
|
|
|
2023-05-12 17:26:53 +00:00
|
|
|
import (
|
2023-05-13 19:51:57 +00:00
|
|
|
"fmt"
|
2023-05-14 21:04:22 +00:00
|
|
|
"os"
|
2023-05-14 22:00:29 +00:00
|
|
|
"path"
|
2023-05-14 21:04:22 +00:00
|
|
|
"path/filepath"
|
2023-05-12 17:26:53 +00:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
|
2023-05-16 09:24:34 +00:00
|
|
|
"code.dumpstack.io/tools/out-of-tree/cache"
|
2023-05-12 17:26:53 +00:00
|
|
|
"code.dumpstack.io/tools/out-of-tree/config"
|
2023-05-14 07:19:35 +00:00
|
|
|
"code.dumpstack.io/tools/out-of-tree/container"
|
2023-05-18 21:37:07 +00:00
|
|
|
"code.dumpstack.io/tools/out-of-tree/distro"
|
2023-05-17 06:50:52 +00:00
|
|
|
"code.dumpstack.io/tools/out-of-tree/distro/debian/snapshot"
|
2023-05-14 21:04:22 +00:00
|
|
|
"code.dumpstack.io/tools/out-of-tree/fs"
|
2023-05-12 17:26:53 +00:00
|
|
|
)
|
|
|
|
|
2023-05-18 21:37:07 +00:00
|
|
|
func init() {
|
|
|
|
releases := []Release{
|
|
|
|
Wheezy,
|
|
|
|
Jessie,
|
|
|
|
Stretch,
|
|
|
|
Buster,
|
|
|
|
Bullseye,
|
2023-05-24 09:14:18 +00:00
|
|
|
Bookworm,
|
2023-05-18 21:37:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, release := range releases {
|
2023-05-23 16:54:34 +00:00
|
|
|
distro.Register(Debian{release: release})
|
2023-05-18 21:37:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type Debian struct {
|
2023-05-23 16:54:34 +00:00
|
|
|
release Release
|
2023-05-18 21:37:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d Debian) Equal(dd distro.Distro) bool {
|
|
|
|
if dd.ID != distro.Debian {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-05-18 22:26:42 +00:00
|
|
|
return ReleaseFromString(dd.Release) == d.release
|
2023-05-18 21:37:07 +00:00
|
|
|
}
|
|
|
|
|
2023-05-23 16:24:01 +00:00
|
|
|
func (d Debian) Distro() distro.Distro {
|
|
|
|
return distro.Distro{distro.Debian, d.release.String()}
|
|
|
|
}
|
|
|
|
|
2023-05-18 21:37:07 +00:00
|
|
|
func (d Debian) Packages() (packages []string, err error) {
|
2023-05-23 16:54:34 +00:00
|
|
|
c, err := container.New(d.Distro())
|
2023-05-23 13:20:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
err = c.Build(d.image(), d.envs(), d.runs())
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-18 21:37:07 +00:00
|
|
|
kernels, err := GetKernels()
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Err(err).Msg("get kernels")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, dk := range kernels {
|
2023-05-29 08:16:21 +00:00
|
|
|
if d.release != dk.Release {
|
2023-05-27 18:30:54 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2023-05-29 19:53:41 +00:00
|
|
|
version := kver(dk.Version.Package)
|
|
|
|
|
|
|
|
// filter out pre-release kernels
|
|
|
|
switch dk.Release {
|
|
|
|
case Wheezy:
|
|
|
|
if version.LessThan(kver("3.2-rc0")) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
case Jessie:
|
|
|
|
if version.LessThan(kver("3.16-rc0")) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
case Stretch:
|
|
|
|
if version.LessThan(kver("4.9-rc0")) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
case Buster:
|
|
|
|
if version.LessThan(kver("4.19-rc0")) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
case Bullseye:
|
|
|
|
if version.LessThan(kver("5.10-rc0")) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
case Bookworm:
|
|
|
|
if version.LessThan(kver("6.1-rc0")) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-23 09:22:50 +00:00
|
|
|
p := dk.Image.Deb.Name[:len(dk.Image.Deb.Name)-4] // w/o .deb
|
2023-05-18 21:37:07 +00:00
|
|
|
packages = append(packages, p)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-12 20:05:44 +00:00
|
|
|
type Release int
|
2023-05-11 22:17:46 +00:00
|
|
|
|
|
|
|
const (
|
2023-05-12 20:05:44 +00:00
|
|
|
None Release = iota
|
|
|
|
Buzz
|
|
|
|
Hamm
|
|
|
|
Woody
|
|
|
|
Etch
|
|
|
|
Lenny
|
|
|
|
Squeeze
|
|
|
|
Wheezy
|
2023-05-11 22:17:46 +00:00
|
|
|
Jessie
|
|
|
|
Stretch
|
|
|
|
Buster
|
|
|
|
Bullseye
|
|
|
|
Bookworm
|
|
|
|
)
|
|
|
|
|
2023-05-12 20:05:44 +00:00
|
|
|
var ReleaseStrings = [...]string{
|
|
|
|
"",
|
2023-05-23 17:53:58 +00:00
|
|
|
"buzz",
|
|
|
|
"hamm",
|
|
|
|
"woody",
|
|
|
|
"etch",
|
|
|
|
"lenny",
|
|
|
|
"squeeze",
|
|
|
|
"wheezy",
|
|
|
|
"jessie",
|
|
|
|
"stretch",
|
|
|
|
"buster",
|
|
|
|
"bullseye",
|
|
|
|
"bookworm",
|
2023-05-11 22:17:46 +00:00
|
|
|
}
|
|
|
|
|
2023-05-24 07:15:34 +00:00
|
|
|
func (cn Release) Name() string {
|
2023-05-12 20:05:44 +00:00
|
|
|
return ReleaseStrings[cn]
|
|
|
|
}
|
|
|
|
|
2023-05-24 07:15:34 +00:00
|
|
|
func (cn Release) String() string {
|
|
|
|
return fmt.Sprintf("%d", cn)
|
|
|
|
}
|
|
|
|
|
2023-05-18 22:26:42 +00:00
|
|
|
func ReleaseFromString(s string) (r Release) {
|
2023-05-12 20:05:44 +00:00
|
|
|
switch strings.ToLower(s) {
|
2023-05-28 11:59:44 +00:00
|
|
|
case "1", "buzz":
|
|
|
|
r = Buzz
|
|
|
|
case "2", "hamm":
|
|
|
|
r = Hamm
|
|
|
|
case "3", "woody":
|
|
|
|
r = Woody
|
|
|
|
case "4", "etch":
|
|
|
|
r = Etch
|
|
|
|
case "5", "lenny":
|
|
|
|
r = Lenny
|
|
|
|
case "6", "squeeze":
|
|
|
|
r = Squeeze
|
2023-05-12 20:05:44 +00:00
|
|
|
case "7", "wheezy":
|
|
|
|
r = Wheezy
|
|
|
|
case "8", "jessie":
|
|
|
|
r = Jessie
|
|
|
|
case "9", "stretch":
|
|
|
|
r = Stretch
|
|
|
|
case "10", "buster":
|
|
|
|
r = Buster
|
|
|
|
case "11", "bullseye":
|
|
|
|
r = Bullseye
|
2023-05-24 09:12:33 +00:00
|
|
|
case "12", "bookworm":
|
|
|
|
r = Bookworm
|
2023-05-12 20:05:44 +00:00
|
|
|
default:
|
|
|
|
r = None
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-23 13:20:48 +00:00
|
|
|
func (d Debian) envs() (envs []string) {
|
2023-05-13 19:51:57 +00:00
|
|
|
envs = append(envs, "DEBIAN_FRONTEND=noninteractive")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-23 13:20:48 +00:00
|
|
|
func (d Debian) image() (image string) {
|
2023-05-14 09:53:59 +00:00
|
|
|
image += "debian:"
|
2023-05-13 19:51:57 +00:00
|
|
|
|
2023-05-23 13:20:48 +00:00
|
|
|
switch d.release {
|
2023-05-14 09:53:59 +00:00
|
|
|
case Wheezy:
|
|
|
|
image += "wheezy-20190228"
|
|
|
|
case Jessie:
|
|
|
|
image += "jessie-20210326"
|
|
|
|
case Stretch:
|
|
|
|
image += "stretch-20220622"
|
|
|
|
default:
|
2023-05-24 07:17:05 +00:00
|
|
|
image += d.release.Name()
|
2023-05-14 09:53:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func repositories(release Release) (repos []string) {
|
2023-05-13 19:51:57 +00:00
|
|
|
var snapshot string
|
|
|
|
|
|
|
|
switch release {
|
2023-05-14 09:53:59 +00:00
|
|
|
// Latest snapshots that include release
|
2023-05-13 19:51:57 +00:00
|
|
|
case Wheezy:
|
2023-05-14 09:53:59 +00:00
|
|
|
// doesn't include snapshot repos in /etc/apt/source.list
|
|
|
|
snapshot = "20190321T212815Z"
|
2023-05-14 22:20:34 +00:00
|
|
|
case Jessie:
|
|
|
|
snapshot = "20230322T152120Z"
|
|
|
|
case Stretch:
|
|
|
|
snapshot = "20230423T032533Z"
|
2023-05-13 19:51:57 +00:00
|
|
|
default:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-14 09:53:59 +00:00
|
|
|
repo := func(archive, s string) {
|
|
|
|
format := "deb [check-valid-until=no trusted=yes] " +
|
|
|
|
"http://snapshot.debian.org/archive/%s/%s " +
|
|
|
|
"%s%s main"
|
2023-05-24 07:15:34 +00:00
|
|
|
r := fmt.Sprintf(format, archive, snapshot, release.Name(), s)
|
2023-05-14 09:53:59 +00:00
|
|
|
repos = append(repos, r)
|
|
|
|
}
|
|
|
|
|
|
|
|
repo("debian", "")
|
|
|
|
repo("debian", "-updates")
|
2023-05-24 09:32:43 +00:00
|
|
|
if release <= 7 {
|
2023-05-24 09:28:43 +00:00
|
|
|
repo("debian", "-backports")
|
|
|
|
}
|
2023-05-14 09:53:59 +00:00
|
|
|
repo("debian-security", "/updates")
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-23 13:20:48 +00:00
|
|
|
func (d Debian) runs() (commands []string) {
|
2023-05-13 19:51:57 +00:00
|
|
|
cmdf := func(f string, s ...interface{}) {
|
|
|
|
commands = append(commands, fmt.Sprintf(f, s...))
|
|
|
|
}
|
|
|
|
|
2023-05-23 13:20:48 +00:00
|
|
|
repos := repositories(d.release)
|
2023-05-13 19:51:57 +00:00
|
|
|
|
2023-05-14 09:53:59 +00:00
|
|
|
if len(repos) != 0 {
|
|
|
|
cmdf("rm /etc/apt/sources.list")
|
|
|
|
for _, repo := range repos {
|
|
|
|
cmdf("echo '%s' >> /etc/apt/sources.list", repo)
|
|
|
|
}
|
|
|
|
} else {
|
2023-05-16 19:37:57 +00:00
|
|
|
cmdf("apt-get update || sed -i " +
|
2023-05-14 21:12:24 +00:00
|
|
|
"-e '/snapshot/!d' " +
|
|
|
|
"-e 's/# deb/deb [check-valid-until=no trusted=yes]/' " +
|
|
|
|
"/etc/apt/sources.list")
|
2023-05-14 09:53:59 +00:00
|
|
|
}
|
2023-05-13 19:51:57 +00:00
|
|
|
|
2023-05-16 19:20:58 +00:00
|
|
|
cmdf("apt-get update || apt-get update || apt-get update")
|
2023-05-16 17:52:15 +00:00
|
|
|
|
2023-05-17 05:28:34 +00:00
|
|
|
pkglist := []string{
|
|
|
|
"wget", "build-essential", "libelf-dev", "git",
|
2023-05-24 09:24:41 +00:00
|
|
|
"kmod", "linux-base", "libssl-dev",
|
2023-05-26 15:44:06 +00:00
|
|
|
"firmware-linux-free",
|
2023-05-29 21:30:48 +00:00
|
|
|
"libxml2", "libglib2.0.0", "irqbalance", "libcap-ng0",
|
|
|
|
"libnuma1", "sgml-base", "shared-mime-info", "xdg-user-dirs",
|
|
|
|
"xml-core", "python3",
|
2023-05-16 09:23:44 +00:00
|
|
|
}
|
|
|
|
|
2023-05-26 12:43:44 +00:00
|
|
|
gccs := "'^(gcc-[0-9].[0-9]|gcc-[0-9]|gcc-[1-9][0-9])$'"
|
|
|
|
pkglist = append(pkglist, gccs)
|
|
|
|
|
2023-05-24 09:28:43 +00:00
|
|
|
if d.release >= 8 {
|
|
|
|
pkglist = append(pkglist, "initramfs-tools")
|
2023-05-26 12:43:44 +00:00
|
|
|
} else {
|
|
|
|
// by default Debian backports repositories have a lower
|
|
|
|
// priority than stable, so we should specify it manually
|
|
|
|
cmdf("apt-get -y install -t %s-backports "+
|
|
|
|
"initramfs-tools", d.release.Name())
|
2023-05-24 09:28:43 +00:00
|
|
|
}
|
|
|
|
|
2023-05-29 21:55:32 +00:00
|
|
|
if d.release >= 9 {
|
|
|
|
pkglist = append(pkglist, "apparmor")
|
|
|
|
}
|
|
|
|
|
2023-05-23 13:20:48 +00:00
|
|
|
if d.release < 9 {
|
2023-05-17 05:28:34 +00:00
|
|
|
pkglist = append(pkglist, "module-init-tools")
|
|
|
|
}
|
|
|
|
|
|
|
|
var packages string
|
|
|
|
for _, pkg := range pkglist {
|
|
|
|
packages += fmt.Sprintf("%s ", pkg)
|
2023-05-14 21:17:21 +00:00
|
|
|
}
|
|
|
|
|
2023-05-16 20:30:04 +00:00
|
|
|
cmdf("timeout 5m apt-get install -y %s "+
|
|
|
|
"|| timeout 10m apt-get install -y %s "+
|
2023-05-16 19:20:58 +00:00
|
|
|
"|| apt-get install -y %s", packages, packages, packages)
|
2023-05-16 17:52:15 +00:00
|
|
|
|
2023-05-29 20:13:40 +00:00
|
|
|
if d.release == Wheezy {
|
|
|
|
// We need newer libc for deb8*~bpo70+1
|
|
|
|
format := "deb [check-valid-until=no trusted=yes] " +
|
|
|
|
"http://snapshot.debian.org/archive/debian/%s " +
|
|
|
|
"jessie main"
|
|
|
|
// Keep it here not in repos to have apt-priority close
|
|
|
|
repo := fmt.Sprintf(format, "20190321T212815Z")
|
|
|
|
cmdf("echo '%s' >> /etc/apt/sources.list", repo)
|
|
|
|
cmdf("echo 'Package: *' >> /etc/apt/preferences.d/jessie")
|
|
|
|
cmdf("echo 'Pin: release a=jessie' >> /etc/apt/preferences.d/jessie")
|
|
|
|
cmdf("echo 'Pin-Priority: 10' >> /etc/apt/preferences.d/jessie")
|
|
|
|
|
|
|
|
cmdf("apt-get -y update")
|
|
|
|
|
|
|
|
// glibc guarantee backwards compatibility, so should be no problem
|
|
|
|
cmdf("apt-get -y install -t jessie libc6-dev")
|
|
|
|
}
|
|
|
|
|
2023-05-13 19:51:57 +00:00
|
|
|
cmdf("mkdir -p /lib/modules")
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
2023-05-14 07:19:35 +00:00
|
|
|
|
2023-05-23 22:00:20 +00:00
|
|
|
func (d Debian) Kernels() (kernels []distro.KernelInfo, err error) {
|
|
|
|
c, err := container.New(d.Distro())
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !c.Exist() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
cpath := config.Dir("volumes", c.Name())
|
|
|
|
rootfs := config.File("images", c.Name()+".img")
|
2023-05-14 21:04:22 +00:00
|
|
|
|
2023-05-14 22:00:29 +00:00
|
|
|
files, err := os.ReadDir(cpath)
|
2023-05-14 21:04:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, file := range files {
|
|
|
|
if !strings.Contains(file.Name(), "linux-image") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
pkgname := file.Name()
|
|
|
|
|
2023-05-14 22:00:29 +00:00
|
|
|
kpkgdir := filepath.Join(cpath, pkgname)
|
2023-05-14 21:04:22 +00:00
|
|
|
|
|
|
|
bootdir := filepath.Join(kpkgdir, "boot")
|
|
|
|
|
|
|
|
vmlinuz, err := fs.FindBySubstring(bootdir, "vmlinuz")
|
|
|
|
if err != nil {
|
|
|
|
log.Warn().Msgf("cannot find vmlinuz for %s", pkgname)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
initrd, err := fs.FindBySubstring(bootdir, "initrd")
|
|
|
|
if err != nil {
|
|
|
|
log.Warn().Msgf("cannot find initrd for %s", pkgname)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
modulesdir := filepath.Join(kpkgdir, "lib/modules")
|
|
|
|
|
|
|
|
modules, err := fs.FindBySubstring(modulesdir, "")
|
|
|
|
if err != nil {
|
|
|
|
log.Warn().Msgf("cannot find modules for %s", pkgname)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug().Msgf("%s %s %s", vmlinuz, initrd, modules)
|
|
|
|
|
2023-05-14 22:00:29 +00:00
|
|
|
release := strings.Replace(pkgname, "linux-image-", "", -1)
|
|
|
|
|
2023-05-23 21:33:50 +00:00
|
|
|
ki := distro.KernelInfo{
|
2023-05-23 22:00:20 +00:00
|
|
|
Distro: d.Distro(),
|
2023-05-14 22:00:29 +00:00
|
|
|
KernelVersion: path.Base(modules),
|
|
|
|
KernelRelease: release,
|
2023-05-23 22:00:20 +00:00
|
|
|
ContainerName: c.Name(),
|
2023-05-14 21:04:22 +00:00
|
|
|
|
|
|
|
KernelPath: vmlinuz,
|
|
|
|
InitrdPath: initrd,
|
|
|
|
ModulesPath: modules,
|
|
|
|
|
|
|
|
RootFS: rootfs,
|
2023-05-25 23:00:42 +00:00
|
|
|
|
|
|
|
Package: pkgname,
|
2023-05-14 21:04:22 +00:00
|
|
|
}
|
|
|
|
|
2023-05-31 16:15:27 +00:00
|
|
|
smapBlocklist := []string{
|
|
|
|
"3.10.5-1~bpo70+1",
|
|
|
|
"3.10.11-1~bpo70+1",
|
|
|
|
"3.9.6-1~bpo70+1",
|
|
|
|
}
|
|
|
|
for _, ver := range smapBlocklist {
|
|
|
|
if strings.Contains(release, ver) {
|
|
|
|
ki.CPU.Flags = append(ki.CPU.Flags, "smap=off")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-23 22:00:20 +00:00
|
|
|
kernels = append(kernels, ki)
|
2023-05-14 21:04:22 +00:00
|
|
|
}
|
|
|
|
|
2023-05-14 07:19:35 +00:00
|
|
|
return
|
|
|
|
}
|
2023-05-14 22:15:43 +00:00
|
|
|
|
2023-05-23 22:36:46 +00:00
|
|
|
func (d Debian) volumes(pkgname string) (volumes []container.Volume) {
|
|
|
|
c, err := container.New(d.Distro())
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
pkgdir := filepath.Join("volumes", c.Name(), pkgname)
|
2023-05-14 22:15:43 +00:00
|
|
|
|
2023-05-22 14:28:28 +00:00
|
|
|
volumes = append(volumes, container.Volume{
|
|
|
|
Src: config.Dir(pkgdir, "/lib/modules"),
|
|
|
|
Dest: "/lib/modules",
|
|
|
|
})
|
|
|
|
|
|
|
|
volumes = append(volumes, container.Volume{
|
|
|
|
Src: config.Dir(pkgdir, "/usr/src"),
|
|
|
|
Dest: "/usr/src",
|
|
|
|
})
|
|
|
|
|
|
|
|
volumes = append(volumes, container.Volume{
|
|
|
|
Src: config.Dir(pkgdir, "/boot"),
|
|
|
|
Dest: "/boot",
|
|
|
|
})
|
2023-05-14 22:15:43 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
2023-05-16 09:24:34 +00:00
|
|
|
|
2023-05-23 22:36:46 +00:00
|
|
|
func (d Debian) Install(pkgname string, headers bool) (err error) {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
d.cleanup(pkgname)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2023-05-16 09:24:34 +00:00
|
|
|
dk, err := getCachedKernel(pkgname + ".deb")
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-17 06:50:52 +00:00
|
|
|
var pkgs []snapshot.Package
|
|
|
|
if headers {
|
|
|
|
pkgs = dk.Packages()
|
|
|
|
} else {
|
|
|
|
pkgs = []snapshot.Package{dk.Image}
|
|
|
|
}
|
|
|
|
|
2023-05-26 12:43:44 +00:00
|
|
|
var commands []string
|
|
|
|
cmdf := func(f string, s ...interface{}) {
|
|
|
|
commands = append(commands, fmt.Sprintf(f, s...))
|
|
|
|
}
|
2023-05-23 22:36:46 +00:00
|
|
|
|
2023-05-17 06:50:52 +00:00
|
|
|
for _, pkg := range pkgs {
|
2023-05-16 09:24:34 +00:00
|
|
|
found, newurl := cache.PackageURL(
|
2023-05-23 22:36:46 +00:00
|
|
|
distro.Debian,
|
2023-05-16 09:24:34 +00:00
|
|
|
pkg.Deb.URL,
|
|
|
|
)
|
|
|
|
if found {
|
|
|
|
log.Debug().Msgf("cached deb found %s", newurl)
|
|
|
|
pkg.Deb.URL = newurl
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO use faketime on old releases?
|
|
|
|
pkg.Deb.URL = strings.Replace(pkg.Deb.URL, "https", "http", -1)
|
|
|
|
|
2023-05-26 12:43:44 +00:00
|
|
|
cmdf("wget --no-verbose " +
|
|
|
|
"--timeout=10 --waitretry=1 --tries=10 " +
|
|
|
|
"--no-check-certificate " + pkg.Deb.URL)
|
2023-05-16 09:24:34 +00:00
|
|
|
}
|
|
|
|
|
2023-05-26 12:43:44 +00:00
|
|
|
// prepare local repository
|
|
|
|
cmdf("mkdir debs && mv *.deb debs/")
|
|
|
|
cmdf("dpkg-scanpackages debs /dev/null | gzip > debs/Packages.gz")
|
2023-05-26 15:44:06 +00:00
|
|
|
cmdf(`echo "deb [trusted=yes] file:$(pwd) debs/" >> /etc/apt/sources.list.d/local.list`)
|
2023-05-26 12:56:18 +00:00
|
|
|
cmdf("apt-get update -o Dir::Etc::sourcelist='sources.list.d/local.list' -o Dir::Etc::sourceparts='-' -o APT::Get::List-Cleanup='0'")
|
2023-05-26 12:43:44 +00:00
|
|
|
|
2023-05-26 15:44:06 +00:00
|
|
|
// make sure apt-get will not download the repo version
|
|
|
|
cmdf("echo 'Package: *' >> /etc/apt/preferences.d/pin")
|
2023-05-26 17:32:35 +00:00
|
|
|
cmdf(`echo 'Pin: origin "*.debian.org"' >> /etc/apt/preferences.d/pin`)
|
2023-05-26 15:44:06 +00:00
|
|
|
cmdf("echo 'Pin-Priority: 100' >> /etc/apt/preferences.d/pin")
|
|
|
|
|
2023-05-26 12:43:44 +00:00
|
|
|
// cut package names and install
|
|
|
|
cmdf("ls debs | grep deb | cut -d '_' -f 1 | " +
|
|
|
|
"xargs apt-get -y --force-yes install")
|
2023-05-16 09:24:34 +00:00
|
|
|
|
2023-05-26 15:44:06 +00:00
|
|
|
// for debug
|
|
|
|
cmdf("ls debs | grep deb | cut -d '_' -f 1 | xargs apt-cache policy")
|
|
|
|
|
2023-05-23 22:36:46 +00:00
|
|
|
c, err := container.New(d.Distro())
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Volumes = d.volumes(pkgname)
|
|
|
|
for i := range c.Volumes {
|
|
|
|
c.Volumes[i].Dest = "/target" + c.Volumes[i].Dest
|
|
|
|
}
|
|
|
|
|
2023-05-26 12:43:44 +00:00
|
|
|
cmdf("cp -r /boot /target/")
|
|
|
|
cmdf("cp -r /lib/modules /target/lib/")
|
|
|
|
cmdf("cp -rL /usr/src /target/usr/")
|
2023-05-23 22:36:46 +00:00
|
|
|
|
2023-05-26 12:43:44 +00:00
|
|
|
_, err = c.Run("", commands)
|
2023-05-23 22:36:46 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-16 09:24:34 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-23 22:36:46 +00:00
|
|
|
func (d Debian) cleanup(pkgname string) {
|
|
|
|
c, err := container.New(d.Distro())
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
pkgdir := config.Dir(filepath.Join("volumes", c.Name(), pkgname))
|
2023-05-16 09:24:34 +00:00
|
|
|
|
|
|
|
log.Debug().Msgf("cleanup %s", pkgdir)
|
|
|
|
|
2023-05-23 22:36:46 +00:00
|
|
|
err = os.RemoveAll(pkgdir)
|
2023-05-16 09:24:34 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Warn().Err(err).Msg("cleanup")
|
|
|
|
}
|
|
|
|
}
|