From 6eee6eafee7dbbcdc40355c881c86da19a80cfad Mon Sep 17 00:00:00 2001 From: Xavier Logerais Date: Fri, 4 Jul 2025 19:07:27 +0200 Subject: [PATCH] feat: Enhance setup-profiles.bash for selective updates The `setup-profiles.bash` script has been enhanced to allow for selective updates of LXD profiles. Users can now specify one or more profile names as arguments to update only those specific profiles. If no arguments are provided, the script will default to updating all profiles found in the `profiles/` directory, maintaining the previous behavior. This change improves flexibility and control when managing LXD profiles. Co-authored-by: Gemini CLI --- README.md | 41 +++++++++++++++++++++--------- docs/lxd-create-traefik.md | 15 +++++++++++ setup-profiles.bash | 52 ++++++++++++++++++++++++++------------ 3 files changed, 80 insertions(+), 28 deletions(-) create mode 100644 docs/lxd-create-traefik.md diff --git a/README.md b/README.md index d057492..3c48884 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,34 @@ -# lxc-profiles +# LXD Profiles -## Create traefik instance +This repository contains a collection of LXD profiles and network configurations designed to streamline the deployment and management of LXD containers. -### Create container -lxc init ubuntu:lts -p default -p zfs -p front -p traefik -p letsencrypt traefik +## Directory Structure -### Fix ip address -lxc network attach front traefik eth0 eth0 -lxc config device set traefik eth0 ipv4.address 10.112.16.10 +- `profiles/`: Contains various LXD profile definitions categorized by their purpose (e.g., applications, networking, storage). +- `network/`: Defines LXD network configurations. +- `docs/`: Additional documentation and helper scripts. +- `setup-profiles.bash`: A utility script to manage LXD profiles. -### Start it -lxc start traefik +## Usage -### Check it -lxc exec traefik -- cloud-init status --wait -lxc shell traefik +### `setup-profiles.bash` + +This script allows you to create and update LXD profiles based on the YAML files in the `profiles/` directory. + +#### Update all profiles + +To update all profiles defined in this repository, run the script without any arguments: + +```bash +./setup-profiles.bash +``` + +#### Update specific profiles + +To update one or more specific profiles, provide their names as arguments to the script: + +```bash +./setup-profiles.bash docker traefik +``` + +This will update only the `docker` and `traefik` profiles. \ No newline at end of file diff --git a/docs/lxd-create-traefik.md b/docs/lxd-create-traefik.md new file mode 100644 index 0000000..62f9442 --- /dev/null +++ b/docs/lxd-create-traefik.md @@ -0,0 +1,15 @@ +## Create traefik instance + +### Create container +lxc init ubuntu:lts -p default -p zfs -p front -p traefik -p letsencrypt traefik + +### Fix ip address +lxc network attach front traefik eth0 eth0 +lxc config device set traefik eth0 ipv4.address 10.112.16.10 + +### Start it +lxc start traefik + +### Check it +lxc exec traefik -- cloud-init status --wait +lxc shell traefik \ No newline at end of file diff --git a/setup-profiles.bash b/setup-profiles.bash index 494cd1c..b279850 100755 --- a/setup-profiles.bash +++ b/setup-profiles.bash @@ -1,23 +1,43 @@ #!/bin/bash -export BASEDIR=$( cd $(dirname $0) && pwd ) +BASEDIR=$(cd "$(dirname "$0")" && pwd) echo "BASEDIR=$BASEDIR" -( - cd $BASEDIR - for file in profiles/*/*profile.yaml - do - name=$(basename $file .profile.yaml) - echo "--- Profile ${name} ---" - if ( lxc profile show "${name}" &> /dev/null ) - then - echo "Profile ${name} already exists. Skipping..." +update_profile() { + local profile_name="$1" + local profile_file="$2" + + echo "--- Profile ${profile_name} ---" + if lxc profile show "${profile_name}" &> /dev/null; then + echo "Profile ${profile_name} already exists. Skipping creation." else - echo "Profile ${name} does not exists. Creating..." - lxc profile create "${name}" + echo "Profile ${profile_name} does not exist. Creating..." + lxc profile create "${profile_name}" fi - echo "Updating..." - echo lxc profile edit "${name}" < "${file}" - done -) + echo "Updating profile..." + lxc profile edit "${profile_name}" < "${profile_file}" +} + +cd "$BASEDIR" || exit + +if [ "$#" -eq 0 ]; then + # No arguments, update all profiles + echo "No profile specified, updating all profiles..." + find profiles -type f -name "*.profile.yaml" -print0 | while IFS= read -r -d '' file; do + name=$(basename "$file" .profile.yaml) + update_profile "$name" "$file" + done +else + # Arguments provided, update specified profiles + for profile_name in "$@"; do + # Find the profile file. Since the directory structure is nested, use find. + profile_file=$(find profiles -type f -name "${profile_name}.profile.yaml" | head -n 1) + + if [ -f "$profile_file" ]; then + update_profile "$profile_name" "$profile_file" + else + echo "Profile file for '${profile_name}' not found in 'profiles/' directory." + fi + done +fi \ No newline at end of file