|
|
#!/bin/bash |
|
|
|
|
|
|
|
|
|
|
|
set -e |
|
|
|
|
|
echo "[PWA] Injecting PWA meta tags into Streamlit's index.html..." |
|
|
|
|
|
|
|
|
STREAMLIT_INDEX=$(python3 -c "import streamlit; import os; print(os.path.join(os.path.dirname(streamlit.__file__), 'static', 'index.html'))") |
|
|
|
|
|
if [ ! -f "$STREAMLIT_INDEX" ]; then |
|
|
echo "[PWA] ERROR: Streamlit index.html not found at: $STREAMLIT_INDEX" |
|
|
exit 1 |
|
|
fi |
|
|
|
|
|
echo "[PWA] Found Streamlit index.html at: $STREAMLIT_INDEX" |
|
|
|
|
|
|
|
|
if grep -q "PWA (Progressive Web App) Meta Tags" "$STREAMLIT_INDEX"; then |
|
|
echo "[PWA] PWA tags already injected, skipping..." |
|
|
exit 0 |
|
|
fi |
|
|
|
|
|
|
|
|
INJECT_FILE="/app/pwa-head-inject.html" |
|
|
if [ ! -f "$INJECT_FILE" ]; then |
|
|
echo "[PWA] ERROR: Injection file not found at: $INJECT_FILE" |
|
|
exit 1 |
|
|
fi |
|
|
|
|
|
|
|
|
cp "$STREAMLIT_INDEX" "${STREAMLIT_INDEX}.backup" |
|
|
|
|
|
|
|
|
awk -v inject_file="$INJECT_FILE" ' |
|
|
/<head>/ { |
|
|
print |
|
|
while ((getline line < inject_file) > 0) { |
|
|
print line |
|
|
} |
|
|
close(inject_file) |
|
|
next |
|
|
} |
|
|
{ print } |
|
|
' "${STREAMLIT_INDEX}.backup" > "$STREAMLIT_INDEX" |
|
|
|
|
|
echo "[PWA] PWA meta tags successfully injected!" |
|
|
echo "[PWA] Backup saved as: ${STREAMLIT_INDEX}.backup" |
|
|
|