branded header, nav, footer for OTB https://outsidethebox.top
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.
 
 
 
 

48 lines
1.2 KiB

#!/bin/bash
set -e
APP_DIR="/opt/otb_tracker"
cd "$APP_DIR" || exit 1
STAMP="$(date +%Y%m%d-%H%M%S)"
BKDIR="backups/shared-brand-$STAMP"
mkdir -p "$BKDIR"
cp -av backend/app.py "$BKDIR"/
HEADER="$(cat /home/def/otb-shared-brand/header.html)"
FOOTER="$(cat /home/def/otb-shared-brand/footer.html | sed 's|__OTB_BRAND_JS__|/static/brand.js|g')"
BRANDCSS="$(cat /home/def/otb-shared-brand/brand.css)"
BRANDJS="$(cat /home/def/otb-shared-brand/brand.js)"
mkdir -p static
printf '%s
' "$BRANDJS" > static/brand.js
python3 - <<PY2
from pathlib import Path
import re
app = Path("backend/app.py")
text = app.read_text(encoding="utf-8")
header = '''$HEADER'''
footer = '''$FOOTER'''
brandcss = '''$BRANDCSS'''
style_block = f"<style>\n{brandcss}\n</style>"
text = re.sub(r'<style>\s*/\* ===== OTB shared branding ===== \*/.*?</style>', '', text, flags=re.S)
if header not in text:
text = text.replace("<body>", "<body>\n" + header)
if footer not in text:
text = text.replace("</body>", footer + "\n</body>")
if style_block not in text:
text = text.replace("</head>", style_block + "\n</head>")
app.write_text(text, encoding="utf-8")
print("otb-tracker branding injected")
PY2
sudo systemctl restart otb-tracker.service || true