From 04ca9093a33f246a5ab95d26aac0e62030425d65 Mon Sep 17 00:00:00 2001 From: Lucas Zampieri Date: Fri, 31 Jul 2026 17:56:50 -0300 Subject: [PATCH] KindleHIDPassthrough: stop the daemon before unpacking, delegate to install.sh Installing or updating over a live install was silently landing a partial tree. The running daemon holds dist/ld-linux-armhf.so.3 open for execution, so writes to it come back ETXTBSY, and busybox tar stops at the first entry it cannot replace instead of skipping it. That file is entry 8 of 120 in the release tarball, so the extract wrote six .so files and abandoned the rest, then set -e ended the script before the upstart job, the udev rule, the scriptlet and the KOReader plugin were installed. KFPM still reported success. Stop the daemon and give it a moment before unpacking. The rest of the script duplicated logic that upstream already has in scripts/install.sh, and the copies had drifted. The KOReader plugin was merged into place rather than replaced, so lua files dropped between releases stayed behind and KOReader kept loading them, and nothing cleared the mesquite cache, so BTManager carried on serving the previous version's html and js. Hand off to scripts/install.sh installAll instead, which owns daemon lifecycle, stale file removal, config.ini preservation and the appreg refresh, and stays in step with the tarball it shipped in. Uninstall delegates the same way, keeping an inline fallback for the case where the install directory is already gone. Signed-off-by: Lucas Zampieri --- KindleHIDPassthrough/install.sh | 47 ++++++------------------------- KindleHIDPassthrough/uninstall.sh | 47 +++++++++---------------------- 2 files changed, 22 insertions(+), 72 deletions(-) diff --git a/KindleHIDPassthrough/install.sh b/KindleHIDPassthrough/install.sh index 2b5b3a5..e7f56b6 100644 --- a/KindleHIDPassthrough/install.sh +++ b/KindleHIDPassthrough/install.sh @@ -6,50 +6,21 @@ TMPDIR=/mnt/us/KFPM-Temporary INSTALL_DIR=/mnt/us/kindle_hid_passthrough RELEASE_URL="https://github.com/zampierilucas/kindle-hid-passthrough/releases/latest/download" -mkdir -p "$TMPDIR" +# The running daemon keeps dist/ld-linux-armhf.so.3 busy, and busybox tar stops +# at the first entry it cannot replace, so stop it before unpacking. +/sbin/stop hid-passthrough 2>/dev/null || true +pkill -f "kindle-hid-passthrough" 2>/dev/null || true +pkill -f "ld-linux-armhf." 2>/dev/null || true +sleep 2 -# ---- Download and extract release ---- +mkdir -p "$TMPDIR" "$INSTALL_DIR" curl -fSL --progress-bar -o "$TMPDIR/release.tar.gz" \ "$RELEASE_URL/kindle-hid-passthrough-armv7.tar.gz" -mkdir -p "$INSTALL_DIR" tar -xzf "$TMPDIR/release.tar.gz" -C "$INSTALL_DIR" -# ---- Install system files (requires rw root) ---- - -/usr/sbin/mntroot rw - -cp "$INSTALL_DIR/assets/hid-passthrough.upstart" /etc/upstart/hid-passthrough.conf -cp "$INSTALL_DIR/assets/99-hid-keyboard.rules" /etc/udev/rules.d/ -/usr/sbin/udevadm control --reload-rules - -/usr/sbin/mntroot ro || true - -# ---- Set permissions ---- - -chmod +x "$INSTALL_DIR/kindle-hid-passthrough" -chmod +x "$INSTALL_DIR/illusion/BTManager.sh" -mkdir -p "$INSTALL_DIR/cache" - -# ---- Install scriptlet (registers WAF app on first launch) ---- - -cp "$INSTALL_DIR/illusion/BTManager.sh" /mnt/us/documents/BTManager.sh -chmod +x /mnt/us/documents/BTManager.sh - -# ---- Install KOReader plugin (if KOReader is installed) ---- - -if [ -d /mnt/us/koreader/plugins/ ] && [ -d "$INSTALL_DIR/koreader-plugin/hidpassthrough.koplugin" ]; then - mkdir -p /mnt/us/koreader/plugins/hidpassthrough.koplugin - cp -r "$INSTALL_DIR/koreader-plugin/hidpassthrough.koplugin/." \ - /mnt/us/koreader/plugins/hidpassthrough.koplugin/ -fi - -# ---- Start daemon ---- - -/sbin/initctl start hid-passthrough || true - -# ---- Cleanup ---- - rm -rf "$TMPDIR" +sh "$INSTALL_DIR/scripts/install.sh" installAll + exit 0 diff --git a/KindleHIDPassthrough/uninstall.sh b/KindleHIDPassthrough/uninstall.sh index f7c4847..1ad1dcf 100644 --- a/KindleHIDPassthrough/uninstall.sh +++ b/KindleHIDPassthrough/uninstall.sh @@ -3,41 +3,20 @@ set -e INSTALL_DIR=/mnt/us/kindle_hid_passthrough -APPREG_DB=/var/local/appreg.db -APP_ID="com.lzampier.btmanager" -# ---- Stop service ---- - -/sbin/initctl stop hid-passthrough 2>/dev/null || true - -# ---- Remove system files ---- - -/usr/sbin/mntroot rw - -rm -f /etc/upstart/hid-passthrough.conf -rm -f /etc/udev/rules.d/99-hid-keyboard.rules -[ -f /usr/local/bin/dev_is_keyboard.sh ] && rm -f /usr/local/bin/dev_is_keyboard.sh -/usr/sbin/udevadm control --reload-rules 2>/dev/null || true - -/usr/sbin/mntroot ro || true - -# ---- Unregister WAF app ---- - -if [ -f "$APPREG_DB" ]; then - sqlite3 "$APPREG_DB" </dev/null || true + /usr/sbin/mntroot rw + rm -f /etc/upstart/hid-passthrough.conf + rm -f /etc/udev/rules.d/99-hid-keyboard.rules + [ -f /usr/local/bin/dev_is_keyboard.sh ] && rm -f /usr/local/bin/dev_is_keyboard.sh + /usr/sbin/udevadm control --reload-rules 2>/dev/null || true + /usr/sbin/mntroot ro || true + rm -rf "$INSTALL_DIR" /mnt/us/koreader/plugins/hidpassthrough.koplugin + rm -f /mnt/us/documents/BTManager.sh fi -# ---- Remove KOReader plugin (if installed) ---- - -rm -rf /mnt/us/koreader/plugins/hidpassthrough.koplugin - -# ---- Remove files ---- - -rm -rf "$INSTALL_DIR" -rm -f /mnt/us/documents/BTManager.sh - exit 0