build: add initial build support for ubuntu 24.04

This commit is contained in:
Alexandre Pujol 2024-02-28 17:35:14 +00:00
parent 431e93c9df
commit ae9f7e7442
No known key found for this signature in database
GPG key ID: C5469996F0DF68EC
4 changed files with 106 additions and 19 deletions

View file

@ -21,7 +21,29 @@ var (
"opensuse": {"suse"},
"whonix": {},
}
)
func NewOSRelease() map[string]string {
var lines []string
var err error
for _, name := range []string{osReleaseFile, "/usr/lib/os-release"} {
path := paths.New(name)
if path.Exist() {
lines, err = path.ReadFileAsLines()
if err != nil {
panic(err)
}
break
}
}
os := map[string]string{}
for _, line := range lines {
item := strings.Split(line, "=")
if len(item) == 2 {
os[item[0]] = strings.Trim(item[1], "\"")
}
}
return os
}
func getSupportedDistribution() string {
dist, present := os.LookupEnv("DISTRIBUTION")
@ -29,25 +51,12 @@ func getSupportedDistribution() string {
return dist
}
lines, err := paths.New(osReleaseFile).ReadFileAsLines()
if err != nil {
panic(err)
}
id := ""
id_like := ""
for _, line := range lines {
item := strings.Split(line, "=")
if item[0] == "ID" {
id = strings.Split(strings.Trim(item[1], "\""), " ")[0]
} else if item[0] == "ID_LIKE" {
id_like = strings.Split(strings.Trim(item[1], "\""), " ")[0]
}
}
os := NewOSRelease()
id := os["ID"]
if id == "ubuntu" {
return id
}
id_like := os["ID_LIKE"]
for main, based := range supportedDists {
if main == id || main == id_like {
return main
@ -80,3 +89,39 @@ func copyTo(src *paths.Path, dst *paths.Path) error {
}
return nil
}
// Displace files in the package sources
func displaceFiles(files []string) error {
const ext = ".apparmor.d"
for _, name := range files {
origin := RootApparmord.Join(name)
dest := RootApparmord.Join(name + ext)
if err := origin.Rename(dest); err != nil {
return err
}
file, err := paths.New("debian/apparmor.d.displace").Append()
if err != nil {
return err
}
if _, err := file.WriteString("/etc/apparmor.d/" + name + ext + "\n"); err != nil {
return err
}
}
return nil
}
func overwriteProfile(path *paths.Path) []string {
res := []string{}
lines, err := path.ReadFileAsLines()
if err != nil {
panic(err)
}
for _, line := range lines {
if strings.HasPrefix(line, "#") || line == "" {
continue
}
res = append(res, line)
}
return res
}