include $(TOPDIR)/rules.mk

PKG_NAME:=uniberg-uconfigd-role-controller
PKG_VERSION:=$(shell git show -s --format=%cd --date=short)
PKG_RELEASE:=1

PKG_BUILD_PARALLEL:=1

include $(INCLUDE_DIR)/package.mk

define Build/Prepare
endef

define Build/Compile
endef

define Package/uniberg-uconfigd-role-controller
  SECTION:=net
  CATEGORY:=Network
  TITLE:=Meta-Package for the controller role
  DEPENDS:=+uniberg-uconfigd
endef

define Package/uniberg-uconfigd-role-controller/install
	$(INSTALL_DIR) $(1)/lib/uniberg/uconfig $(1)/etc/uci-defaults $(1)/lib/uniberg/uconfig/controller $(1)/usr/share/www $(1)/usr/bin $(1)/etc/init.d
	echo "controller" > $(1)/lib/uniberg/role

	$(CP) ./files/init-config-template.json $(1)/lib/uniberg/uconfig/
	$(CP) ./files/nginx.conf $(1)/lib/uniberg/uconfig/controller/

	$(CP) $(TOPDIR)/../../base/edge-frontend/out/* $(1)/usr/share/www/
	$(CP) $(TOPDIR)/../../base/edge-api/bin/edge-api.linux.arm $(1)/usr/bin/edge-api
	$(CP) $(TOPDIR)/../../base/controller/src/uconfigd-controller.linux.arm $(1)/usr/bin/uconfigd-controller

	$(INSTALL_BIN) ./files/90-edge-api.sh $(1)/etc/uci-defaults/90-edge-api
	$(INSTALL_BIN) ./files/uniberg-ub-edge-api.init $(1)/etc/init.d/uniberg-ub-edge-api

	$(INSTALL_BIN) ./files/uniberg-uconfigd-controller.init $(1)/etc/init.d/uniberg-uconfigd-controller
	$(INSTALL_BIN) ./files/uniberg-controller.sh $(1)/usr/bin/uniberg-controller.sh

	$(INSTALL_BIN) ./files/95-uci-defaults.sh $(1)/etc/uci-defaults/95-uniberg-uconfigd-controller.sh
endef

$(eval $(call BuildPackage,uniberg-uconfigd-role-controller))
