If script is executable then execute it, if not then assume it is a shell script.

This commit is contained in:
Darko Poljak 2017-06-28 13:57:48 +02:00
parent 62378dc8b9
commit 9aa4465718
2 changed files with 14 additions and 2 deletions

View File

@ -237,8 +237,14 @@ class Local(object):
Return the output as a string.
"""
command = [os.environ.get('CDIST_LOCAL_SHELL', "/bin/sh"), "-e"]
command.append(script)
if os.access(script, os.X_OK):
self.log.debug('%s is executable, running it', script)
command=[script]
else:
command = [os.environ.get('CDIST_LOCAL_SHELL', "/bin/sh"), "-e"]
self.log.debug('%s is NOT executable, running it with %s',
script, " ".join(command))
command.append(script)
return self.run(command=command, env=env, return_output=return_output,
message_prefix=message_prefix, save_output=save_output)

View File

@ -79,6 +79,12 @@ two underscores (__) to prevent collisions with other executables in $PATH.
To implement a new type, create the directory **cdist/conf/type/__NAME**.
Type manifest and gencode can be written in any language. They just need to be
executable and have a proper shebang. If they are not executable then cdist assumes
they are written in shell so they are executed using '/bin/sh -e' or 'CDIST_LOCAL_SHELL'.
For executable shell code it is suggested that shebang is '#!/bin/sh -e'.
Defining parameters
-------------------