From d5eb072a46a26488b87ef9bcc1fc0cfb7fdabdf7 Mon Sep 17 00:00:00 2001 From: SysAdmin Agent Date: Tue, 24 Mar 2026 11:18:18 +0000 Subject: [PATCH] Fix GrampsWeb: recursive CSS find + auto-create admin on startup (STI-90) - Use `find` instead of `*.css` glob to catch fonts/fonts.css in subdirs - Add Python script to auto-create Admin user if no users exist yet Co-Authored-By: Claude Opus 4.6 --- compose.yml | 22 ++++++++++++++++++++-- deploy-production/docker-compose.prod.yml | 22 ++++++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/compose.yml b/compose.yml index 6a5c4f1..db90232 100644 --- a/compose.yml +++ b/compose.yml @@ -232,8 +232,8 @@ services: echo "[grampsweb] patched JS paths: $$f" fi done - for f in /app/static/*.css; do - if [ -f "$$f" ] && grep -q 'fonts/' "$$f" 2>/dev/null; then + find /app/static -name '*.css' 2>/dev/null | while read f; do + if grep -q '\.\./fonts/' "$$f" 2>/dev/null; then sed -i "s|'../fonts/|'fonts/|g" "$$f" sed -i "s|\"../fonts/|\"fonts/|g" "$$f" echo "[grampsweb] patched CSS font paths: $$f" @@ -241,6 +241,24 @@ services: done echo "[grampsweb] Done." fi + echo "[grampsweb] Ensuring admin user exists ..." + python3 << 'PYEOF' 2>&1 | grep -v Gtk + from gramps_webapi.app import create_app + from gramps_webapi.auth import add_user, get_number_users, ROLE_OWNER + import os + email = os.environ.get('GRAMPSWEB_ADMIN_EMAIL', '') + pw = os.environ.get('GRAMPSWEB_ADMIN_PASSWORD', '') + if email and pw: + app = create_app() + with app.app_context(): + if get_number_users() == 0: + add_user(name='Admin', email=email, password=pw, role=ROLE_OWNER) + print('[grampsweb] Admin user created') + else: + print('[grampsweb] Users already exist, skipping') + else: + print('[grampsweb] No admin credentials configured, skipping') + PYEOF exec gunicorn -w $${GUNICORN_NUM_WORKERS:-8} -b 0.0.0.0:5000 \ gramps_webapi.wsgi:app --timeout $${GUNICORN_TIMEOUT:-120} \ --limit-request-line 8190 diff --git a/deploy-production/docker-compose.prod.yml b/deploy-production/docker-compose.prod.yml index 59a9b0d..f6ee61d 100644 --- a/deploy-production/docker-compose.prod.yml +++ b/deploy-production/docker-compose.prod.yml @@ -158,8 +158,8 @@ services: echo "[grampsweb] patched JS paths: $$f" fi done - for f in /app/static/*.css; do - if [ -f "$$f" ] && grep -q 'fonts/' "$$f" 2>/dev/null; then + find /app/static -name '*.css' 2>/dev/null | while read f; do + if grep -q '\.\./fonts/' "$$f" 2>/dev/null; then sed -i "s|'../fonts/|'fonts/|g" "$$f" sed -i "s|\"../fonts/|\"fonts/|g" "$$f" echo "[grampsweb] patched CSS font paths: $$f" @@ -167,6 +167,24 @@ services: done echo "[grampsweb] Done." fi + echo "[grampsweb] Ensuring admin user exists ..." + python3 << 'PYEOF' 2>&1 | grep -v Gtk + from gramps_webapi.app import create_app + from gramps_webapi.auth import add_user, get_number_users, ROLE_OWNER + import os + email = os.environ.get('GRAMPSWEB_ADMIN_EMAIL', '') + pw = os.environ.get('GRAMPSWEB_ADMIN_PASSWORD', '') + if email and pw: + app = create_app() + with app.app_context(): + if get_number_users() == 0: + add_user(name='Admin', email=email, password=pw, role=ROLE_OWNER) + print('[grampsweb] Admin user created') + else: + print('[grampsweb] Users already exist, skipping') + else: + print('[grampsweb] No admin credentials configured, skipping') + PYEOF exec gunicorn -w $${GUNICORN_NUM_WORKERS:-8} -b 0.0.0.0:5000 \ gramps_webapi.wsgi:app --timeout $${GUNICORN_TIMEOUT:-120} \ --limit-request-line 8190