Skip to content

Commit

Permalink
Add checks 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 committed Aug 14, 2021
1 parent fce1e07 commit 1ba357e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions actions/debootstrap_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ func (d *DebootstrapAction) listOptionFiles(context *debos.DebosContext) []strin
}

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

files := d.listOptionFiles(context)

// Check if all needed files exists
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) Verify(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
11 changes: 11 additions & 0 deletions actions/image_partition_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,17 @@ func (i ImagePartitionAction) PostMachineCleanup(context *debos.DebosContext) er
}

func (i *ImagePartitionAction) Verify(context *debos.DebosContext) error {
commands := []string{
"blkid", "mkfs.btrfs", "mkfs.ext2", "mkfs.ext3", "mkfs.ext4", "mkfs.f2fs",
"mkfs.hfs", "mkfs.hfsplus", "mkfs.vfat", "mkfs.xfs", "parted", "sfdisk", "udevadm" }

cmd := debos.Command{}
for _, c := range commands {
if err := cmd.CheckExists(strings.Title(c), c, "--help"); err != nil {
return err
}
}

if len(i.GptGap) > 0 {
log.Println("WARNING: special version of parted is needed for 'gpt_gap' option")
if i.PartitionType != "gpt" {
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) Verify(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
5 changes: 5 additions & 0 deletions actions/pack_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ func NewPackAction() *PackAction {
}

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

_, compressionAvailable := tarOpts[pf.Compression]
if compressionAvailable {
return nil
Expand Down

0 comments on commit 1ba357e

Please sign in to comment.