2023-06-15 15:24:29 +00:00
|
|
|
package opensuse
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2023-06-17 08:46:07 +00:00
|
|
|
"code.dumpstack.io/tools/out-of-tree/cache"
|
2023-06-15 15:24:29 +00:00
|
|
|
"code.dumpstack.io/tools/out-of-tree/container"
|
|
|
|
"code.dumpstack.io/tools/out-of-tree/distro"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
releases := []string{
|
2023-06-17 12:48:14 +00:00
|
|
|
"12.1", "12.2", "12.3",
|
2023-06-17 08:46:07 +00:00
|
|
|
"13.1", "13.2",
|
2023-06-15 15:24:29 +00:00
|
|
|
"42.1", "42.2", "42.3",
|
|
|
|
"15.0", "15.1", "15.2", "15.3", "15.4", "15.5",
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, release := range releases {
|
|
|
|
distro.Register(OpenSUSE{release: release})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type OpenSUSE struct {
|
|
|
|
release string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suse OpenSUSE) Equal(d distro.Distro) bool {
|
|
|
|
return suse.release == d.Release && distro.OpenSUSE == d.ID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suse OpenSUSE) Distro() distro.Distro {
|
|
|
|
return distro.Distro{ID: distro.OpenSUSE, Release: suse.release}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suse OpenSUSE) Packages() (pkgs []string, err error) {
|
|
|
|
c, err := container.New(suse.Distro())
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var name string
|
2023-06-17 12:48:14 +00:00
|
|
|
if strings.HasPrefix(suse.release, "12") {
|
2023-06-18 12:58:40 +00:00
|
|
|
var cnt string
|
|
|
|
switch suse.release {
|
|
|
|
case "12.1", "12.2":
|
|
|
|
name = "opensuse:12.1"
|
|
|
|
cnt = "openSUSE-12.1"
|
|
|
|
case "12.3":
|
|
|
|
name = "opensuse:12.3"
|
|
|
|
cnt = "openSUSE-12.3"
|
|
|
|
}
|
|
|
|
|
|
|
|
cnturl := cache.ContainerURL(cnt)
|
2024-02-21 18:55:48 +00:00
|
|
|
err = container.Import(cnturl, name)
|
2023-06-17 12:48:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2024-10-17 12:28:53 +00:00
|
|
|
c.LocalBase = true
|
|
|
|
|
2023-06-17 12:48:14 +00:00
|
|
|
} else if strings.HasPrefix(suse.release, "13") {
|
2023-06-17 08:46:07 +00:00
|
|
|
name = "opensuse:13"
|
|
|
|
cnturl := cache.ContainerURL("openSUSE-13.2")
|
2024-02-21 18:55:48 +00:00
|
|
|
err = container.Import(cnturl, name)
|
2023-06-17 08:46:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2024-10-17 12:28:53 +00:00
|
|
|
c.LocalBase = true
|
|
|
|
|
2023-06-17 08:46:07 +00:00
|
|
|
} else if strings.HasPrefix(suse.release, "42") {
|
2023-06-15 15:24:29 +00:00
|
|
|
name = "opensuse/leap:42"
|
|
|
|
} else if strings.HasPrefix(suse.release, "15") {
|
|
|
|
name = "opensuse/leap:" + suse.release
|
|
|
|
}
|
|
|
|
|
2024-06-06 12:59:04 +00:00
|
|
|
err = c.Build(name, suse.envs(), suse.runs())
|
|
|
|
if err != nil {
|
|
|
|
return
|
2023-06-15 15:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd := "zypper search -s --match-exact kernel-default | grep x86_64 " +
|
|
|
|
"| cut -d '|' -f 4 | sed 's/ //g'"
|
|
|
|
|
|
|
|
output, err := c.Run("", []string{cmd})
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-12-02 17:18:07 +00:00
|
|
|
// TODO Find a way for non-interactive installation of
|
|
|
|
// retracted kernels
|
|
|
|
retracted := []string{
|
|
|
|
"5.14.21-150400.24.49.3",
|
|
|
|
"5.14.21-150400.24.84.1",
|
|
|
|
"5.14.21-150500.55.22.1",
|
|
|
|
"5.3.18-150300.59.81.1",
|
|
|
|
"5.3.18-59.30.1",
|
|
|
|
"5.3.18-lp152.98.1",
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, k := range strings.Fields(output) {
|
|
|
|
skip := false
|
|
|
|
for _, rk := range retracted {
|
|
|
|
if rk == k {
|
|
|
|
skip = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if skip {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
pkgs = append(pkgs, k)
|
|
|
|
}
|
|
|
|
|
2023-06-15 15:24:29 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suse OpenSUSE) Kernels() (kernels []distro.KernelInfo, err error) {
|
|
|
|
c, err := container.New(suse.Distro())
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-06-20 16:01:38 +00:00
|
|
|
kernels, err = c.Kernels()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range kernels {
|
|
|
|
kernels[i].KernelRelease = strings.Replace(
|
|
|
|
kernels[i].KernelRelease, "-default", "", -1)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
2023-06-15 15:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suse OpenSUSE) envs() (envs []string) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suse OpenSUSE) runs() (commands []string) {
|
|
|
|
cmdf := func(f string, s ...interface{}) {
|
|
|
|
commands = append(commands, fmt.Sprintf(f, s...))
|
|
|
|
}
|
|
|
|
|
|
|
|
main := "http://download.opensuse.org/"
|
|
|
|
discontinued := "http://ftp.gwdg.de/pub/opensuse/discontinued/"
|
|
|
|
|
|
|
|
var repourls []string
|
|
|
|
|
2023-06-17 12:48:14 +00:00
|
|
|
if strings.HasPrefix(suse.release, "12") ||
|
|
|
|
strings.HasPrefix(suse.release, "13") {
|
|
|
|
|
2023-06-17 08:46:07 +00:00
|
|
|
dist := discontinued + "distribution/%s/repo/oss/"
|
|
|
|
update := discontinued + "update/%s/"
|
|
|
|
repourls = append(repourls,
|
|
|
|
fmt.Sprintf(dist, suse.release),
|
|
|
|
fmt.Sprintf(update, suse.release),
|
|
|
|
)
|
|
|
|
} else if strings.HasPrefix(suse.release, "42") {
|
2023-06-15 15:24:29 +00:00
|
|
|
dist := discontinued + "distribution/leap/%s/repo/oss/suse/"
|
|
|
|
update := discontinued + "update/leap/%s/oss/"
|
|
|
|
repourls = append(repourls,
|
|
|
|
fmt.Sprintf(dist, suse.release),
|
|
|
|
fmt.Sprintf(update, suse.release),
|
|
|
|
)
|
|
|
|
} else if strings.HasPrefix(suse.release, "15") {
|
|
|
|
dist := main + "distribution/leap/%s/repo/oss/"
|
|
|
|
update := main + "update/leap/%s/oss/"
|
|
|
|
repourls = append(repourls,
|
|
|
|
fmt.Sprintf(dist, suse.release),
|
|
|
|
fmt.Sprintf(update, suse.release),
|
|
|
|
)
|
|
|
|
|
|
|
|
switch suse.release {
|
|
|
|
case "15.3", "15.4", "15.5":
|
|
|
|
sle := main + "update/leap/%s/sle/"
|
|
|
|
repourls = append(repourls,
|
|
|
|
fmt.Sprintf(sle, suse.release),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdf("rm /etc/zypp/repos.d/*")
|
|
|
|
|
2023-06-18 11:40:59 +00:00
|
|
|
switch suse.release {
|
|
|
|
case "12.1", "12.2":
|
|
|
|
repourl := discontinued + "distribution/12.3/repo/oss/"
|
|
|
|
cmdf(`echo -e `+
|
|
|
|
`"[dracut]\n`+
|
|
|
|
`name=dracut\n`+
|
|
|
|
`enabled=1\n`+
|
|
|
|
`autorefresh=0\n`+
|
|
|
|
`gpgcheck=0\n`+
|
|
|
|
// higher number is lower priority
|
|
|
|
// default is 99
|
|
|
|
`priority=100\n`+
|
|
|
|
`baseurl=%s" > /etc/zypp/repos.d/dracut.repo`,
|
|
|
|
repourl,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-06-15 15:24:29 +00:00
|
|
|
for i, repourl := range repourls {
|
|
|
|
cmdf(`echo -e `+
|
|
|
|
`"[%d]\n`+
|
|
|
|
`name=%d\n`+
|
|
|
|
`enabled=1\n`+
|
|
|
|
`autorefresh=0\n`+
|
|
|
|
`gpgcheck=0\n`+
|
|
|
|
`baseurl=%s" > /etc/zypp/repos.d/%d.repo`,
|
|
|
|
i, i, repourl, i,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdf("zypper -n refresh")
|
|
|
|
|
2023-06-17 12:48:14 +00:00
|
|
|
params := "--no-recommends --force-resolution"
|
|
|
|
if !strings.HasPrefix(suse.release, "12") {
|
|
|
|
params += " --replacefiles"
|
|
|
|
}
|
2023-06-17 08:46:07 +00:00
|
|
|
|
|
|
|
cmdf("zypper -n update %s", params)
|
|
|
|
|
2023-06-15 15:24:29 +00:00
|
|
|
cmdf("zypper --no-refresh -n install %s -t pattern devel_kernel", params)
|
|
|
|
|
|
|
|
// Cache dependencies
|
|
|
|
cmdf("zypper -n install %s kernel-default kernel-default-devel "+
|
|
|
|
"&& zypper -n remove -U kernel-default kernel-default-devel",
|
|
|
|
params)
|
|
|
|
|
2023-06-18 11:40:59 +00:00
|
|
|
switch suse.release {
|
|
|
|
case "12.1", "12.2":
|
|
|
|
cmdf("zypper -n install %s -r dracut dracut", params)
|
2023-06-18 12:02:32 +00:00
|
|
|
cmdf("rm /etc/zypp/repos.d/dracut.repo")
|
2023-06-18 12:19:36 +00:00
|
|
|
case "12.3":
|
|
|
|
cmdf("zypper -n install %s dracut", params)
|
2023-06-18 11:40:59 +00:00
|
|
|
}
|
|
|
|
|
2023-06-17 12:48:14 +00:00
|
|
|
if !strings.HasPrefix(suse.release, "12") {
|
|
|
|
cmdf("zypper --no-refresh -n install %s kmod which", params)
|
|
|
|
}
|
2023-06-17 08:46:07 +00:00
|
|
|
|
|
|
|
if strings.HasPrefix(suse.release, "13") {
|
|
|
|
cmdf("zypper --no-refresh -n install %s kernel-firmware", params)
|
|
|
|
}
|
2023-06-18 12:25:37 +00:00
|
|
|
|
|
|
|
cmdf("rm -rf /boot/*")
|
|
|
|
cmdf("rm -rf /lib/modules/*")
|
2023-06-15 15:24:29 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suse OpenSUSE) Install(version string, headers bool) (err error) {
|
|
|
|
var commands []string
|
|
|
|
cmdf := func(f string, s ...interface{}) {
|
|
|
|
commands = append(commands, fmt.Sprintf(f, s...))
|
|
|
|
}
|
|
|
|
|
2023-06-17 13:36:00 +00:00
|
|
|
installcmd := "zypper --no-refresh -n install "
|
|
|
|
if !strings.HasPrefix(suse.release, "12") {
|
|
|
|
installcmd += " --replacefiles"
|
|
|
|
}
|
|
|
|
installcmd += " --no-recommends --force-resolution --capability"
|
2023-06-15 15:24:29 +00:00
|
|
|
cmdf("%s kernel-default=%s", installcmd, version)
|
|
|
|
if headers {
|
|
|
|
cmdf("%s kernel-default-devel=%s", installcmd, version)
|
|
|
|
}
|
|
|
|
|
2023-06-20 06:34:11 +00:00
|
|
|
cmdf("mkdir /usr/lib/dracut/modules.d/42workaround")
|
|
|
|
wsetuppath := "/usr/lib/dracut/modules.d/42workaround/module-setup.sh"
|
|
|
|
|
|
|
|
cmdf("echo 'check() { return 0; }' >> %s", wsetuppath)
|
|
|
|
cmdf("echo 'depends() { return 0; }' >> %s", wsetuppath)
|
|
|
|
cmdf(`echo 'install() { `+
|
|
|
|
`inst_hook pre-mount 91 "$moddir/workaround.sh"; `+
|
|
|
|
`}' >> %s`, wsetuppath)
|
|
|
|
cmdf("echo 'installkernel() { "+
|
|
|
|
"instmods af_packet e1000; "+
|
|
|
|
"}' >> %s", wsetuppath)
|
|
|
|
|
|
|
|
wpath := "/usr/lib/dracut/modules.d/42workaround/workaround.sh"
|
|
|
|
|
|
|
|
cmdf("echo '#!/bin/sh' >> %s", wpath)
|
|
|
|
cmdf("echo 'modprobe af_packet' >> %s", wpath)
|
|
|
|
cmdf("echo 'modprobe e1000' >> %s", wpath)
|
2023-06-17 14:44:51 +00:00
|
|
|
|
2023-06-20 11:30:09 +00:00
|
|
|
modules := "ata_piix e1000 rfkill af_packet"
|
|
|
|
if suse.release != "15.2" {
|
|
|
|
modules += " libata ext4 sd_mod"
|
|
|
|
}
|
2023-06-17 14:44:51 +00:00
|
|
|
|
2023-06-19 22:34:08 +00:00
|
|
|
format := "dracut "
|
2023-06-20 06:34:11 +00:00
|
|
|
format += "-a workaround "
|
|
|
|
|
2023-06-18 11:40:59 +00:00
|
|
|
if strings.HasPrefix(suse.release, "12") {
|
2023-06-19 22:34:08 +00:00
|
|
|
format += "--no-hostonly --add-drivers '%s' "
|
2023-06-17 14:44:51 +00:00
|
|
|
} else {
|
2023-06-18 11:40:59 +00:00
|
|
|
format += "--force-drivers '%s' "
|
2023-06-17 14:44:51 +00:00
|
|
|
}
|
2023-06-18 11:40:59 +00:00
|
|
|
format += "-f /boot/initrd-$(ls /lib/modules) $(ls /lib/modules)"
|
|
|
|
|
|
|
|
cmdf(format, modules)
|
2023-06-15 15:24:29 +00:00
|
|
|
|
|
|
|
cmdf("cp -r /boot /target/")
|
|
|
|
cmdf("cp -r /lib/modules /target/lib/")
|
|
|
|
cmdf("cp -r /usr/src /target/usr/")
|
|
|
|
|
|
|
|
c, err := container.New(suse.Distro())
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range c.Volumes {
|
|
|
|
c.Volumes[i].Dest = "/target" + c.Volumes[i].Dest
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = c.Run("", commands)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suse OpenSUSE) RootFS() string {
|
|
|
|
return fmt.Sprintf("out_of_tree_opensuse_%s.img",
|
|
|
|
strings.Split(suse.release, ".")[0])
|
|
|
|
}
|