#!/bin/bash
# lrunagent - execute runagent using module label instead of module ID
label="$1"
# Check if label is provided
if [[ -z "$label" ]]; then
echo "Usage: lrunagent <label>"
exit 1
fi
# Find all modules with ui_name
found_module=""
modules=$(redis-cli --raw keys 'module/*/ui_name' 2>/dev/null)
if [[ -z "$modules" ]]; then
echo "Error: No modules found in the system"
exit 1
fi
# Iterate through all modules to find the one with the correct label
while IFS= read -r key; do
if [[ -n "$key" ]]; then
# Get the module label
current_label=$(redis-cli --raw get "$key" 2>/dev/null)
if [[ "$current_label" == "$label" ]]; then
# Extract module ID from key path
found_module=$(echo "$key" | sed 's|module/||' | sed 's|/ui_name||')
break
fi
fi
done <<< "$modules"
# Check if module was found
if [[ -z "$found_module" ]]; then
echo "Error: No module found with label '$label'"
exit 1
fi
# Execute runagent with the found module ID
exec runagent -m "$found_module"