Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
b2274376
Commit
b2274376
authored
Jul 07, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
provisioner/shell: inline_shebang for inline scripts
parent
6a5bbaa0
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
0 deletions
+39
-0
CHANGELOG.md
CHANGELOG.md
+4
-0
provisioner/shell/provisioner.go
provisioner/shell/provisioner.go
+8
-0
provisioner/shell/provisioner_test.go
provisioner/shell/provisioner_test.go
+27
-0
No files found.
CHANGELOG.md
View file @
b2274376
...
...
@@ -11,6 +11,10 @@ IMPROVEMENTS:
*
core: If SCP is not available, a more descriptive error message
is shown telling the user. [GH-127]
*
shell: Scripts are now executed by default according to their shebang,
not with
`/bin/sh`
. [GH-105]
*
shell: You can specify what interpreter you want inline scripts to
run with
`inline_shebang`
.
*
virtualbox: Delete the packer-made SSH port forwarding prior to
exporting the VM.
...
...
provisioner/shell/provisioner.go
View file @
b2274376
...
...
@@ -25,6 +25,9 @@ type config struct {
// in the context of a single shell.
Inline
[]
string
// The shebang value used when running inline scripts.
InlineShebang
string
`mapstructure:"inline_shebang"`
// The local path of the shell script to upload and execute.
Script
string
...
...
@@ -69,6 +72,10 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
p
.
config
.
Inline
=
nil
}
if
p
.
config
.
InlineShebang
==
""
{
p
.
config
.
InlineShebang
=
"/bin/sh"
}
if
p
.
config
.
RemotePath
==
""
{
p
.
config
.
RemotePath
=
DefaultRemotePath
}
...
...
@@ -136,6 +143,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
// Write our contents to it
writer
:=
bufio
.
NewWriter
(
tf
)
writer
.
WriteString
(
fmt
.
Sprintf
(
"#!%s
\n
"
,
p
.
config
.
InlineShebang
))
for
_
,
command
:=
range
p
.
config
.
Inline
{
if
_
,
err
:=
writer
.
WriteString
(
command
+
"
\n
"
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Error preparing shell script: %s"
,
err
)
...
...
provisioner/shell/provisioner_test.go
View file @
b2274376
...
...
@@ -35,6 +35,33 @@ func TestProvisionerPrepare_Defaults(t *testing.T) {
}
}
func
TestProvisionerPrepare_InlineShebang
(
t
*
testing
.
T
)
{
config
:=
testConfig
()
delete
(
config
,
"inline_shebang"
)
p
:=
new
(
Provisioner
)
err
:=
p
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
if
p
.
config
.
InlineShebang
!=
"/bin/sh"
{
t
.
Fatalf
(
"bad value: %s"
,
p
.
config
.
InlineShebang
)
}
// Test with a good one
config
[
"inline_shebang"
]
=
"foo"
p
=
new
(
Provisioner
)
err
=
p
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
if
p
.
config
.
InlineShebang
!=
"foo"
{
t
.
Fatalf
(
"bad value: %s"
,
p
.
config
.
InlineShebang
)
}
}
func
TestProvisionerPrepare_Script
(
t
*
testing
.
T
)
{
config
:=
testConfig
()
delete
(
config
,
"inline"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment