You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
174 lines
5.4 KiB
174 lines
5.4 KiB
cd /opt/otb_tracker || exit 1 |
|
cat > /tmp/otb_tracker_shared_brand_patch.sh <<'EOF' |
|
#!/usr/bin/env bash |
|
set -euo pipefail |
|
|
|
APP_ROOT="/opt/otb_tracker" |
|
SHARED_ROOT="/opt/otb/otb-shared-brand" |
|
STAMP="$(date +%Y%m%d-%H%M%S)" |
|
|
|
cd "$APP_ROOT" || exit 1 |
|
|
|
echo "===== detect template/static roots =====" |
|
TPL_ROOT="" |
|
STATIC_ROOT="" |
|
|
|
if [ -d "$APP_ROOT/templates" ]; then |
|
TPL_ROOT="$APP_ROOT/templates" |
|
elif [ -d "$APP_ROOT/backend/templates" ]; then |
|
TPL_ROOT="$APP_ROOT/backend/templates" |
|
else |
|
echo "ERROR: no templates dir found" |
|
exit 1 |
|
fi |
|
|
|
if [ -d "$APP_ROOT/static" ]; then |
|
STATIC_ROOT="$APP_ROOT/static" |
|
elif [ -d "$APP_ROOT/backend/static" ]; then |
|
STATIC_ROOT="$APP_ROOT/backend/static" |
|
else |
|
echo "ERROR: no static dir found" |
|
exit 1 |
|
fi |
|
|
|
echo "Templates: $TPL_ROOT" |
|
echo "Static: $STATIC_ROOT" |
|
|
|
echo "===== ensure shared brand exists and is current =====" |
|
cd "$SHARED_ROOT" || exit 1 |
|
git pull origin main |
|
cd "$APP_ROOT" || exit 1 |
|
|
|
echo "===== backup =====" |
|
mkdir -p "$APP_ROOT/backups/shared-brand-$STAMP" |
|
cp -a "$TPL_ROOT" "$APP_ROOT/backups/shared-brand-$STAMP/templates" |
|
cp -a "$STATIC_ROOT" "$APP_ROOT/backups/shared-brand-$STAMP/static" |
|
|
|
echo "===== create includes dir =====" |
|
mkdir -p "$TPL_ROOT/includes" |
|
mkdir -p "$STATIC_ROOT/css" |
|
|
|
echo "===== sync shared assets =====" |
|
cp "$SHARED_ROOT/brand.css" "$STATIC_ROOT/css/brand.css" |
|
cp "$SHARED_ROOT/brand.js" "$STATIC_ROOT/brand.js" |
|
|
|
echo "===== sync shared header include =====" |
|
cp "$SHARED_ROOT/fragments/header.html" "$TPL_ROOT/includes/site_nav.html" |
|
|
|
echo "===== write canonical shared footer includes =====" |
|
cat > "$TPL_ROOT/includes/otb_statusbar.html" <<'EOT' |
|
<div class="otb-statusbar"> |
|
<div class="otb-statusbar-inner"> |
|
<strong>All billing is calculated in 🇨🇦 CAD</strong> |
|
<span class="otb-dot"></span> |
|
<span>Crypto conversions use the <a href="https://monitor.outsidethebox.top" target="_blank" rel="noopener noreferrer">OTB Oracle</a></span> |
|
<span class="otb-dot"></span> |
|
<span> |
|
Methods: |
|
<strong>Credit Card</strong> <span style="opacity:0.7;">(via Square)</span>, |
|
<strong>e-Transfer</strong>, |
|
and <strong>enabled crypto assets</strong> |
|
</span> |
|
</div> |
|
</div> |
|
EOT |
|
|
|
cat > "$TPL_ROOT/includes/otb_footer.html" <<'EOT' |
|
{% include "includes/otb_statusbar.html" %} |
|
<script src="/static/brand.js" defer></script> |
|
EOT |
|
|
|
echo "===== patch html templates =====" |
|
python3 <<PY |
|
from pathlib import Path |
|
import re |
|
|
|
tpl_root = Path("$TPL_ROOT") |
|
html_files = list(tpl_root.rglob("*.html")) |
|
|
|
for p in html_files: |
|
if "includes" in p.parts: |
|
continue |
|
|
|
text = p.read_text(encoding="utf-8") |
|
|
|
# add shared brand.css after local style.css if missing |
|
text = re.sub( |
|
r'(<link rel="stylesheet" href="/static/css/style\.css"\s*/?>)', |
|
r'\\1\n <link rel="stylesheet" href="/static/css/brand.css?v=0.3.6" />', |
|
text, |
|
count=1 |
|
) |
|
text = re.sub( |
|
r'(<link rel="stylesheet" href="/static/css/style\.css"\s*>)', |
|
r'\\1\n <link rel="stylesheet" href="/static/css/brand.css?v=0.3.6" />', |
|
text, |
|
count=1 |
|
) |
|
|
|
# normalize brand css/js cache versions |
|
text = text.replace('/static/css/brand.css?v=0.3.5', '/static/css/brand.css?v=0.3.6') |
|
text = text.replace('/static/css/brand.css?v=0.3.6?v=0.3.6', '/static/css/brand.css?v=0.3.6') |
|
text = text.replace('/static/brand.js?v=0.3.5', '/static/brand.js?v=0.3.6') |
|
text = text.replace('/static/brand.js?v=0.3.6?v=0.3.6', '/static/brand.js?v=0.3.6') |
|
|
|
# replace inline shared header block if present |
|
text = re.sub( |
|
r'<header class="site-header">.*?</header>', |
|
'{% include "includes/site_nav.html" %}', |
|
text, |
|
count=1, |
|
flags=re.S |
|
) |
|
|
|
# replace older nav block if present |
|
text = re.sub( |
|
r'<div class="container">\s*<div class="nav">.*?</div>\s*', |
|
'{% include "includes/site_nav.html" %}\n', |
|
text, |
|
count=1, |
|
flags=re.S |
|
) |
|
|
|
# if no shared nav include and no obvious header/nav remains, insert after <body> |
|
if '{% include "includes/site_nav.html" %}' not in text: |
|
if '<body>' in text: |
|
text = text.replace('<body>', '<body>\n {% include "includes/site_nav.html" %}', 1) |
|
|
|
# replace inline statusbar/footer block with shared footer include |
|
text = re.sub( |
|
r'<div class="otb-statusbar">.*?</div>\s*</div>\s*(<script src="/static/brand\.js".*?</script>)?', |
|
'{% include "includes/otb_footer.html" %}', |
|
text, |
|
count=1, |
|
flags=re.S |
|
) |
|
|
|
# if brand.js still directly included, remove it because footer include owns it |
|
text = re.sub( |
|
r'\s*<script src="/static/brand\.js(?:\?v=[^"]*)?" defer></script>\s*', |
|
'\n', |
|
text, |
|
flags=re.S |
|
) |
|
|
|
# if footer include absent, append before </body> |
|
if '{% include "includes/otb_footer.html" %}' not in text: |
|
text = text.replace('</body>', ' {% include "includes/otb_footer.html" %}\n</body>', 1) |
|
|
|
p.write_text(text, encoding="utf-8") |
|
print(f"patched: {p}") |
|
PY |
|
|
|
echo "===== restart service =====" |
|
sudo systemctl restart otb-tracker.service |
|
|
|
echo "===== verify =====" |
|
grep -Rni 'includes/site_nav.html\|includes/otb_footer.html\|/static/css/brand.css\|video.outsidethebox.top' "$TPL_ROOT" | sed -n '1,200p' |
|
ls -l "$STATIC_ROOT/css/brand.css" "$STATIC_ROOT/brand.js" |
|
|
|
echo "===== done =====" |
|
EOF |
|
|
|
chmod +x /tmp/otb_tracker_shared_brand_patch.sh |
|
/tmp/otb_tracker_shared_brand_patch.sh
|
|
|