77 lines
3.2 KiB
Bash
77 lines
3.2 KiB
Bash
#!/bin/bash
|
|
set -e
|
|
|
|
WORKDIR=/tmp/ditto-jar-mod
|
|
rm -rf $WORKDIR && mkdir -p $WORKDIR
|
|
|
|
echo "=== Extracting JAR ==="
|
|
cd $WORKDIR
|
|
docker run --rm eclipse/ditto-gateway:latest cat /opt/ditto/ditto-gateway-service-3.8.12-allinone.jar > ditto-gateway-service-3.8.12-allinone.jar
|
|
jar xf ditto-gateway-service-3.8.12-allinone.jar reference.conf
|
|
|
|
echo "=== Original reference.conf tail ==="
|
|
tail -5 reference.conf
|
|
|
|
echo "=== Adding auth config to reference.conf ==="
|
|
# Remove the last closing brace, add our config, re-add the closing brace
|
|
# The reference.conf ends with nested braces - find the very last line
|
|
python3 << 'PYEOF'
|
|
with open("/tmp/ditto-jar-mod/reference.conf", "r") as f:
|
|
lines = f.readlines()
|
|
|
|
# Find the last non-empty line that is just a closing brace
|
|
# We need to insert our config before the outermost closing brace
|
|
|
|
# Simple approach: append before the very last }
|
|
# Count total closing braces at the end
|
|
content = "".join(lines)
|
|
|
|
# The reference.conf has a complex nested structure
|
|
# We'll add our ditto config as a new root-level block at the end
|
|
# We need to close the last block and add a comma, then our new block
|
|
|
|
# Actually, simpler: just append if the file ends with }
|
|
# Find the position of the very last }
|
|
last_brace_pos = content.rfind('}')
|
|
if last_brace_pos >= 0:
|
|
# Check if there's content after the last } (like kamon.conf include)
|
|
rest = content[last_brace_pos+1:].strip()
|
|
if rest:
|
|
# There's content after the last }, our approach is wrong
|
|
print(f"Content after last }}: {rest[:100]}")
|
|
# Insert before the last } with a comma
|
|
new_content = content[:last_brace_pos].rstrip()
|
|
# Remove trailing comma if present
|
|
if new_content.endswith(','):
|
|
new_content = new_content[:-1]
|
|
new_content += ',\n\n# Custom auth overrides\n' + rest[:0] + '\n' + ' authentication {\n pre-authentication {\n enabled = true\n }\n devops {\n secured = false\n }\n }\n}\n'
|
|
# Just append
|
|
new_content = content.rstrip() + '\n\n# Custom auth overrides\nditto {\n gateway {\n authentication {\n pre-authentication {\n enabled = true\n }\n devops {\n secured = false\n }\n }\n }\n}\n'
|
|
else:
|
|
# Last char is }, replace it with our config + }
|
|
new_content = content[:last_brace_pos].rstrip()
|
|
# Remove trailing comma
|
|
if new_content.endswith(','):
|
|
new_content = new_content[:-1]
|
|
new_content += ',\n\n# Custom auth overrides\n gateway {\n authentication {\n pre-authentication {\n enabled = true\n }\n devops {\n secured = false\n }\n }\n }\n}\n'
|
|
else:
|
|
new_content = content
|
|
|
|
with open("/tmp/ditto-jar-mod/reference.conf", "w") as f:
|
|
f.write(new_content)
|
|
|
|
print("reference.conf modified successfully")
|
|
PYEOF
|
|
|
|
echo "=== Modified reference.conf tail ==="
|
|
tail -20 reference.conf
|
|
|
|
echo "=== Updating JAR (replacing reference.conf) ==="
|
|
jar uf ditto-gateway-service-3.8.12-allinone.jar reference.conf
|
|
|
|
echo "=== Verifying modified reference.conf in JAR ==="
|
|
jar xf ditto-gateway-service-3.8.12-allinone.jar reference.conf
|
|
grep -c "pre-authentication" reference.conf || echo "NOT FOUND in JAR"
|
|
|
|
echo "=== Done. JAR is ready at $WORKDIR ==="
|