File size: 1,404 Bytes
4f625d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# Inject PWA meta tags into Streamlit's index.html head section
# This script modifies the Streamlit index.html during Docker build

set -e

echo "[PWA] Injecting PWA meta tags into Streamlit's index.html..."

# Find 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"

# Check if already injected (to make script idempotent)
if grep -q "PWA (Progressive Web App) Meta Tags" "$STREAMLIT_INDEX"; then
    echo "[PWA] PWA tags already injected, skipping..."
    exit 0
fi

# Read the injection content
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

# Create backup
cp "$STREAMLIT_INDEX" "${STREAMLIT_INDEX}.backup"

# Use awk to inject after <head> tag
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"