mirror of
https://github.com/kairos-io/kairos-sdk.git
synced 2025-09-05 09:10:19 +00:00
Add init system information to state output (#56)
Signed-off-by: Itxaka <itxaka@kairos.io>
This commit is contained in:
@@ -42,6 +42,7 @@ type PartitionState struct {
|
|||||||
type Kairos struct {
|
type Kairos struct {
|
||||||
Flavor string `yaml:"flavor" json:"flavor"`
|
Flavor string `yaml:"flavor" json:"flavor"`
|
||||||
Version string `yaml:"version" json:"version"`
|
Version string `yaml:"version" json:"version"`
|
||||||
|
Init string `yaml:"init" json:"init"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Runtime struct {
|
type Runtime struct {
|
||||||
@@ -224,6 +225,7 @@ func detectKairos(r *Runtime) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
k.Version = v
|
k.Version = v
|
||||||
}
|
}
|
||||||
|
k.Init = utils.GetInit()
|
||||||
r.Kairos = *k
|
r.Kairos = *k
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -20,6 +20,12 @@ import (
|
|||||||
"github.com/qeesung/image2ascii/convert"
|
"github.com/qeesung/image2ascii/convert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
systemd = "systemd"
|
||||||
|
openrc = "openrc"
|
||||||
|
unknown = "unknown"
|
||||||
|
)
|
||||||
|
|
||||||
func SH(c string) (string, error) {
|
func SH(c string) (string, error) {
|
||||||
cmd := exec.Command("/bin/sh", "-c", c)
|
cmd := exec.Command("/bin/sh", "-c", c)
|
||||||
cmd.Env = os.Environ()
|
cmd.Env = os.Environ()
|
||||||
@@ -110,6 +116,27 @@ func Flavor() string {
|
|||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetInit Return the init system used by the OS
|
||||||
|
func GetInit() string {
|
||||||
|
for _, file := range []string{"/run/systemd/system", "/sbin/systemctl", "/usr/bin/systemctl", "/usr/sbin/systemctl", "/usr/bin/systemctl"} {
|
||||||
|
_, err := os.Stat(file)
|
||||||
|
// Found systemd
|
||||||
|
if err == nil {
|
||||||
|
return systemd
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, file := range []string{"/sbin/openrc", "/usr/sbin/openrc", "/bin/openrc", "/usr/bin/openrc"} {
|
||||||
|
_, err := os.Stat(file)
|
||||||
|
// Found openrc
|
||||||
|
if err == nil {
|
||||||
|
return openrc
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return unknown
|
||||||
|
}
|
||||||
|
|
||||||
func Name() string {
|
func Name() string {
|
||||||
v, err := OSRelease("NAME")
|
v, err := OSRelease("NAME")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -120,8 +147,7 @@ func Name() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsOpenRCBased() bool {
|
func IsOpenRCBased() bool {
|
||||||
n := Name()
|
return GetInit() == openrc
|
||||||
return strings.Contains(n, "alpine")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ShellSTDIN(s, c string) (string, error) {
|
func ShellSTDIN(s, c string) (string, error) {
|
||||||
|
Reference in New Issue
Block a user