ASR_BASE

Change-Id: Icf3719cc0afe3eeb3edc7fa80a2eb5199ca9dda1
diff --git a/external/subpack/net/nut/Config.in b/external/subpack/net/nut/Config.in
new file mode 100644
index 0000000..cd2f43e
--- /dev/null
+++ b/external/subpack/net/nut/Config.in
@@ -0,0 +1,32 @@
+	config NUT_SSL
+		depends on PACKAGE_nut
+		bool "Build with support for OpenSSL"
+		help
+			SSL allows sessions between upsd and clients to be encrypted and can
+			also be used to authenticate servers. This means that stealing port
+			3493 from upsd will no longer net you interesting passwords. SSL is
+			available via OpenSSL on OpenWRT (NSS doesn't seem to work). If you
+			are happy with using passwords to authenticate clients, you can save
+			some space and build NUT without SSL support.
+		default n
+	
+	config NUT_DRIVER_USB
+		depends on PACKAGE_nut
+		bool "Build with support for USB drivers"
+		help
+			If you have a UPS connected via USB, select this.
+		default y
+	
+	config NUT_DRIVER_SNMP
+		depends on PACKAGE_nut
+		bool "Build with support for SNMP drivers"
+		help
+			If you have a UPS you can connect to via SNMP, select this.
+		default n
+
+	config NUT_DRIVER_SERIAL
+		depends on PACKAGE_nut
+		bool "Build with suport for serial drivers"
+		help
+			If you have a UPS connected via serial cable, select this.
+		default y
diff --git a/external/subpack/net/nut/Makefile b/external/subpack/net/nut/Makefile
new file mode 100644
index 0000000..c26c583
--- /dev/null
+++ b/external/subpack/net/nut/Makefile
@@ -0,0 +1,566 @@
+
+# Copyright (C) 2006-2016 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=nut
+PKG_VERSION:=2.7.4
+PKG_RELEASE:=22
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=http://www.networkupstools.org/source/2.7/
+PKG_HASH:=980e82918c52d364605c0703a5dcf01f74ad2ef06e3d365949e43b7d406d25a7
+PKG_LICENSE:=GPL-2.0-or-later GPL-3.0-or-later GPL-1.0-or-later Artistic-1.0-Perl
+PKG_LICENSE_FILES:=LICENSE-GPL2 LICENSE-GPL3 COPYING
+PKG_FIXUP:=autoreconf
+
+PKG_INSTALL:=1
+
+PKG_CONFIG_DEPENDS:= \
+	CONFIG_NUT_DRIVER_SNMP \
+	CONFIG_NUT_DRIVER_USB \
+	CONFIG_NUT_DRIVER_SERIAL \
+	CONFIG_NUT_SSL \
+	CONFIG_PACKAGE_nut-web-cgi
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/nut/Default
+	SECTION:=net
+	CATEGORY:=Network
+	URL:=http://www.networkupstools.org/
+	TITLE:=Network UPS Tools (NUT)
+endef
+
+define Package/nut/description/Default
+Network UPS Tools (NUT) is a client/server monitoring system that
+allows computers to share uninterruptible power supply (UPS) and
+power distribution unit (PDU) hardware. Clients access the hardware
+through the server, and are notified whenever the power status
+changes.
+endef
+
+define Package/nut
+	$(call Package/nut/Default)
+	MENU:=1
+endef
+
+define Package/nut/description
+$(call Package/nut/description/Default)
+endef
+
+define Package/nut/config
+	source "$(SOURCE)/Config.in"
+endef
+
+define Package/nut/install
+	true
+endef
+
+define Package/nut-server/install
+	# Server portion
+	$(INSTALL_DIR) $(1)/etc/nut
+	$(INSTALL_DIR) $(1)/usr/sbin
+	$(INSTALL_DIR) $(1)/etc/init.d
+	$(INSTALL_DIR) $(1)/usr/share/nut
+	$(INSTALL_BIN) ./files/nut-server.init $(1)/etc/init.d/nut-server
+	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/upsd $(1)/usr/sbin
+	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/share/nut/cmdvartab $(1)/usr/share/nut/
+	$(INSTALL_DIR) $(1)/etc/config
+	$(INSTALL_CONF) ./files/nut_server $(1)/etc/config/nut_server
+	ln -sf ../../var/etc/nut/upsd.users  $(1)/etc/nut/upsd.users
+	ln -sf ../../var/etc/nut/upsd.conf $(1)/etc/nut/upsd.conf
+	# Driver common portion
+	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/upsdrvctl $(1)/usr/sbin
+	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/share/nut/driver.list $(1)/usr/share/nut/
+	ln -sf ../../var/etc/nut/ups.conf $(1)/etc/nut/ups.conf
+	# Mangle libhid.usermap into a format (hotplug shell script) useful for OpenWrt
+	$(INSTALL_DIR) $(1)/etc/hotplug.d/usb
+	$(INSTALL_DIR) $(1)/etc/hotplug.d/tty
+	$(INSTALL_BIN) ./files/nut_serial.hotplug $(1)/etc/hotplug.d/tty/40-nut_serial
+	$(INSTALL_BIN) ./files/30-libhid-ups.head $(1)/etc/hotplug.d/usb/30-libhid-ups
+	$(CP) $(PKG_INSTALL_DIR)/etc/hotplug/usb/libhid.usermap $(PKG_BUILD_DIR)/30-libhid-ups.middle
+	$(SED) '/^$$$$/d' \
+		-e '/^#/d' \
+		-E -e 's:^[^ ][^ ]*  *0x0003  *0x0{0,3}([^ ][^ ]*)  *0x0{0,3}*([^ ][^ ]*).*:\1/\2/* | \\:' \
+		$(PKG_BUILD_DIR)/30-libhid-ups.middle
+	tail -n+2 $(PKG_BUILD_DIR)/30-libhid-ups.middle >>$(1)/etc/hotplug.d/usb/30-libhid-ups
+	cat ./files/30-libhid-ups.tail >>$(1)/etc/hotplug.d/usb/30-libhid-ups
+endef
+
+define Package/nut-common
+	$(call Package/nut/Default)
+	TITLE+= (common)
+	DEPENDS:= nut \
+		+NUT_DRIVER_SNMP:libnetsnmp \
+		+NUT_DRIVER_USB:libusb-compat \
+		+NUT_SSL:libopenssl
+endef
+
+define Package/nut-common/description
+$(call Package/nut/description/Default)
+This package contains the common files.
+endef
+
+define Package/nut-common/conffiles
+/etc/nut/nut.conf
+endef
+
+define Package/nut-common/install
+	$(INSTALL_DIR) $(1)/etc/nut
+	$(INSTALL_DIR) $(1)/usr/lib
+	$(CP) $(PKG_INSTALL_DIR)/usr/lib/libupsclient.so* $(1)/usr/lib/
+	ln -sf /var/etc/nut/nut.conf $(1)/etc/nut/nut.conf
+endef
+
+define Package/nut-server
+	$(call Package/nut/Default)
+	TITLE+= (server)
+	DEPENDS:=nut +nut-common
+	USERID:=nut=113:nut=113
+endef
+
+define Package/nut-server/description
+$(call Package/nut/description/Default)
+upsd is responsible for serving the data from the drivers to the
+clients. It connects to each driver and maintains a local cache of the
+current state. Queries from the clients are served from this cache, so
+delays are minimal. This program is essential, and must be running at
+all times to actually make any use out of the drivers and clients.
+endef
+
+define Package/nut-server/conffiles
+/etc/config/nut_server
+/etc/nut/upsd.conf
+/etc/nut/upsd.users
+/etc/nut/ups.conf
+endef
+
+define Package/nut-upsmon
+  $(call Package/nut/Default)
+	TITLE+= (monitor)
+	DEPENDS:=nut +nut-common
+	USERID:=nutmon=114:nutmon=114
+endef
+
+define Package/nut-upsmon/description
+$(call Package/nut/description/Default)
+upsmon is the client process that is responsible for the most important
+part of UPS monitoring--shutting down the system when the power goes
+out. It can call out to other helper programs for notification purposes
+during power events. upsmon can monitor multiple systems using a single
+process. Every UPS that is defined in the upsmon.conf configuration file
+is assigned a power value and a type (slave or master).
+endef
+
+define Package/nut-upsmon/conffiles
+/etc/config/nut_monitor
+/etc/nut/upsmon.conf
+endef
+
+define Package/nut-upsmon/install
+	$(INSTALL_DIR) $(1)/etc/nut
+	$(INSTALL_DIR) $(1)/usr/sbin
+	$(INSTALL_DIR) $(1)/etc/init.d
+	$(INSTALL_BIN) ./files/nut-monitor.init $(1)/etc/init.d/nut-monitor
+	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/upsmon $(1)/usr/sbin/
+	$(INSTALL_BIN) ./files/nutshutdown $(1)/usr/sbin/nutshutdown
+	$(INSTALL_DIR) $(1)/etc/config
+	$(INSTALL_CONF) ./files/nut_monitor $(1)/etc/config/nut_monitor
+	ln -sf /var/etc/nut/upsmon.conf $(1)/etc/nut/upsmon.conf
+endef
+
+define Package/nut-upsmon-sendmail-notify
+	$(call Package/nut/Default)
+	TITLE+= (upsmon with notifications via sendmail)
+	DEPENDS:=nut +nut-upsmon
+	CONFLICTS:=nut-upssched
+endef
+
+define Package/nut-upsmon-sendmail-notify/description
+$(call Package/nut/description/Default)
+upsmon with default notification via sendmail
+endef
+
+define Package/nut-upsmon-sendmail-notify/install
+	$(INSTALL_DIR) $(1)/usr/bin $(1)/etc/uci-defaults
+	$(INSTALL_BIN) ./files/nut-sendmail-notify $(1)/usr/bin/
+	$(INSTALL_DATA) ./files/nut-sendmail-notify.default $(1)/etc/uci-defaults/nut-sendmail-notify
+endef
+
+define Package/nut-upsc
+	$(call Package/nut/Default)
+	TITLE+= (upsc command)
+	DEPENDS:=nut +nut-common
+endef
+
+define Package/nut-upsc/description
+$(call Package/nut/description/Default)
+upsc is provided as a quick way to poll the status of a UPS server. It
+can be used inside shell scripts and other programs that need UPS data
+but do not want to include the full interface.
+endef
+
+define Package/nut-upsc/install
+	$(INSTALL_DIR) $(1)/usr/bin
+	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/upsc $(1)/usr/bin
+endef
+
+define Package/nut-upslog
+	$(call Package/nut/Default)
+	TITLE+= (logging client)
+	DEPENDS:=nut +nut-common
+endef
+
+define Package/nut-upslog/description
+$(call Package/nut/description/Default)
+upslog is a daemon that will poll a UPS at periodic intervals, fetch the
+variables that interest you, format them, and write them to a file.
+endef
+
+define Package/nut-upslog/install
+	$(INSTALL_DIR) $(1)/usr/bin
+	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/upslog $(1)/usr/bin/
+endef
+
+define Package/nut-upscmd
+	$(call Package/nut/Default)
+	TITLE+= (controller)
+	DEPENDS:=nut +nut-common
+endef
+
+define Package/nut-upscmd/description
+$(call Package/nut/description/Default)
+upscmd allows you to invoke "instant commands" in your UPS hardware. Not
+all hardware supports this, so check the list with -l to see if anything
+will work on your equipment. On hardware that supports it, you can use
+this program to start and stop battery tests, invoke a front panel test
+(beep!), turn the load on or off, and more.
+endef
+
+define Package/nut-upscmd/install
+	$(INSTALL_DIR) $(1)/usr/bin
+	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/upscmd $(1)/usr/bin/
+endef
+
+define Package/nut-upsrw
+	$(call Package/nut/Default)
+	TITLE+= (variable editor)
+	DEPENDS:=nut +nut-common
+endef
+
+define Package/nut-upsrw/description
+$(call Package/nut/description/Default)
+upsrw allows you to view and change the read/write variables inside your
+UPS. It sends commands via the upsd to your driver, which configures the
+hardware for you. The list of variables that allow you to change their
+values is based on the capabilities of your UPS equipment. Not all
+models support this feature. Typically, cheaper hardware does not
+support any of them.
+endef
+
+define Package/nut-upsrw/install
+	$(INSTALL_DIR) $(1)/usr/bin
+	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/upsrw $(1)/usr/bin/
+endef
+
+define Package/nut-upssched
+	$(call Package/nut/Default)
+	TITLE+= (helper for triggering events from upsmon)
+	DEPENDS:=nut +nut-common +nut-upsmon
+endef
+
+define Package/nut-upssched/description
+$(call Package/nut/description/Default)
+upssched was created to allow users to execute programs at times relative
+to events being monitored by upsmon. The original purpose was to allow
+for a shutdown to occur after some fixed period on battery, but there are
+other uses that are possible.
+You can alternatively write your own script and save some space.
+endef
+
+define Package/nut-upssched/conffiles
+/etc/nut/upssched.conf
+endef
+
+define Package/nut-upssched/install
+	$(INSTALL_DIR) $(1)/usr/bin
+	$(INSTALL_DIR) $(1)/usr/sbin
+	$(INSTALL_DIR) $(1)/etc/nut
+	$(INSTALL_DIR) $(1)/etc/uci-defaults
+	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/upssched-cmd $(1)/usr/bin/
+	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/upssched $(1)/usr/sbin/
+	$(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/nut/upssched.conf.sample $(1)/etc/nut/upssched.conf
+	$(INSTALL_DATA) ./files/nut-sched.default $(1)/etc/uci-defaults/nut-upssched
+endef
+
+define Package/nut-web-cgi
+	$(call Package/nut/Default)
+	TITLE+= Web CGI interface
+	DEPENDS:=nut +nut-common +PACKAGE_nut-web-cgi:libgd
+endef
+
+define Package/nut-web-cgi/description
+The CGI programs are clients that run through your web server.
+They allow you to see UPS status and perform certain administrative
+commands from any web browser. Javascript and cookies are not required.
+endef
+
+define Package/nut-web-cgi/conffiles
+/etc/nut/hosts.conf
+/etc/nut/upsset.conf
+/etc/nut/upsstats.html
+/etc/nut/upsstats-single.html
+/etc/config/nut_cgi
+/etc/httpd.conf
+endef
+
+define Package/nut-web-cgi/install
+	$(INSTALL_DIR) $(1)/www/cgi-bin/nut $(1)/www/nut
+	$(INSTALL_DIR) $(1)/etc/nut
+	$(CP) $(PKG_INSTALL_DIR)/usr/html/* $(1)/www/nut/
+	$(INSTALL_DIR) $(1)/etc/uci-defaults
+	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/cgi-bin/* $(1)/www/cgi-bin/nut
+	$(INSTALL_CONF) ./files/add_nut_httpd_conf $(1)/etc/uci-defaults/add_nut_httpd_conf
+	$(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/nut/upsstats.html.sample $(1)/etc/nut/upsstats.html
+	$(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/nut/upsstats-single.html.sample $(1)/etc/nut/upsstats-single.html
+	$(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/nut/upsset.conf.sample $(1)/etc/nut/upsset.conf.disable
+	$(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/nut/upsset.conf.sample $(1)/etc/nut/upsset.conf.enable
+	$(SED) 's/### \?//' $(1)/etc/nut/upsset.conf.enable
+	$(INSTALL_DIR) $(1)/etc/config
+	$(INSTALL_CONF) ./files/nut_cgi $(1)/etc/config/nut_cgi
+	$(INSTALL_DIR) $(1)/etc/init.d
+	$(INSTALL_BIN) ./files/nut-cgi.init $(1)/etc/init.d/nut-cgi
+	ln -sf /var/etc/nut/hosts.conf $(1)/etc/nut/hosts.conf
+	ln -sf /var/etc/nut/upsset.conf $(1)/etc/nut/upsset.conf
+endef
+
+define Package/nut-avahi-service
+	$(call Package/nut/Default)
+	TITLE+= (Avahi service)
+	DEPENDS:=nut +avahi-daemon
+endef
+
+define Package/nut-avahi-service/description
+This package contains the service definition for announcing the
+attached UPS via mDNS/DNS-SD.
+endef
+
+define Package/nut-avahi-service/conffiles
+/etc/avahi/services/nut.service
+endef
+
+define Package/nut-avahi-service/install
+	$(INSTALL_DIR) $(1)/etc/avahi/services
+	$(INSTALL_CONF) ./files/nut.service $(1)/etc/avahi/services/
+endef
+
+# Dealing with all of the drivers is very repetitive, but the previous
+# maintainer had a neat solution which just needed some tweaking.
+define DriverPackage
+        define Package/nut-driver-$(2)
+		$(call Package/nut/Default)
+		TITLE:=$(2) (NUT $(1) driver)
+		DEPENDS:=nut +nut-server
+		$(if $(filter $(1),snmp),DEPENDS+= @NUT_DRIVER_SNMP)
+		$(if $(filter $(1),usb),DEPENDS+= @NUT_DRIVER_USB)
+		$(if $(filter $(1),serial),DEPENDS+= @NUT_DRIVER_SERIAL)
+        endef
+	# Deliberately empty description in order to trigger a build failure.
+	# It should be overridden by the list below, and when updating to a
+	# new version of nut we will need to provide descriptions for any new
+	# drivers.
+        define Package/nut-driver-$(2)/description
+
+        endef
+        define Package/nut-driver-$(2)/install
+		$(INSTALL_DIR) $$(1)/lib/nut
+		$(CP) $$(PKG_INSTALL_DIR)/lib/nut/$(2) $$(1)/lib/nut/
+		$(if $(filter $(2),clone),$(CP) $$(PKG_INSTALL_DIR)/lib/nut/$(2)-outlet $$(1)/lib/nut/)
+        endef
+endef
+define DriverDescription
+        define Package/nut-driver-$(2)/description
+		$(3)
+        endef
+endef
+# These lists are lifted *directly* from drivers/Makefile.am in the nut
+# source tree. This it to make it simpler to keep in sync when updating
+# to a newer version of nut. Do not edit this manually.
+#
+# DO NOT EDIT (except to update with a fresh cut/paste)!
+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 skel solis tripplite tripplitesu upscode2 victronups powerpanel \
+ blazer_ser clone clone-outlet ivtscd apcsmart apcsmart-old apcupsd-ups riello_ser	\
+ nutdrv_qx
+SNMP_DRIVERLIST = snmp-ups
+USB_LIBUSB_DRIVERLIST = usbhid-ups bcmxcp_usb tripplite_usb \
+ blazer_usb richcomm_usb riello_usb \
+ nutdrv_atcl_usb \
+ nutdrv_qx
+# END: DO NOT EDIT!
+SERIAL_DRIVERLIST_IGNORE:=skel clone-outlet nutdrv_qx
+# nutdrv_qx can be either USB or serial. Given most routers have USB
+# instead of serial ports, and not wanting two identical packages with
+# different names that conflict with each other, only the option for the
+# driver with USB bindings is provided. If you really want to save that
+# tiny bit of space and build it without USB support, remove nutdrv_qx
+# from the previous line.
+
+$(foreach d,$(filter-out $(SERIAL_DRIVERLIST_IGNORE),$(SERIAL_DRIVERLIST)),$(eval $(call DriverPackage,serial,$(d))))
+$(foreach d,$(SNMP_DRIVERLIST),$(eval $(call DriverPackage,snmp,$(d))))
+$(foreach d,$(USB_LIBUSB_DRIVERLIST),$(eval $(call DriverPackage,usb,$(d))))
+
+$(eval $(call DriverDescription,serial,al175,\
+	Driver for Eltek UPS models with AL175 alarm module))
+$(eval $(call DriverDescription,serial,bcmxcp,\
+	Driver for UPSes supporting the serial BCM/XCP protocol))
+$(eval $(call DriverDescription,serial,belkin,\
+	Driver for Belkin serial UPS equipment))
+$(eval $(call DriverDescription,serial,belkinunv,\
+	Driver for Belkin "Universal UPS" and compatible))
+$(eval $(call DriverDescription,serial,bestfcom,\
+	Driver for Best Power Fortress/Ferrups))
+$(eval $(call DriverDescription,serial,bestfortress,\
+	Driver for old Best Fortress UPS equipment))
+$(eval $(call DriverDescription,serial,bestuferrups,\
+	Driver for Best Power Micro-Ferrups))
+$(eval $(call DriverDescription,serial,bestups,\
+	Driver for Best Power / SOLA (Phoenixtec protocol) UPS equipment))
+$(eval $(call DriverDescription,serial,dummy-ups,\
+	Driver for multi-purpose UPS emulation))
+$(eval $(call DriverDescription,serial,etapro,\
+	Driver for ETA UPS equipment))
+$(eval $(call DriverDescription,serial,everups,\
+	Driver for Ever UPS models))
+$(eval $(call DriverDescription,serial,gamatronic,\
+	Driver for Gamatronic UPS equipment))
+$(eval $(call DriverDescription,serial,genericups,\
+	Driver for contact-closure UPS equipment))
+$(eval $(call DriverDescription,serial,isbmex,\
+	Driver for ISBMEX UPS equipment))
+$(eval $(call DriverDescription,serial,liebert,\
+	Driver for Liebert contact-closure UPS equipment))
+$(eval $(call DriverDescription,serial,liebert-esp2,\
+	Driver for Liebert UPS, using the ESP-II serial protocol))
+$(eval $(call DriverDescription,serial,masterguard,\
+	Driver for Masterguard UPS equipment))
+$(eval $(call DriverDescription,serial,metasys,\
+	Driver for Meta System UPS equipment))
+$(eval $(call DriverDescription,serial,oldmge-shut,\
+	Driver for SHUT Protocol UPS equipment, deprecated, use mge-shut))
+$(eval $(call DriverDescription,serial,mge-utalk,\
+	Driver for MGE UPS SYSTEMS UTalk protocol equipment))
+$(eval $(call DriverDescription,serial,microdowell,\
+	Driver for Microdowell Enterprise UPS series))
+$(eval $(call DriverDescription,serial,mge-shut,\
+	Driver for SHUT Protocol UPS equipment))
+$(eval $(call DriverDescription,serial,oneac,\
+	Driver for Oneac UPS equipment))
+$(eval $(call DriverDescription,serial,optiups,\
+	Driver for Opti-UPS (Viewsonic) UPS and Zinto D (ONLINE-USV) equipment))
+$(eval $(call DriverDescription,serial,powercom,\
+	Driver for serial Powercom/Trust/Advice UPS equipment))
+$(eval $(call DriverDescription,serial,rhino,\
+	Driver for Brazilian Microsol RHINO UPS equipment))
+$(eval $(call DriverDescription,serial,safenet,\
+	Driver for SafeNet compatible UPS equipment))
+$(eval $(call DriverDescription,serial,solis,\
+	Driver for Brazilian Microsol SOLIS UPS equipment))
+$(eval $(call DriverDescription,serial,tripplite,\
+	Driver for Tripp-Lite SmartPro UPS equipment))
+$(eval $(call DriverDescription,serial,tripplitesu,\
+	Driver for Tripp-Lite SmartOnline (SU) UPS equipment))
+$(eval $(call DriverDescription,serial,upscode2,\
+	Driver for UPScode II compatible UPS equipment))
+$(eval $(call DriverDescription,serial,victronups,\
+	Driver for IMV/Victron UPS unit Match, Match Lite, NetUps))
+$(eval $(call DriverDescription,serial,powerpanel,\
+	Driver for PowerPanel Plus compatible UPS equipment))
+$(eval $(call DriverDescription,serial,blazer_ser,\
+	Driver for Megatec/Q1 protocol serial based UPS equipment))
+$(eval $(call DriverDescription,serial,clone,\
+	UPS driver clone))
+$(eval $(call DriverDescription,serial,ivtscd,\
+	Driver for the IVT Solar Controller Device))
+$(eval $(call DriverDescription,serial,apcsmart,\
+	Driver for American Power Conversion Smart Protocol UPS equipment))
+$(eval $(call DriverDescription,serial,apcsmart-old,\
+	Driver for American Power Conversion Smart Protocol UPS equipment))
+$(eval $(call DriverDescription,serial,apcupsd-ups,\
+	Driver for apcupsd client access))
+$(eval $(call DriverDescription,serial,riello_ser,\
+	Driver for Riello UPS Protocol UPS equipment))
+$(eval $(call DriverDescription,snmp,snmp-ups,\
+	Multi-MIB Driver for SNMP UPS equipment))
+$(eval $(call DriverDescription,usb,usbhid-ups,\
+	Driver for USB/HID UPS equipment))
+$(eval $(call DriverDescription,usb,bcmxcp_usb,\
+	Experimental driver for UPSes supporting the BCM/XCP protocol over USB))
+$(eval $(call DriverDescription,usb,tripplite_usb,\
+	Driver for older Tripp Lite USB UPSes (not PDC HID)))
+$(eval $(call DriverDescription,usb,blazer_usb,\
+	Driver for Megatec/Q1 protocol USB based UPS equipment))
+$(eval $(call DriverDescription,usb,richcomm_usb,\
+	Driver for UPS equipment using Richcomm dry-contact to USB solution))
+$(eval $(call DriverDescription,usb,riello_usb,\
+	Driver for Riello UPS Protocol UPS equipment via USB))
+$(eval $(call DriverDescription,usb,nutdrv_atcl_usb,\
+	Driver for ATCL FOR UPS equipment))
+$(eval $(call DriverDescription,usb,nutdrv_qx,\
+	Driver for Q* protocol serial and USB based UPS equipment))
+
+CONFIGURE_ARGS += \
+	--sysconfdir=/etc/nut \
+	--datadir=/usr/share/nut \
+	--with-dev \
+	--$(if $(CONFIG_NUT_DRIVER_USB),with,without)-usb \
+	--without-avahi \
+	--$(if $(CONFIG_NUT_DRIVER_SNMP),with,without)-snmp \
+	--$(if $(CONFIG_NUT_DRIVER_SERIAL),with,without)-serial \
+	--without-doc \
+	--without-neon \
+	--without-powerman \
+	--without-wrap \
+	--with-hotplug-dir=/etc/hotplug \
+	--with$(if $(CONFIG_PACKAGE_nut-web-cgi),,out)-cgi \
+	--without-ipmi \
+	--without-freeipmi \
+	--$(if $(CONFIG_NUT_SSL),with,without)-ssl $(if $(CONFIG_NUT_SSL),--with-openssl) \
+	--without-libltdl \
+	--with-statepath=/var/run/nut \
+	--with-drvpath=/lib/nut \
+	--with-user=root \
+	--with-group=root \
+	$(if $(CONFIG_PACKAGE_nut-web-cgi),--with-gd-includes="`pkg-config --cflags gdlib`") \
+	$(if $(CONFIG_PACKAGE_nut-web-cgi),--with-gd-libs="`pkg-config --libs gdlib`")
+
+define Build/InstallDev
+	$(INSTALL_DIR) $(1)/usr/include $(1)/usr/lib/pkgconfig
+	$(CP) $(PKG_INSTALL_DIR)/usr/lib/lib*.so* $(1)/usr/lib/
+	$(CP) $(PKG_INSTALL_DIR)/usr/include/*.h $(1)/usr/include/
+	$(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/*.pc $(1)/usr/lib/pkgconfig/
+endef
+
+$(eval $(call BuildPackage,nut))
+$(eval $(call BuildPackage,nut-common))
+$(eval $(call BuildPackage,nut-server))
+$(eval $(call BuildPackage,nut-upsmon))
+$(eval $(call BuildPackage,nut-upsmon-sendmail-notify))
+$(eval $(call BuildPackage,nut-upsc))
+$(eval $(call BuildPackage,nut-upscmd))
+$(eval $(call BuildPackage,nut-upslog))
+$(eval $(call BuildPackage,nut-upsrw))
+$(eval $(call BuildPackage,nut-upssched))
+$(eval $(call BuildPackage,nut-web-cgi))
+$(eval $(call BuildPackage,nut-avahi-service))
+$(foreach d,$(filter-out $(SERIAL_DRIVERLIST_IGNORE),$(SERIAL_DRIVERLIST)),$(eval $(call BuildPackage,nut-driver-$(d))))
+$(foreach d,$(SNMP_DRIVERLIST),$(eval $(call BuildPackage,nut-driver-$(d))))
+$(foreach d,$(USB_LIBUSB_DRIVERLIST),$(eval $(call BuildPackage,nut-driver-$(d))))
diff --git a/external/subpack/net/nut/files/30-libhid-ups.head b/external/subpack/net/nut/files/30-libhid-ups.head
new file mode 100755
index 0000000..eebda99
--- /dev/null
+++ b/external/subpack/net/nut/files/30-libhid-ups.head
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+nut_driver_config() {
+	local cfg="$1"
+	local nomatch="$2"
+
+	config_get runas "$cfg" runas "nut"
+	config_get vendorid "$cfg" vendorid
+	config_get productid "$cfg" productid
+
+	[ "$ACTION" = "add" ] && [ -n "$DEVNAME" ] && {
+		chmod 0660 /dev/"$DEVNAME"
+		chown "${runas:-root}":"$(id -gn "${runas:-root}")" /dev/"$DEVNAME"
+	}
+
+	if [ "$nomatch" = "1" ]; then
+		[ "$ACTION" = "add" ] && {
+			/etc/init.d/nut-server start "$cfg"
+		}
+	elif [ "$(printf "%04x" 0x"$pvendid")" = "$vendorid" ] && \
+		[ "$(printf "%04x" 0x"$pprodid")" = "$productid" ]; then
+			[ "$ACTION" = "add" ] && {
+				/etc/init.d/nut-server start "$cfg"
+			}
+			[ "$ACTION" = "remove" ] && {
+				/etc/init.d/nut-server stop "$cfg"
+			}
+			found=1
+	fi
+}
+
+perform_libhid_action() {
+	. /lib/functions.sh
+
+	local vendorid productid runas
+	local pvendid pprodid found
+
+	pvendid=${PRODUCT%/*}
+	pvendid=${pvendid%/*}
+	pprodid=${PRODUCT%/*}
+	pprodid=${pprodid##*/}
+
+	config_load nut_server
+	config_foreach nut_driver_config driver 0
+	[ "$found" != "1" ] && config_foreach nut_driver_config driver 1
+	/etc/init.d/nut-server start upsd
+}
+
+[ -n "$PRODUCT" ] && case "$PRODUCT" in
diff --git a/external/subpack/net/nut/files/30-libhid-ups.tail b/external/subpack/net/nut/files/30-libhid-ups.tail
new file mode 100644
index 0000000..3846bc3
--- /dev/null
+++ b/external/subpack/net/nut/files/30-libhid-ups.tail
@@ -0,0 +1,5 @@
+"")
+	[ -f /var/run/nut/disable-hotplug ] || \
+		/etc/init.d/nut-server enabled && perform_libhid_action
+	;;
+esac
diff --git a/external/subpack/net/nut/files/add_nut_httpd_conf b/external/subpack/net/nut/files/add_nut_httpd_conf
new file mode 100644
index 0000000..b8fa847
--- /dev/null
+++ b/external/subpack/net/nut/files/add_nut_httpd_conf
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+grep -q '/cgi-bin/nut' /etc/httpd.conf 2>/dev/null || {
+	echo '/cgi-bin/nut:root:$p$root' >>/etc/httpd.conf
+	/etc/init.d/uhttpd restart
+}
diff --git a/external/subpack/net/nut/files/nut-cgi.init b/external/subpack/net/nut/files/nut-cgi.init
new file mode 100755
index 0000000..68d39f6
--- /dev/null
+++ b/external/subpack/net/nut/files/nut-cgi.init
@@ -0,0 +1,76 @@
+#!/bin/sh /etc/rc.common
+# Copyright © 2012 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+START=87
+STOP=23
+USE_PROCD=1
+
+DEFAULT=/etc/default/nut
+UPSCGI_C=/var/etc/nut/hosts.conf
+UPSCGI_S=/var/etc/nut/upsset.conf
+
+nut_upscgi_upsset() {
+	local cfg="$1"
+	local enable
+
+	config_get_bool enable "$cfg" enable 0
+
+	if [ "$enable" -eq 1 ]; then
+		ln -sf /etc/nut/upsset.conf.enable "$UPSCGI_S"
+	else
+		ln -sf /etc/nut/upsset.conf.disable "$UPSCGI_S"
+	fi
+}
+
+nut_upscgi_add() {
+	local cfg="$1"
+	local upsname
+	local hostname
+	local port
+	local displayname
+
+	config_get upsname "$cfg" upsname
+	config_get hostname "$cfg" hostname localhost
+	config_get port "$cfg" port
+	config_get pass "$cfg" password
+	system="$upsname@$hostname"
+	if [ -n "$port" ]; then
+	    system="$system:$port";
+	fi
+	config_get displayname "$cfg" displayname
+	echo "MONITOR $system \"$displayname\"" >> "$UPSCGI_C"
+}
+
+service_reload() {
+	mkdir -m 0755 -p "$(dirname "$UPSCGI_C")"
+	rm -f "$UPSCGI_C"
+	rm -f "$UPSCGI_S"
+
+	config_load nut_cgi
+
+	config_foreach nut_upscgi_add host
+	config_foreach nut_upscgi_upsset upsset
+
+	[ -s "$UPSCGI_C" ] && chmod 640 "$UPSCGI_C"
+}
+
+start_service() {
+	service_reload
+}
+
+reload_service() {
+	service_reload
+}
+
+stop_service() {
+	rm -f "$UPSCGI_C"
+	rm -f "$UPSCGI_S"
+	ln -sf /etc/nut/upsset.conf.disable "$UPSCGI_S"
+}
+
+service_triggers() {
+	procd_add_reload_trigger "nut_cgi"
+}
diff --git a/external/subpack/net/nut/files/nut-monitor.init b/external/subpack/net/nut/files/nut-monitor.init
new file mode 100755
index 0000000..e57a287
--- /dev/null
+++ b/external/subpack/net/nut/files/nut-monitor.init
@@ -0,0 +1,231 @@
+#!/bin/sh /etc/rc.common
+
+START=82
+STOP=28
+USE_PROCD=1
+UPSMON_C=/var/etc/nut/upsmon.conf
+
+nut_upsmon_conf() {
+	local cfg="$1"
+	local RUNAS val optval
+
+	echo "# Config file automatically generated from UCI config" > "$UPSMON_C"
+
+	config_get RUNAS "$cfg" runas "nutmon"
+	[ -n "$RUNAS" ] && echo "RUN_AS_USER $RUNAS" >> "$UPSMON_C"
+	runas="$RUNAS"
+
+	config_get val "$cfg" minsupplies 1
+	echo "MINSUPPLIES $val" >> "$UPSMON_C"
+
+	config_get val "$cfg" shutdowncmd "/usr/sbin/nutshutdown"
+	echo "SHUTDOWNCMD \"$val\"" >> "$UPSMON_C"
+
+	config_get val "$cfg" notifycmd
+	[ -n "$val" ] && echo "NOTIFYCMD \"$val\"" >> "$UPSMON_C"
+
+	config_get val "$cfg" pollfreq 5
+	echo "POLLFREQ $val" >> "$UPSMON_C"
+
+	config_get val "$cfg" pollfreqalert 5
+	echo "POLLFREQALERT $val" >> "$UPSMON_C"
+
+	config_get val "$cfg" hostsync 15
+	echo "HOSTSYNC $val" >> "$UPSMON_C"
+
+	config_get val "$cfg" deadtime 15
+	echo "DEADTIME $val" >> "$UPSMON_C"
+
+	echo "POWERDOWNFLAG /var/run/killpower" >> "$UPSMON_C"
+
+	config_get val "$cfg" onlinemsg
+	[ -n "$val" ] && echo "NOTIFYMSG ONLINE \"$val\"" >> "$UPSMON_C"
+	config_get val "$cfg" onbattmsg
+	[ -n "$val" ] && echo "NOTIFYMSG ONBATT \"$val\"" >> "$UPSMON_C"
+	config_get val "$cfg" lowbattmsg
+	[ -n "$val" ] && echo "NOTIFYMSG LOWBATT \"$val\"" >> "$UPSMON_C"
+	config_get val "$cfg" fsdmsg
+	[ -n "$val" ] && echo "NOTIFYMSG FSD \"$val\"" >> "$UPSMON_C"
+	config_get val "$cfg" commokmsg
+	[ -n "$val" ] && echo "NOTIFYMSG COMMOK \"$val\"" >> "$UPSMON_C"
+	config_get val "$cfg" commbadmsg
+	[ -n "$val" ] && echo "NOTIFYMSG COMMBAD \"$val\"" >> "$UPSMON_C"
+	config_get val "$cfg" shutdownmsg
+	[ -n "$val" ] && echo "NOTIFYMSG SHUTDOWN \"$val\"" >> "$UPSMON_C"
+	config_get val "$cfg" replbattmsg
+	[ -n "$val" ] && echo "NOTIFYMSG REPLBATT \"$val\"" >> "$UPSMON_C"
+	config_get val "$cfg" nocommmsg
+	[ -n "$val" ] && echo "NOTIFYMSG NOCOMM \"$val\"" >> "$UPSMON_C"
+	config_get val "$cfg" noparentmsg
+	[ -n "$val" ] && echo "NOTIFYMSG NOPARENT \"$val\"" >> "$UPSMON_C"
+
+	notifylist() {
+		local value="$1"
+		append optval "$value" "+"
+	}
+
+	setnotify() {
+		local cfg="$1"
+		local optname="$2"
+		local optval
+		config_list_foreach "$cfg" "$optname" notifylist
+		if [ -z "$optval" ]; then
+			# If no list fallback to trying option, fallback to default
+			config_get optval "$cfg" "$optname" "$default"
+			if [ -n "$optval" ]; then
+				echo "$optval"
+			else
+				# No default, so do the NUT default
+				echo "SYSLOG"
+			fi
+		else
+			echo "$optval"
+		fi
+        }
+
+	local default optval
+	val=""
+	config_list_foreach "$cfg" defaultnotify notifylist
+	default="$optval"
+	{
+		echo "NOTIFYFLAG ONLINE $(setnotify "$cfg" onlinenotify)" ; \
+		echo "NOTIFYFLAG ONBATT $(setnotify "$cfg" onbattnotify)" ; \
+		echo "NOTIFYFLAG LOWBATT $(setnotify "$cfg" lowbatnotify)" ; \
+		echo "NOTIFYFLAG FSD $(setnotify "$cfg" fsdnotify)" ; \
+		echo "NOTIFYFLAG COMMOK $(setnotify "$cfg" commoknotify)" ; \
+		echo "NOTIFYFLAG COMMBAD $(setnotify "$cfg" commbadnotify)" ; \
+		echo "NOTIFYFLAG SHUTDOWN $(setnotify "$cfg" shutdownnotify)" ; \
+		echo "NOTIFYFLAG REPLBATT $(setnotify "$cfg" repolbattnotify)" ; \
+		echo "NOTIFYFLAG NOCOMM $(setnotify "$cfg" nocommnotify)" ; \
+		echo "NOTIFYFLAG NOPARENT $(setnotify "$cfg" noparentnotify)" ; \
+	} >> "$UPSMON_C"
+
+	config_get val "$cfg" rbwarntime 43200
+	echo "RBWARNTIME $val" >> "$UPSMON_C"
+
+	config_get val "$cfg" nocommwarntime 300
+	echo "NOCOMMWARNTIME $val" >> "$UPSMON_C"
+
+	config_get val "$cfg" finaldelay 5
+	echo "FINALDELAY $val" >> "$UPSMON_C"
+
+	config_get val "$cfg" certpath
+	if [ -n "$val" ]; then echo "CERTPATH $val" >> "$UPSMON_C"; fi
+
+	config_get_bool val "$cfg" certverify 0
+	if [ -n "$val" ]; then echo "CERTVERIFY $val" >> "$UPSMON_C"; fi
+
+	config_get_bool val "$cfg" forcessl 0
+	if [ -n "$val" ]; then echo "FORCESSL $val" >> "$UPSMON_C"; fi
+
+	havemon=1
+}
+
+nut_upsmon_add() {
+	local cfg="$1"
+	local type="$2"
+	local upsname
+	local hostname
+	local port
+	local powervalue
+	local username
+	local password
+	local system
+
+	config_get upsname "$cfg" upsname
+	config_get hostname "$cfg" hostname localhost
+	config_get port "$cfg" port
+	config_get powervalue "$cfg" powervalue 1
+	config_get username "$cfg" username
+	config_get password "$cfg" password
+	system="$upsname@$hostname"
+	if [ -n "$port" ]; then
+	    system="$system:$port";
+	fi
+	echo "MONITOR $system $powervalue $username $password $type" >> "$UPSMON_C"
+
+	havems=1
+}
+
+build_config() {
+	mkdir -m 0750 -p "$(dirname "$UPSMON_C")"
+
+	config_load nut_monitor
+	config_foreach nut_upsmon_conf upsmon
+	config_foreach nut_upsmon_add master master
+	config_foreach nut_upsmon_add slave slave
+
+	[ ! -s /var/etc/nut/nut.conf ] && {
+		echo "MODE=netclient" >>/var/etc/nut/nut.conf
+		chmod 640 /var/etc/nut/nut.conf
+		chgrp "$(id -gn "${runas:-nutmon}")" /var/etc/nut/nut.conf
+	}
+
+	[ -s "$UPSMON_C" ] && chmod 640 "$UPSMON_C"
+	[ -s "$UPSMON_C" ] && chgrp "$(id -gn "${runas:-nutmon}")" "$UPSMON_C"
+}
+
+interface_triggers() {
+	local action="$1"
+	local triggerlist trigger
+
+	config_get triggerlist "upsmon" triggerlist
+
+	. "${IPKG_INSTROOT}"/lib/functions/network.sh
+
+	if [ -n "$triggerlist" ]; then
+		for trigger in $triggerlist; do
+			if [ "$action" = "add_trigger" ]; then
+				procd_add_interface_trigger "interface.*" "$trigger" /etc/init.d/nut-monitor restart
+			else
+				network_is_up "$trigger" && return 0
+			fi
+		done
+	else
+		if [ "$action" = "add_trigger" ]; then
+			procd_add_raw_trigger "interface.*.up" 2000 /etc/init.d/nut-monitor restart
+		else
+			ubus call network.device status | grep -q '"up": true' && return 0
+		fi
+	fi
+	[ "$action" = "add_trigger" ] || return 1
+}
+
+start_service() {
+	local runas=nutmon
+	local havemon havems
+	build_config
+
+	[ "$havemon" != 1 ] && return 1
+	[ "$havems" != 1 ] && return 1
+	interface_triggers "check_interface_up" || return 0
+
+	procd_open_instance "upsmon"
+	procd_set_param respawn 10 20 6
+	procd_set_param stderr 1
+	procd_set_param stdout 0
+	procd_set_param command /usr/sbin/upsmon -D
+	procd_close_instance
+
+	return 0
+}
+
+reload_service() {
+	if pgrep upsmon >/dev/null 2>/dev/null; then
+		local runas=nutmon
+		build_config
+		/usr/sbin/upsmon -c reload
+	else
+		restart
+	fi
+}
+
+stop_service() {
+	upsmon -c stop
+}
+
+service_triggers() {
+	config_load nut_monitor
+	interface_triggers "add_trigger"
+	procd_add_reload_trigger "nut_monitor"
+}
diff --git a/external/subpack/net/nut/files/nut-sched.default b/external/subpack/net/nut/files/nut-sched.default
new file mode 100644
index 0000000..d8b13f0
--- /dev/null
+++ b/external/subpack/net/nut/files/nut-sched.default
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+uci batch <<EOF
+set nut_monitor.@upsmon[-1]=upsmon
+set nut_monitor.@upsmon[-1].notifycmd=/usr/bin/upssched-cmd
+set nut_monitor.@upsmon[-1].defaultnotify="SYSLOG EXEC"
+commit nut_monitor
+EOF
+
+
diff --git a/external/subpack/net/nut/files/nut-sendmail-notify b/external/subpack/net/nut/files/nut-sendmail-notify
new file mode 100755
index 0000000..f21e41e
--- /dev/null
+++ b/external/subpack/net/nut/files/nut-sendmail-notify
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+{
+exec /usr/sbin/sendmail root <<EOF
+From: root
+To: root
+Subject: UPS $NOTIFYTYPE Notification
+
+$1
+.
+EOF
+} &
diff --git a/external/subpack/net/nut/files/nut-sendmail-notify.default b/external/subpack/net/nut/files/nut-sendmail-notify.default
new file mode 100644
index 0000000..2babb7d
--- /dev/null
+++ b/external/subpack/net/nut/files/nut-sendmail-notify.default
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+. "${IPKG_INSTROOT}"/lib/functions.sh
+
+REMOVEDEFAULTNOTIFY=0
+SKIPADDSYSLOG=0
+SKIPADDEXEC=0
+
+upsmon() {
+	local cfg="$1"
+	local val
+
+	config_get val "$cfg" defaultnotify
+	if [ -n "$val" ]; then
+		if echo "$val" |grep -q "IGNORE"; then
+			REMOVEDEFAULTNOTIFY=1
+		else
+			SKIPADDSYSLOG=1
+			if echo "$val" |grep -q "EXEC"; then
+				SKIPADDEXEC=1
+			fi
+		fi
+	fi
+}
+
+config_load nut_monitor
+config_foreach upsmon upsmon
+
+uci set nut_monitor.@upsmon[-1]=upsmon
+uci set nut_monitor.@upsmon[-1].notifycmd=/usr/bin/nut-sendmail-notify
+
+if [ "$REMOVEDEFAULTNOTIFY" = "1" ]; then
+	uci delete nut_monitor.@upsmon[-1].defaultnotify || true
+fi
+
+if [ "$SKIPADDEXEC" != "1" ]; then
+	uci add_list nut_monitor.@upsmon[-1].defaultnotify="EXEC"
+fi
+
+if [ "$SKIPADDSYSLOG" != "1" ]; then
+	uci add_list nut_monitor.@upsmon[-1].defaultnotify="SYSLOG"
+fi
+
+uci commit nut_monitor
diff --git a/external/subpack/net/nut/files/nut-server.init b/external/subpack/net/nut/files/nut-server.init
new file mode 100755
index 0000000..7d550bd
--- /dev/null
+++ b/external/subpack/net/nut/files/nut-server.init
@@ -0,0 +1,363 @@
+#!/bin/sh /etc/rc.common
+# Copyright © 2012 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+START=70
+STOP=30
+
+USERS_C=/var/etc/nut/upsd.users
+UPSD_C=/var/etc/nut/upsd.conf
+UPS_C=/var/etc/nut/ups.conf
+
+USE_PROCD=1
+
+get_write_driver_config() {
+	local cfg="$1"
+	local var="$2"
+	local def="$3"
+	local flag="$4"
+	local val
+
+	[ -z "$flag" ] && {
+		config_get val "$cfg" "$var" "$def"
+		[ -n "$val" ] && [ "$val" != "0" ] && echo "$var = $val" >>"$UPS_C"
+	}
+
+	[ -n "$flag" ] && {
+		config_get_bool val "$cfg" "$var" "$def"
+		[ "$val" = 1 ] && echo "$var" >>"$UPS_C"
+	}
+}
+
+upsd_statepath() {
+	local statepath
+
+	config_get statepath upsd statepath /var/run/nut
+	STATEPATH="$statepath"
+}
+
+upsd_runas() {
+	local runas
+
+	[ -n "$RUNAS" ] && return 0
+
+	config_get runas upsd runas nut
+	RUNAS="$runas"
+}
+
+listen_address() {
+    local cfg="$1"
+
+    config_get address "$cfg" address "::1"
+    config_get port "$cfg" port
+    echo "LISTEN $address $port" >>"$UPSD_C"
+}
+
+upsd_config() {
+    local cfg="$1"
+    local maxage maxconn certfile runas statepath
+
+    # Note runas support requires you make sure USB device file is readable by
+    # the runas user
+    config_get runas "$cfg" runas nut
+    RUNAS="$runas"
+
+    config_get statepath "$cfg" statepath /var/run/nut
+    STATEPATH="$statepath"
+
+    config_get maxage "$cfg" maxage
+    [ -n "$maxage" ] && echo "MAXAGE $maxage" >>"$UPSD_C"
+
+    [ -n "$statepath" ] && echo "STATEPATH $statepath" >>"$UPSD_C"
+
+    config_get maxconn "$cfg" maxconn
+    [ -n "$maxconn" ] && echo "MAXCONN $maxconn" >>"$UPSD_C"
+
+    #NOTE: certs only apply to SSL-enabled version
+    config_get certfile "$cfg" certfile
+    [ -n "$certfile" ] && echo "CERTFILE $certfile" >>"$UPSD_C"
+}
+
+nut_user_add() {
+	local cfg="$1"
+	local a
+	local val
+
+	config_get val "$cfg" username "$1"
+	echo "[$val]" >> "$USERS_C"
+
+	config_get val "$cfg" password
+	echo "  password = $val" >> "$USERS_C"
+
+	config_get val "$cfg" actions
+	for a in $val; do
+	    echo "  actions = $a" >> "$USERS_C"
+	done
+
+	instcmd() {
+		local val="$1"
+		echo "  instcmds = $val" >> "$USERS_C"
+	}
+
+	config_list_foreach "$cfg" instcmd instcmd
+
+	config_get val "$cfg" upsmon
+	if [ -n "$val" ]; then
+	    echo "  upsmon $val" >> "$USERS_C"
+	fi
+}
+
+build_server_config() {
+        mkdir -p "$(dirname "$UPSD_C")"
+	chmod 0640 "$UPS_C"
+	rm -f "$USERS_C"
+	rm -f "$UPSD_C"
+	rm -f /var/etc/nut/nut.conf
+
+	echo "# Config file automatically generated from UCI config" > "$USERS_C"
+	echo "# Config file automatically generated from UCI config" > "$UPSD_C"
+
+	config_foreach nut_user_add user
+	config_foreach listen_address listen_address
+	config_foreach upsd_config upsd
+	echo "MODE=netserver" >>/var/etc/nut/nut.conf
+
+	chmod 0640 "$USERS_C"
+	chmod 0640 "$UPSD_C"
+	chmod 0644 /var/etc/nut/nut.conf
+
+	[ -d "${STATEPATH}" ] || {
+		mkdir -p "${STATEPATH}"
+		chmod 0750 "${STATEPATH}"
+	}
+
+	if [ -n "$RUNAS" ]; then
+		chown "$RUNAS":"$(id -gn "$RUNAS")" "${STATEPATH}"
+		chgrp "$(id -gn "$RUNAS")" "$USERS_C"
+		chgrp "$(id -gn "$RUNAS")" "$UPSD_C"
+	fi
+	haveserver=1
+}
+
+build_driver_config() {
+	local cfg="$1"
+
+	echo "[$cfg]" >>"$UPS_C"
+
+	get_write_driver_config "$cfg" bus
+	get_write_driver_config "$cfg" community
+	get_write_driver_config "$cfg" desc
+	get_write_driver_config "$cfg" driver "usbhid-ups"
+	get_write_driver_config "$cfg" ignorelb 0 1
+	get_write_driver_config "$cfg" interruptonly 0 1
+	get_write_driver_config "$cfg" interruptsize
+	get_write_driver_config "$cfg" maxreport
+	get_write_driver_config "$cfg" maxstartdelay
+	get_write_driver_config "$cfg" mfr
+	get_write_driver_config "$cfg" model
+	get_write_driver_config "$cfg" nolock 0 1
+	get_write_driver_config "$cfg" notransferoids 0 1
+	get_write_driver_config "$cfg" offdelay
+	get_write_driver_config "$cfg" ondelay
+	get_write_driver_config "$cfg" pollfreq
+	get_write_driver_config "$cfg" port "auto"
+	get_write_driver_config "$cfg" product
+	get_write_driver_config "$cfg" productid
+	get_write_driver_config "$cfg" retrydelay
+	get_write_driver_config "$cfg" sdorder
+	get_write_driver_config "$cfg" sdtime
+	get_write_driver_config "$cfg" serial
+	get_write_driver_config "$cfg" snmp_version
+	get_write_driver_config "$cfg" snmp_retries
+	get_write_driver_config "$cfg" snmp_timeout
+	get_write_driver_config "$cfg" synchronous
+	get_write_driver_config "$cfg" vendor
+	get_write_driver_config "$cfg" vendorid
+
+	defoverride() {
+		local overvar="$1"
+		local defover="$2"
+		local overtype="$(echo "$overvar" | tr '_' '.')"
+		local overval
+
+		config_get overval "${defover}_${overvar}" value
+		[ -n "$overval" ] && echo "${defover}.${overtype} = $overval" >>"$UPS_C"
+	}
+
+	config_list_foreach "$cfg" override defoverride override
+	config_list_foreach "$cfg" default defoverride default
+
+	other() {
+		local othervar="$1"
+		local othervarflag="$2"
+		local otherval
+
+		if [ "$othervarflag" = "otherflag" ]; then
+			config_get_bool otherval "${othervarflag}_${othervar}" value
+			[ "$otherval" = "1" ] && echo "${othervar}" >>"$UPS_C"
+		else
+			config_get otherval "${othervarflag}_${othervar}" value
+			[ -n "$otherval" ] && echo "${othervar} = $otherval" >>"$UPS_C"
+		fi
+	}
+
+	config_list_foreach "$cfg" other other other
+	config_list_foreach "$cfg" otherflag other otherflag
+	echo "" >>$UPS_C
+	havedriver=1
+}
+
+build_global_driver_config() {
+	local cfg="$1"
+
+	# Global driver config
+	get_write_driver_config "$cfg" chroot
+	get_write_driver_config "$cfg" driverpath
+	get_write_driver_config "$cfg" maxstartdelay
+	get_write_driver_config "$cfg" maxretry
+	get_write_driver_config "$cfg" retrydelay
+	get_write_driver_config "$cfg" pollinterval
+	get_write_driver_config "$cfg" synchronous
+	config_get runas "$cfg" user nut
+	RUNAS="$runas"
+
+	echo "" >>"$UPS_C"
+}
+
+build_config() {
+	local STATEPATH=/var/run/nut
+
+        mkdir -p "$(dirname "$UPS_C")"
+	rm -f "$UPS_C"
+	echo "# Config file automatically generated from UCI config" > "$UPS_C"
+	chmod 0640 "$UPS_C"
+
+	config_load nut_server
+
+	upsd_runas
+	config_foreach build_global_driver_config driver_global
+	config_foreach build_driver_config driver
+	upsd_statepath
+	build_server_config
+	[ -n "$RUNAS" ] && chgrp "$(id -gn "$RUNAS")" "$UPS_C"
+}
+
+start_driver_instance() {
+	local cfg="$1"
+	local requested="$2"
+	local driver
+	local STATEPATH=/var/run/nut
+	local RUNAS=nut
+
+	[ "$havedriver" != 1 ] && return
+
+	# If wanting a specific instance, only start it
+	if [ "$requested" != "$cfg" ] && [ "$request" != "" ]; then
+		return 0
+	fi
+
+	mkdir -p "$(dirname "$UPS_C")"
+	chmod 0755 "$UPS_C"
+
+	upsd_statepath
+	build_config
+
+	# Avoid hotplug inadvertenly restarting driver during
+	# forced shutdown
+	[ -f /var/run/killpower ] && return 0
+	if [ -d /var/run/nut ] && [ -f /var/run/nut/disable-hotplug ]; then
+	       return 0
+	fi
+
+	if [ -n "$RUNAS" ]; then
+		chown "$RUNAS":"$(id -gn "$RUNAS")" "${STATEPATH}"
+		chgrp "$(id -gn "$RUNAS")" "$UPS_C"
+	fi
+
+	config_get driver "$cfg" driver "usbhid-ups"
+	procd_open_instance "$cfg"
+	procd_set_param respawn
+	procd_set_param stderr 0
+	procd_set_param stdout 1
+	procd_set_param command /lib/nut/"${driver}" -D -a "$cfg" ${RUNAS:+-u "$RUNAS"}
+	procd_close_instance
+}
+
+interface_triggers() {
+	local action="$1"
+	local triggerlist trigger
+
+	config_get triggerlist upsd triggerlist
+
+	. /lib/functions/network.sh
+
+	if [ -n "$triggerlist" ]; then
+		for trigger in $triggerlist; do
+			if [ "$action" = "add_trigger" ]; then
+				procd_add_interface_trigger "interface.*" "$trigger" /etc/init.d/nut-server reload
+			else
+				network_is_up "$trigger" && return 0
+			fi
+		done
+	else
+		if [ "$action" = "add_trigger" ]; then
+			procd_add_raw_trigger "interface.*.up" 2000 /etc/init.d/nut-server reload
+		else
+			ubus call network.device status | grep -q '"up": true' && return 0
+		fi
+	fi
+	[ "$action" = "add_trigger" ] || return 1
+}
+
+start_server_instance() {
+	local cfg="$1"
+
+	[ "$haveserver" != 1 ] && return
+	interface_triggers "check_interface_up" || return
+
+	procd_open_instance "$cfg"
+	procd_set_param respawn
+	procd_set_param stderr 0
+	procd_set_param stdout 1
+	procd_set_param command /usr/sbin/upsd -D ${RUNAS:+-u "$RUNAS"}
+	procd_close_instance
+}
+
+start_service() {
+	local STATEPATH=/var/run/nut
+
+	# Avoid hotplug inadvertenly restarting driver during
+	# forced shutdown
+	[ -f /var/run/killpower ] && return 0
+
+	config_load nut_server
+	build_config
+
+	case $@ in
+	"")
+		config_foreach start_driver_instance driver "$@"
+		start_server_instance upsd
+		;;
+	*upsd*)
+		start_server_instance upsd
+		;;
+	*)
+		config_foreach start_driver_instance driver "$@"
+		;;
+	esac
+}
+
+reload_service() {
+	stop_service "$@"
+	sleep 2
+	start_service "$@"
+}
+
+service_triggers() {
+	config_load nut_server
+
+	interface_triggers "add_trigger"
+	procd_add_reload_trigger "nut_server"
+}
diff --git a/external/subpack/net/nut/files/nut.service b/external/subpack/net/nut/files/nut.service
new file mode 100644
index 0000000..5ad6b31
--- /dev/null
+++ b/external/subpack/net/nut/files/nut.service
@@ -0,0 +1,34 @@
+<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
+<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
+
+<!--
+  This file is part of NUT - Network UPS Tools
+
+  NUT is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as
+  published by the Free Software Foundation; either version 2 of the
+  License, or (at your option) any later version.
+
+  NUT is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with NUT; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+  02111-1307 USA.
+-->
+
+<!-- See avahi.service(5) for more information about this configuration file -->
+
+<service-group>
+
+  <name replace-wildcards="yes">%h</name>
+
+  <service>
+    <type>_nut._tcp</type>
+    <port>3493</port>
+  </service>
+
+</service-group>
diff --git a/external/subpack/net/nut/files/nut_cgi b/external/subpack/net/nut/files/nut_cgi
new file mode 100644
index 0000000..dca5de0
--- /dev/null
+++ b/external/subpack/net/nut/files/nut_cgi
@@ -0,0 +1,8 @@
+#config host
+#	option upsname upsname
+#	option hostname localhost
+#	option port # optional port number
+#	option displayname "Display Name"
+
+config upsset
+	option enable 0
diff --git a/external/subpack/net/nut/files/nut_monitor b/external/subpack/net/nut/files/nut_monitor
new file mode 100644
index 0000000..59e0f36
--- /dev/null
+++ b/external/subpack/net/nut/files/nut_monitor
@@ -0,0 +1,52 @@
+#config upsmon 'upsmon'
+#	option runas nutmon
+#	option minsupplies 1
+#	option shutdowncmd '/usr/sbin/nutshutdown'
+#	option notifycmd /path/to/cmd
+#	list defaultnotify SYSLOG
+#	option pollfreq 5
+#	option pollfreqalert 5
+# 	option hostsync 15
+#	option deadtime 15
+#	option onlinemsg "online message"
+#	option onbattmsg "on battery message"
+#	option lowbattmsg "low battery message"
+#	option fsdmsg "forced shutdown message"
+#	option comokmsg "communications restored message"
+#	option combadmsg "communications bad message"
+#	option shutdowmsg "shutdown message"
+#	option replbattmsg "replace battery message"
+#	option nocommmsg "no communications message"
+#	option noparentmsg "no parent message"
+#	option onlinenotify "online notify flag 1|0"
+#	option onbattnotify "on battery notify flag 1|0"
+#	option lowbattnotify "low battery notify flag 1|0"
+#	option fsdnotify "forced shutdown notify flag 1|0"
+#	option comoknotify "communications restored notify flag 1|0"
+#	option combadnotify "communications bad notify flag 1|0"
+#	option shutdownotify "shutdown notify flag 1|0"
+#	option replbattnotify "replace battery notify flag 1|0"
+#	option nocommnotify "no communications notify flag 1|0"
+#	option noparentnotify "no parent notify flag 1|0"
+#	option rbwarntime 4200 # replace battery warn time
+#	option nocommwarntime 300 # no communications warn time
+#	option finaldelay 5 # final delay
+#	option certpath /path/to/ca/dir
+#	option certverify 0
+#	option forcessl 0
+
+#config master
+#	option upsname upsname
+#	option hostname localhost
+#	option port # optional port number
+#	option powervalue 1
+#	option username upsuser
+#	option password upspassword
+
+#config slave
+#	option upsname upsname
+#	option hostname localhost
+#	option port # optional port number
+#	option powervalue 1
+#	option username upsuser
+#	option password upspassword
diff --git a/external/subpack/net/nut/files/nut_serial.hotplug b/external/subpack/net/nut/files/nut_serial.hotplug
new file mode 100644
index 0000000..fa3bafe
--- /dev/null
+++ b/external/subpack/net/nut/files/nut_serial.hotplug
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+nut_serial() {
+	local cfg="$cfg"
+	local runas enable_usb_serial port
+	config_get_bool enable_usb_serial "$cfg" enable_usb_serial 0
+	config_get port "$cfg" port
+	config_get runas "$cfg" runas "nut"
+
+	[ -z "$runas" ] && config_get runas upsd runas "nut"
+
+	[ "$enable_usb_serial" -eq 1 ] && {
+		# If port is specified only change tty's matching port
+		if [ -n "$port" ] && [ "$port" != /dev/"$DEVNAME" ]; then
+			return 0
+		fi
+		[ -n "$runas" ] && chgrp "$(id -gn "${runas}")" /dev/"$DEVNAME"
+		chmod g+rw /dev/"$DEVNAME"
+	}
+}
+
+nut_on_hotplug_add() {
+	. "${IPKG_INSTROOT}"/lib/functions.sh
+
+	config load nut_server
+	config_foreach nut_serial driver
+}
+
+[ "$ACTION" = "add" ] && [ -n "$DEVNAME" ] && {
+	# On add of a serial port with name ttyUSB*
+	[ -z "${DEVNAME%ttyUSB*}" ] && nut_on_hutplug_add
+	# On add of a serial port with name ttyAMA*
+	[ -z "${DEVNAME%ttyAMA*}" ] && nut_on_hutplug_add
+}
diff --git a/external/subpack/net/nut/files/nut_server b/external/subpack/net/nut/files/nut_server
new file mode 100644
index 0000000..cda9249
--- /dev/null
+++ b/external/subpack/net/nut/files/nut_server
@@ -0,0 +1,26 @@
+#config driver_global 'driver_global'
+#	option user nut
+
+#config driver 'upsname'
+#	option driver usbhid-ups
+#	option port auto
+#	option enable_usb_serial 0
+
+#config user
+#	option username upsuser
+#	option password upspassword
+#	option actions optional-action
+#	list instcmd optional-instant-command
+#	option upsmon slave|master
+
+#config listen_address
+#	option address ::1
+#	option port 3493
+
+#config upsd 'upsd'
+#	option maxage 15
+#	option statepath /var/run/nut
+#	option maxconn 1024
+#	option runas nut
+# NB: certificates only apply to SSL-enabled version
+#       option certfile /usr/local/etc/upsd.pem
diff --git a/external/subpack/net/nut/files/nutshutdown b/external/subpack/net/nut/files/nutshutdown
new file mode 100755
index 0000000..7270f98
--- /dev/null
+++ b/external/subpack/net/nut/files/nutshutdown
@@ -0,0 +1,51 @@
+#!/bin/sh
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+stop_instance() {
+	/etc/init.d/nut-server stop "$1"
+}
+
+shutdown_instance() {
+	local cfg="$1"
+	config_get driver "$cfg" driver "usbhid-ups"
+
+	# Only FSD if killpower was indicated
+	if [ -f /var/run/killpower ]; then
+		/lib/nut/"${driver}" -a "$cfg" -k
+	fi
+}
+
+do_fsd() {
+	if [ -f /var/run/killpower ]; then
+		# Only make FS readonly if we are doing an FSD
+		mount -o remount,ro /overlay /overlay
+		mount -o remount,ro / /
+
+		. ${IPKG_INSTROOT}/lib/functions.sh
+
+		if [ -f /etc/config/nut_server ]; then
+			config_load nut_server
+
+			# Can't FSD unless drivers are stopped
+			config_foreach stop_instance driver
+			# Driver will  wait 'offdelay' before shutting down
+			config_foreach shutdown_instance driver
+			# So this can happen
+			rm -f /var/run/killpower
+			poweroff
+			# And just in case
+			sleep 120
+			# Uh-oh failed to poweroff UPS
+			reboot -f
+		else
+			poweroff
+		fi
+	else
+		poweroff
+	fi
+}
+
+do_fsd
diff --git a/external/subpack/net/nut/patches/0001-Add-compatibility-with-openssl-1.1.0.patch b/external/subpack/net/nut/patches/0001-Add-compatibility-with-openssl-1.1.0.patch
new file mode 100644
index 0000000..23d10fb
--- /dev/null
+++ b/external/subpack/net/nut/patches/0001-Add-compatibility-with-openssl-1.1.0.patch
@@ -0,0 +1,166 @@
+commit 612c05efb3c3b243da603a3a050993281888b6e3
+Author: Arjen de Korte <build+github@de-korte.org>
+Date:   Fri Mar 15 10:17:32 2019 +0100
+
+    Add support for openssl-1.1.0 (#504)
+    
+    * Add support for openssl-1.1.0
+    
+    * Allow TLSv1 and higher (not just TLSv1)
+    
+    * Fix check for empty string
+    
+    * Report TLS handshake in debug mode
+    
+    * Update nut_check_libopenssl.m4
+    
+    * Update upsclient.c
+    
+    * Update netssl.c
+
+--- a/clients/upsclient.c
++++ b/clients/upsclient.c
+@@ -299,11 +299,6 @@ int upscli_init(int certverify, const ch
+ {
+ #ifdef WITH_OPENSSL
+ 	int ret, ssl_mode = SSL_VERIFY_NONE;
+-#if OPENSSL_VERSION_NUMBER >= 0x10000000L
+-	const SSL_METHOD	*ssl_method;
+-#else
+-	SSL_METHOD	*ssl_method;
+-#endif
+ #elif defined(WITH_NSS) /* WITH_OPENSSL */
+ 	SECStatus	status;
+ #endif /* WITH_OPENSSL | WITH_NSS */
+@@ -315,22 +310,32 @@ int upscli_init(int certverify, const ch
+ 	}
+ 	
+ #ifdef WITH_OPENSSL
+-	
+-	SSL_library_init();
+-	SSL_load_error_strings();
+ 
+-	ssl_method = TLSv1_client_method();
++#if OPENSSL_VERSION_NUMBER < 0x10100000L
++	SSL_load_error_strings();
++	SSL_library_init();
+ 
+-	if (!ssl_method) {
+-		return 0;
+-	}
++	ssl_ctx = SSL_CTX_new(SSLv23_client_method());
++#else
++	ssl_ctx = SSL_CTX_new(TLS_client_method());
++#endif
+ 
+-	ssl_ctx = SSL_CTX_new(ssl_method);
+ 	if (!ssl_ctx) {
+ 		upslogx(LOG_ERR, "Can not initialize SSL context");
+ 		return -1;
+ 	}
+ 	
++#if OPENSSL_VERSION_NUMBER < 0x10100000L
++	/* set minimum protocol TLSv1 */
++	SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
++#else
++	ret = SSL_CTX_set_min_proto_version(ssl_ctx, TLS1_VERSION);
++	if (ret != 1) {
++		upslogx(LOG_ERR, "Can not set minimum protocol to TLSv1");
++		return -1;
++	}
++#endif
++
+ 	if (!certpath) {
+ 		if (certverify == 1) {
+ 			upslogx(LOG_ERR, "Can not verify certificate if any is specified");
+@@ -737,7 +742,7 @@ static int upscli_sslinit(UPSCONN_t *ups
+ 	switch(res)
+ 	{
+ 	case 1:
+-		upsdebugx(3, "SSL connected");
++		upsdebugx(3, "SSL connected (%s)", SSL_get_version(ups->ssl));
+ 		break;
+ 	case 0:
+ 		upslog_with_errno(1, "SSL_connect do not accept handshake.");
+--- a/clients/upssched.c
++++ b/clients/upssched.c
+@@ -794,7 +794,7 @@ static void parse_at(const char *ntype,
+ 	}
+ 
+ 	if (!strcmp(cmd, "EXECUTE")) {
+-		if (ca1 == '\0') {
++		if (ca1[0] == '\0') {
+ 			upslogx(LOG_ERR, "Empty EXECUTE command argument");
+ 			return;
+ 		}
+--- a/m4/nut_check_libopenssl.m4
++++ b/m4/nut_check_libopenssl.m4
+@@ -58,7 +58,7 @@ if test -z "${nut_have_libopenssl_seen}"
+ 
+ 	dnl check if openssl is usable
+ 	AC_CHECK_HEADERS(openssl/ssl.h, [nut_have_openssl=yes], [nut_have_openssl=no], [AC_INCLUDES_DEFAULT])
+-	AC_CHECK_FUNCS(SSL_library_init, [], [nut_have_openssl=no])
++	AC_CHECK_FUNCS(SSL_CTX_new, [], [nut_have_openssl=no])
+ 
+ 	if test "${nut_have_openssl}" = "yes"; then
+ 		nut_with_ssl="yes"
+--- a/server/netssl.c
++++ b/server/netssl.c
+@@ -274,7 +274,7 @@ void net_starttls(nut_ctype_t *client, i
+ 	{
+ 	case 1:
+ 		client->ssl_connected = 1;
+-		upsdebugx(3, "SSL connected");
++		upsdebugx(3, "SSL connected (%s)", SSL_get_version(client->ssl));
+ 		break;
+ 		
+ 	case 0:
+@@ -370,13 +370,7 @@ void ssl_init(void)
+ {
+ #ifdef WITH_NSS
+ 	SECStatus status;
+-#elif defined(WITH_OPENSSL)
+-#if OPENSSL_VERSION_NUMBER >= 0x10000000L
+-	const SSL_METHOD	*ssl_method;
+-#else
+-	SSL_METHOD	*ssl_method;
+-#endif
+-#endif /* WITH_NSS|WITH_OPENSSL */
++#endif /* WITH_NSS */
+ 
+ 	if (!certfile) {
+ 		return;
+@@ -386,18 +380,29 @@ void ssl_init(void)
+ 
+ #ifdef WITH_OPENSSL
+ 
++#if OPENSSL_VERSION_NUMBER < 0x10100000L
+ 	SSL_load_error_strings();
+ 	SSL_library_init();
+ 
+-	if ((ssl_method = TLSv1_server_method()) == NULL) {
++	ssl_ctx = SSL_CTX_new(SSLv23_server_method());
++#else
++	ssl_ctx = SSL_CTX_new(TLS_server_method());
++#endif
++
++	if (!ssl_ctx) {
+ 		ssl_debug();
+-		fatalx(EXIT_FAILURE, "TLSv1_server_method failed");
++		fatalx(EXIT_FAILURE, "SSL_CTX_new failed");
+ 	}
+ 
+-	if ((ssl_ctx = SSL_CTX_new(ssl_method)) == NULL) {
++#if OPENSSL_VERSION_NUMBER < 0x10100000L
++	/* set minimum protocol TLSv1 */
++	SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
++#else
++	if (SSL_CTX_set_min_proto_version(ssl_ctx, TLS1_VERSION) != 1) {
+ 		ssl_debug();
+-		fatalx(EXIT_FAILURE, "SSL_CTX_new failed");
++		fatalx(EXIT_FAILURE, "SSL_CTX_set_min_proto_version(TLS1_VERSION)");
+ 	}
++#endif
+ 
+ 	if (SSL_CTX_use_certificate_chain_file(ssl_ctx, certfile) != 1) {
+ 		ssl_debug();