screenshots.mk 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. .PHONY: update-screenshots start stop
  2. ROOT := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/../../../..)
  3. OLIVETIN ?= $(ROOT)/service/OliveTin
  4. PORT := 11337
  5. ifndef CONFIGDIR
  6. $(error CONFIGDIR must be set before including screenshots.mk)
  7. endif
  8. .DEFAULT_GOAL := update-screenshots
  9. start:
  10. @set -e; \
  11. if curl -sf "http://localhost:$(PORT)/" >/dev/null 2>&1; then \
  12. echo "Port $(PORT) is already in use; run 'make stop' first"; \
  13. exit 1; \
  14. fi; \
  15. cd "$(ROOT)/service" && "$(OLIVETIN)" -configdir "$(CONFIGDIR)" & \
  16. pid=$$!; \
  17. for i in 1 2 3 4 5 6 7 8 9 10; do \
  18. if curl -sf "http://localhost:$(PORT)/" >/dev/null; then \
  19. exit 0; \
  20. fi; \
  21. if ! kill -0 $$pid 2>/dev/null; then \
  22. echo "OliveTin exited before listening on port $(PORT)"; \
  23. exit 1; \
  24. fi; \
  25. sleep 1; \
  26. done; \
  27. echo "Timed out waiting for OliveTin on port $(PORT)"; \
  28. exit 1
  29. stop:
  30. @set +e; \
  31. if command -v fuser >/dev/null 2>&1; then \
  32. fuser -k $(PORT)/tcp 2>/dev/null; \
  33. else \
  34. for pid in $$(lsof -t -i :$(PORT) 2>/dev/null); do kill $$pid 2>/dev/null; done; \
  35. fi; \
  36. for i in 1 2 3 4 5; do \
  37. curl -sf "http://localhost:$(PORT)/" >/dev/null || exit 0; \
  38. sleep 1; \
  39. done; \
  40. exit 0
  41. update-screenshots: stop start
  42. cd "$(CONFIGDIR)" && repo-helper screenshot --config screenshots.ini
  43. @$(MAKE) stop