# LuCI PrivateRouter Theme
#
# Licensed under the Apache License v2.0
# http://www.apache.org/licenses/LICENSE-2.0

include $(TOPDIR)/rules.mk

THEME_NAME:=privaterouter
THEME_TITLE:=PrivateRouter

PKG_NAME:=luci-theme-$(THEME_NAME)
PKG_VERSION:=0.3.1
PKG_RELEASE:=8

include $(INCLUDE_DIR)/package.mk

define Package/luci-theme-$(THEME_NAME)
  SECTION:=luci
  CATEGORY:=LuCI
  SUBMENU:=9. Themes
  DEPENDS:=+libc
  TITLE:=Tema LuCi - $(THEME_TITLE)
  URL:=https://privaterouter.com
  PKGARCH:=all
endef

define Build/Configure
endef

define Build/Compile
endef

define Package/luci-theme-$(THEME_NAME)/install
	$(INSTALL_DIR) $(1)/etc/uci-defaults
	echo "uci set luci.themes.$(THEME_TITLE)=/luci-static/$(THEME_NAME); uci commit luci" > $(1)/etc/uci-defaults/30-luci-theme-$(THEME_NAME)
	$(INSTALL_DIR) $(1)/www/luci-static/$(THEME_NAME)
	$(CP) -a ./luasrc/* $(1)/www/luci-static/$(THEME_NAME)/ 2>/dev/null || true
	$(INSTALL_DIR) $(1)/usr/lib/lua/luci/view/themes/$(THEME_NAME)
	$(CP) -a ./template/* $(1)/usr/lib/lua/luci/view/themes/$(THEME_NAME)/ 2>/dev/null || true
    $(INSTALL_DIR) $(1)/tmp/luci-theme-$(THEME_NAME)
    $(CP) ./css/custom.css $(1)/tmp/luci-theme-$(THEME_NAME)/custom.css
endef

define Package/luci-theme-$(THEME_NAME)/postinst
#!/bin/sh
[ -n "$${IPKG_INSTROOT}" ] || {
        ( . /etc/uci-defaults/30-luci-theme-$(THEME_NAME) ) && rm -f /etc/uci-defaults/30-luci-theme-$(THEME_NAME)
        # Always overwrite custom.css
        mv -f /tmp/luci-theme-$(THEME_NAME)/custom.css /www/luci-static/resources/view/dashboard/css/custom.css
        # Remove the temporary directory
        rm -rf /tmp/luci-theme-$(THEME_NAME)
}
endef


$(eval $(call BuildPackage,luci-theme-$(THEME_NAME)))
