mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-03 10:04:42 +00:00
Split off cli into separate binaries (#37)
* 🎨 Split off cli into separate binaries This commit splits off the cli into 3 binaries: - agent - cli - provider The provider now is a separate component that can be tested by itself and have its own lifecycle. This paves the way to a ligher c3os variant, HA support and other features that can be provided on runtime. This is working, but still there are low hanging fruit to care about. Fixes #14 * 🤖 Add provider bin to releases * ⚙️ Handle signals * ⚙️ Reduce buildsize footprint * 🎨 Scan for providers also in /system/providers * 🤖 Run goreleaser * 🎨 Refactoring
This commit is contained in:
committed by
Itxaka
parent
74bfd373db
commit
63cd28d1cb
82
internal/utils/system.go
Normal file
82
internal/utils/system.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/pterm/pterm"
|
||||
)
|
||||
|
||||
func Reboot() {
|
||||
pterm.Info.Println("Rebooting node")
|
||||
SH("reboot")
|
||||
}
|
||||
|
||||
func PowerOFF() {
|
||||
pterm.Info.Println("Shutdown node")
|
||||
if IsOpenRCBased() {
|
||||
SH("poweroff")
|
||||
} else {
|
||||
SH("shutdown")
|
||||
}
|
||||
}
|
||||
|
||||
func Version() string {
|
||||
release, _ := godotenv.Read("/etc/os-release")
|
||||
v := release["VERSION"]
|
||||
v = strings.ReplaceAll(v, "+k3s1-c3OS", "-")
|
||||
return strings.ReplaceAll(v, "+k3s-c3OS", "-")
|
||||
}
|
||||
|
||||
func OSRelease(key string) (string, error) {
|
||||
release, err := godotenv.Read("/etc/os-release")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
v, exists := release[key]
|
||||
if !exists {
|
||||
return "", fmt.Errorf("key not found")
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func Flavor() string {
|
||||
release, _ := godotenv.Read("/etc/os-release")
|
||||
v := release["NAME"]
|
||||
return strings.ReplaceAll(v, "c3os-", "")
|
||||
}
|
||||
|
||||
func IsOpenRCBased() bool {
|
||||
f := Flavor()
|
||||
return f == "alpine" || f == "alpine-arm-rpi"
|
||||
}
|
||||
|
||||
func GetInterfaceIP(in string) string {
|
||||
ifaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
fmt.Println("failed getting system interfaces")
|
||||
return ""
|
||||
}
|
||||
for _, i := range ifaces {
|
||||
if i.Name == in {
|
||||
addrs, _ := i.Addrs()
|
||||
// handle err
|
||||
for _, addr := range addrs {
|
||||
var ip net.IP
|
||||
switch v := addr.(type) {
|
||||
case *net.IPNet:
|
||||
ip = v.IP
|
||||
case *net.IPAddr:
|
||||
ip = v.IP
|
||||
}
|
||||
if ip != nil {
|
||||
return ip.String()
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
Reference in New Issue
Block a user