package rosa

import (
	"strings"

	"hakurei.app/internal/pkg"
)

func (t Toolchain) newUtilLinux() (pkg.Artifact, string) {
	const (
		version  = "2.42"
		checksum = "Uy8Nxg9DsW5YwDoeaZeZTyQJ2YmnaaL_fSsQXsLUiFFUd7wnZeD_3SEaVO7ClJlk"
	)
	return t.NewPackage("util-linux", version, newTar(
		"https://www.kernel.org/pub/linux/utils/util-linux/"+
			"v"+strings.Join(strings.SplitN(version, ".", 3)[:2], ".")+
			"/util-linux-"+version+".tar.gz",
		checksum,
		pkg.TarGzip,
	), &PackageAttr{
		ScriptEarly: `
ln -s ../system/bin/bash /bin/
`,
	}, &MakeHelper{
		Configure: []KV{
			{"disable-use-tty-group"},
			{"disable-makeinstall-setuid"},
			{"disable-makeinstall-chown"},
			{"enable-fs-paths-default", "" +
				"/system/sbin:" +
				"/system/sbin/fs.d:" +
				"/system/sbin/fs"},

			{"disable-su"},
			{"disable-liblastlog2"},
			{"disable-pam-lastlog2"},
		},

		// check script claims:
		// For development purpose only.
		// Don't execute on production system!
		SkipCheck: true,
	},
		Bash,

		KernelHeaders,
	), version
}
func init() {
	artifactsM[UtilLinux] = Metadata{
		f: Toolchain.newUtilLinux,

		Name:        "util-linux",
		Description: "a random collection of Linux utilities",
		Website:     "https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git",

		ID: 8179,

		// release candidates confuse Anitya
		latest: (*Versions).getStable,
	}
}
