emitter.spec 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. ##
  2. ## emitter.spec -- OpenPKG RPM Package Specification
  3. ## Copyright (c) 2000-2018 OpenPKG Project <http://openpkg.org/>
  4. ##
  5. ## Permission to use, copy, modify, and distribute this software for
  6. ## any purpose with or without fee is hereby granted, provided that
  7. ## the above copyright notice and this permission notice appear in all
  8. ## copies.
  9. ##
  10. ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  11. ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  12. ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  13. ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
  14. ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  15. ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  16. ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  17. ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  18. ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  19. ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  20. ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  21. ## SUCH DAMAGE.
  22. ##
  23. # package version
  24. %define V_emitter_base 2.0.437
  25. %define V_emitter_snap 20180808
  26. # package information
  27. Name: emitter
  28. Summary: MQTT Broker
  29. URL: https://emitter.io
  30. Vendor: Misakai Ltd.
  31. Packager: OpenPKG Project
  32. Distribution: OpenPKG Community
  33. Class: EVAL
  34. Group: Networking
  35. License: AGPL
  36. Version: %{V_emitter_base}.%{V_emitter_snap}
  37. Release: 20180808
  38. # list of sources
  39. Source0: http://download.openpkg.org/components/versioned/emitter/emitter-%{V_emitter_snap}.tar.xz
  40. Source1: rc.emitter
  41. Source2: emitter.conf
  42. # build information
  43. BuildPreReq: OpenPKG, openpkg >= 20160101, go
  44. PreReq: OpenPKG, openpkg >= 20160101
  45. %description
  46. Emitter is a real-time communication service for connecting
  47. online devices. Infrastructure and APIs for IoT, gaming, apps and
  48. real-time web. At its core, Emitter is a distributed, scalable and
  49. fault-tolerant publish-subscribe messaging platform based on MQTT
  50. protocol and featuring message storage.
  51. %track
  52. prog emitter:release = {
  53. version = %{V_emitter_base}
  54. url = https://github.com/emitter-io/emitter/releases
  55. regex = v(__VER__)\.tar\.gz
  56. }
  57. prog emitter:snapshot = {
  58. version = %{V_emitter_snap}
  59. url = http://download.openpkg.org/components/versioned/emitter/
  60. regex = emitter-(__VER__)\.tar\.xz
  61. }
  62. %prep
  63. %setup -q -n emitter
  64. %build
  65. # build server program
  66. ( export GOPATH=`pwd`
  67. cd src/github.com/emitter-io/emitter
  68. go build -x
  69. ) || exit $?
  70. # generate secrets
  71. ./src/github.com/emitter-io/emitter/emitter >tmp 2>&1
  72. license=`grep "generated new license:" tmp | sed -e 's;^.*: ;;'`
  73. secret=`grep "generated new secret key:" tmp | sed -e 's;^.*: ;;'`
  74. ( echo "##"
  75. echo "## emitter.sh -- Emitter secrets"
  76. echo "##"
  77. echo ""
  78. echo "EMITTER_LICENSE=\"$license\""
  79. echo "EMITTER_SECRET=\"$secret\""
  80. echo ""
  81. ) >emitter.sh
  82. rm -f tmp
  83. %install
  84. # create directory hierarchy
  85. %{l_shtool} mkdir -f -p -m 755 \
  86. $RPM_BUILD_ROOT%{l_prefix}/sbin \
  87. $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
  88. $RPM_BUILD_ROOT%{l_prefix}/etc/emitter \
  89. $RPM_BUILD_ROOT%{l_prefix}/var/emitter/log \
  90. $RPM_BUILD_ROOT%{l_prefix}/var/emitter/run
  91. # install program
  92. %{l_shtool} install -c -s -m 755 \
  93. src/github.com/emitter-io/emitter/emitter \
  94. $RPM_BUILD_ROOT%{l_prefix}/sbin/
  95. # install run-command script
  96. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  97. %{SOURCE rc.emitter} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
  98. # install default configuration files
  99. %{l_shtool} install -c -m 600 %{l_value -s -a} \
  100. emitter.sh \
  101. $RPM_BUILD_ROOT%{l_prefix}/etc/emitter/
  102. %{l_shtool} install -c -m 644 %{l_value -s -a} \
  103. %{SOURCE emitter.conf} \
  104. $RPM_BUILD_ROOT%{l_prefix}/etc/emitter/
  105. # determine installation files
  106. %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
  107. %{l_files_std} \
  108. '%config %attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/etc/emitter/*' \
  109. '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/emitter/*'
  110. %files -f files
  111. %clean
  112. %post
  113. if [ $1 -eq 1 ]; then
  114. # display final hints on initial installation
  115. ( echo "Start Emitter by running:"
  116. echo " \$ $RPM_INSTALL_PREFIX/bin/openpkg rc emitter start"
  117. echo "Then use the EMITTER_SECRET from..."
  118. echo " \$ $RPM_INSTALL_PREFIX/etc/emitter/emitter.sh"
  119. echo "...to generate your channel keys on:"
  120. echo " http://127.0.0.1:9080/keygen"
  121. ) | %{l_rpmtool} msg -b -t notice
  122. elif [ $1 -eq 2 ]; then
  123. # after upgrade, restart service
  124. eval `%{l_rc} emitter status 2>/dev/null`
  125. [ ".$emitter_active" = .yes ] && %{l_rc} emitter restart
  126. fi
  127. exit 0
  128. %preun
  129. # before erase, stop service and remove log files
  130. if [ $1 -eq 0 ]; then
  131. # stop service
  132. %{l_rc} emitter stop 2>/dev/null
  133. # remove log files
  134. rm -f $RPM_INSTALL_PREFIX/var/emitter/log/* >/dev/null 2>&1 || true
  135. rm -f $RPM_INSTALL_PREFIX/var/emitter/run/* >/dev/null 2>&1 || true
  136. fi
  137. exit 0