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): ...@@ -141,17 +141,18 @@ class GenericBaseRecipe(object):
accepting to run only if no other instance is running. accepting to run only if no other instance is running.
""" """
lines = [ '#!/bin/bash' ] lines = [ '#!/bin/sh' ]
for comment in comments: if comments:
lines.append('# %s' % comment) lines += '# ', '\n# '.join(comments), '\n'
if environment: lines.append('COMMAND=' + shlex.quote(command))
for key in environment:
lines.append('export %s=%s' % (key, environment[key])) for key in environment or ():
lines.append('export %s=%s' % (key, environment[key]))
if pidfile: if pidfile:
lines.append(dedent("""\ lines.append(dedent("""
# Check for other instances # Check for other instances
pidfile=%s pidfile=%s
if [ -e $pidfile ]; then if [ -e $pidfile ]; then
...@@ -163,37 +164,31 @@ class GenericBaseRecipe(object): ...@@ -163,37 +164,31 @@ class GenericBaseRecipe(object):
rm $pidfile rm $pidfile
fi fi
fi fi
echo $$ > $pidfile""" % (pidfile, command))) echo $$ > $pidfile""" % shlex.quote(pidfile)))
# Inspired by http://stackoverflow.com/a/10826085
lines.append(dedent("""\
COMMAND=%s
lines.append(dedent('''
# If the wrapped command uses a shebang, execute the referenced # If the wrapped command uses a shebang, execute the referenced
# executable passing the script path as first argument. # executable passing the script path as first argument.
# This is to workaround the limitation of 127 characters in #! # This is to workaround the limitation of 127 characters in #!
if [[ -f $COMMAND && x$(head -c2 "$COMMAND") = x"#!" ]]; then [ ! -f "$COMMAND" ] || {
SHEBANG=$(head -1 "$COMMAND") [ "`head -c2`" != "#!" ] || read -r EXE ARG
INTERPRETER=( ${SHEBANG#\#!} ) } < "$COMMAND"
COMMAND="${INTERPRETER[@]} $COMMAND"
fi
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: for param in parameters:
if len(lines[-1]) < 40: if len(lines[-1]) < 40:
lines[-1] += ' ' + shlex.quote(param) lines[-1] += ' ' + param
else: else:
lines[-1] += ' \\' lines[-1] += ' \\'
lines.append('\t' + shlex.quote(param)) lines.append('\t' + param)
if parameters_extra:
# pass-through further parameters
lines[-1] += ' \\'
lines.append('\t"$@"')
content = '\n'.join(lines) + '\n' lines.append('')
return self.createFile(name, content, 0700) return self.createFile(name, '\n'.join(lines), 0700)
def createDirectory(self, parent, name, mode=0700): def createDirectory(self, parent, name, mode=0700):
path = os.path.join(parent, name) 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