#
# Copyright (C) 2026 xiexiaobao
#
# This is free software, licensed under the GPL 2.0 license.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=expand-overlay
PKG_VERSION:=1.0
PKG_RELEASE:=1

PKG_MAINTAINER:=xiexiaobao
PKG_LICENSE:=GPL-2.0

include $(INCLUDE_DIR)/package.mk

define Package/expand-overlay
  SECTION:=utils
  CATEGORY:=Utilities
  TITLE:=eMMC partition layout: 3G overlay + data partition
  DEPENDS:=+sfdisk +e2fsprogs +block-mount
  PKGARCH:=all
endef

define Package/expand-overlay/description
  First-boot eMMC partition layout for NanoPi R6C:
  - p3 (3GB): overlay filesystem (system/config)
  - p4 (~54GB): data partition (mounted at /mnt/data, for Docker)
  Stage 1 (uci-defaults): resizes p3 to 3GB, creates p4.
  Stage 2 (init.d): resizes p3 fs, formats & mounts p4.
endef

define Build/Configure
endef

define Build/Compile
endef

define Package/expand-overlay/install
	$(INSTALL_DIR) $(1)/etc/uci-defaults
	$(INSTALL_BIN) ./files/expand-overlay.sh $(1)/etc/uci-defaults/99-expand-overlay
	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_BIN) ./files/expand-overlay.init $(1)/etc/init.d/expand-overlay
endef

$(eval $(call BuildPackage,expand-overlay))
