Browse Source

miaou-recipe smarter with recipe_args

main
pvincent 3 days ago
parent
commit
7069f83643
  1. 2
      README.md
  2. 6
      recipes/helloworld.recipe
  3. 0
      recipes/wordpress.recipe
  4. 30
      tools/miaou-recipe

2
README.md

@ -3,3 +3,5 @@ miaou-incus
incus customized along opinionated conventions plus additional tools

6
recipes/helloworld.recipe

@ -0,0 +1,6 @@
echo "count: $#"
echo "args: $@"
echo "$1"
echo "$2"
echo "$3"
echo "Hello World from container: $(hostname -f)"

0
recipes/wordpress.container → recipes/wordpress.recipe

30
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
Loading…
Cancel
Save