mirror of
https://github.com/kairos-io/osbuilder.git
synced 2025-09-25 21:48:31 +00:00
Add iso builder
This adds a new package for the iso builder run directly on go. This is extracted from the original elemental-cli and then from the now build-less kairos-agent This uses no deps on elemental, only deps are on kairos-agent for the config stuff mainly. Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com>
This commit is contained in:
40
tools-image/enki/pkg/utils/common.go
Normal file
40
tools-image/enki/pkg/utils/common.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/kairos-io/enki/pkg/constants"
|
||||
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// CreateSquashFS creates a squash file at destination from a source, with options
|
||||
// TODO: Check validity of source maybe?
|
||||
func CreateSquashFS(runner v1.Runner, logger v1.Logger, source string, destination string, options []string) error {
|
||||
// create args
|
||||
args := []string{source, destination}
|
||||
// append options passed to args in order to have the correct order
|
||||
// protect against options passed together in the same string , i.e. "-x add" instead of "-x", "add"
|
||||
var optionsExpanded []string
|
||||
for _, op := range options {
|
||||
optionsExpanded = append(optionsExpanded, strings.Split(op, " ")...)
|
||||
}
|
||||
args = append(args, optionsExpanded...)
|
||||
out, err := runner.Run("mksquashfs", args...)
|
||||
if err != nil {
|
||||
logger.Debugf("Error running squashfs creation, stdout: %s", out)
|
||||
logger.Errorf("Error while creating squashfs from %s to %s: %s", source, destination, err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GolangArchToArch(arch string) (string, error) {
|
||||
switch strings.ToLower(arch) {
|
||||
case constants.ArchAmd64:
|
||||
return constants.Archx86, nil
|
||||
case constants.ArchArm64:
|
||||
return constants.ArchArm64, nil
|
||||
default:
|
||||
return "", fmt.Errorf("invalid arch")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user