From 1f04e2ca7b62e178f22c3fae22bbc87d1c216820 Mon Sep 17 00:00:00 2001 From: pvincent Date: Tue, 11 Aug 2026 23:47:08 +0400 Subject: [PATCH] recipe doesnt work anymore --- tools/miaou-create | 29 +++++++--------- tools/miaou-destroy | 68 ++++++++++++++++++------------------- tools/miaou-exec | 69 +++++++++++++++++++------------------- tools/miaou-ls | 44 ++++++++++++------------ tools/miaou-pull | 55 +++++++++++++++--------------- tools/miaou-push | 53 ++++++++++++++--------------- tools/miaou-recipe | 82 ++++++++++++++++++++++----------------------- tools/miaou-start | 42 +++++++++++------------ tools/miaou-stop | 44 ++++++++++++------------ 9 files changed, 236 insertions(+), 250 deletions(-) diff --git a/tools/miaou-create b/tools/miaou-create index beeb57a..a1bc75b 100755 --- a/tools/miaou-create +++ b/tools/miaou-create @@ -73,17 +73,6 @@ function mount_miaou_bash { incus $optional_project config device add $target MIAOU-BASH disk source=$MIAOU_BASH_DIR path=/opt/miaou-bash readonly=true | grep -q 'Device MIAOU-BASH added' } -function infocmp_xterm_ghostty { - ! command -v ghostty >/dev/null && return - - local target="$1" - local optional_project=${2:-} - [[ -n $optional_project ]] && optional_project="--project $optional_project" - - echo "export GHOSTTY infocmp from host to container" - infocmp -x xterm-ghostty | incus exec $optional_project $target -- tic -x - 2>/dev/null -} - function assign_host_zoneinfo { local target="$1" local optional_project=${2:-} @@ -113,12 +102,19 @@ function refresh_template { if incus --project "$PROJECT_SANDBOX" info "$TEMPLATE_SANDBOX" | grep '^Status: STOPPED'; then incus --project "$PROJECT_SANDBOX" start "$TEMPLATE_SANDBOX" fi - incus --project "$PROJECT_SANDBOX" exec "$TEMPLATE_SANDBOX" -- bash </dev/null && infocmp_xterm_ghostty "$TEMPLATE_SANDBOX" "$PROJECT_SANDBOX" refresh_template echo "template:"$TEMPLATE_SANDBOX" from project:$PROJECT_SANDBOX built successfully!" } diff --git a/tools/miaou-destroy b/tools/miaou-destroy index 11f03fd..7caff5a 100755 --- a/tools/miaou-destroy +++ b/tools/miaou-destroy @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env miaou-bash # CONSTANTS @@ -11,55 +11,53 @@ FORCE=false # FUNCTIONS function usage { - echo "$(basename "$0") ... [--yes|-y] [--force|-f]" + echo "$(basename "$0") ... [--yes|-y] [--force|-f]" } function parse_options { - while [[ $# -gt 0 ]]; do - case "$1" in - --help | -h) - usage && exit 0 - ;; - --yes | -y) - YES=true - ;; - --force | -f) - FORCE=true - ;; - -*) - echo >&2 "Error: unknown option: $1" && usage && exit 2 - ;; - *) - CONTAINERS+=("$1") - ;; - esac - shift - done + while [[ $# -gt 0 ]]; do + case "$1" in + --help | -h) + usage && exit 0 + ;; + --yes | -y) + YES=true + ;; + --force | -f) + FORCE=true + ;; + -*) + echo >&2 "Error: unknown option: $1" && usage && exit 2 + ;; + *) + CONTAINERS+=("$1") + ;; + esac + shift + done - [[ ${#CONTAINERS[@]} == 0 ]] && usage && exit 1 || true + [[ ${#CONTAINERS[@]} == 0 ]] && usage && exit 1 || true } function force_option { - [[ $FORCE == false ]] && return - echo '--force ' + [[ $FORCE == false ]] && return + echo '--force ' } function destroy { - if [[ $YES == false ]]; then - local message count - count=${#CONTAINERS[@]} - message="you are about to destroy $(_pluralize_simple $count container): ${CONTAINERS[*]}" - _confirm_destructive "$message" $(force_option) - fi - incus delete "${CONTAINERS[@]}" $(force_option) + if [[ $YES == false ]]; then + local message count + count=${#CONTAINERS[@]} + message="you are about to destroy $(_pluralize_simple $count container): ${CONTAINERS[*]}" + _confirm_destructive "$message" $(force_option) + fi + incus delete "${CONTAINERS[@]}" $(force_option) } # MAIN -set -Eueo pipefail - # shellcheck source=/opt/miaou-bash/lib/functions.bash -source "$MIAOU_BASH_DIR/lib/functions.bash" +source "$MIAOU_BASH_DIR"/lib/functions.bash _flatten_short_options ARGS parse_options "${ARGS[@]}" diff --git a/tools/miaou-exec b/tools/miaou-exec index 227c2e7..d41ccef 100755 --- a/tools/miaou-exec +++ b/tools/miaou-exec @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env miaou-bash # CONSTANTS @@ -9,49 +9,48 @@ COMMAND_LINE=() # FUNCTIONS function usage { - echo Usage: - echo -e "\t$(basename "$0") [--] " - echo - echo "Examples:" - echo -e "\t$(basename "$0") container1 uptime" - echo -e "\t$(basename "$0") container1 -- ls -la" - echo -e "\t$(basename "$0") container1 -- bash < [--] " + echo + echo "Examples:" + echo -e "\t$(basename "$0") container1 uptime" + echo -e "\t$(basename "$0") container1 -- ls -la" + echo -e "\t$(basename "$0") container1 -- bash <&2 "Unknown option: $1" && usage && exit 2 - ;; - *) - [[ -z $CONTAINER ]] && CONTAINER=$1 || COMMAND_LINE+=("$1") - ;; - esac - shift 1 - done - - # echo "CONTAINER=$CONTAINER" - # echo "COMMAND_LINE=(${COMMAND_LINE[@]})" - - ([[ -z $CONTAINER ]] || [[ ${#COMMAND_LINE[@]} == 0 ]]) && usage && exit 1 || true + while [[ $# -gt 0 ]]; do + case "$1" in + --help | -h) + usage && exit 0 + ;; + --) + shift 1 + COMMAND_LINE+=("$@") + break + ;; + -*) + # options if any + echo >&2 "Unknown option: $1" && usage && exit 2 + ;; + *) + [[ -z $CONTAINER ]] && CONTAINER=$1 || COMMAND_LINE+=("$1") + ;; + esac + shift 1 + done + + # echo "CONTAINER=$CONTAINER" + # echo "COMMAND_LINE=(${COMMAND_LINE[@]})" + + ([[ -z $CONTAINER ]] || [[ ${#COMMAND_LINE[@]} == 0 ]]) && usage && exit 1 || true } function exec { - incus exec "$CONTAINER" -- "${COMMAND_LINE[@]}" + incus exec "$CONTAINER" -- "${COMMAND_LINE[@]}" } # MAIN -set -Eue parse_options "$@" exec diff --git a/tools/miaou-ls b/tools/miaou-ls index 9fe3f8b..07f8c47 100755 --- a/tools/miaou-ls +++ b/tools/miaou-ls @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env miaou-bash # CONSTANTS @@ -8,33 +8,33 @@ TYPE=container # FUNCTIONS function usage { - echo "$(basename "$0") [CONTAINER_PREFIX] < --vm >" + echo "$(basename "$0") [CONTAINER_PREFIX] < --vm >" } function parse_options { - while [[ $# -gt 0 ]]; do - case "$1" in - --help | -h) - usage && exit 0 - ;; - --vm) - TYPE='VIRTUAL-MACHINE' - ;; - *) - if [[ -z $CONTAINER_PREFIX ]]; then - CONTAINER_PREFIX=$1 - else - echo >&2 "Unknown option: $1" && usage && exit 2 - fi - ;; - esac - - shift 1 # Move to the next argument - done + while [[ $# -gt 0 ]]; do + case "$1" in + --help | -h) + usage && exit 0 + ;; + --vm) + TYPE='VIRTUAL-MACHINE' + ;; + *) + if [[ -z $CONTAINER_PREFIX ]]; then + CONTAINER_PREFIX=$1 + else + echo >&2 "Unknown option: $1" && usage && exit 2 + fi + ;; + esac + + shift 1 # Move to the next argument + done } function ls { - incus list -c ns4 -f compact,noheader "$CONTAINER_PREFIX" type=$TYPE + incus list -c ns4 -f compact,noheader "$CONTAINER_PREFIX" type=$TYPE } # MAIN diff --git a/tools/miaou-pull b/tools/miaou-pull index 0bdbfc1..d5e5077 100755 --- a/tools/miaou-pull +++ b/tools/miaou-pull @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env miaou-bash # CONSTANTS @@ -10,46 +10,45 @@ DESTINATION_FOLDER='' # FUNCTIONS function usage { - echo "$(basename "$0") " + echo "$(basename "$0") " } function parse_options { - while [[ $# -gt 0 ]]; do - case "$1" in - --help | -h) - usage && exit 0 - ;; - *) - if [[ -z $CONTAINER ]]; then - CONTAINER=$1 - elif [[ -z $SOURCE_FILE ]]; then - SOURCE_FILE=$1 - elif [[ -z $DESTINATION_FOLDER ]]; then - DESTINATION_FOLDER=$1 - else - echo >&2 "Unknown option: $1" && usage && exit 2 - fi - ;; - esac - - shift 1 # Move to the next argument - done - - [[ -n $CONTAINER ]] || [[ -n $SOURCE_FILE ]] || [[ -n $DESTINATION_FOLDER ]] || (usage && exit 1) + while [[ $# -gt 0 ]]; do + case "$1" in + --help | -h) + usage && exit 0 + ;; + *) + if [[ -z $CONTAINER ]]; then + CONTAINER=$1 + elif [[ -z $SOURCE_FILE ]]; then + SOURCE_FILE=$1 + elif [[ -z $DESTINATION_FOLDER ]]; then + DESTINATION_FOLDER=$1 + else + echo >&2 "Unknown option: $1" && usage && exit 2 + fi + ;; + esac + + shift 1 # Move to the next argument + done + + [[ -n $CONTAINER ]] || [[ -n $SOURCE_FILE ]] || [[ -n $DESTINATION_FOLDER ]] || (usage && exit 1) } function normalize_source_file { - local directory=$(dirname $SOURCE_FILE) - [[ $directory =~ ^\.$ ]] && SOURCE_FILE="/root/$SOURCE_FILE" + local directory=$(dirname $SOURCE_FILE) + [[ $directory =~ ^\.$ ]] && SOURCE_FILE="/root/$SOURCE_FILE" } function copy { - incus file pull "$CONTAINER/$SOURCE_FILE" "$DESTINATION_FOLDER" --create-dirs + incus file pull "$CONTAINER/$SOURCE_FILE" "$DESTINATION_FOLDER" --create-dirs } # MAIN -set -Eue parse_options $* normalize_source_file copy diff --git a/tools/miaou-push b/tools/miaou-push index c9d873f..3a300ff 100755 --- a/tools/miaou-push +++ b/tools/miaou-push @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env miaou-bash # CONSTANTS @@ -10,40 +10,39 @@ DESTINATION_FOLDER='' # FUNCTIONS function usage { - echo "$(basename "$0") " + echo "$(basename "$0") " } function parse_options { - while [[ $# -gt 0 ]]; do - case "$1" in - --help | -h) - usage && exit 0 - ;; - *) - if [[ -z $CONTAINER ]]; then - CONTAINER=$1 - elif [[ -z $SOURCE_FILE ]]; then - SOURCE_FILE=$1 - elif [[ -z $DESTINATION_FOLDER ]]; then - DESTINATION_FOLDER=$1 - else - echo >&2 "Unknown option: $1" && usage && exit 2 - fi - ;; - esac - - shift 1 # Move to the next argument - done - - [[ -n $CONTAINER ]] || [[ -n $SOURCE_FILE ]] || [[ -n $DESTINATION_FOLDER ]] || (usage && exit 1) + while [[ $# -gt 0 ]]; do + case "$1" in + --help | -h) + usage && exit 0 + ;; + *) + if [[ -z $CONTAINER ]]; then + CONTAINER=$1 + elif [[ -z $SOURCE_FILE ]]; then + SOURCE_FILE=$1 + elif [[ -z $DESTINATION_FOLDER ]]; then + DESTINATION_FOLDER=$1 + else + echo >&2 "Unknown option: $1" && usage && exit 2 + fi + ;; + esac + + shift 1 # Move to the next argument + done + + [[ -n $CONTAINER ]] || [[ -n $SOURCE_FILE ]] || [[ -n $DESTINATION_FOLDER ]] || (usage && exit 1) } function copy { - incus file push "$SOURCE_FILE" "$CONTAINER/$DESTINATION_FOLDER" --uid 0 --gid 0 --create-dirs + incus file push "$SOURCE_FILE" "$CONTAINER/$DESTINATION_FOLDER" --uid 0 --gid 0 --create-dirs } # MAIN -set -Eue -parse_options $* +parse_options "$@" copy diff --git a/tools/miaou-recipe b/tools/miaou-recipe index 67b57b3..bd1d82a 100755 --- a/tools/miaou-recipe +++ b/tools/miaou-recipe @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env miaou-bash # CONSTANTS @@ -12,59 +12,59 @@ RECIPE_ARGS=() # FUNCTIONS function usage { - 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" + 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 { - while [[ $# -gt 0 ]]; do - case "$1" in - --help | -h) - usage && exit 0 - ;; - --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 - elif [[ -z $SCRIPT ]]; then - SCRIPT=$1 - else - echo >&2 "Unknown option: $1" && usage && exit 2 - fi - ;; - esac + while [[ $# -gt 0 ]]; do + case "$1" in + --help | -h) + usage && exit 0 + ;; + --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 + elif [[ -z $SCRIPT ]]; then + SCRIPT=$1 + else + echo >&2 "Unknown option: $1" && usage && exit 2 + fi + ;; + esac - shift 1 # Move to the next argument - done - [[ -n $CONTAINER ]] && [[ -n $SCRIPT ]] || (usage && exit 1) + shift 1 # Move to the next argument + done + [[ -n $CONTAINER ]] && [[ -n $SCRIPT ]] || (usage && exit 1) } function debug_option { - [[ $DEBUG == 'true' ]] && echo "-x" || true + [[ $DEBUG == 'true' ]] && echo "-x" || true } function recipe { - [[ ! -f $SCRIPT ]] && echo >&2 "Script not found: $SCRIPT" && exit 3 - local recipe_name=$(basename "$SCRIPT") - cat "$SCRIPT" | incus exec "$CONTAINER" -- env RECIPE_NAME="$recipe_name" bash $(debug_option) -s -- "${RECIPE_ARGS[@]}" + [[ ! -f $SCRIPT ]] && echo >&2 "Script not found: $SCRIPT" && exit 3 + local recipe_name=$(basename "$SCRIPT") + cat "$SCRIPT" | incus exec "$CONTAINER" -- env RECIPE_NAME="$recipe_name" bash $(debug_option) -s -- "${RECIPE_ARGS[@]}" } function show_success { - echo "Recipe <$(basename "$SCRIPT")> successfully performed on container <$CONTAINER>" + echo "Recipe <$(basename "$SCRIPT")> successfully performed on container <$CONTAINER>" } # MAIN diff --git a/tools/miaou-start b/tools/miaou-start index 1136ae6..688e15e 100755 --- a/tools/miaou-start +++ b/tools/miaou-start @@ -1,43 +1,41 @@ -#!/usr/bin/env bash +#!/usr/bin/env miaou-bash # CONSTANTS -BASEDIR=$(dirname "$0") CONTAINERS=() USER= # FUNCTIONS function usage { - echo "$(basename "$0") ..." + echo "$(basename "$0") ..." } function parse_options { - while [[ $# -gt 0 ]]; do - case "$1" in - --help | -h) - usage && exit 0 - ;; - -*) - echo >&2 "Error: unknown option: $1" && usage && exit 2 - ;; - *) - CONTAINERS+=("$1") - ;; - esac - - shift 1 # Move to the next argument - done - - [[ ${#CONTAINERS[@]} == 0 ]] && usage && exit 1 || true + while [[ $# -gt 0 ]]; do + case "$1" in + --help | -h) + usage && exit 0 + ;; + -*) + echo >&2 "Error: unknown option: $1" && usage && exit 2 + ;; + *) + CONTAINERS+=("$1") + ;; + esac + + shift 1 # Move to the next argument + done + + [[ ${#CONTAINERS[@]} == 0 ]] && usage && exit 1 || true } function start { - incus start "${CONTAINERS[@]}" + incus start "${CONTAINERS[@]}" } # MAIN -set -Eue parse_options $* start diff --git a/tools/miaou-stop b/tools/miaou-stop index add611c..079e9b1 100755 --- a/tools/miaou-stop +++ b/tools/miaou-stop @@ -1,42 +1,40 @@ -#!/usr/bin/env bash +#!/usr/bin/env miaou-bash # CONSTANTS -BASEDIR=$(dirname "$0") CONTAINERS=() # FUNCTIONS function usage { - echo "$(basename "$0") ..." + echo "$(basename "$0") ..." } function parse_options { - while [[ $# -gt 0 ]]; do - case "$1" in - --help | -h) - usage && exit 0 - ;; - -*) - echo >&2 "Error: unknown option: $1" && usage && exit 2 - ;; - *) - CONTAINERS+=("$1") - ;; - esac - - shift 1 # Move to the next argument - done - - [[ ${#CONTAINERS[@]} == 0 ]] && usage && exit 1 || true + while [[ $# -gt 0 ]]; do + case "$1" in + --help | -h) + usage && exit 0 + ;; + -*) + echo >&2 "Error: unknown option: $1" && usage && exit 2 + ;; + *) + CONTAINERS+=("$1") + ;; + esac + + shift 1 # Move to the next argument + done + + [[ ${#CONTAINERS[@]} == 0 ]] && usage && exit 1 || true } function stop { - incus stop "${CONTAINERS[@]}" + incus stop "${CONTAINERS[@]}" } # MAIN -set -Eue -parse_options $* +parse_options "$@" stop