Increase compatibility with alpine systems (#132)

This commit is contained in:
Itxaka
2023-05-30 19:51:03 +00:00
committed by GitHub
parent 553a768e5b
commit 0811f0f054
5 changed files with 34 additions and 9 deletions

View File

@@ -73,6 +73,11 @@ build-immucore:
RUN CGO_ENABLED=0 go build -o immucore -ldflags "${LDFLAGS}" RUN CGO_ENABLED=0 go build -o immucore -ldflags "${LDFLAGS}"
SAVE ARTIFACT /work/immucore immucore AS LOCAL build/immucore-$VERSION SAVE ARTIFACT /work/immucore immucore AS LOCAL build/immucore-$VERSION
build-immucore-image:
FROM +build-immucore
COPY +build-immucore/immucore /usr/bin/immucore
SAVE IMAGE immucore:latest
dracut-artifacts: dracut-artifacts:
FROM $BASE_IMAGE FROM $BASE_IMAGE
WORKDIR /build WORKDIR /build

View File

@@ -165,11 +165,10 @@ func GetState() string {
} }
switch r.BootState { switch r.BootState {
case state.Active, state.Passive: case state.Active, state.Passive:
label = r.State.FilesystemLabel label = "COS_STATE"
case state.Recovery: case state.Recovery:
label = r.Recovery.FilesystemLabel label = "COS_RECOVERY"
} default:
if label == "" {
return errors.New("could not get label") return errors.New("could not get label")
} }
return nil return nil

View File

@@ -64,11 +64,29 @@ func IsMounted(dev string) bool {
// Does NOT need to be mounted // Does NOT need to be mounted
// Needs full path so either /dev/sda1 or /dev/disk/by-{label,uuid}/{label,uuid} . // Needs full path so either /dev/sda1 or /dev/disk/by-{label,uuid}/{label,uuid} .
func DiskFSType(s string) string { func DiskFSType(s string) string {
Log.Debug().Str("device", s).Msg("Getting disk type for device")
out, e := CommandWithPath(fmt.Sprintf("blkid %s -s TYPE -o value", s)) out, e := CommandWithPath(fmt.Sprintf("blkid %s -s TYPE -o value", s))
if e != nil { if e != nil {
Log.Debug().Err(e).Msg("blkid") Log.Debug().Err(e).Msg("blkid")
} }
out = strings.Trim(strings.Trim(out, " "), "\n") out = strings.Trim(strings.Trim(out, " "), "\n")
blkidVersion, _ := CommandWithPath("blkid --help")
if strings.Contains(blkidVersion, "BusyBox") {
// BusyBox blkid returns the whole thing ¬_¬
splitted := strings.Fields(out)
if len(splitted) == 0 {
Log.Debug().Str("what", out).Msg("blkid output")
return "ext4"
}
typeFs := splitted[len(splitted)-1]
typeFsSplitted := strings.Split(typeFs, "=")
if len(typeFsSplitted) < 1 {
Log.Debug().Str("what", typeFs).Msg("typeFs split")
return "ext4"
}
finalFS := typeFsSplitted[1]
out = strings.TrimSpace(strings.Trim(finalFS, "\""))
}
Log.Debug().Str("what", s).Str("type", out).Msg("Partition FS type") Log.Debug().Str("what", s).Str("type", out).Msg("Partition FS type")
return out return out
} }

View File

@@ -60,7 +60,7 @@ func (s *State) MountRootDagStep(g *herd.Graph) error {
return nil return nil
} }
_ = internalUtils.Fsck(s.path("/run/initramfs/cos-state", s.TargetImage)) _ = internalUtils.Fsck(s.path("/run/initramfs/cos-state", s.TargetImage))
cmd := fmt.Sprintf("losetup --show -f %s", s.path("/run/initramfs/cos-state", s.TargetImage)) cmd := fmt.Sprintf("losetup -f %s", s.path("/run/initramfs/cos-state", s.TargetImage))
_, err := utils.SH(cmd) _, err := utils.SH(cmd)
s.LogIfError(err, "losetup") s.LogIfError(err, "losetup")
// Trigger udevadm // Trigger udevadm

View File

@@ -136,11 +136,14 @@ func (s *State) MountOP(what, where, t string, options []string, timeout time.Du
select { select {
default: default:
// check fs type just-in-time before running the OP // check fs type just-in-time before running the OP
fsType := internalUtils.DiskFSType(what) if t != "tmpfs" {
// If not empty and it does not match fsType := internalUtils.DiskFSType(what)
if fsType != "" && t != fsType { // If not empty and it does not match
t = fsType if fsType != "" && t != fsType {
t = fsType
}
} }
err := internalUtils.CreateIfNotExists(where) err := internalUtils.CreateIfNotExists(where)
if err != nil { if err != nil {
l.Err(err).Msg("Creating dir") l.Err(err).Msg("Creating dir")