Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/htop.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_PACKAGE_htop=m
CONFIG_HTOP_LMSENSORS=y
1 change: 1 addition & 0 deletions config/utils.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_PACKAGE_nano-full=m
6 changes: 6 additions & 0 deletions docs/design/distfeed.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,9 @@ https://downloads.openwrt.org/releases/${openwrt_version}/packages/${package_arc
https://downloads.openwrt.org/releases/${openwrt_version}/packages/${package_arch}/routing/packages.adb
EOF
```

Packages from `customfeeds.list` are not rebuilt or QA'd by NethSecurity, so the nightly
package-update cron and the UI's package update check/install flow never consider them: both
run `apk` through `/usr/sbin/apk-official`, which temporarily moves `customfeeds.list` aside for
the duration of a single `apk` call and restores it afterwards. Direct/manual `apk` invocations
are unaffected and still see `customfeeds.list` normally.
4 changes: 2 additions & 2 deletions packages/ns-api/files/ns.update
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ def check_package_updates():
try:
# download metadata only if they are older than 5 minutes
if (time.time() - last_package_check()) > 300:
subprocess.run(["/usr/bin/apk", "update"], check=True, capture_output=True)
subprocess.run(["/usr/sbin/apk-official", "update"], check=True, capture_output=True)
except Exception as e:
print(e, file=sys.stderr)
return utils.generic_error("apk_update_failed")
p = subprocess.run(["/usr/bin/apk", "list", "--upgradable"], check=True, capture_output=True, text=True)
p = subprocess.run(["/usr/sbin/apk-official", "list", "--upgradable"], check=True, capture_output=True, text=True)
for line in p.stdout.split("\n"):
if not line:
continue
Expand Down
1 change: 1 addition & 0 deletions packages/ns-plug/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ define Package/ns-plug/install
$(INSTALL_BIN) ./files/ns-plug $(1)/usr/sbin/ns-plug
$(INSTALL_BIN) ./files/ns-plug-alert-proxy $(1)/usr/sbin/ns-plug-alert-proxy
$(INSTALL_BIN) ./files/distfeed-setup $(1)/usr/sbin/distfeed-setup
$(INSTALL_BIN) ./files/apk-official $(1)/usr/sbin/apk-official
$(INSTALL_BIN) ./files/remote-backup $(1)/usr/sbin
$(INSTALL_BIN) ./files/send-backup $(1)/usr/sbin
$(INSTALL_BIN) ./files/send-heartbeat $(1)/usr/sbin
Expand Down
26 changes: 26 additions & 0 deletions packages/ns-plug/files/apk-official
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

#
# Copyright (C) 2026 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-2.0-only
#

# Runs a single apk subcommand with the user-added customfeeds.list
# (docs/design/distfeed.md "Upstream OpenWrt repositories") temporarily
# excluded, so automatic update paths never install a package that bypassed
# the NethSecurity distfeed/QA channel. Serialized via flock so overlapping
# invocations (cron, UI, manual admin apk use) don't race on the file.

LOCK=/var/run/apk-official.lock
CUSTOMFEEDS=/etc/apk/repositories.d/customfeeds.list
DISABLED="${CUSTOMFEEDS}.disabled"

exec 9>"$LOCK"
flock 9

@gsanchietti gsanchietti Aug 6, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why flock is needed?
apk should already handle the lock

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed: apk handles the lock.
When another instance is running, this is the error that apk returns:

ERROR: Unable to lock database: Resource temporarily unavailable
ERROR: Failed to open apk database: Resource temporarily unavailable

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not concerned about apk, more about the file move. We could lose the custom feeds if concurrent requests are being made, if it's acceptable, I'll remove it no problem


[ -f "$CUSTOMFEEDS" ] && mv "$CUSTOMFEEDS" "$DISABLED"
apk "$@"
status=$?
[ -f "$DISABLED" ] && mv "$DISABLED" "$CUSTOMFEEDS"

exit $status
4 changes: 3 additions & 1 deletion packages/ns-plug/files/distfeed-setup
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
# setup default variables
. /etc/openwrt_release
. /etc/os-release
openwrt_version="$(cat /etc/openwrt_version)"
openwrt_version="${openwrt_version#v}"
cat << EOF > /etc/apk/repositories.d/99-defaults.list
# This file is handled by nethsecurity and should not be edited manually. Changes will be overwritten.
# Create a 98-overrides.list file to override these values if needed.
set -default target_arch=$DISTRIB_TARGET
set -default package_arch=$DISTRIB_ARCH
set -default openwrt_version=$(cat /etc/openwrt_version)
set -default openwrt_version=$openwrt_version
set -default repo_channel=$(cat /etc/repo-channel)
set -default version=$VERSION_ID
EOF
Expand Down
6 changes: 3 additions & 3 deletions packages/ns-plug/files/update-packages
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ error_exit() {
}

# Update metadata, make sure to output even if in case of error
output=$(apk update 2>&1)
output=$(apk-official update 2>&1)
status=$?
echo "$output" | logger -s -t update-packages
[ $status -ne 0 ] && error_exit "Failed to update metadata"

error_count=0
# Upgrade each package individually and capture output
apk list --upgradable 2>/dev/null | grep -o '{[^}]*}' | tr -d '{}' | sed 's|.*/||' | while read -r package; do
output=$(apk upgrade "$package" 2>&1)
apk-official list --upgradable 2>/dev/null | grep -o '{[^}]*}' | tr -d '{}' | sed 's|.*/||' | while read -r package; do
output=$(apk-official upgrade "$package" 2>&1)
status=$?
[ $status -ne 0 ] && error_count=$((error_count + 1))
echo "$output" | logger -s -t update-packages
Expand Down
Loading