mirror of
https://github.com/roddhjav/apparmor.d.git
synced 2024-11-15 07:54:17 +01:00
458db2601a
Fix #146, #136
48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
// apparmor.d - Full set of apparmor profiles
|
|
// Copyright (C) 2023 Alexandre Pujol <alexandre@pujol.io>
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
package util
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/arduino/go-paths-helper"
|
|
)
|
|
|
|
var osReleaseFile = "/etc/os-release"
|
|
|
|
var firstPartyDists = []string{"arch", "debian", "ubuntu", "opensuse", "whonix"}
|
|
|
|
func GetSupportedDistribution() (string, error) {
|
|
dist, present := os.LookupEnv("DISTRIBUTION")
|
|
if present {
|
|
return dist, nil
|
|
}
|
|
|
|
lines, err := paths.New(osReleaseFile).ReadFileAsLines()
|
|
if err != nil {
|
|
return "", 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]
|
|
}
|
|
}
|
|
|
|
if InSlice(id, firstPartyDists) {
|
|
return id, nil
|
|
} else if InSlice(id_like, firstPartyDists) {
|
|
return id_like, nil
|
|
}
|
|
return id, fmt.Errorf("%s is not a supported distribution", id)
|
|
}
|