Spaces:
Runtime error
Runtime error
Upload entrypoint.sh
Browse files- entrypoint.sh +91 -0
entrypoint.sh
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
|
| 4 |
+
echo "Starting PDF TEI Editor application..."
|
| 5 |
+
|
| 6 |
+
# Set default port if not provided
|
| 7 |
+
PORT=${PORT:-8000}
|
| 8 |
+
|
| 9 |
+
# Change to app directory
|
| 10 |
+
cd /app
|
| 11 |
+
|
| 12 |
+
# Initialize database directory if it doesn't exist
|
| 13 |
+
if [ ! -d "/app/data/db" ]; then
|
| 14 |
+
echo "Initializing database directory..."
|
| 15 |
+
mkdir -p /app/data/db
|
| 16 |
+
fi
|
| 17 |
+
|
| 18 |
+
# Copy default config files if they don't exist
|
| 19 |
+
for config_file in /app/config/*.json; do
|
| 20 |
+
if [ -f "$config_file" ]; then
|
| 21 |
+
filename=$(basename "$config_file")
|
| 22 |
+
if [ ! -f "/app/data/db/$filename" ]; then
|
| 23 |
+
echo "Copying default $filename..."
|
| 24 |
+
cp "$config_file" "/app/data/db/$filename"
|
| 25 |
+
fi
|
| 26 |
+
fi
|
| 27 |
+
done
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
# Create default accounts if no environment variables are set
|
| 31 |
+
if [ -z "$APP_ADMIN_PASSWORD" ] && [ -z "$APP_DEMO_PASSWORD" ]; then
|
| 32 |
+
echo "No custom passwords provided, setting up default demo accounts..."
|
| 33 |
+
|
| 34 |
+
# Set default login message with security warning
|
| 35 |
+
export APP_LOGIN_MESSAGE="<h2>⚠️ Demo Installation</h2><p>Default accounts: <code>admin/admin</code> and <code>demo/demo</code>. For testing purposes only. <a href='https://github.com/mpilhlt/pdf-tei-editor/blob/main/docs/testdrive-docker.md' target='_blank'>Configure real passwords in production!</a></p>"
|
| 36 |
+
# Use Python to properly escape the message for JSON
|
| 37 |
+
ESCAPED_DEFAULT_MESSAGE=$(.venv/bin/python -c "import json, os; print(json.dumps(os.environ.get('APP_LOGIN_MESSAGE', '')))")
|
| 38 |
+
.venv/bin/python bin/manage.py config set application.login-message "$ESCAPED_DEFAULT_MESSAGE" 2>/dev/null || echo "Warning: Failed to set default login message"
|
| 39 |
+
|
| 40 |
+
# Create default admin and demo user
|
| 41 |
+
export APP_ADMIN_PASSWORD="admin"
|
| 42 |
+
export APP_DEMO_PASSWORD="demo"
|
| 43 |
+
fi
|
| 44 |
+
|
| 45 |
+
# Set login message if APP_LOGIN_MESSAGE is provided
|
| 46 |
+
if [ -n "$APP_LOGIN_MESSAGE" ]; then
|
| 47 |
+
echo "Setting login message from environment variable..."
|
| 48 |
+
# Use Python to properly escape the message for JSON
|
| 49 |
+
ESCAPED_MESSAGE=$(.venv/bin/python -c "import json, os; print(json.dumps(os.environ.get('APP_LOGIN_MESSAGE', '')))")
|
| 50 |
+
.venv/bin/python bin/manage.py config set application.login-message "$ESCAPED_MESSAGE" 2>/dev/null || echo "Warning: Failed to set login message"
|
| 51 |
+
fi
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
# Create or update admin user if APP_ADMIN_PASSWORD is set
|
| 55 |
+
if [ -n "$APP_ADMIN_PASSWORD" ]; then
|
| 56 |
+
echo "Setting up admin user from environment variable..."
|
| 57 |
+
if .venv/bin/python bin/manage.py user add admin \
|
| 58 |
+
--password "$APP_ADMIN_PASSWORD" \
|
| 59 |
+
--fullname "Administrator" \
|
| 60 |
+
--roles "admin" \
|
| 61 |
+
--email "admin@localhost";
|
| 62 |
+
then
|
| 63 |
+
echo "Admin user created successfully"
|
| 64 |
+
else
|
| 65 |
+
echo "Warning: Failed to create admin user"
|
| 66 |
+
fi
|
| 67 |
+
fi
|
| 68 |
+
|
| 69 |
+
# Create or update demo user if APP_DEMO_PASSWORD is set
|
| 70 |
+
if [ -n "$APP_DEMO_PASSWORD" ]; then
|
| 71 |
+
echo "Creating new demo user..."
|
| 72 |
+
if .venv/bin/python bin/manage.py user add demo \
|
| 73 |
+
--password "$APP_DEMO_PASSWORD" \
|
| 74 |
+
--fullname "Demo User" \
|
| 75 |
+
--roles "user,annotator,reviewer" \
|
| 76 |
+
--email "demo@localhost";
|
| 77 |
+
then
|
| 78 |
+
echo "Demo user created successfully"
|
| 79 |
+
else
|
| 80 |
+
echo "Warning: Failed to create demo user"
|
| 81 |
+
fi
|
| 82 |
+
fi
|
| 83 |
+
|
| 84 |
+
# Import demo data if present
|
| 85 |
+
if [ -f /app/docker/import-demo-data.sh ]; then
|
| 86 |
+
echo "Importing demo data..."
|
| 87 |
+
/app/docker/import-demo-data.sh
|
| 88 |
+
fi
|
| 89 |
+
|
| 90 |
+
# Start the PDF TEI Editor application bound to all interfaces for Docker
|
| 91 |
+
exec .venv/bin/python bin/start-prod 0.0.0.0 $PORT
|