Skip to content

Commit

Permalink
Add CheckEnv steps for used commands to the actions that need it
Browse files Browse the repository at this point in the history
  • Loading branch information
eds-collabora authored and sjoerdsimons committed Dec 30, 2023
1 parent 67bf64b commit 9527ef3
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 4 deletions.
9 changes: 9 additions & 0 deletions actions/debootstrap_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ func (d *DebootstrapAction) Verify(context *debos.DebosContext) error {
return nil
}

func (d *DebootstrapAction) CheckEnv(context *debos.DebosContext) error {
// Check that debootstrap is available
cmd := debos.Command{}
if err := cmd.CheckExists("Debootstrap", "debootstrap", "--version"); err != nil {
return err
}
return nil
}

func (d *DebootstrapAction) PreMachine(context *debos.DebosContext, m *fakemachine.Machine, args *[]string) error {

mounts := d.listOptionFiles(context)
Expand Down
8 changes: 8 additions & 0 deletions actions/filesystem_deploy_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ func NewFilesystemDeployAction() *FilesystemDeployAction {
return fd
}

func (fd *FilesystemDeployAction) CheckEnv(context *debos.DebosContext) error {
cmd := debos.Command{}
if err := cmd.CheckExists("Cp", "cp", "--help"); err != nil {
return err
}
return nil
}

func (fd *FilesystemDeployAction) setupFSTab(context *debos.DebosContext) error {
if context.ImageFSTab.Len() == 0 {
return errors.New("Fstab not generated, missing image-partition action?")
Expand Down
34 changes: 30 additions & 4 deletions actions/image_partition_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,7 @@ func (i ImagePartitionAction) PreMachine(context *debos.DebosContext, m *fakemac
return nil
}

func (i ImagePartitionAction) formatPartition(p *Partition, context debos.DebosContext) error {
label := fmt.Sprintf("Formatting partition %d", p.number)
path := i.getPartitionDevice(p.number, context)

func (i ImagePartitionAction) getPartitionCommand(p *Partition) []string {
cmdline := []string{}
switch p.FS {
case "vfat":
Expand Down Expand Up @@ -385,6 +382,14 @@ func (i ImagePartitionAction) formatPartition(p *Partition, context debos.DebosC
}
}
}
return cmdline
}

func (i ImagePartitionAction) formatPartition(p *Partition, context debos.DebosContext) error {
label := fmt.Sprintf("Formatting partition %d", p.number)
path := i.getPartitionDevice(p.number, context)

cmdline := i.getPartitionCommand(p)

if len(cmdline) != 0 {
cmdline = append(cmdline, path)
Expand Down Expand Up @@ -655,6 +660,27 @@ func (i ImagePartitionAction) PostMachineCleanup(context *debos.DebosContext) er
return nil
}

func (i *ImagePartitionAction) CheckEnv(context *debos.DebosContext) error {
commands := []string{
"blkid", "parted", "sfdisk", "udevadm" }

cmd := debos.Command{}
for _, c := range commands {
if err := cmd.CheckExists(strings.Title(c), c, "--help"); err != nil {
return err
}
}
for idx, _ := range i.Partitions {
p := &i.Partitions[idx]
cmdline := i.getPartitionCommand(p)
cmd := debos.Command{}
if err := cmd.CheckExists(strings.Title(cmdline[0]), cmdline[0], "-V"); err != nil {
return err
}
}
return nil
}

func (i *ImagePartitionAction) Verify(context *debos.DebosContext) error {
if len(i.GptGap) > 0 {
log.Println("WARNING: special version of parted is needed for 'gpt_gap' option")
Expand Down
8 changes: 8 additions & 0 deletions actions/ostree_deploy_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ func NewOstreeDeployAction() *OstreeDeployAction {
return ot
}

func (ot *OstreeDeployAction) CheckEnv(context *debos.DebosContext) error {
cmd := debos.Command{}
if err := cmd.CheckExists("Cp", "cp", "--help"); err != nil {
return err
}
return nil
}

func (ot *OstreeDeployAction) setupFSTab(deployment *ostree.Deployment, context *debos.DebosContext) error {
deploymentDir := fmt.Sprintf("ostree/deploy/%s/deploy/%s.%d",
deployment.Osname(), deployment.Csum(), deployment.Deployserial())
Expand Down
8 changes: 8 additions & 0 deletions actions/pack_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ func (pf *PackAction) Verify(context *debos.DebosContext) error {
pf.Compression, strings.Join(possibleTypes, ", "))
}

func (pf *PackAction) CheckEnv(context *debos.DebosContext) error {
cmd := debos.Command{}
if err := cmd.CheckExists("Tar", "tar", "--help"); err != nil {
return err
}
return nil
}

func (pf *PackAction) Run(context *debos.DebosContext) error {
usePigz := false
if pf.Compression == "gz" {
Expand Down
9 changes: 9 additions & 0 deletions actions/recipe_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ func (recipe *RecipeAction) Verify(context *debos.DebosContext) error {
return nil
}

func (recipe *RecipeAction) CheckEnv(context *debos.DebosContext) error {
for _, a := range recipe.Actions.Actions {
if err := a.CheckEnv(&recipe.context); err != nil {
return err
}
}
return nil
}

func (recipe *RecipeAction) PreMachine(context *debos.DebosContext, m *fakemachine.Machine, args *[]string) error {
// TODO: check args?

Expand Down

0 comments on commit 9527ef3

Please sign in to comment.