diff --git a/README.md b/README.md index e2bafb1..630c555 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,5 @@ miaou-incus incus customized along opinionated conventions plus additional tools + + diff --git a/recipes/helloworld.recipe b/recipes/helloworld.recipe new file mode 100644 index 0000000..36e205a --- /dev/null +++ b/recipes/helloworld.recipe @@ -0,0 +1,6 @@ +echo "count: $#" +echo "args: $@" +echo "$1" +echo "$2" +echo "$3" +echo "Hello World from container: $(hostname -f)" diff --git a/recipes/wordpress.container b/recipes/wordpress.recipe similarity index 100% rename from recipes/wordpress.container rename to recipes/wordpress.recipe diff --git a/tools/miaou-recipe b/tools/miaou-recipe index 8e43352..5601649 100755 --- a/tools/miaou-recipe +++ b/tools/miaou-recipe @@ -3,15 +3,22 @@ # CONSTANTS BASEDIR=$(dirname "$0") -CONTAINER='' +CONTAINER=${CONTAINER:-} SCRIPT='' DEBUG=false +QUIET=false FORCE=${FORCE:-false} +RECIPE_ARGS= # FUNCTIONS function usage { - echo "$(basename "$0") {CONTAINER_NAME} {PATH_TO_SCRIPT} [[--debug|-d]]" + echo "$(basename "$0") {CONTAINER_NAME} {PATH_TO_SCRIPT} [--debug|-d] [--quiet|-q] -- [recipe_args]" + echo "execute a recipe inside a container with extra_args" + echo -------------- + echo call examples: + echo " miaou-recipe ct1 recipes/helloworld.recipe -- one two" + echo " CONTAINER=ct1 miaou-recipe recipes/helloworld.recipe" } function parse_options { @@ -23,6 +30,14 @@ function parse_options { --debug | -d) DEBUG=true ;; + --quiet | -q) + QUIET=true + ;; + --) + shift 1 + RECIPE_ARGS=("$@") # array of arguments, useful to prevent quoted strings => "${RECIPE_ARGS[@]}" + break + ;; *) if [[ -z $CONTAINER ]]; then CONTAINER=$1 @@ -45,15 +60,16 @@ function debug_option { function recipe { [[ ! -f $SCRIPT ]] && echo >&2 "Script not found: $SCRIPT" && exit 3 + cat "$SCRIPT" | incus exec "$CONTAINER" -- env FORCE="$FORCE" bash $(debug_option) -s -- "${RECIPE_ARGS[@]}" +} - # hot changes - cat "$SCRIPT" | incus exec "$CONTAINER" -- env FORCE="$FORCE" bash $(debug_option) - +function show_success { + echo "Recipe <$(basename "$SCRIPT")> successfully performed on container <$CONTAINER>" } # MAIN set -Eue -parse_options $* +parse_options "$@" recipe -echo "Recipe <$(basename "$SCRIPT")> successfully performed on container <$CONTAINER>" +$QUIET || show_success