cacti.spec 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. ##
  2. ## cacti.spec -- OpenPKG RPM Package Specification
  3. ## Copyright (c) 2000-2017 OpenPKG Foundation e.V. <http://openpkg.net/>
  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 information
  24. Name: cacti
  25. Summary: Network Monitoring and Graphing Frontend
  26. URL: http://www.cacti.net/
  27. Vendor: raXnet
  28. Packager: OpenPKG Foundation e.V.
  29. Distribution: OpenPKG Community
  30. Class: PLUS
  31. Group: Monitoring
  32. License: GPL
  33. Version: 1.1.22
  34. Release: 20170911
  35. # list of sources
  36. Source0: http://www.cacti.net/downloads/cacti-%{version}.tar.gz
  37. Source1: cacti-setup.sh
  38. Source2: cacti-cron.sh
  39. Source3: cacti-apache.conf
  40. Source4: rc.cacti
  41. # build information
  42. BuildPreReq: OpenPKG, openpkg >= 20160101
  43. PreReq: OpenPKG, openpkg >= 20160101
  44. PreReq: rrdtool, mysql, snmp, perl, php, dcron
  45. PreReq: apache
  46. PreReq: apache-php
  47. PreReq: apache-php::with_mysql = yes
  48. PreReq: apache-php::with_mm = yes
  49. PreReq: apache-php::with_xml = yes
  50. PreReq: php
  51. PreReq: php::with_mysql = yes
  52. PreReq: php::with_mm = yes
  53. PreReq: php::with_xml = yes
  54. %description
  55. Cacti is a complete PHP-driven frontend to RRDTool. It stores all
  56. of the necessary information to create graphs and populate them
  57. with data in a MySQL database. Along with being able to maintain
  58. Graphs, Data Sources, and Round Robin Archives in a database,
  59. Cacti handles the data gathering as well. There is also SNMP
  60. support for those used to creating traffic graphs with MRTG.
  61. %track
  62. prog cacti = {
  63. version = %{version}
  64. url = http://www.cacti.net/downloads/
  65. regex = cacti-(__VER__)\.tar\.gz
  66. }
  67. %prep
  68. %setup -q
  69. %build
  70. %install
  71. # create installation hierarchy
  72. %{l_shtool} mkdir -f -p -m 755 \
  73. $RPM_BUILD_ROOT%{l_prefix}/sbin \
  74. $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
  75. $RPM_BUILD_ROOT%{l_prefix}/etc/dcron/crontabs \
  76. $RPM_BUILD_ROOT%{l_prefix}/etc/cacti \
  77. $RPM_BUILD_ROOT%{l_prefix}/share/cacti \
  78. $RPM_BUILD_ROOT%{l_prefix}/var/cacti/run
  79. # adjust configuration
  80. %{l_shtool} subst \
  81. -e 's;"cactiuser";"cacti";g' \
  82. include/config.php
  83. %{l_shtool} subst \
  84. -e 's;perl <path_cacti>;%{l_prefix}/bin/perl %{l_prefix}/share/cacti;' \
  85. -e 's;\(path_php_binary.*\)<DEFAULT>;\1%{l_prefix}/bin/php;' \
  86. -e 's;\(path_snmpwalk.*\)<DEFAULT>;\1%{l_prefix}/bin/snmpwalk;' \
  87. -e 's;\(path_snmpget.*\)<DEFAULT>;\1%{l_prefix}/bin/snmpget;' \
  88. -e 's;\(path_rrdtool.*\)<DEFAULT>;\1%{l_prefix}/bin/rrdtool;' \
  89. -e 's;\(path_webroot.*\)<DEFAULT>;\1%{l_prefix}/share/cacti;' \
  90. -e 's;\(path_webcacti.*\)<DEFAULT>;\1/cacti/;' \
  91. -e 's;\(smnp_version.*\)ucd-snmp;\1net-snmp;' \
  92. cacti.sql
  93. %{l_shtool} subst \
  94. -e 's;docs/;../docs/;g' \
  95. -e 's;"/bin";"%{l_prefix}/bin", "%{l_prefix}/sbin", "/bin";g' \
  96. install/index.php
  97. %{l_shtool} subst \
  98. -e 's;#!/usr/bin/php;#!%{l_prefix}/bin/php;' \
  99. cmd.php
  100. # install all files and strip down installation afterwards
  101. cp -rp * $RPM_BUILD_ROOT%{l_prefix}/share/cacti/
  102. ( cd $RPM_BUILD_ROOT%{l_prefix}/share/cacti
  103. rm -f LICENSE README
  104. rm -rf cactid
  105. rm -f rra/.placeholder
  106. rm -f log/rrd.log
  107. ) || exit $?
  108. # move variable data into separate locations
  109. mv $RPM_BUILD_ROOT%{l_prefix}/share/cacti/log \
  110. $RPM_BUILD_ROOT%{l_prefix}/var/cacti/log
  111. ln -s \
  112. %{l_prefix}/var/cacti/log \
  113. $RPM_BUILD_ROOT%{l_prefix}/share/cacti/log
  114. mv $RPM_BUILD_ROOT%{l_prefix}/share/cacti/rra \
  115. $RPM_BUILD_ROOT%{l_prefix}/var/cacti/rra
  116. ln -s \
  117. %{l_prefix}/var/cacti/rra \
  118. $RPM_BUILD_ROOT%{l_prefix}/share/cacti/rra
  119. # internally Cacti appends the webroot to its directory
  120. # but we don't want to do this, so use a self-ref link.
  121. ( cd $RPM_BUILD_ROOT%{l_prefix}/share/cacti
  122. ln -s . cacti
  123. ) || exit $?
  124. # install run-command script
  125. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  126. %{SOURCE rc.cacti} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
  127. # install MySQL database setup script
  128. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  129. %{SOURCE cacti-setup.sh} \
  130. $RPM_BUILD_ROOT%{l_prefix}/sbin/cacti-setup
  131. # install Cron job script
  132. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  133. %{SOURCE cacti-cron.sh} \
  134. $RPM_BUILD_ROOT%{l_prefix}/sbin/cacti-cron
  135. # install custom Apache configuration
  136. l_hostname=`%{l_shtool} echo -e %h`
  137. l_domainname=`%{l_shtool} echo -e %d | cut -c2-`
  138. %{l_shtool} install -c -m 644 %{l_value -s -a} \
  139. -e "s;@l_hostname@;$l_hostname;g" \
  140. -e "s;@l_domainname@;$l_domainname;g" \
  141. %{SOURCE cacti-apache.conf} \
  142. $RPM_BUILD_ROOT%{l_prefix}/etc/cacti/
  143. # install custom crontab
  144. ( echo "##"
  145. echo "## Cacti crontab"
  146. echo "##"
  147. echo ""
  148. echo "*/5 * * * * su %{l_rusr} -c %{l_prefix}/sbin/cacti-cron"
  149. echo ""
  150. ) >$RPM_BUILD_ROOT%{l_prefix}/etc/dcron/crontabs/cacti
  151. # determine installation files
  152. %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
  153. %{l_files_std} \
  154. '%config %{l_prefix}/etc/cacti/*' \
  155. '%config %attr(-,%{l_susr},%{l_sgrp}) %{l_prefix}/etc/dcron/crontabs/cacti' \
  156. '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/cacti'
  157. %files -f files
  158. %clean
  159. %post
  160. if [ $1 -eq 1 ]; then
  161. # display final hints on initial installation
  162. ( echo "1. To complete this installation of Cacti please start MySQL and"
  163. echo " initialize the Cacti database like this:"
  164. echo " \$ $RPM_INSTALL_PREFIX/bin/openpkg rc mysql start"
  165. echo " \$ $RPM_INSTALL_PREFIX/sbin/cacti-setup"
  166. echo ""
  167. echo "2. By default, Cacti is run by the OpenPKG cron jobs only every"
  168. echo " 5 minutes. To run Cacti every 1 minute for even more granular"
  169. echo " data gathering, edit the following crontab(5) file:"
  170. echo " \$ vi $RPM_INSTALL_PREFIX/etc/dcron/crontabs/cacti"
  171. echo ""
  172. echo "3. By default, Cacti runs its own Apache server on IPv4 address"
  173. echo " 127.0.0.1, TCP port 8080. Please change this by editing the"
  174. echo " \"Listen 127.0.0.1:8080\" directive in the configuration file"
  175. echo " $RPM_INSTALL_PREFIX/etc/cacti/cacti-apache.conf"
  176. echo ""
  177. echo "4. After this postinstallation, start Cacti by running"
  178. echo " \$ $RPM_INSTALL_PREFIX/bin/openpkg rc cacti start"
  179. echo " and connect with a browser to:"
  180. echo " http://127.0.0.1:8080/"
  181. echo " Follow Cacti's initial configuration dialogs, and then login"
  182. echo " as 'admin' (with initial password 'admin') to change the"
  183. echo " password to a custom one."
  184. ) | %{l_rpmtool} msg -b -t notice
  185. fi
  186. if [ $1 -eq 2 ]; then
  187. # after upgrade, restart service
  188. eval `%{l_rc} cacti status 2>/dev/null`
  189. [ ".$cacti_active" = .yes ] && %{l_rc} cacti restart
  190. fi
  191. exit 0
  192. %preun
  193. if [ $1 -eq 0 ]; then
  194. # before erase, stop service and remove log files
  195. %{l_rc} cacti stop 2>/dev/null
  196. rm -f $RPM_INSTALL_PREFIX/var/cacti/log/* >/dev/null 2>&1 || true
  197. fi
  198. exit 0