From 8ee0af1a3b8ed726d089779ac01ec8d0fee2dc22 Mon Sep 17 00:00:00 2001 From: Jonh Wendell Date: Fri, 27 Mar 2015 11:23:58 -0300 Subject: [PATCH] Execute entries with a single string as shell commands Documentation says about that, but it's not implemented like that. If the command to be executed is an array with just one string, it's likely the user passed the entire command inside the string. Plus, they benefit from shell expansion of wildcards like '*'. --- bootstrapvz/plugins/image_commands/README.md | 6 ++++++ bootstrapvz/plugins/image_commands/tasks.py | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/bootstrapvz/plugins/image_commands/README.md b/bootstrapvz/plugins/image_commands/README.md index 61583d5..e4ffb8b 100644 --- a/bootstrapvz/plugins/image_commands/README.md +++ b/bootstrapvz/plugins/image_commands/README.md @@ -10,6 +10,12 @@ Plugin is defined in the manifest file, plugin section with: The *commands* element is an array of commands. Each command is an array describing the executable and its arguments. +If you need shell expansion of wildcards, like __\*__, just put the entire command as a single entry: + + "image_commands": { + "commands": [ [ "rm -f /tmp/*" ]], + } + Command is executed in current context. It is possible to use variables to access the image or execute chroot commands in the image. Available variables are: diff --git a/bootstrapvz/plugins/image_commands/tasks.py b/bootstrapvz/plugins/image_commands/tasks.py index 70ec370..2ea50e9 100644 --- a/bootstrapvz/plugins/image_commands/tasks.py +++ b/bootstrapvz/plugins/image_commands/tasks.py @@ -11,4 +11,5 @@ class ImageExecuteCommand(Task): from bootstrapvz.common.tools import log_check_call for raw_command in info.manifest.plugins['image_commands']['commands']: command = map(lambda part: part.format(root=info.root, **info.manifest_vars), raw_command) - log_check_call(command) + shell = len(command) == 1 + log_check_call(command, shell=shell)