Fix YAML parsing by using grep/sed instead of python
This commit is contained in:
@@ -49,27 +49,22 @@ if command -v bbctl &> /dev/null; then
|
||||
echo "Successfully saved registration to $REG_FILE"
|
||||
|
||||
# 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..."
|
||||
|
||||
eval $(docker run --rm -v "$(pwd)/$REG_FILE:/reg.yaml" python:3.11-slim python -c "
|
||||
import yaml # PyYAML is standard in some images, but if not we might need manual parsing or install
|
||||
try:
|
||||
import yaml
|
||||
except ImportError:
|
||||
# Fallback: simple line parsing if yaml module missing in minimal image (though python:3.11-slim usually needs pip install)
|
||||
# Let's just do manual parsing to be safe and fast without network
|
||||
d = {}
|
||||
with open('/reg.yaml') as f:
|
||||
for line in f:
|
||||
if ':' in line:
|
||||
k,v = line.split(':', 1)
|
||||
d[k.strip()] = v.strip()
|
||||
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\", \"\")}')
|
||||
")
|
||||
# Helper function to extract value by key
|
||||
get_yaml_val() {
|
||||
grep "^$1:" "$REG_FILE" | sed 's/^[^:]*: *//' | tr -d '\r'
|
||||
}
|
||||
|
||||
REG_ID=$(get_yaml_val "id")
|
||||
AS_TOKEN=$(get_yaml_val "as_token")
|
||||
HS_TOKEN=$(get_yaml_val "hs_token")
|
||||
BOT_USERNAME=$(get_yaml_val "sender_localpart")
|
||||
|
||||
if [ -n "$REG_ID" ]; then
|
||||
echo " -> ID: $REG_ID"
|
||||
fi
|
||||
else
|
||||
echo "Could not parse YAML from bbctl output. Falling back to manual input."
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user