You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.1 KiB

#!/usr/bin/env bash
# CONSTANTS
BASEDIR=$(dirname "$0")
DEBIAN='images:debian/13'
APT_ARCHIVES=/var/cache/apt/archives
CONTAINER=''
# FUNCTIONS
function usage {
echo "$(basename "$0") <CONTAINER_NAME>"
}
function parse_options {
while [[ $# -gt 0 ]]; do
case "$1" in
--help | -h)
usage && exit 0
;;
*)
if [[ -z $CONTAINER ]]; then
CONTAINER=$1
else
echo >&2 "Unknown option: $1" && usage && exit 2
fi
;;
esac
shift 1 # Move to the next argument
done
[[ -n $CONTAINER ]] || (usage && exit 1)
}
# cold changes
function before_start {
if [[ -v MIAOU_BASH_DIR ]]; then
incus config device add $CONTAINER MIAOU-BASH disk source=$MIAOU_BASH_DIR path=/opt/miaou-bash readonly=true | grep -q 'Device MIAOU-BASH added'
incus config set $CONTAINER environment.PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/miaou-bash/tools
else
echo >&2 "Warn: variable MIAOU_BASH_DIR missing!"
fi
incus config device add $CONTAINER MIAOU-HOSTED-ARCHIVES disk source=$APT_ARCHIVES path=/var/cache/apt-hosted-archives readonly=true | grep -q 'Device MIAOU-HOSTED-ARCHIVES added'
incus file delete $CONTAINER/etc/apt/sources.list
incus file push --uid 0 --gid 0 --mode 644 --create-dirs /etc/apt/sources.list.d/debian.sources $CONTAINER/etc/apt/sources.list.d/debian.sources
cat << EOF | incus file push --uid 0 --gid 0 --mode 644 --create-dirs - $CONTAINER/etc/systemd/resolved.conf.d/10-disable-ipv4-listener.conf
[Resolve]
LLMNR=no
DNSStubListener=no
EOF
}
# hot changes
function after_start {
# FIXME: should be done in some other way
incus exec "$CONTAINER" -- apt-get update
incus exec "$CONTAINER" -- apt-get install -y curl
incus exec "$CONTAINER" -- /opt/miaou-bash/install.sh
local domain=$(incus network get incusbr0 dns.domain)
domain=${domain:-incus}
cat << EOF | incus file push --uid 0 --gid 0 --mode 644 --create-dirs - $CONTAINER/etc/hosts
127.0.1.1 $CONTAINER.$domain $CONTAINER
127.0.0.1 localhost
EOF
}
function create {
incus create $DEBIAN $CONTAINER
before_start
incus start $CONTAINER
after_start
}
# MAIN
set -Eue
parse_options $*
create
echo Success