|
|
@ -1,4 +1,4 @@ |
|
|
#!/usr/bin/env bash |
|
|
|
|
|
|
|
|
#!/usr/bin/env miaou-bash |
|
|
|
|
|
|
|
|
# CONSTANTS |
|
|
# CONSTANTS |
|
|
|
|
|
|
|
|
@ -9,12 +9,13 @@ PROJECT_SANDBOX=sandbox |
|
|
TEMPLATE_SANDBOX=miaou-debian13-template |
|
|
TEMPLATE_SANDBOX=miaou-debian13-template |
|
|
TEMPLATE_REFRESH_DELAY="7 days" |
|
|
TEMPLATE_REFRESH_DELAY="7 days" |
|
|
|
|
|
|
|
|
|
|
|
BARE_MINIMAL=false |
|
|
CONTAINER= |
|
|
CONTAINER= |
|
|
|
|
|
|
|
|
# FUNCTIONS |
|
|
# FUNCTIONS |
|
|
|
|
|
|
|
|
function usage { |
|
|
function usage { |
|
|
echo "$(basename "$0") <CONTAINER_NAME>" |
|
|
|
|
|
|
|
|
echo "$(basename "$0") <CONTAINER_NAME> [--bare-minimal]" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function humanize_ago { |
|
|
function humanize_ago { |
|
|
@ -45,6 +46,9 @@ function parse_options { |
|
|
--help | -h) |
|
|
--help | -h) |
|
|
usage && exit 0 |
|
|
usage && exit 0 |
|
|
;; |
|
|
;; |
|
|
|
|
|
--bare-minimal) |
|
|
|
|
|
BARE_MINIMAL=true |
|
|
|
|
|
;; |
|
|
*) |
|
|
*) |
|
|
if [[ -z $CONTAINER ]]; then |
|
|
if [[ -z $CONTAINER ]]; then |
|
|
CONTAINER=$1 |
|
|
CONTAINER=$1 |
|
|
@ -78,6 +82,23 @@ function infocmp_xterm_ghostty { |
|
|
infocmp -x xterm-ghostty | incus exec $optional_project $target -- tic -x - 2>/dev/null |
|
|
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:-} |
|
|
|
|
|
[[ -n $optional_project ]] && optional_project="--project $optional_project" |
|
|
|
|
|
|
|
|
|
|
|
local host_zoneinfo |
|
|
|
|
|
host_zoneinfo=$(realpath /etc/localtime) |
|
|
|
|
|
echo "assign ZONEINFO from host: $host_zoneinfo" |
|
|
|
|
|
|
|
|
|
|
|
# TODO:optional_project might be an array, "${optional_project[@]}" |
|
|
|
|
|
incus exec $optional_project "$target" -- bash <<-EOF |
|
|
|
|
|
ln -fs "$host_zoneinfo" /etc/localtime |
|
|
|
|
|
dpkg-reconfigure -f noninteractive tzdata |
|
|
|
|
|
EOF |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function build_sandbox_project { |
|
|
function build_sandbox_project { |
|
|
if ! incus project show $PROJECT_SANDBOX >/dev/null; then |
|
|
if ! incus project show $PROJECT_SANDBOX >/dev/null; then |
|
|
incus project create $PROJECT_SANDBOX |
|
|
incus project create $PROJECT_SANDBOX |
|
|
@ -97,7 +118,9 @@ function refresh_template { |
|
|
/opt/miaou-bash/install.sh 2>/dev/null |
|
|
/opt/miaou-bash/install.sh 2>/dev/null |
|
|
EOF |
|
|
EOF |
|
|
incus --project "$PROJECT_SANDBOX" stop "$TEMPLATE_SANDBOX" |
|
|
incus --project "$PROJECT_SANDBOX" stop "$TEMPLATE_SANDBOX" |
|
|
local image_date=$(incus --project "$PROJECT_SANDBOX" list "$TEMPLATE_SANDBOX" -f compact,noheader -cl) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local image_date |
|
|
|
|
|
image_date=$(incus --project "$PROJECT_SANDBOX" list "$TEMPLATE_SANDBOX" -f compact,noheader -cl) |
|
|
echo "template refreshed at: $image_date" |
|
|
echo "template refreshed at: $image_date" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -119,6 +142,8 @@ EOF |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function prepare_template_for_quick_creation { |
|
|
function prepare_template_for_quick_creation { |
|
|
|
|
|
[[ $BARE_MINIMAL == true ]] && return |
|
|
|
|
|
|
|
|
local image_date=$(incus list "$TEMPLATE_SANDBOX" -f compact,noheader -cl --project "$PROJECT_SANDBOX") |
|
|
local image_date=$(incus list "$TEMPLATE_SANDBOX" -f compact,noheader -cl --project "$PROJECT_SANDBOX") |
|
|
if [[ -z $image_date ]]; then |
|
|
if [[ -z $image_date ]]; then |
|
|
build_template_from_scratch |
|
|
build_template_from_scratch |
|
|
@ -153,6 +178,12 @@ function assert_not_sandboxing { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function create { |
|
|
function create { |
|
|
|
|
|
if [[ "$BARE_MINIMAL" == true ]]; then |
|
|
|
|
|
incus launch "$MIAOU_IMAGE" "$CONTAINER" |
|
|
|
|
|
command -v ghostty >/dev/null && infocmp_xterm_ghostty "$CONTAINER" |
|
|
|
|
|
|
|
|
|
|
|
assign_host_zoneinfo "$CONTAINER" |
|
|
|
|
|
else |
|
|
if incus --project "$PROJECT_SANDBOX" info "$TEMPLATE_SANDBOX" | grep '^Status: RUNNING'; then |
|
|
if incus --project "$PROJECT_SANDBOX" info "$TEMPLATE_SANDBOX" | grep '^Status: RUNNING'; then |
|
|
incus --project "$PROJECT_SANDBOX" stop "$TEMPLATE_SANDBOX" |
|
|
incus --project "$PROJECT_SANDBOX" stop "$TEMPLATE_SANDBOX" |
|
|
fi |
|
|
fi |
|
|
@ -160,6 +191,7 @@ function create { |
|
|
incus file delete "$CONTAINER/etc/machine-id" |
|
|
incus file delete "$CONTAINER/etc/machine-id" |
|
|
incus config unset "$CONTAINER" volatile.eth0.hwaddr |
|
|
incus config unset "$CONTAINER" volatile.eth0.hwaddr |
|
|
incus start "$CONTAINER" |
|
|
incus start "$CONTAINER" |
|
|
|
|
|
fi |
|
|
customize_host "$CONTAINER" |
|
|
customize_host "$CONTAINER" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|