Makefile 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. RELEASEURL:="https://github.com/vladimirok5959/bash-empty-daemon/releases/download/latest/daemon.zip"
  2. BINDIR:=/usr/local/bin
  3. LROTDIR:=/etc/logrotate.d
  4. INITD:=/etc/init.d
  5. INSTALLDIR:=/etc
  6. SINITED:="0"
  7. default: check info
  8. install: check dir-test download create-link create-logrotate create-autostart show-done-msg
  9. check:
  10. $(eval SINITED="1")
  11. @echo "Check for dependences..."
  12. @wget -V > /dev/null
  13. @unzip -v > /dev/null
  14. dir-test: check-manual-run check-if-name-set
  15. @echo "Check directories..."
  16. @if [ ! -d "$(BINDIR)" ]; then \
  17. echo "Aborted. Dir '$(BINDIR)' is not exists"; \
  18. exit 1; \
  19. fi
  20. @if [ ! -d "$(LROTDIR)" ]; then \
  21. echo "Aborted. Dir '$(LROTDIR)' is not exists"; \
  22. exit 1; \
  23. fi
  24. @if [ ! -d "$(INSTALLDIR)" ]; then \
  25. echo "Aborted. Dir '$(INSTALLDIR)' is not exists"; \
  26. exit 1; \
  27. fi
  28. @if [ -d "$(INSTALLDIR)/$(NAME)" ]; then \
  29. echo "Aborted. Directory '$(INSTALLDIR)/$(NAME)' already exists"; \
  30. exit 1; \
  31. fi
  32. info: check-manual-run
  33. @echo "You can run 'make install NAME=my-service'"
  34. download: check-manual-run check-if-name-set
  35. @if [ ! -z "$(NAME)" ]; then \
  36. echo "Download latest empty daemon..."; \
  37. cd $(INSTALLDIR); \
  38. mkdir $(NAME); \
  39. cd $(NAME); \
  40. wget -q $(RELEASEURL) > /dev/null; \
  41. echo "Installing..."; \
  42. unzip -o daemon.zip > /dev/null; \
  43. rm daemon.zip; \
  44. mv run.sh $(NAME).sh; \
  45. chmod 744 $(NAME).sh; \
  46. fi
  47. create-link: check-manual-run check-if-name-set
  48. @if [ ! -z "$(NAME)" ]; then \
  49. echo "Create symlink..."; \
  50. ln -sf $(INSTALLDIR)/$(NAME)/$(NAME).sh $(BINDIR)/$(NAME); \
  51. fi
  52. create-logrotate: check-manual-run check-if-name-set
  53. @if [ ! -z "$(NAME)" ]; then \
  54. echo "Create config file for logrotate..."; \
  55. echo "$(INSTALLDIR)/$(NAME)/logs/all.log {" > $(LROTDIR)/$(NAME); \
  56. echo " daily" >> $(LROTDIR)/$(NAME); \
  57. echo " missingok" >> $(LROTDIR)/$(NAME); \
  58. echo " rotate 14" >> $(LROTDIR)/$(NAME); \
  59. echo " compress" >> $(LROTDIR)/$(NAME); \
  60. echo " delaycompress" >> $(LROTDIR)/$(NAME); \
  61. echo " notifempty" >> $(LROTDIR)/$(NAME); \
  62. echo " create 640 root root" >> $(LROTDIR)/$(NAME); \
  63. echo " sharedscripts" >> $(LROTDIR)/$(NAME); \
  64. echo "}" >> $(LROTDIR)/$(NAME); \
  65. fi
  66. create-autostart:
  67. @if [ ! -d "$(INITD)" ]; then \
  68. echo "Aborted. Dir '$(INITD)' is not exists"; \
  69. exit 1; \
  70. fi
  71. @if [ ! -z "$(NAME)" ]; then \
  72. echo "Create auto start script..."; \
  73. echo "#!/bin/sh" > $(INITD)/$(NAME); \
  74. echo "" >> $(INITD)/$(NAME); \
  75. echo "### BEGIN INIT INFO" >> $(INITD)/$(NAME); \
  76. echo "# Provides: $(NAME)" >> $(INITD)/$(NAME); \
  77. echo "# Required-Start: \$$local_fs \$$network \$$syslog" >> $(INITD)/$(NAME); \
  78. echo "# Required-Stop: \$$local_fs \$$network \$$syslog" >> $(INITD)/$(NAME); \
  79. echo "# Default-Start: 2 3 4 5" >> $(INITD)/$(NAME); \
  80. echo "# Default-Stop: 0 1 6" >> $(INITD)/$(NAME); \
  81. echo "# Short-Description: starts the daemon ($(NAME))" >> $(INITD)/$(NAME); \
  82. echo "# Description: starts the daemon ($(NAME)) using start-stop-daemon" >> $(INITD)/$(NAME); \
  83. echo "### END INIT INFO" >> $(INITD)/$(NAME); \
  84. echo "" >> $(INITD)/$(NAME); \
  85. echo "/usr/local/bin/$(NAME) \$$1" >> $(INITD)/$(NAME); \
  86. echo "exit 0" >> $(INITD)/$(NAME); \
  87. chmod 0755 $(INITD)/$(NAME); \
  88. ln -sf ../init.d/$(NAME) /etc/rc0.d/K01$(NAME); \
  89. ln -sf ../init.d/$(NAME) /etc/rc1.d/K01$(NAME); \
  90. ln -sf ../init.d/$(NAME) /etc/rc2.d/K01$(NAME); \
  91. ln -sf ../init.d/$(NAME) /etc/rc3.d/S01$(NAME); \
  92. ln -sf ../init.d/$(NAME) /etc/rc4.d/S01$(NAME); \
  93. ln -sf ../init.d/$(NAME) /etc/rc5.d/S01$(NAME); \
  94. ln -sf ../init.d/$(NAME) /etc/rc6.d/K01$(NAME); \
  95. fi
  96. show-done-msg: check-manual-run
  97. @echo "Done! Daemon with name '$(NAME)' successfully generated!"
  98. check-if-name-set:
  99. @if [ -z "$(NAME)" ]; then \
  100. echo "You must provide a NAME for daemon. For example 'make install NAME=my-service'..."; \
  101. exit 1; \
  102. fi
  103. check-manual-run:
  104. @if [ "$(SINITED)" != "1" ]; then \
  105. echo "Aborted. You can't run this command manually"; \
  106. exit 1; \
  107. fi