2023-02-06 14:41:52 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-02-06 15:02:18 +00:00
|
|
|
"os"
|
2023-02-06 14:41:52 +00:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// https://github.com/kairos-io/packages/blob/7c3581a8ba6371e5ce10c3a98bae54fde6a505af/packages/system/dracut/immutable-rootfs/30cos-immutable-rootfs/cos-mount-layout.sh#L58
|
|
|
|
|
|
|
|
// input: LABEL=FOO:/mount
|
|
|
|
// output: /dev/disk...:/mount
|
|
|
|
func ParseMount(s string) string {
|
|
|
|
switch {
|
|
|
|
case strings.Contains(s, "UUID="):
|
|
|
|
dat := strings.Split(s, "UUID=")
|
|
|
|
return fmt.Sprintf("/dev/disk/by-uuid/%s", dat[1])
|
|
|
|
case strings.Contains(s, "LABEL="):
|
|
|
|
dat := strings.Split(s, "LABEL=")
|
|
|
|
return fmt.Sprintf("/dev/disk/by-label/%s", dat[1])
|
|
|
|
default:
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
}
|
2023-02-06 15:02:18 +00:00
|
|
|
|
|
|
|
func ReadCMDLineArg(arg string) []string {
|
|
|
|
cmdLine, err := os.ReadFile("/proc/cmdline")
|
|
|
|
if err != nil {
|
|
|
|
return []string{}
|
|
|
|
}
|
|
|
|
res := []string{}
|
|
|
|
fields := strings.Fields(string(cmdLine))
|
|
|
|
for _, f := range fields {
|
|
|
|
if strings.HasPrefix(f, arg) {
|
|
|
|
dat := strings.Split(f, arg)
|
|
|
|
res = append(res, dat[1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|