From ff12605106e8710d358c7ca95f0d999a161087a8 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Mon, 12 Dec 2022 13:14:26 +0100 Subject: [PATCH] rpicamera: remove grep and awk dependency --- internal/rpicamera/rpicamera.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/internal/rpicamera/rpicamera.go b/internal/rpicamera/rpicamera.go index bbbe2b09..73ef1377 100644 --- a/internal/rpicamera/rpicamera.go +++ b/internal/rpicamera/rpicamera.go @@ -55,16 +55,26 @@ func checkArch() error { return nil } -func setupSymlink(name string) error { - cmd := exec.Command("sh", "-c", "ldconfig -p | grep "+name+".so | awk '{ print $4 }'") - byts, err := cmd.Output() +func findLibrary(name string) (string, error) { + byts, err := exec.Command("ldconfig", "-p").Output() if err != nil { - return err + return "", err } - lib := strings.TrimSpace(string(byts)) - if lib == "" { - return fmt.Errorf(name + " not found") + for _, line := range strings.Split(string(byts), "\n") { + f := strings.Split(line, " => ") + if len(f) == 2 && strings.Contains(f[1], name+".so") { + return f[1], nil + } + } + + return "", fmt.Errorf("library '%s' not found", name) +} + +func setupSymlink(name string) error { + lib, err := findLibrary(name) + if err != nil { + return err } os.Remove("/dev/shm/" + name + ".so.x.x.x")