#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright 2016-2023 Jim Klimov
#

set name=pkg.fmri value=pkg:/$(COMPONENT_FMRI)/server@$(IPS_COMPONENT_VERSION),$(BUILD_VERSION)
set name=pkg.human-version value=$(HUMAN_VERSION)
set name=pkg.summary value="$(COMPONENT_SUMMARY) - NUT data server and shared items for drivers"
set name=info.classification value="$(COMPONENT_CLASSIFICATION)"
set name=info.upstream-url value=$(COMPONENT_PROJECT_URL)
set name=info.source-url value=$(COMPONENT_ARCHIVE_URL)
set name=org.opensolaris.consolidation value=$(CONSOLIDATION)

license $(COMPONENT_LICENSE_FILE) license='$(COMPONENT_LICENSE)'

<transform file path=usr/lib/nut/bin/(.+) -> default mode 0555>
<transform dir path=usr/lib/nut/bin -> set group bin>
<transform file path=usr/share/nut/solaris-smf/method/(.+) -> default mode 0555>
<transform dir path=usr/share/nut/solaris-smf/method -> set group bin>
<transform file path=usr.*/man/.+ -> default mangler.man.stability uncommitted>
<transform file path=usr/share/man/man1/(.+) -> set action.hash usr/share/man/man1/%<1> >
<transform file path=usr/share/man/man1m/(.+) -> set action.hash usr/share/man/man1m/%<1> >

dir path=usr/lib/nut/bin group=bin

depend fmri=$(COMPONENT_FMRI)/common@$(IPS_COMPONENT_VERSION),$(BUILD_VERSION) type=require

# NUT data server binaries, shared baseline for drivers, and other resources.
# The upsd should be on the same system as drivers (talking over Unix sockets
# to them) but may be a different system from monitoring clients which just
# want to shut down in time.

### Data server and its resources
file path=usr/sbin/upsd

# For troubleshooting or last-resort automation: tap into Unix sockets
# between upsd and drivers. See nut/docs/sock-protocol.txt for details.
file path=usr/lib/nut/bin/sockdebug
file path=usr/share/man/man1m/sockdebug.1m

# Services for data server and drivers.
# NUT should start generally after networking (if SNMP or NetXML is used,
# or if this box is a client to remote upsd). Ending is trickier - could
# want it to issue killpower late in shutdown, but have network to be able
# to do so (for remote UPSes). This can be tuned in XML manifest by user.
file path=usr/share/nut/solaris-smf/method/svc-nut-server
file path=usr/share/nut/solaris-smf/manifest/nut-server.xml
link path=lib/svc/manifest/system/power/nut-server.xml \
    target=../../../../../usr/share/nut/solaris-smf/manifest/nut-server.xml \
    restart_fmri=svc:/system/manifest-import:default

file path=usr/share/man/man1m/upsd.1m
file path=usr/share/man/man5/upsd.conf.5
file path=usr/share/man/man5/upsd.users.5

# We deliver the sample configs as the ones to use,
# at worst they have no actual information inside and do nothing.
file etc/nut/upsd.conf.sample path=etc/nut/upsd.conf \
    group=nut owner=root mode=0640 preserve=true
file etc/nut/upsd.users.sample path=etc/nut/upsd.users \
    group=nut owner=root mode=0640 preserve=true

# Note: this is not a systemd *.service but an avahi one ;)
file build/$(MACH64)/scripts/avahi/nut.service path=usr/share/nut/nut.avahi-service.example

### Items below might be some nut/drivers-common package, but given how
### the NUT data server always resides with the drivers, they are here.

# Tools and services for driver instance (and group) management
file path=usr/sbin/upsdrvctl
file path=usr/sbin/upsdrvsvcctl

file path=usr/share/man/man1m/upsdrvctl.1m
file path=usr/share/man/man1m/upsdrvsvcctl.1m
file path=usr/share/man/man1m/nutupsdrv.1m

# Note: While nut-scanner can use snmp, neon/xml, ipmi and usb libs, it loads
# them truly dynamically (if available) and skips otherwise. Installing the
# NUT driver packages should pull their relevant libs by harder ELF reqs.
# Reasonably, if you don't want those UPSes (got no drivers) why scan them? :)
file path=usr/bin/nut-scanner
file path=usr/share/man/man1m/nut-scanner.1m

# Script and service to define nut-driver service instances
# separately for each ups.conf device section definition -
# so failing independently and allowing for separate service
# dependencies (e.g. some need a network, others do not).
file path=usr/lib/nut/bin/nut-driver-enumerator.sh
file path=usr/share/man/man1m/nut-driver-enumerator.1m

file path=usr/share/nut/solaris-smf/manifest/nut-driver.xml
file path=usr/share/nut/solaris-smf/manifest/nut-driver-enumerator.xml
link path=lib/svc/manifest/system/power/nut-driver.xml \
    target=../../../../../usr/share/nut/solaris-smf/manifest/nut-driver.xml \
    restart_fmri=svc:/system/manifest-import:default
link path=lib/svc/manifest/system/power/nut-driver-enumerator.xml \
    target=../../../../../usr/share/nut/solaris-smf/manifest/nut-driver-enumerator.xml \
    restart_fmri=svc:/system/manifest-import:default

### Shared by data server and drivers

# Technically this is file is relevant to a nut-server (upsd) and to
# drivers, but they should be on same system anyway and NDE above uses
# it directly. Also upsd may be told to start without any driver config
# (to report "I am alive and known nothing") but drivers can not.
# So it is here. We deliver the sample configs as the ones to use,
# at worst they have no actual information inside and do nothing.
file etc/nut/ups.conf.sample path=etc/nut/ups.conf \
    group=nut owner=root mode=0640 preserve=true
file path=usr/share/man/man5/ups.conf.5