aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/rosa/etc.go
blob: 9126bdd2c28ff90cf3a1111cdedbb974091549bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package rosa

import (
	"os"

	"hakurei.app/internal/pkg"
)

// cureEtc contains deterministic elements of /etc, made available as part of
// [Toolchain]. This silences test suites expecting certain standard files to be
// available in /etc.
type cureEtc struct{}

// Cure writes hardcoded configuration to files under etc.
func (cureEtc) Cure(t *pkg.TContext) (err error) {
	etc := t.GetWorkDir().Append("etc")
	if err = os.MkdirAll(etc.String(), 0700); err != nil {
		return
	}
	for _, f := range [][2]string{
		{"hosts", "127.0.0.1 localhost cure cure-net\n"},
		{"passwd", `root:x:0:0:System administrator:/proc/nonexistent:/bin/sh
cure:x:1023:1023:Cure:/usr/src:/bin/sh
nobody:x:65534:65534:Overflow user:/proc/nonexistent:/system/bin/false
`},
		{"group", `root:x:0:
cure:x:1023:
nobody:x:65534:
`},
	} {
		if err = os.WriteFile(
			etc.Append(f[0]).String(),
			[]byte(f[1]),
			0400,
		); err != nil {
			return
		}
	}
	return os.Chmod(etc.String(), 0500)
}

// Kind returns the hardcoded [pkg.Kind] value.
func (cureEtc) Kind() pkg.Kind { return kindEtc }

// Params is a noop.
func (cureEtc) Params(*pkg.IContext) {}

// Dependencies returns a nil slice.
func (cureEtc) Dependencies() []pkg.Artifact { return nil }

// String returns a hardcoded reporting name.
func (cureEtc) String() string { return "cure-etc" }