Skip to content

Gate the camera package check on the model, and migrate printers off the retired Entware feed host - #21

Open
arlophoenix wants to merge 1 commit into
C0DEbrained:mainfrom
arlophoenix:fix/k1c-camera-guard-and-feed-migration
Open

Gate the camera package check on the model, and migrate printers off the retired Entware feed host#21
arlophoenix wants to merge 1 commit into
C0DEbrained:mainfrom
arlophoenix:fix/k1c-camera-guard-and-feed-migration

Conversation

@arlophoenix

Copy link
Copy Markdown

ensure_mjpg_streamer_packages decides whether to install mjpg-streamer by testing /usr/bin/mjpg_streamer, with no $model check, and install_usb_camera is wired into all six model menus. Only the K1 2025 camera services read /usr/bin and /usr/lib; the K1, 3V3, 3KE, 10SE and E5M services read /opt/bin and /opt/lib, which is Entware's territory, so on those five models the guard is testing a path their own service never looks at. This splits the check so each model is measured against the path it actually uses. Whether any legacy firmware ships /usr/bin/mjpg_streamer and therefore hits this in practice is not something I can check without that hardware, so this is a correctness fix rather than a reported bug.

The same function's failure path was unsafe. helper.sh sets -e and sources every script into one shell, so a return 1 from a sourced function ends the whole program and drops the user to a prompt with no menu — and by the time the check ran, the working Entware streamer had already been stopped and renamed and the init script already copied into place, with nothing left running to undo any of it. The check now runs before anything destructive and its status is handled at both call sites, so a failure reports the reason and returns to the menu with the printer in the state it started in.

Removing that path also removed both seds that rewrote /opt/etc/opkg.conf, and those seds were the only thing still repairing printers left pointing at bin.tranducanh.com after that host stopped serving the repository. Since /opt/etc/opkg.conf lives on the printer's persistent /opt and no helper-script update touches it, those printers would have been stranded with no way back. In their place is a deliberate one-shot migration at startup: it matches on the hostname rather than a line number so anything the user added to the file survives, writes through a temp file and only swaps it in once complete so a full /opt image cannot leave a truncated config behind, and prints a one-time notice naming opkg update as the follow-up, since rewriting the config does not refresh a package index from March 2024. It cannot fail the script.

Finally, install_entware ran its whole body under set +e and then printed a green checkmark regardless of the outcome, symlinking /opt/libexec/sftp-server whether or not the install had produced it — so a failed install reported success and left SFTP broken behind a dangling symlink. It now checks that the install produced what the rest of the script depends on before saying so, and guards the symlink the same way the S48entware boot script it writes already does. The prepare_opt call in that function was removed in 7a6ebfa and has not existed since; it was harmless, because files/entware/generic.sh creates the same directories, but set +e was hiding a command not found on every legacy install.

These four changes have to land together. The first two delete the seds, and the third is what replaces them.

Test plan

  • shellcheck -s bash -S warning -e SC2154,SC2034,SC1090,SC1091,SC1111 on the three changed files introduces no new findings (the three that remain are pre-existing: the duplicated 1080p case pattern and one SC2155 in helper.sh)
  • bash -n parses every script in the repo
  • Stub harness against the real functions: a failed camera install returns to the menu with helper.sh still running, leaves S96mjpg-streamer enabled, and runs no destructive step first; the legacy path issues exactly one opkg update and one package install; usb_camera.sh no longer references opkg.conf on any path
  • Stub harness for the migration: rewrites only the dead hostname, preserves user-added src/gz and non-feed directives verbatim, stays silent when there is nothing to do, and is a no-op on second run
  • Migration against a genuinely full filesystem (1 MB volume filled to 0 KB free): the original config is left byte-identical, no partial temp file survives, and the failure is reported
  • Manual test pass (see checklist below)

The harness above is a local scratch script, not part of this PR; a test directory is a separate change.

Manual test pass

  • On a K1 2025, head -1 /opt/etc/opkg.conf reads bin.entware.net both before and after a USB camera install
  • Rename /usr/bin/mjpg_streamer, run a USB camera install, and confirm you land back in the helper menu rather than a shell prompt
  • After that failed install, /opt/etc/init.d/S96mjpg-streamer is still enabled and /opt/etc/opkg.conf is unchanged
  • Restore /usr/bin/mjpg_streamer, install the built-in camera fix, and confirm the stream comes up in Fluidd
  • On a printer still pointed at bin.tranducanh.com, launch the helper and confirm the notice appears once, the config is rewritten, and the notice does not return on the next launch
  • Reinstall Entware and confirm ls -l /usr/libexec/sftp-server resolves to a real file
  • On a legacy model, install USB camera support and confirm the mjpg-streamer packages land in /opt/bin

Not addressed

The duplicated 1080p|1080p case pattern that silently rejects 1080P, and the plain-HTTP fallback in files/entware/generic.sh that downloads and root-executes opkg from a third-party host, are both real but unrelated to this change and belong in their own PRs. The redundant disable_entware_builtin_mjpg_streamer call in install_builtin_camera is left alone too — the shipped service redoes that work on every start anyway, and untangling it would widen this diff.

… host

ensure_mjpg_streamer_packages tested /usr/bin/mjpg_streamer with no $model
check, but only the K1 2025 camera services read /usr/bin and /usr/lib; the
K1, 3V3, 3KE, 10SE and E5M services read /opt/bin and /opt/lib, which is
Entware's territory. Split the function so each model is checked against the
path its own service actually uses, and move the check ahead of the steps that
disable the running streamer and copy the init script, so a failure leaves the
printer as it was and hands control back to the menu instead of terminating
helper.sh through the global set -e.

Removing that path also removed both seds that rewrote /opt/etc/opkg.conf, and
those seds were the only thing repairing printers still pointed at
bin.tranducanh.com after that host stopped serving the repository. Replace them
with a deliberate one-shot migration at startup that matches on the hostname so
user-added feed lines survive, writes through a temp file so a full /opt image
cannot truncate the config, and tells the user to run opkg update afterwards.

Also stop install_entware reporting success unconditionally: it ran under
set +e, symlinked /opt/libexec/sftp-server whether or not the install produced
it, and printed a green checkmark either way. It also called prepare_opt, which
was removed in 7a6ebfa and no longer exists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant