github.com/vijayrajah/packer@v1.3.2/post-processor/shell-local/post-processor.go (about)

     1  package shell_local
     2  
     3  import (
     4  	sl "github.com/hashicorp/packer/common/shell-local"
     5  	"github.com/hashicorp/packer/packer"
     6  )
     7  
     8  type PostProcessor struct {
     9  	config sl.Config
    10  }
    11  
    12  type ExecuteCommandTemplate struct {
    13  	Vars   string
    14  	Script string
    15  }
    16  
    17  func (p *PostProcessor) Configure(raws ...interface{}) error {
    18  	err := sl.Decode(&p.config, raws...)
    19  	if err != nil {
    20  		return err
    21  	}
    22  	if len(p.config.ExecuteCommand) == 1 {
    23  		// Backwards compatibility -- before we merged the shell-local
    24  		// post-processor and provisioners, the post-processor accepted
    25  		// execute_command as a string rather than a slice of strings. It didn't
    26  		// have a configurable call to shell program, automatically prepending
    27  		// the user-supplied execute_command string with "sh -c". If users are
    28  		// still using the old way of defining ExecuteCommand (by supplying a
    29  		// single string rather than a slice of strings) then we need to
    30  		// prepend this command with the call that the post-processor defaulted
    31  		// to before.
    32  		p.config.ExecuteCommand = append([]string{"sh", "-c"}, p.config.ExecuteCommand...)
    33  	}
    34  
    35  	return sl.Validate(&p.config)
    36  }
    37  
    38  func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, error) {
    39  	// this particular post-processor doesn't do anything with the artifact
    40  	// except to return it.
    41  
    42  	retBool, retErr := sl.Run(ui, &p.config)
    43  	if !retBool {
    44  		return nil, retBool, retErr
    45  	}
    46  
    47  	return artifact, retBool, retErr
    48  }