package-luci.sh 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #!/bin/bash
  2. # package-luci.sh builds luci-app-netpulse as .ipk or .apk with the SDK.
  3. # Mirror of package.sh (agent) without the binary: the package is files-only
  4. # (PKGARCH all), so the SAME artifact works for the gateway and the APs.
  5. #
  6. # Usage:
  7. # package-luci.sh <SDK_VERSION> <SDK_TARGET> <SDK_SUBTARGET> <FORMAT>
  8. #
  9. # SDK_VERSION: 24.10.5 or 25.12.5
  10. # SDK_TARGET: mediatek/filogic or qualcommax/ipq807x
  11. # SDK_SUBTARGET: (empty, detected automatically)
  12. # FORMAT: ipk or apk
  13. #
  14. # The package version defaults to the luci-app-netpulse Makefile and can be
  15. # overridden through the PKG_VERSION / PKG_RELEASE env vars (the CI matches
  16. # the release tag).
  17. #
  18. # Example:
  19. # package-luci.sh 24.10.5 mediatek/filogic "" ipk
  20. # package-luci.sh 25.12.5 qualcommax/ipq807x "" apk
  21. set -euo pipefail
  22. SDK_VERSION="${1:?missing SDK_VERSION}"
  23. SDK_TARGET="${2:?missing SDK_TARGET}"
  24. SDK_SUBTARGET="${3:-}"
  25. FORMAT="${4:?missing FORMAT (ipk|apk)}"
  26. echo "=== package-luci.sh: $FORMAT SDK=$SDK_VERSION target=$SDK_TARGET ==="
  27. SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
  28. REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
  29. APP_DIR="$SCRIPT_DIR/luci-app-netpulse"
  30. WORK_DIR="$(mktemp -d)"
  31. trap 'rm -rf "$WORK_DIR"' EXIT
  32. PKG_VERSION="${PKG_VERSION:-$(sed -n 's/^PKG_VERSION:=//p' "$APP_DIR/Makefile" | head -1)}"
  33. PKG_RELEASE="${PKG_RELEASE:-$(sed -n 's/^PKG_RELEASE:=//p' "$APP_DIR/Makefile" | head -1)}"
  34. # SDK URL. Resolve the real archive name from the download index (the
  35. # toolchain component differs across OpenWrt releases); same scheme as
  36. # package.sh.
  37. SDK_DIR_URL="https://downloads.openwrt.org/releases/${SDK_VERSION}/targets/${SDK_TARGET}/"
  38. # shellcheck source=deploy/openwrt/sdk.sh
  39. . "$SCRIPT_DIR/sdk.sh"
  40. SDK_DIR="$(download_verified_sdk "$SDK_DIR_URL" "$WORK_DIR")" || exit 1
  41. cd "$WORK_DIR"
  42. OUT_DIR="$REPO_ROOT/dist/packages"
  43. mkdir -p "$OUT_DIR"
  44. if [ "$FORMAT" = "ipk" ]; then
  45. echo " Building .ipk (ipkg-build, arch all)..."
  46. PKG_DIR="$WORK_DIR/luci-app-netpulse-pkg"
  47. mkdir -p "$PKG_DIR/CONTROL"
  48. cp -r "$APP_DIR/files/." "$PKG_DIR/"
  49. chmod 755 "$PKG_DIR/usr/libexec/rpcd/luci.netpulse"
  50. cat > "$PKG_DIR/CONTROL/control" << CTRL
  51. Package: luci-app-netpulse
  52. Version: ${PKG_VERSION:-0.0.0}-${PKG_RELEASE:-1}
  53. Depends: luci-base, netpulse-agent
  54. License: AGPL-3.0-only
  55. Section: luci
  56. Architecture: all
  57. Maintainer: Nacho <netpulse@cloudless.club>
  58. Description: Node-local NetPulse agent view for LuCI
  59. LuCI pages for the NetPulse agent on THIS router: procd status, binary
  60. version, RSS, heartbeat, recent syslog lines, restart button and
  61. editable UCI configuration, plus a link to the NetPulse web app.
  62. CTRL
  63. cat > "$PKG_DIR/CONTROL/postinst" << 'POSTINST'
  64. #!/bin/sh
  65. [ -n "$IPKG_INSTROOT" ] && exit 0
  66. /etc/init.d/rpcd restart 2>/dev/null || true
  67. rm -f /tmp/luci-indexcache* 2>/dev/null || true
  68. exit 0
  69. POSTINST
  70. chmod 755 "$PKG_DIR/CONTROL/postinst"
  71. cat > "$PKG_DIR/CONTROL/postrm" << 'POSTRM'
  72. #!/bin/sh
  73. [ -n "$IPKG_INSTROOT" ] && exit 0
  74. /etc/init.d/rpcd restart 2>/dev/null || true
  75. rm -f /tmp/luci-indexcache* 2>/dev/null || true
  76. exit 0
  77. POSTRM
  78. chmod 755 "$PKG_DIR/CONTROL/postrm"
  79. "$SDK_DIR/scripts/ipkg-build" "$PKG_DIR" "$OUT_DIR"
  80. echo " IPK: $(ls "$OUT_DIR"/luci-app-netpulse_*.ipk)"
  81. elif [ "$FORMAT" = "apk" ]; then
  82. echo " Building .apk (real apk v3 via 25.12 SDK)..."
  83. # #468: renaming an ipk to .apk does NOT work: apk-tools v3 on the router
  84. # refuses the ipk bytes with "v2 package format error". Build a real v3
  85. # package with the SDK, same source-less Makefile pattern package.sh uses
  86. # for netpulse-agent: files staged under files/, no-op Build/Compile, and
  87. # the SDK's own `apk mkpkg` produces the signed-v3 tarball. Dependencies
  88. # are recorded as metadata; the SDK does not need them present.
  89. PKG_DIR_SDK="$SDK_DIR/package/utils/luci-app-netpulse"
  90. mkdir -p "$PKG_DIR_SDK/files"
  91. cp -r "$APP_DIR/files/." "$PKG_DIR_SDK/files/"
  92. chmod 755 "$PKG_DIR_SDK/files/usr/libexec/rpcd/luci.netpulse"
  93. cat > "$PKG_DIR_SDK/Makefile" << 'MAKE'
  94. include $(TOPDIR)/rules.mk
  95. PKG_NAME:=luci-app-netpulse
  96. PKG_VERSION:=@PKG_VERSION@
  97. PKG_RELEASE:=@PKG_RELEASE@
  98. PKG_LICENSE:=AGPL-3.0-only
  99. PKG_MAINTAINER:=Nacho <netpulse@cloudless.club>
  100. include $(INCLUDE_DIR)/package.mk
  101. define Package/luci-app-netpulse
  102. SECTION:=luci
  103. CATEGORY:=LuCI
  104. TITLE:=Node-local NetPulse agent view for LuCI
  105. URL:=https://github.com/gnacho/netpulse
  106. DEPENDS:=+luci-base +netpulse-agent
  107. PKGARCH:=all
  108. endef
  109. define Package/luci-app-netpulse/description
  110. LuCI pages for the NetPulse agent on this router: procd status,
  111. binary version, RSS, heartbeat, recent syslog lines, restart button
  112. and editable UCI configuration, plus a link to the NetPulse web app.
  113. endef
  114. define Build/Compile
  115. endef
  116. define Package/luci-app-netpulse/install
  117. $(INSTALL_DIR) $(1)/usr/share/luci/menu.d
  118. $(INSTALL_DATA) ./files/usr/share/luci/menu.d/luci-app-netpulse.json $(1)/usr/share/luci/menu.d/
  119. $(INSTALL_DIR) $(1)/usr/share/rpcd/acl.d
  120. $(INSTALL_DATA) ./files/usr/share/rpcd/acl.d/luci-app-netpulse.json $(1)/usr/share/rpcd/acl.d/
  121. $(INSTALL_DIR) $(1)/usr/libexec/rpcd
  122. $(INSTALL_BIN) ./files/usr/libexec/rpcd/luci.netpulse $(1)/usr/libexec/rpcd/
  123. $(INSTALL_DIR) $(1)/www/luci-static/resources/view/netpulse
  124. $(INSTALL_DATA) ./files/www/luci-static/resources/view/netpulse/*.js $(1)/www/luci-static/resources/view/netpulse/
  125. endef
  126. define Package/luci-app-netpulse/postinst
  127. #!/bin/sh
  128. [ -n "$${IPKG_INSTROOT}" ] && exit 0
  129. /etc/init.d/rpcd restart 2>/dev/null || true
  130. rm -f /tmp/luci-indexcache* 2>/dev/null || true
  131. exit 0
  132. endef
  133. $(eval $(call BuildPackage,luci-app-netpulse))
  134. MAKE
  135. sed -i "s/@PKG_VERSION@/${PKG_VERSION:-0.0.0}/; s/@PKG_RELEASE@/${PKG_RELEASE:-1}/" "$PKG_DIR_SDK/Makefile"
  136. cd "$SDK_DIR"
  137. # .config válido sin terminal (menuconfig muere en CI headless).
  138. make defconfig >/dev/null 2>&1 || true
  139. make package/luci-app-netpulse/compile V=s 2>&1 | tail -20
  140. find bin/packages -name "luci-app-netpulse*.apk" -exec cp {} "$OUT_DIR/" \;
  141. echo " APK: $(ls "$OUT_DIR"/luci-app-netpulse*.apk 2>/dev/null || echo 'NOT FOUND')"
  142. else
  143. echo "ERROR: FORMAT must be ipk or apk" >&2
  144. exit 1
  145. fi
  146. echo "=== package-luci.sh: OK ==="