Fix YAML parsing by using grep/sed instead of python

This commit is contained in:
Gemini Bot
2025-12-06 18:37:33 +00:00
parent 595b16a4cc
commit 45c2a5c04e

View File

@@ -49,27 +49,22 @@ if command -v bbctl &> /dev/null; then
echo "Successfully saved registration to $REG_FILE" echo "Successfully saved registration to $REG_FILE"
# Now we need to parse values from this file to populate config variables # Now we need to parse values from this file to populate config variables
# We use python one-liner to extract vars # We use grep/sed to extract vars to avoid python dependencies
echo "Extracting tokens..." echo "Extracting tokens..."
eval $(docker run --rm -v "$(pwd)/$REG_FILE:/reg.yaml" python:3.11-slim python -c " # Helper function to extract value by key
import yaml # PyYAML is standard in some images, but if not we might need manual parsing or install get_yaml_val() {
try: grep "^$1:" "$REG_FILE" | sed 's/^[^:]*: *//' | tr -d '\r'
import yaml }
except ImportError:
# Fallback: simple line parsing if yaml module missing in minimal image (though python:3.11-slim usually needs pip install) REG_ID=$(get_yaml_val "id")
# Let's just do manual parsing to be safe and fast without network AS_TOKEN=$(get_yaml_val "as_token")
d = {} HS_TOKEN=$(get_yaml_val "hs_token")
with open('/reg.yaml') as f: BOT_USERNAME=$(get_yaml_val "sender_localpart")
for line in f:
if ':' in line: if [ -n "$REG_ID" ]; then
k,v = line.split(':', 1) echo " -> ID: $REG_ID"
d[k.strip()] = v.strip() fi
print(f'REG_ID={d.get(\"id\", \"\")}')
print(f'AS_TOKEN={d.get(\"as_token\", \"\")}')
print(f'HS_TOKEN={d.get(\"hs_token\", \"\")}')
print(f'BOT_USERNAME={d.get(\"sender_localpart\", \"\")}')
")
else else
echo "Could not parse YAML from bbctl output. Falling back to manual input." echo "Could not parse YAML from bbctl output. Falling back to manual input."
fi fi