Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Carlos Ramos Carreño
slapos
Commits
71d0c4fd
Commit
71d0c4fd
authored
Apr 19, 2016
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wrapper script: use dash instead of bash
parent
605e564b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
27 deletions
+22
-27
slapos/recipe/librecipe/generic.py
slapos/recipe/librecipe/generic.py
+22
-27
No files found.
slapos/recipe/librecipe/generic.py
View file @
71d0c4fd
...
...
@@ -141,17 +141,18 @@ class GenericBaseRecipe(object):
accepting to run only if no other instance is running.
"""
lines
=
[
'#!/bin/
ba
sh'
]
lines
=
[
'#!/bin/sh'
]
for
comment
in
comments
:
lines
.
append
(
'# %s'
%
comment
)
if
comments
:
lines
+=
'# '
,
'
\
n
# '
.
join
(
comments
),
'
\
n
'
if
environment
:
for
key
in
environment
:
lines
.
append
(
'export %s=%s'
%
(
key
,
environment
[
key
]))
lines
.
append
(
'COMMAND='
+
shlex
.
quote
(
command
))
for
key
in
environment
or
():
lines
.
append
(
'export %s=%s'
%
(
key
,
environment
[
key
]))
if
pidfile
:
lines
.
append
(
dedent
(
"""
\
lines
.
append
(
dedent
(
"""
# Check for other instances
pidfile=%s
if [ -e $pidfile ]; then
...
...
@@ -163,37 +164,31 @@ class GenericBaseRecipe(object):
rm $pidfile
fi
fi
echo $$ > $pidfile"""
%
(
pidfile
,
command
)))
# Inspired by http://stackoverflow.com/a/10826085
lines
.
append
(
dedent
(
"""
\
COMMAND=%s
echo $$ > $pidfile"""
%
shlex
.
quote
(
pidfile
)))
lines
.
append
(
dedent
(
'''
# If the wrapped command uses a shebang, execute the referenced
# executable passing the script path as first argument.
# This is to workaround the limitation of 127 characters in #!
if [[ -f $COMMAND && x$(head -c2 "$COMMAND") = x"#!" ]]; then
SHEBANG=$(head -1 "$COMMAND")
INTERPRETER=( ${SHEBANG#
\
#!} )
COMMAND="${INTERPRETER[@]} $COMMAND"
fi
[ ! -f "$COMMAND" ] || {
[ "`head -c2`" != "#!" ] || read -r EXE ARG
} < "$COMMAND"
exec $
COMMAND """
%
shlex
.
quote
(
command
)
))
exec $
EXE ${ARG:+"$ARG"} "$COMMAND"'''
))
parameters
=
map
(
shlex
.
quote
,
parameters
)
if
parameters_extra
:
# pass-through further parameters
parameters
.
append
(
'"$@"'
)
for
param
in
parameters
:
if
len
(
lines
[
-
1
])
<
40
:
lines
[
-
1
]
+=
' '
+
shlex
.
quote
(
param
)
lines
[
-
1
]
+=
' '
+
param
else
:
lines
[
-
1
]
+=
'
\
\
'
lines
.
append
(
'
\
t
'
+
shlex
.
quote
(
param
))
if
parameters_extra
:
# pass-through further parameters
lines
[
-
1
]
+=
'
\
\
'
lines
.
append
(
'
\
t
"$@"'
)
lines
.
append
(
'
\
t
'
+
param
)
content
=
'
\
n
'
.
join
(
lines
)
+
'
\
n
'
return
self
.
createFile
(
name
,
content
,
0700
)
lines
.
append
(
''
)
return
self
.
createFile
(
name
,
'
\
n
'
.
join
(
lines
)
,
0700
)
def
createDirectory
(
self
,
parent
,
name
,
mode
=
0700
):
path
=
os
.
path
.
join
(
parent
,
name
)
...
...
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