feat: Enhance setup-profiles.bash

The `setup-profiles.bash` script has been significantly enhanced to:
- Include a prerequisite check for `yq`.
- Extract the LXD profile name directly from the YAML file using `yq`.

The README.md has been updated to reflect the new usage of `setup-profiles.bash`,
which now accepts file paths as arguments for specific profile updates.

Co-authored-by: Gemini CLI <gemini-cli@google.com>
This commit is contained in:
xavierandGemini CLI committed 2025-07-04 19:30:52 +02:00
1 parent 6eee6eafee
commit 91a4ef1c1a
2 files changed
+26 -16

No files matched your search

+2 -2
View File
@@ -25,10 +25,10 @@ To update all profiles defined in this repository, run the script without any ar
#### Update specific profiles #### Update specific profiles
To update one or more specific profiles, provide their names as arguments to the script: To update one or more specific profiles, provide their file paths as arguments to the script:
```bash ```bash
./setup-profiles.bash docker traefik ./setup-profiles.bash profiles/containerization/docker.profile.yaml profiles/applications/traefik.profile.yaml
``` ```
This will update only the `docker` and `traefik` profiles. This will update only the `docker` and `traefik` profiles.
+24 -14
View File
@@ -4,11 +4,25 @@ BASEDIR=$(cd "$(dirname "$0")" && pwd)
echo "BASEDIR=$BASEDIR" echo "BASEDIR=$BASEDIR"
update_profile() { # Prerequisite check for yq
local profile_name="$1" if ! command -v yq &> /dev/null
local profile_file="$2" then
echo "Error: yq is not installed."
echo "Please install yq to use this script. Refer to https://github.com/mikefarah/yq#install for installation methods."
exit 1
fi
echo "--- Profile ${profile_name} ---" update_profile() {
local profile_file="$1"
local profile_name
profile_name=$(yq --expression '.name' "$profile_file")
if [ -z "$profile_name" ]; then
echo "Error: Could not extract profile name from $profile_file. Skipping."
return 1
fi
echo "--- Profile ${profile_name} (from ${profile_file}) ---"
if lxc profile show "${profile_name}" &> /dev/null; then if lxc profile show "${profile_name}" &> /dev/null; then
echo "Profile ${profile_name} already exists. Skipping creation." echo "Profile ${profile_name} already exists. Skipping creation."
else else
@@ -25,19 +39,15 @@ if [ "$#" -eq 0 ]; then
# No arguments, update all profiles # No arguments, update all profiles
echo "No profile specified, updating all profiles..." echo "No profile specified, updating all profiles..."
find profiles -type f -name "*.profile.yaml" -print0 | while IFS= read -r -d '' file; do find profiles -type f -name "*.profile.yaml" -print0 | while IFS= read -r -d '' file; do
name=$(basename "$file" .profile.yaml) update_profile "$file"
update_profile "$name" "$file"
done done
else else
# Arguments provided, update specified profiles # Arguments provided, treat them as file paths
for profile_name in "$@"; do for file_path in "$@"; do
# Find the profile file. Since the directory structure is nested, use find. if [ -f "$file_path" ]; then
profile_file=$(find profiles -type f -name "${profile_name}.profile.yaml" | head -n 1) update_profile "$file_path"
if [ -f "$profile_file" ]; then
update_profile "$profile_name" "$profile_file"
else else
echo "Profile file for '${profile_name}' not found in 'profiles/' directory." echo "Error: Profile file '$file_path' not found. Skipping."
fi fi
done done
fi fi