2023-05-18 09:49:48 +00:00
|
|
|
package ubuntu
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-05-18 11:28:06 +00:00
|
|
|
"strings"
|
|
|
|
"time"
|
2023-05-18 09:49:48 +00:00
|
|
|
|
|
|
|
"code.dumpstack.io/tools/out-of-tree/config"
|
2023-05-18 11:28:06 +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-18 09:49:48 +00:00
|
|
|
)
|
|
|
|
|
2023-05-18 21:37:07 +00:00
|
|
|
func init() {
|
|
|
|
releases := []string{
|
|
|
|
"12.04",
|
|
|
|
"14.04",
|
|
|
|
"16.04",
|
|
|
|
"18.04",
|
|
|
|
"20.04",
|
|
|
|
"22.04",
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, release := range releases {
|
|
|
|
container := "out_of_tree_ubuntu_" + release
|
|
|
|
container = strings.Replace(container, ".", "__", -1)
|
|
|
|
|
|
|
|
distro.Register(Ubuntu{
|
|
|
|
release: release,
|
|
|
|
container: container,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type Ubuntu struct {
|
|
|
|
release string
|
|
|
|
container string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u Ubuntu) ID() distro.ID {
|
|
|
|
return distro.Ubuntu
|
|
|
|
}
|
|
|
|
|
2023-05-18 22:02:41 +00:00
|
|
|
func (u Ubuntu) Release() string {
|
|
|
|
return u.release
|
|
|
|
}
|
|
|
|
|
2023-05-18 21:37:07 +00:00
|
|
|
func (u Ubuntu) Equal(d distro.Distro) bool {
|
|
|
|
return u.release == d.Release && distro.Ubuntu == d.ID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u Ubuntu) Packages() (pkgs []string, err error) {
|
|
|
|
c, err := container.New(u.container, time.Hour)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := "apt-cache search " +
|
|
|
|
"--names-only '^linux-image-[0-9\\.\\-]*-generic' " +
|
|
|
|
"| awk '{ print $1 }'"
|
|
|
|
|
|
|
|
output, err := c.Run(config.Dir("tmp"), cmd)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, pkg := range strings.Fields(output) {
|
|
|
|
pkgs = append(pkgs, pkg)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-18 18:27:51 +00:00
|
|
|
func Envs(km config.Target) (envs []string) {
|
2023-05-18 09:49:48 +00:00
|
|
|
envs = append(envs, "DEBIAN_FRONTEND=noninteractive")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-18 18:27:51 +00:00
|
|
|
func Runs(km config.Target) (commands []string) {
|
2023-05-18 09:49:48 +00:00
|
|
|
cmdf := func(f string, s ...interface{}) {
|
|
|
|
commands = append(commands, fmt.Sprintf(f, s...))
|
|
|
|
}
|
|
|
|
|
2023-05-18 16:07:24 +00:00
|
|
|
if km.Distro.Release < "14.04" {
|
2023-05-18 09:49:48 +00:00
|
|
|
cmdf("sed -i 's/archive.ubuntu.com/old-releases.ubuntu.com/' " +
|
|
|
|
"/etc/apt/sources.list")
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdf("apt-get update")
|
|
|
|
cmdf("apt-get install -y build-essential libelf-dev")
|
|
|
|
cmdf("apt-get install -y wget git")
|
|
|
|
|
2023-05-18 16:07:24 +00:00
|
|
|
if km.Distro.Release < "14.04" {
|
2023-05-18 09:49:48 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdf("apt-get install -y libseccomp-dev")
|
|
|
|
|
|
|
|
// Install and remove a single kernel and headers.
|
|
|
|
// This ensures that all dependencies are cached.
|
|
|
|
|
2023-05-18 10:50:24 +00:00
|
|
|
cmd := "export HEADERS=$(apt-cache search " +
|
2023-05-18 09:49:48 +00:00
|
|
|
"--names-only '^linux-headers-[0-9\\.\\-]*-generic' " +
|
2023-05-18 10:50:24 +00:00
|
|
|
"| awk '{ print $1 }' | head -n 1)"
|
2023-05-18 09:49:48 +00:00
|
|
|
|
2023-05-18 10:50:24 +00:00
|
|
|
cmd += " KERNEL=$(echo $HEADERS | sed 's/headers/image/')"
|
|
|
|
cmd += " MODULES=$(echo $HEADERS | sed 's/headers/modules/')"
|
2023-05-18 09:49:48 +00:00
|
|
|
|
2023-05-18 10:50:24 +00:00
|
|
|
cmd += " && apt-get install -y $HEADERS $KERNEL $MODULES"
|
|
|
|
cmd += " && apt-get remove -y $HEADERS $KERNEL $MODULES"
|
|
|
|
|
|
|
|
cmdf(cmd)
|
2023-05-18 09:49:48 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
2023-05-18 11:28:06 +00:00
|
|
|
|
2023-05-18 18:27:51 +00:00
|
|
|
func Install(km config.Target, pkgname string, headers bool) (commands []string, err error) {
|
2023-05-18 11:46:12 +00:00
|
|
|
|
|
|
|
var headerspkg string
|
|
|
|
if headers {
|
|
|
|
headerspkg = strings.Replace(pkgname, "image", "headers", -1)
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdf := func(f string, s ...interface{}) {
|
|
|
|
commands = append(commands, fmt.Sprintf(f, s...))
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdf("apt-get install -y %s %s", pkgname, headerspkg)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-18 18:27:51 +00:00
|
|
|
func Cleanup(km config.Target, pkgname string) {
|
2023-05-18 11:46:12 +00:00
|
|
|
return
|
|
|
|
}
|