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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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}"
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:
FROM $BASE_IMAGE
WORKDIR /build

View File

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

View File

@ -64,11 +64,29 @@ func IsMounted(dev string) bool {
// Does NOT need to be mounted
// Needs full path so either /dev/sda1 or /dev/disk/by-{label,uuid}/{label,uuid} .
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))
if e != nil {
Log.Debug().Err(e).Msg("blkid")
}
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")
return out
}

View File

@ -60,7 +60,7 @@ func (s *State) MountRootDagStep(g *herd.Graph) error {
return nil
}
_ = 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)
s.LogIfError(err, "losetup")
// Trigger udevadm

View File

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