fix add packages script

This commit is contained in:
2026-03-08 14:33:55 -04:00
parent be02d9fc43
commit 815517f1bc

View File

@@ -39,10 +39,45 @@ if [ ! -f ".config" ]; then
make defconfig make defconfig
fi fi
PACKAGE_INDEX="tmp/.config-package.in"
PACKAGE_INFO="tmp/.packageinfo"
# Ensure package metadata exists for reliable package name lookups.
if [ ! -f "$PACKAGE_INDEX" ] && [ ! -f "$PACKAGE_INFO" ]; then
echo "⚙️ Generating package metadata..."
make defconfig >/dev/null
fi
is_already_enabled() {
local pkg="$1"
awk -v package_y="CONFIG_PACKAGE_${pkg}=y" \
-v package_m="CONFIG_PACKAGE_${pkg}=m" \
-v default_y="CONFIG_DEFAULT_${pkg}=y" \
'$0 == package_y || $0 == package_m || $0 == default_y { found=1; exit }
END { exit !found }' .config
}
package_exists() {
local pkg="$1"
if [ -f "$PACKAGE_INDEX" ] &&
awk -v key="PACKAGE_${pkg}" '$1 == "config" && $2 == key { found=1; exit }
END { exit !found }' "$PACKAGE_INDEX"; then
return 0
fi
if [ -f "$PACKAGE_INFO" ] && grep -Fqx "Package: $pkg" "$PACKAGE_INFO"; then
return 0
fi
return 1
}
echo "📦 Reading packages from $PKG_FILE ..." echo "📦 Reading packages from $PKG_FILE ..."
# Read all non-empty, non-comment lines, split by any whitespace # Read package tokens from file, while allowing inline comments.
PACKAGES=$(grep -v '^[[:space:]]*$' "$PKG_FILE" | grep -v '^#' | tr '\n' ' ') PACKAGES=$(awk '{ sub(/#.*/, ""); for (i = 1; i <= NF; i++) print $i }' "$PKG_FILE")
ADDED=() ADDED=()
MISSING=() MISSING=()
@@ -51,13 +86,13 @@ for pkg in $PACKAGES; do
CONFIG_NAME="CONFIG_PACKAGE_${pkg}" CONFIG_NAME="CONFIG_PACKAGE_${pkg}"
# Skip if already enabled # Skip if already enabled
if grep -q "^${CONFIG_NAME}=y" .config; then if is_already_enabled "$pkg"; then
echo "✅ Already enabled: $pkg" echo "✅ Already enabled: $pkg"
continue continue
fi fi
# Check if package exists in package/ or feeds/ # Check if package exists in OpenWrt package metadata.
if ! find package feeds -type d -path "*/${pkg}" -mindepth 1 -maxdepth 3 2>/dev/null | grep -q .; then if ! package_exists "$pkg"; then
echo "⚠️ Package not found: $pkg" echo "⚠️ Package not found: $pkg"
MISSING+=("$pkg") MISSING+=("$pkg")
continue continue