postinst 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/sh
  2. set -e
  3. case "$1" in
  4. configure)
  5. # ── Create dedicated system user ──────────────────────────────────
  6. if ! getent passwd squidstats > /dev/null 2>&1; then
  7. adduser \
  8. --system \
  9. --group \
  10. --no-create-home \
  11. --home /var/lib/squidstats \
  12. --shell /usr/sbin/nologin \
  13. --gecos "SquidStats web application" \
  14. squidstats
  15. fi
  16. # Add to the proxy group so the service can read squid access logs
  17. if getent group proxy > /dev/null 2>&1; then
  18. usermod -aG proxy squidstats 2>/dev/null || true
  19. fi
  20. # ── Runtime directories ───────────────────────────────────────────
  21. install -d -m 0750 -o squidstats -g squidstats /var/log/squidstats
  22. install -d -m 0750 -o squidstats -g squidstats /var/lib/squidstats
  23. # ── Configuration file ────────────────────────────────────────────
  24. # On first install the example config is the real config; protect it
  25. if [ -f /etc/squidstats/squidstats.env ]; then
  26. chown root:squidstats /etc/squidstats/squidstats.env
  27. chmod 0640 /etc/squidstats/squidstats.env
  28. fi
  29. # ── Create Python virtualenv on the target system ────────────────
  30. if [ ! -d /opt/SquidStats/venv ]; then
  31. python3 -m venv /opt/SquidStats/venv
  32. /opt/SquidStats/venv/bin/python3 -m pip install --upgrade pip setuptools wheel
  33. /opt/SquidStats/venv/bin/pip install --no-cache-dir -r /opt/SquidStats/app/requirements.txt
  34. fi
  35. # ── Application directory ownership ──────────────────────────────
  36. # The app code is owned by root; only the venv needs to be readable
  37. chown -R root:squidstats /opt/SquidStats/
  38. chmod -R o-rwx /opt/SquidStats/
  39. # Allow the service user to write to the data directory
  40. chown -R squidstats:squidstats /var/lib/squidstats/
  41. ;;
  42. esac
  43. #DEBHELPER#
  44. exit 0