Commit 71d0c4fd authored by Julien Muchembled's avatar Julien Muchembled

wrapper script: use dash instead of bash

parent 605e564b
......@@ -141,17 +141,18 @@ class GenericBaseRecipe(object):
accepting to run only if no other instance is running.
"""
lines = [ '#!/bin/bash' ]
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('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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment