build: new structure for internal config files.
This commit is contained in:
parent
e67a66ff94
commit
f8d970faf0
4 changed files with 350 additions and 58 deletions
|
|
@ -6,9 +6,7 @@ package prepare
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/arduino/go-paths-helper"
|
||||
"github.com/roddhjav/apparmor.d/pkg/prebuild/cfg"
|
||||
"github.com/roddhjav/apparmor.d/pkg/util"
|
||||
)
|
||||
|
|
@ -32,10 +30,10 @@ func (p Configure) Apply() ([]string, error) {
|
|||
case "arch", "opensuse":
|
||||
|
||||
case "ubuntu":
|
||||
debianOverwriteClean()
|
||||
if cfg.Overwrite {
|
||||
profiles := getOverwriteProfiles()
|
||||
debianOverwrite(profiles)
|
||||
cfg.Overwrite.AptClean()
|
||||
if cfg.Overwrite.Enabled {
|
||||
profiles := cfg.Overwrite.Get()
|
||||
cfg.Overwrite.Apt(profiles)
|
||||
} else {
|
||||
if err := util.CopyTo(cfg.DistDir.Join("ubuntu"), cfg.RootApparmord); err != nil {
|
||||
return res, err
|
||||
|
|
@ -43,7 +41,7 @@ func (p Configure) Apply() ([]string, error) {
|
|||
}
|
||||
|
||||
case "debian", "whonix":
|
||||
debianOverwriteClean()
|
||||
cfg.Overwrite.AptClean()
|
||||
|
||||
// Copy Debian specific abstractions
|
||||
if err := util.CopyTo(cfg.DistDir.Join("ubuntu"), cfg.RootApparmord); err != nil {
|
||||
|
|
@ -56,53 +54,3 @@ func (p Configure) Apply() ([]string, error) {
|
|||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// Overwrite upstream profile: rename our profile & hide upstream
|
||||
func debianOverwrite(files []string) {
|
||||
const ext = ".apparmor.d"
|
||||
file, err := paths.New("debian/apparmor.d.hide").Append()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for _, name := range files {
|
||||
origin := cfg.RootApparmord.Join(name)
|
||||
dest := cfg.RootApparmord.Join(name + ext)
|
||||
if err := origin.Rename(dest); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if _, err := file.WriteString("/etc/apparmor.d/" + name + "\n"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clean the debian/apparmor.d.hide file
|
||||
func debianOverwriteClean() {
|
||||
const debianHide = `# This file is generated by "make", all edit will be lost.
|
||||
|
||||
/etc/apparmor.d/usr.bin.firefox
|
||||
/etc/apparmor.d/usr.sbin.cups-browsed
|
||||
/etc/apparmor.d/usr.sbin.cupsd
|
||||
/etc/apparmor.d/usr.sbin.rsyslogd
|
||||
`
|
||||
path := paths.New("debian/apparmor.d.hide")
|
||||
if err := path.WriteFile([]byte(debianHide)); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Get the list of upstream profiles to overwrite from dist/overwrite
|
||||
func getOverwriteProfiles() []string {
|
||||
res := []string{}
|
||||
lines, err := cfg.DistDir.Join("overwrite").ReadFileAsLines()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for _, line := range lines {
|
||||
if strings.HasPrefix(line, "#") || line == "" {
|
||||
continue
|
||||
}
|
||||
res = append(res, line)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue