From 42db2ac21b79b6dd4587c02970dc7422c687e608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 15 Mar 2024 15:06:46 +0100 Subject: [PATCH] Use a config file instead of hard coded string --- conf/lxd-preseed.yml | 44 +++++++++++++++++++++++++++ scripts/_common.sh | 71 +++++++------------------------------------- 2 files changed, 54 insertions(+), 61 deletions(-) create mode 100644 conf/lxd-preseed.yml diff --git a/conf/lxd-preseed.yml b/conf/lxd-preseed.yml new file mode 100644 index 0000000..b6ae646 --- /dev/null +++ b/conf/lxd-preseed.yml @@ -0,0 +1,44 @@ +config: + cluster.https_address: __DOMAIN__:8443 + core.https_address: __DOMAIN__:8443 + core.trust_password: __YUNO_PWD__ +networks: +- config: + ipv4.address: 192.168.__LXC_NETWORK__.1/24 + ipv4.nat: "true" + ipv6.address: none + description: "" + name: lxdbr0 + type: bridge + project: default +storage_pools: +- config: + size: __BTRFS_SIZE__GB + source: /var/lib/lxd/disks/local.img + description: "" + name: local + driver: btrfs +profiles: +- config: {} + description: Default LXD profile + devices: + lxdbr0: + nictype: bridged + parent: lxdbr0 + type: nic + root: + path: / + pool: local + type: disk + name: default +projects: +- config: + features.images: "true" + features.networks: "true" + features.profiles: "true" + features.storage.volumes: "true" + description: Default LXD project + name: default +cluster: + server_name: __DOMAIN__ + enabled: true diff --git a/scripts/_common.sh b/scripts/_common.sh index e362c27..7c83742 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -29,7 +29,16 @@ setup_lxd() { ynh_print_info "Configuring lxd..." if [ "$cluster" -eq 1 ]; then - setup_lxd + yunohost firewall allow TCP 8443 + + free_space=$(df --output=avail / | sed 1d) + btrfs_size=$(( free_space * 90 / 100 / 1024 / 1024 )) + lxc_network=$((1 + RANDOM % 254)) + ynh_add_config --template="lxd-preseed.yml" --destination="$install_dir/lxd-preseed.yml" + lxd init --preseed < "$install_dir/lxd-preseed.yml" + rm "$install_dir/lxd-preseed.yml" + + lxc config set core.https_address "[::]" else lxd init --auto # --storage-backend=dir fi @@ -46,66 +55,6 @@ exposed_ports_if_cluster() { fi } -setup_lxd_cluster() { - local free_space=$(df --output=avail / | sed 1d) - local btrfs_size=$(( free_space * 90 / 100 / 1024 / 1024 )) - local lxc_network=$((1 + RANDOM % 254)) - - yunohost firewall allow TCP 8443 - - tmpfile=$(mktemp --suffix=.preseed.yml) - cat >"$tmpfile" <