Move all functions under pkg

Signed-off-by: Itxaka <itxaka@kairos.io>
This commit is contained in:
Itxaka
2023-11-30 10:24:55 +01:00
parent 4ec8386ac8
commit 365f16e8f1
4 changed files with 249 additions and 237 deletions

28
pkg/lib/utils.go Normal file
View File

@@ -0,0 +1,28 @@
package lib
import (
"fmt"
"os"
"os/exec"
"time"
)
func SH(c string) (string, error) {
o, err := exec.Command("/bin/sh", "-c", c).CombinedOutput()
return string(o), err
}
func Waitdevice(device string, attempts int) error {
for tries := 0; tries < attempts; tries++ {
_, err := SH("udevadm settle")
if err != nil {
return err
}
_, err = os.Lstat(device)
if !os.IsNotExist(err) {
return nil
}
time.Sleep(1 * time.Second)
}
return fmt.Errorf("no device found")
}