mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-08 16:22:15 -04:00
Use sudo only if prevent_sudo is not set
This commit is contained in:
parent
347f02a7f2
commit
a5ca2e5a27
1 changed files with 14 additions and 2 deletions
|
|
@ -338,8 +338,14 @@ func (p *Provisioner) createJson(ui packer.Ui, comm packer.Communicator) (string
|
|||
|
||||
func (p *Provisioner) createDir(ui packer.Ui, comm packer.Communicator, dir string) error {
|
||||
ui.Message(fmt.Sprintf("Creating directory: %s", dir))
|
||||
|
||||
mkdirCmd := fmt.Sprintf("mkdir -p '%s'", dir)
|
||||
if !p.config.PreventSudo {
|
||||
mkdirCmd = "sudo " + mkdirCmd
|
||||
}
|
||||
|
||||
cmd := &packer.RemoteCmd{
|
||||
Command: fmt.Sprintf("sudo mkdir -p '%s'", dir),
|
||||
Command: mkdirCmd,
|
||||
}
|
||||
|
||||
if err := cmd.StartWithUi(comm, ui); err != nil {
|
||||
|
|
@ -387,8 +393,14 @@ func (p *Provisioner) cleanClient(ui packer.Ui, comm packer.Communicator, node s
|
|||
|
||||
func (p *Provisioner) removeDir(ui packer.Ui, comm packer.Communicator, dir string) error {
|
||||
ui.Message(fmt.Sprintf("Removing directory: %s", dir))
|
||||
|
||||
rmCmd := fmt.Sprintf("rm -rf '%s'", dir)
|
||||
if !p.config.PreventSudo {
|
||||
rmCmd = "sudo " + rmCmd
|
||||
}
|
||||
|
||||
cmd := &packer.RemoteCmd{
|
||||
Command: fmt.Sprintf("sudo rm -rf %s", dir),
|
||||
Command: rmCmd,
|
||||
}
|
||||
|
||||
if err := cmd.StartWithUi(comm, ui); err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue