Browse Source

recipe doesnt work anymore

main
pvincent 2 weeks ago
parent
commit
1f04e2ca7b
  1. 29
      tools/miaou-create
  2. 68
      tools/miaou-destroy
  3. 69
      tools/miaou-exec
  4. 44
      tools/miaou-ls
  5. 55
      tools/miaou-pull
  6. 53
      tools/miaou-push
  7. 82
      tools/miaou-recipe
  8. 42
      tools/miaou-start
  9. 44
      tools/miaou-stop

29
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' 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 { function assign_host_zoneinfo {
local target="$1" local target="$1"
local optional_project=${2:-} local optional_project=${2:-}
@ -113,12 +102,19 @@ function refresh_template {
if incus --project "$PROJECT_SANDBOX" info "$TEMPLATE_SANDBOX" | grep '^Status: STOPPED'; then if incus --project "$PROJECT_SANDBOX" info "$TEMPLATE_SANDBOX" | grep '^Status: STOPPED'; then
incus --project "$PROJECT_SANDBOX" start "$TEMPLATE_SANDBOX" incus --project "$PROJECT_SANDBOX" start "$TEMPLATE_SANDBOX"
fi fi
incus --project "$PROJECT_SANDBOX" exec "$TEMPLATE_SANDBOX" -- bash <<EOF
apt-get update
apt-get dist-upgrade -y
apt-get install -y curl
/opt/miaou-bash/install.sh
script=$(
cat <<-EOF
apt-get update
apt-get dist-upgrade -y
apt-get install -y curl
MIAOU_BASH_DIR=/opt/miaou-bash
export MIAOU_BASH_DIR
"\$MIAOU_BASH_DIR"/bin/miaou-bash "\$MIAOU_BASH_DIR"/lib/init.bash
EOF EOF
)
incus --project "$PROJECT_SANDBOX" exec "$TEMPLATE_SANDBOX" -- bash -c "$script"
incus --project "$PROJECT_SANDBOX" stop "$TEMPLATE_SANDBOX" incus --project "$PROJECT_SANDBOX" stop "$TEMPLATE_SANDBOX"
local image_date local image_date
@ -138,7 +134,6 @@ LLMNR=no
DNSStubListener=no DNSStubListener=no
EOF EOF
mount_miaou_bash "$TEMPLATE_SANDBOX" "$PROJECT_SANDBOX" mount_miaou_bash "$TEMPLATE_SANDBOX" "$PROJECT_SANDBOX"
command -v ghostty >/dev/null && infocmp_xterm_ghostty "$TEMPLATE_SANDBOX" "$PROJECT_SANDBOX"
refresh_template refresh_template
echo "template:"$TEMPLATE_SANDBOX" from project:$PROJECT_SANDBOX built successfully!" echo "template:"$TEMPLATE_SANDBOX" from project:$PROJECT_SANDBOX built successfully!"
} }

68
tools/miaou-destroy

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env miaou-bash
# CONSTANTS # CONSTANTS
@ -11,55 +11,53 @@ FORCE=false
# FUNCTIONS # FUNCTIONS
function usage { function usage {
echo "$(basename "$0") <CONTAINER_NAME>... [--yes|-y] [--force|-f]"
echo "$(basename "$0") <CONTAINER_NAME>... [--yes|-y] [--force|-f]"
} }
function parse_options { 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 { function force_option {
[[ $FORCE == false ]] && return
echo '--force '
[[ $FORCE == false ]] && return
echo '--force '
} }
function destroy { 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 # MAIN
set -Eueo pipefail
# shellcheck source=/opt/miaou-bash/lib/functions.bash # 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 _flatten_short_options ARGS
parse_options "${ARGS[@]}" parse_options "${ARGS[@]}"

69
tools/miaou-exec

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env miaou-bash
# CONSTANTS # CONSTANTS
@ -9,49 +9,48 @@ COMMAND_LINE=()
# FUNCTIONS # FUNCTIONS
function usage { function usage {
echo Usage:
echo -e "\t$(basename "$0") <CONTAINER_NAME> [--] <COMMAND>"
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 <<EOF\n\t\tls -l\n\t\tuptime\n\tEOF"
echo Usage:
echo -e "\t$(basename "$0") <CONTAINER_NAME> [--] <COMMAND>"
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 <<EOF\n\t\tls -l\n\t\tuptime\n\tEOF"
} }
function parse_options { function parse_options {
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
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 { function exec {
incus exec "$CONTAINER" -- "${COMMAND_LINE[@]}"
incus exec "$CONTAINER" -- "${COMMAND_LINE[@]}"
} }
# MAIN # MAIN
set -Eue
parse_options "$@" parse_options "$@"
exec exec

44
tools/miaou-ls

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env miaou-bash
# CONSTANTS # CONSTANTS
@ -8,33 +8,33 @@ TYPE=container
# FUNCTIONS # FUNCTIONS
function usage { function usage {
echo "$(basename "$0") [CONTAINER_PREFIX] < --vm >"
echo "$(basename "$0") [CONTAINER_PREFIX] < --vm >"
} }
function parse_options { 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 { 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 # MAIN

55
tools/miaou-pull

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env miaou-bash
# CONSTANTS # CONSTANTS
@ -10,46 +10,45 @@ DESTINATION_FOLDER=''
# FUNCTIONS # FUNCTIONS
function usage { function usage {
echo "$(basename "$0") <CONTAINER_NAME> <SOURCE_FILE_FROM_CONTAINER> <DESTINATION_FOLDER_TO_HOST>"
echo "$(basename "$0") <CONTAINER_NAME> <SOURCE_FILE_FROM_CONTAINER> <DESTINATION_FOLDER_TO_HOST>"
} }
function parse_options { 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 { 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 { function copy {
incus file pull "$CONTAINER/$SOURCE_FILE" "$DESTINATION_FOLDER" --create-dirs
incus file pull "$CONTAINER/$SOURCE_FILE" "$DESTINATION_FOLDER" --create-dirs
} }
# MAIN # MAIN
set -Eue
parse_options $* parse_options $*
normalize_source_file normalize_source_file
copy copy

53
tools/miaou-push

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env miaou-bash
# CONSTANTS # CONSTANTS
@ -10,40 +10,39 @@ DESTINATION_FOLDER=''
# FUNCTIONS # FUNCTIONS
function usage { function usage {
echo "$(basename "$0") <CONTAINER_NAME> <SOURCE_FILE_FROM_HOST> <DESTINATION_FOLDER_TO_CONTAINER>"
echo "$(basename "$0") <CONTAINER_NAME> <SOURCE_FILE_FROM_HOST> <DESTINATION_FOLDER_TO_CONTAINER>"
} }
function parse_options { 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 { 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 # MAIN
set -Eue
parse_options $*
parse_options "$@"
copy copy

82
tools/miaou-recipe

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env miaou-bash
# CONSTANTS # CONSTANTS
@ -12,59 +12,59 @@ RECIPE_ARGS=()
# FUNCTIONS # FUNCTIONS
function usage { 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 { 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 { function debug_option {
[[ $DEBUG == 'true' ]] && echo "-x" || true
[[ $DEBUG == 'true' ]] && echo "-x" || true
} }
function recipe { 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 { function show_success {
echo "Recipe <$(basename "$SCRIPT")> successfully performed on container <$CONTAINER>"
echo "Recipe <$(basename "$SCRIPT")> successfully performed on container <$CONTAINER>"
} }
# MAIN # MAIN

42
tools/miaou-start

@ -1,43 +1,41 @@
#!/usr/bin/env bash
#!/usr/bin/env miaou-bash
# CONSTANTS # CONSTANTS
BASEDIR=$(dirname "$0")
CONTAINERS=() CONTAINERS=()
USER= USER=
# FUNCTIONS # FUNCTIONS
function usage { function usage {
echo "$(basename "$0") <CONTAINER_NAME>..."
echo "$(basename "$0") <CONTAINER_NAME>..."
} }
function parse_options { 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 { function start {
incus start "${CONTAINERS[@]}"
incus start "${CONTAINERS[@]}"
} }
# MAIN # MAIN
set -Eue
parse_options $* parse_options $*
start start

44
tools/miaou-stop

@ -1,42 +1,40 @@
#!/usr/bin/env bash
#!/usr/bin/env miaou-bash
# CONSTANTS # CONSTANTS
BASEDIR=$(dirname "$0")
CONTAINERS=() CONTAINERS=()
# FUNCTIONS # FUNCTIONS
function usage { function usage {
echo "$(basename "$0") <CONTAINER_NAME>..."
echo "$(basename "$0") <CONTAINER_NAME>..."
} }
function parse_options { 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 { function stop {
incus stop "${CONTAINERS[@]}"
incus stop "${CONTAINERS[@]}"
} }
# MAIN # MAIN
set -Eue
parse_options $*
parse_options "$@"
stop stop
Loading…
Cancel
Save