|
|
@ -32,7 +32,7 @@ function prepare_lxd { |
|
|
|
echo "define lxd and assign to user <$USER>" |
|
|
|
sudo groupadd --force "$NEW_GROUP" |
|
|
|
sudo usermod --append --groups "$NEW_GROUP" "$(whoami)" |
|
|
|
exec sg "$NEW_GROUP" "exec '$0' $(printf "'%s' " SESSION_RELOAD_REQUIRED "$@")" |
|
|
|
exec sg "$NEW_GROUP" exec "$0 $TARGET SESSION_RELOAD_REQUIRED $@" |
|
|
|
# no further processing because exec has been called! |
|
|
|
else |
|
|
|
echo "user <$USER> already belongs to group <lxd>!" |
|
|
@ -40,75 +40,65 @@ function prepare_lxd { |
|
|
|
|
|
|
|
sudo /opt/miaou-bash/tools/idem_apt_install lxd btrfs-progs |
|
|
|
|
|
|
|
override_lxd_service |
|
|
|
|
|
|
|
# test lxdbr0 |
|
|
|
if ! lxc network info lxdbr0 &>/dev/null; then |
|
|
|
|
|
|
|
echo "bridge <lxdbr0> down, so initialization will use default preseed..." |
|
|
|
sudo lxd init |
|
|
|
# cat <<EOF | sudo lxd init --preseed |
|
|
|
|
|
|
|
# NEW |
|
|
|
# networks: |
|
|
|
# - config: |
|
|
|
# ipv4.address: auto |
|
|
|
# ipv6.address: none |
|
|
|
# description: "" |
|
|
|
# name: lxdbr0 |
|
|
|
# type: "" |
|
|
|
# project: default |
|
|
|
# storage_pools: |
|
|
|
# - config: |
|
|
|
# source: /dev/sda4 |
|
|
|
# description: "" |
|
|
|
# name: default |
|
|
|
# driver: btrfs |
|
|
|
# profiles: |
|
|
|
# - config: {} |
|
|
|
# description: "" |
|
|
|
# devices: |
|
|
|
# eth0: |
|
|
|
# name: eth0 |
|
|
|
# network: lxdbr0 |
|
|
|
# type: nic |
|
|
|
# root: |
|
|
|
# path: / |
|
|
|
# pool: default |
|
|
|
# type: disk |
|
|
|
# name: default |
|
|
|
# projects: [] |
|
|
|
# cluster: null |
|
|
|
|
|
|
|
# OLD |
|
|
|
# networks: |
|
|
|
# - config: |
|
|
|
# ipv4.address: auto |
|
|
|
# ipv6.address: none |
|
|
|
# description: "" |
|
|
|
# name: lxdbr0 |
|
|
|
# type: "" |
|
|
|
# project: default |
|
|
|
# storage_pools: |
|
|
|
# - config: |
|
|
|
# source: /dev/sda4 |
|
|
|
# description: "" |
|
|
|
# name: default |
|
|
|
# driver: btrfs |
|
|
|
# profiles: |
|
|
|
# - config: {} |
|
|
|
# description: "" |
|
|
|
# devices: |
|
|
|
# eth0: |
|
|
|
# name: eth0 |
|
|
|
# network: lxdbr0 |
|
|
|
# type: nic |
|
|
|
# root: |
|
|
|
# path: / |
|
|
|
# pool: default |
|
|
|
# type: disk |
|
|
|
# name: default |
|
|
|
# projects: [] |
|
|
|
# cluster: null |
|
|
|
|
|
|
|
echo OK |
|
|
|
|
|
|
|
empty_block_partition='' |
|
|
|
if lsblk -o NAME,FSTYPE,GROUP --noheadings -p | grep -E ^.─ | grep disk; then |
|
|
|
# FIXME: when nesting no DISK type partition found! |
|
|
|
empty_block_partition=$(lsblk -o NAME,FSTYPE,GROUP --noheadings -p | grep -E ^.─ | grep disk | awk '{if($3=="") print $1}' | cut -d'/' -f3) |
|
|
|
fi |
|
|
|
if [[ -n "$empty_block_partition" ]]; then |
|
|
|
echo "use empty block partition /dev/$empty_block_partition" |
|
|
|
cat <<EOF | sudo lxd init --preseed |
|
|
|
config: {} |
|
|
|
networks: |
|
|
|
- config: |
|
|
|
ipv4.address: auto |
|
|
|
ipv6.address: none |
|
|
|
description: "" |
|
|
|
name: lxdbr0 |
|
|
|
type: "" |
|
|
|
project: default |
|
|
|
storage_pools: |
|
|
|
- config: |
|
|
|
source: /dev/$empty_block_partition |
|
|
|
description: "" |
|
|
|
name: default |
|
|
|
driver: btrfs |
|
|
|
profiles: |
|
|
|
- config: {} |
|
|
|
description: "" |
|
|
|
devices: |
|
|
|
eth0: |
|
|
|
name: eth0 |
|
|
|
network: lxdbr0 |
|
|
|
type: nic |
|
|
|
root: |
|
|
|
path: / |
|
|
|
pool: default |
|
|
|
type: disk |
|
|
|
name: default |
|
|
|
projects: [] |
|
|
|
cluster: null |
|
|
|
EOF |
|
|
|
echo OK |
|
|
|
else |
|
|
|
echo "use dir partition" |
|
|
|
cat <<EOF | lxd init --preseed |
|
|
|
config: {} |
|
|
|
networks: |
|
|
|
- name: lxdbr0 |
|
|
|
type: bridge |
|
|
|
config: |
|
|
|
ipv4.address: auto |
|
|
|
ipv6.address: none |
|
|
|
EOF |
|
|
|
fi |
|
|
|
else |
|
|
|
echo "bridge <lxdbr0> found implies it has been already initialized!" |
|
|
|
fi |
|
|
@ -118,7 +108,8 @@ function prepare_lxd { |
|
|
|
set_alias 'll' 'list -c ns4mDN' |
|
|
|
|
|
|
|
# test environment container hostname |
|
|
|
local env_container_hostname=$(lxc profile get default environment.container_hostname) |
|
|
|
local env_container_hostname |
|
|
|
env_container_hostname=$(lxc profile get default environment.container_hostname) |
|
|
|
if [[ -z "$env_container_hostname" ]]; then |
|
|
|
env_container_hostname=$(hostname -s) |
|
|
|
if env | grep -q container_hostname; then |
|
|
@ -137,12 +128,6 @@ function prepare_lxd { |
|
|
|
echo -n "subuid, subgid allowing <$(whoami)> ..." |
|
|
|
printf "root:$(id -u):1\n" | sudo tee -a /etc/subuid /etc/subgid |
|
|
|
PREFIX="" echoinfo DONE |
|
|
|
|
|
|
|
# root:1000:1 |
|
|
|
# root:100000:65536 |
|
|
|
# _lxd:100000:65536 |
|
|
|
# <USER>:100000:65536 |
|
|
|
|
|
|
|
else |
|
|
|
echo "subuid, subgid allowing <$(whoami)> already done!" |
|
|
|
fi |
|
|
@ -156,8 +141,8 @@ function prepare_lxd { |
|
|
|
fi |
|
|
|
|
|
|
|
if [[ ! -d "$HOME/LXD/BACKUP" ]]; then |
|
|
|
echo -n "$HOME/LXD/SHARED creating ... " |
|
|
|
mkdir "$HOME/LXD/SHARED" -p |
|
|
|
echo -n "$HOME/LXD/BACKUP creating ... " |
|
|
|
mkdir "$HOME/LXD/BACKUP" -p |
|
|
|
PREFIX="" echoinfo DONE |
|
|
|
else |
|
|
|
echo "folder <$HOME/LXD/BACKUP> already created!" |
|
|
@ -169,11 +154,11 @@ function set_alias { |
|
|
|
local name="$1" |
|
|
|
local command="$2" |
|
|
|
if ! lxc alias list -f csv | grep -q "^$name,"; then |
|
|
|
echo -n "define lxc alias $name ..." |
|
|
|
echo -n "defining new lxc alias <$name> ..." |
|
|
|
lxc alias add "$name" "$command" |
|
|
|
PREFIX="" echoinfo OK |
|
|
|
else |
|
|
|
echo "lxc alias "$name" already defined!" |
|
|
|
echo "lxc alias <$name> already defined!" |
|
|
|
fi |
|
|
|
|
|
|
|
} |
|
|
@ -329,7 +314,7 @@ function extra_dev_desktop { |
|
|
|
: |
|
|
|
} |
|
|
|
|
|
|
|
function override_lxd_service_to_reload_nftables { |
|
|
|
function override_lxd_service { |
|
|
|
local PREFIX="lxd:override" |
|
|
|
|
|
|
|
if [[ ! -d /etc/systemd/system/lxd.service.d ]]; then |
|
|
@ -338,8 +323,10 @@ function override_lxd_service_to_reload_nftables { |
|
|
|
cat <<EOF | sudo tee /etc/systemd/system/lxd.service.d/override.conf |
|
|
|
[Service] |
|
|
|
ExecStartPost=systemctl reload nftables.service |
|
|
|
Environment=LANGUAGE=en:en_US |
|
|
|
EOF |
|
|
|
sudo systemctl daemon-reload |
|
|
|
sudo systemctl restart lxd.service |
|
|
|
PREFIX="" echo "OK" |
|
|
|
else |
|
|
|
echo "lxd service already overridden!" |
|
|
@ -357,9 +344,23 @@ function ask_for_credential { |
|
|
|
echo "successfully checked!" |
|
|
|
} |
|
|
|
|
|
|
|
function preload_bookworm_image { |
|
|
|
local PREFIX="preload:bookworm" |
|
|
|
|
|
|
|
if [[ $(lxc image list debian/12/cloud -f csv | wc -l) -lt 1 ]]; then |
|
|
|
echo -n "downloading images from publc remote, please hold on..." |
|
|
|
lxc image copy images:debian/12/cloud local: --copy-aliases --quiet |
|
|
|
PREFIX="" echoinfo OK |
|
|
|
else |
|
|
|
echo -n "refreshing images from publc remote..." |
|
|
|
lxc image refresh debian/12/cloud --quiet |
|
|
|
PREFIX="" echoinfo DONE |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
|
### MAIN |
|
|
|
|
|
|
|
if [[ "${1:-}" == "SESSION_RELOAD_REQUIRED" ]]; then |
|
|
|
if [[ "${2:-}" == "SESSION_RELOAD_REQUIRED" ]]; then |
|
|
|
SESSION_RELOAD_REQUIRED=true |
|
|
|
shift |
|
|
|
else |
|
|
@ -392,12 +393,11 @@ else |
|
|
|
add_toolbox_sudoers |
|
|
|
prepare_nftables |
|
|
|
prepare_lxd "$@" |
|
|
|
override_lxd_service_to_reload_nftables |
|
|
|
preload_bookworm_image |
|
|
|
miaou_resolver |
|
|
|
miaou_evalfrombashrc |
|
|
|
miaou_configfiles |
|
|
|
ask_for_credential |
|
|
|
prepare_nftables |
|
|
|
opt_link |
|
|
|
extra_dev_desktop |
|
|
|
|
|
|
|