mirror of
https://github.com/rancher/os.git
synced 2025-09-02 23:34:57 +00:00
fix for alpine's simpler blkid cmd
Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
@@ -3,10 +3,15 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/docker/docker/pkg/mount"
|
||||
"github.com/rancher/os/log"
|
||||
)
|
||||
|
||||
func mountProc() error {
|
||||
@@ -43,3 +48,32 @@ func Mount(device, directory, fsType, options string) error {
|
||||
func Unmount(target string) error {
|
||||
return mount.Unmount(target)
|
||||
}
|
||||
|
||||
func Blkid(label string) (deviceName, deviceType string) {
|
||||
// Not all blkid's have `blkid -L label (see busybox/alpine)
|
||||
cmd := exec.Command("blkid")
|
||||
cmd.Stderr = os.Stderr
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
log.Errorf("Failed to run blkid: %s", err)
|
||||
return
|
||||
}
|
||||
r := bytes.NewReader(out)
|
||||
s := bufio.NewScanner(r)
|
||||
for s.Scan() {
|
||||
line := s.Text()
|
||||
log.Debugf("blkid: %s", cmd, line)
|
||||
if !strings.Contains(line, `LABEL="`+label+`"`) {
|
||||
continue
|
||||
}
|
||||
d := strings.Split(line, ":")
|
||||
deviceName = d[0]
|
||||
|
||||
s1 := strings.Split(line, `TYPE="`)
|
||||
s2 := strings.Split(s1[1], `"`)
|
||||
deviceType = s2[0]
|
||||
log.Debugf("blkid type of %s: %s", deviceName, deviceType)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user