nut-2.7.4.ebuild 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. # Copyright 1999-2016 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=5
  4. inherit autotools bash-completion-r1 eutils fixheadtails multilib user systemd flag-o-matic toolchain-funcs
  5. MY_P=${P/_/-}
  6. DESCRIPTION="Network-UPS Tools"
  7. HOMEPAGE="http://www.networkupstools.org/"
  8. # Nut mirrors are presently broken
  9. SRC_URI="http://random.networkupstools.org/source/${PV%.*}/${MY_P}.tar.gz
  10. http://www.networkupstools.org/source/${PV%.*}/${MY_P}.tar.gz"
  11. LICENSE="GPL-2"
  12. SLOT="0"
  13. KEYWORDS="~amd64 ~arm ~ppc ~ppc64 ~x86 ~x86-fbsd"
  14. IUSE="cgi ipmi snmp +usb selinux ssl tcpd xml zeroconf"
  15. CDEPEND="
  16. cgi? ( >=media-libs/gd-2[png] )
  17. snmp? ( net-analyzer/net-snmp )
  18. usb? ( virtual/libusb:0 )
  19. ssl? ( >=dev-libs/openssl-1 )
  20. tcpd? ( sys-apps/tcp-wrappers )
  21. xml? ( >=net-libs/neon-0.25.0 )
  22. ipmi? ( sys-libs/freeipmi )
  23. zeroconf? ( net-dns/avahi )
  24. virtual/udev"
  25. DEPEND="$CDEPEND
  26. >=sys-apps/sed-4
  27. virtual/pkgconfig"
  28. RDEPEND="${CDEPEND}
  29. selinux? ( sec-policy/selinux-nut )
  30. "
  31. S=${WORKDIR}/${MY_P}
  32. # Bug #480664 requested UPS_DRIVERS_IUSE for more flexibility in building this package
  33. SERIAL_DRIVERLIST="al175 bcmxcp belkin belkinunv bestfcom bestfortress bestuferrups bestups dummy-ups etapro everups gamatronic genericups isbmex liebert liebert-esp2 masterguard metasys oldmge-shut mge-utalk microdowell mge-shut oneac optiups powercom rhino safenet solis tripplite tripplitesu upscode2 victronups powerpanel blazer_ser clone clone-outlet ivtscd apcsmart apcsmart-old apcupsd-ups riello_ser nutdrv_qx"
  34. SNMP_DRIVERLIST="snmp-ups"
  35. USB_LIBUSB_DRIVERLIST="usbhid-ups bcmxcp_usb tripplite_usb blazer_usb richcomm_usb riello_usb nutdrv_qx"
  36. USB_DRIVERLIST=${USB_LIBUSB_DRIVERLIST}
  37. #HAL_DRIVERLIST="usbhid-ups bcmxcp_usb tripplite_usb blazer_usb riello_usb nutdrv_qx"
  38. NEONXML_DRIVERLIST="netxml-ups"
  39. IPMI_DRIVERLIST="nut-ipmipsu"
  40. # Now we build from it:
  41. for name in ${SERIAL_DRIVERLIST} ; do
  42. IUSE_UPS_DRIVERS="${IUSE_UPS_DRIVERS} +ups_drivers_${name}"
  43. done
  44. for name in ${USB_DRIVERLIST} ; do
  45. IUSE_UPS_DRIVERS="${IUSE_UPS_DRIVERS} +ups_drivers_${name}"
  46. REQUIRED_USE="${REQUIRED_USE} ups_drivers_${name}? ( usb )"
  47. done
  48. for name in ${NEONXML_DRIVERLIST}; do
  49. IUSE_UPS_DRIVERS="${IUSE_UPS_DRIVERS} ups_drivers_${name}"
  50. REQUIRED_USE="${REQUIRED_USE} ups_drivers_${name}? ( xml )"
  51. done
  52. for name in ${SNMP_DRIVERLIST} ; do
  53. IUSE_UPS_DRIVERS="${IUSE_UPS_DRIVERS} ups_drivers_${name}"
  54. REQUIRED_USE="${REQUIRED_USE} ups_drivers_${name}? ( snmp )"
  55. done
  56. for name in ${IPMI_DRIVERLIST} ; do
  57. IUSE_UPS_DRIVERS="${IUSE_UPS_DRIVERS} ups_drivers_${name}"
  58. REQUIRED_USE="${REQUIRED_USE} ups_drivers_${name}? ( ipmi )"
  59. done
  60. IUSE="${IUSE} ${IUSE_UPS_DRIVERS}"
  61. # public files should be 644 root:root
  62. NUT_PUBLIC_FILES="/etc/nut/{ups,upssched}.conf"
  63. # private files should be 640 root:nut - readable by nut, writeable by root,
  64. NUT_PRIVATE_FILES="/etc/nut/{upsd.conf,upsd.users,upsmon.conf}"
  65. # public files should be 644 root:root, only installed if USE=cgi
  66. NUT_CGI_FILES="/etc/nut/{{hosts,upsset}.conf,upsstats{,-single}.html}"
  67. pkg_setup() {
  68. enewgroup nut 84
  69. enewuser nut 84 -1 /var/lib/nut nut,uucp
  70. # As of udev-104, NUT must be in uucp and NOT in tty.
  71. gpasswd -d nut tty 2>/dev/null
  72. gpasswd -a nut uucp 2>/dev/null
  73. # in some cases on old systems it wasn't in the nut group either!
  74. gpasswd -a nut nut 2>/dev/null
  75. warningmsg ewarn
  76. }
  77. src_prepare() {
  78. #ht_fix_file configure.in
  79. epatch "${FILESDIR}/nut-2.7.2/nut-2.7.2-no-libdummy.patch"
  80. epatch "${FILESDIR}"/${PN}-2.6.2-lowspeed-buffer-size.patch
  81. #epatch "${FILESDIR}"/${PN}-2.6.3-CVE-2012-2944.patch
  82. #epatch "${FILESDIR}"/${PN}-2.6.5-freeipmi_fru.patch
  83. #epatch "${FILESDIR}"/${PN}-2.7.1-fix-scanning.patch
  84. epatch "${FILESDIR}"/${PN}-2.7.1-snmpusb-order.patch
  85. sed -e "s:GD_LIBS.*=.*-L/usr/X11R6/lib \(.*\) -lXpm -lX11:GD_LIBS=\"\1:" \
  86. -e '/systemdsystemunitdir=.*echo.*sed.*libdir/s,^,#,g' \
  87. -i configure.ac || die
  88. sed -e "s:52.nut-usbups.rules:70-nut-usbups.rules:" \
  89. -i scripts/udev/Makefile.am || die
  90. rm -f ltmain.sh m4/lt* m4/libtool.m4
  91. sed -i \
  92. -e 's:@LIBSSL_LDFLAGS@:@LIBSSL_LIBS@:' \
  93. lib/libupsclient{.pc,-config}.in || die #361685
  94. eautoreconf
  95. }
  96. src_configure() {
  97. local myconf
  98. append-flags -fno-lto
  99. tc-export CC
  100. tc-export CXX
  101. tc-export AR
  102. local UPS_DRIVERS=""
  103. for u in $USE ; do
  104. u2=${u#ups_drivers_}
  105. [[ "${u}" != "${u2}" ]] && UPS_DRIVERS="${UPS_DRIVERS} ${u2}"
  106. done
  107. UPS_DRIVERS="${UPS_DRIVERS# }" UPS_DRIVERS="${UPS_DRIVERS% }"
  108. myconf="${myconf} --with-drivers=${UPS_DRIVERS// /,}"
  109. use cgi && myconf="${myconf} --with-cgipath=/usr/share/nut/cgi"
  110. # TODO: USE flag for sys-power/powerman
  111. econf \
  112. --sysconfdir=/etc/nut \
  113. --datarootdir=/usr/share/nut \
  114. --datadir=/usr/share/nut \
  115. --disable-static \
  116. --with-statepath=/var/lib/nut \
  117. --with-drvpath=/$(get_libdir)/nut \
  118. --with-htmlpath=/usr/share/nut/html \
  119. --with-user=nut \
  120. --with-group=nut \
  121. --with-logfacility=LOG_DAEMON \
  122. --with-dev \
  123. --with-serial \
  124. --without-powerman \
  125. $(use_with cgi) \
  126. $(use_with ipmi) \
  127. $(use_with ipmi freeipmi) \
  128. $(use_with snmp) \
  129. $(use_with ssl) \
  130. $(use_with tcpd wrap) \
  131. $(use_with usb) \
  132. $(use_with xml neon) \
  133. $(use_with zeroconf avahi) \
  134. $(systemd_with_unitdir) \
  135. ${myconf}
  136. }
  137. src_install() {
  138. emake DESTDIR="${D}" install || die
  139. find "${D}" -name '*.la' -exec rm -f {} +
  140. dodir /sbin
  141. dosym /usr/sbin/upsdrvctl /sbin/upsdrvctl
  142. if use cgi; then
  143. elog "CGI monitoring scripts are installed in /usr/share/nut/cgi."
  144. elog "copy them to your web server's ScriptPath to activate (this is a"
  145. elog "change from the old location)."
  146. elog "If you use lighttpd, see lighttpd_nut.conf in the documentation."
  147. fi
  148. # this must be done after all of the install phases
  149. for i in "${D}"/etc/nut/*.sample ; do
  150. mv "${i}" "${i/.sample/}"
  151. done
  152. dodoc AUTHORS ChangeLog docs/*.txt MAINTAINERS NEWS README TODO UPGRADING || die
  153. newdoc lib/README README.lib || die
  154. newdoc "${FILESDIR}"/lighttpd_nut.conf-2.2.0 lighttpd_nut.conf || die
  155. docinto cables
  156. dodoc docs/cables/* || die
  157. newinitd "${FILESDIR}"/nut-2.6.5-init.d-upsd upsd || die
  158. newinitd "${FILESDIR}"/nut-2.2.2-init.d-upsdrv upsdrv || die
  159. newinitd "${FILESDIR}"/nut-2.6.5-init.d-upsmon upsmon || die
  160. newinitd "${FILESDIR}"/nut-2.6.5-init.d-upslog upslog || die
  161. newinitd "${FILESDIR}"/nut.powerfail.initd nut.powerfail || die
  162. keepdir /var/lib/nut
  163. einfo "Setting up permissions on files and directories"
  164. fperms 0700 /var/lib/nut
  165. fowners nut:nut /var/lib/nut
  166. # Do not remove eval here, because the variables contain shell expansions.
  167. eval fperms 0640 ${NUT_PRIVATE_FILES}
  168. eval fowners root:nut ${NUT_PRIVATE_FILES}
  169. # Do not remove eval here, because the variables contain shell expansions.
  170. eval fperms 0644 ${NUT_PUBLIC_FILES}
  171. eval fowners root:root ${NUT_PUBLIC_FILES}
  172. # Do not remove eval here, because the variables contain shell expansions.
  173. if use cgi; then
  174. eval fperms 0644 ${NUT_CGI_FILES}
  175. eval fowners root:root ${NUT_CGI_FILES}
  176. fi
  177. # this is installed for 2.4 and fbsd guys
  178. if ! has_version virtual/udev; then
  179. einfo "Installing non-udev hotplug support"
  180. insinto /etc/hotplug/usb
  181. insopts -m 755
  182. doins scripts/hotplug/nut-usbups.hotplug
  183. fi
  184. dobashcomp "${S}"/scripts/misc/nut.bash_completion
  185. }
  186. pkg_postinst() {
  187. # this is to ensure that everybody that installed old versions still has
  188. # correct permissions
  189. chown nut:nut "${ROOT}"/var/lib/nut 2>/dev/null
  190. chmod 0700 "${ROOT}"/var/lib/nut 2>/dev/null
  191. # Do not remove eval here, because the variables contain shell expansions.
  192. eval chown root:nut "${ROOT}"${NUT_PRIVATE_FILES} 2>/dev/null
  193. eval chmod 0640 "${ROOT}"${NUT_PRIVATE_FILES} 2>/dev/null
  194. # Do not remove eval here, because the variables contain shell expansions.
  195. eval chown root:root "${ROOT}"${NUT_PUBLIC_FILES} 2>/dev/null
  196. eval chmod 0644 "${ROOT}"${NUT_PUBLIC_FILES} 2>/dev/null
  197. # Do not remove eval here, because the variables contain shell expansions.
  198. if use cgi; then
  199. eval chown root:root "${ROOT}"${NUT_CGI_FILES} 2>/dev/null
  200. eval chmod 0644 "${ROOT}"${NUT_CGI_FILES} 2>/dev/null
  201. fi
  202. warningmsg elog
  203. }
  204. warningmsg() {
  205. msgfunc="$1"
  206. [ -z "$msgfunc" ] && die "msgfunc not specified in call to warningmsg!"
  207. ${msgfunc} "Please note that NUT now runs under the 'nut' user."
  208. ${msgfunc} "NUT is in the uucp group for access to RS-232 UPS."
  209. ${msgfunc} "However if you use a USB UPS you may need to look at the udev or"
  210. ${msgfunc} "hotplug rules that are installed, and alter them suitably."
  211. ${msgfunc} ''
  212. ${msgfunc} "You are strongly advised to read the UPGRADING file provided by upstream."
  213. ${msgfunc} ''
  214. ${msgfunc} "Please note that upsdrv is NOT automatically started by upsd anymore."
  215. ${msgfunc} "If you have multiple UPS units, you can use their NUT names to"
  216. ${msgfunc} "have a service per UPS:"
  217. ${msgfunc} "ln -s /etc/init.d/upsdrv /etc/init.d/upsdrv.\$UPSNAME"
  218. ${msgfunc} ''
  219. ${msgfunc} 'If you want apcupsd to power off your UPS when it'
  220. ${msgfunc} 'shuts down your system in a power failure, you must'
  221. ${msgfunc} 'add nut.powerfail to your shutdown runlevel:'
  222. ${msgfunc} ''
  223. ${msgfunc} 'rc-update add nut.powerfail shutdown'
  224. ${msgfunc} ''
  225. }