install.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env bash
  2. # ------------------------------------------------------------------
  3. # WeCom Center — one-step installer for a new Zabbix frontend
  4. #
  5. # Usage:
  6. # ./install.sh # auto-detect a running zabbix-* web container
  7. # ./install.sh /path/to/modules# copy into a plain (non-docker) modules dir
  8. #
  9. # After this script finishes, open Zabbix -> Administration -> Modules,
  10. # press "Scan directory", then Enable "WecomCenter". Then open the
  11. # WeCom Center page and use the "First-time setup / Initialise" button.
  12. # ------------------------------------------------------------------
  13. set -euo pipefail
  14. HERE="$(cd "$(dirname "$0")" && pwd)"
  15. SRC="$HERE/WecomCenter"
  16. if [ ! -d "$SRC" ]; then
  17. echo "ERROR: WecomCenter folder not found next to install.sh" >&2
  18. exit 1
  19. fi
  20. if [ $# -ge 1 ]; then
  21. DEST="$1"
  22. mkdir -p "$DEST"
  23. rm -rf "$DEST/WecomCenter"
  24. cp -r "$SRC" "$DEST/WecomCenter"
  25. echo "OK: copied to $DEST/WecomCenter"
  26. else
  27. C="$(docker ps --format '{{.Names}}' 2>/dev/null | grep -iE 'zabbix.*(web|nginx|apache|frontend)' | head -n1 || true)"
  28. if [ -z "$C" ]; then
  29. echo "ERROR: no running Zabbix frontend container detected." >&2
  30. echo " Pass the modules directory explicitly, e.g.: ./install.sh /opt/zabbix/zabbix-server/web-modules" >&2
  31. exit 1
  32. fi
  33. docker cp "$SRC" "$C:/usr/share/zabbix/modules/"
  34. docker exec "$C" sh -c 'chown -R www-data:www-data /usr/share/zabbix/modules/WecomCenter 2>/dev/null || true'
  35. echo "OK: copied into container '$C' -> /usr/share/zabbix/modules/WecomCenter"
  36. fi
  37. echo
  38. echo "Next steps:"
  39. echo " 1) Zabbix -> Administration -> Modules -> 'Scan directory' -> Enable 'WecomCenter'"
  40. echo " 2) Open 'WeCom Center' -> First-time setup -> paste your group-robot key -> Initialise"
  41. echo " (it creates the media type, robot user, trigger action and {\$WECOM_KEY} macro)"