From d35cb4de549811652e031cff851f5be3f37f2e20 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 16 Oct 2026 23:46:44 +0000 Subject: [PATCH] Linux: bash for root when its shell is plain sh (Void); lint's API level for Downloads; distro tests strip ST-ended OSC, use https mirrors for Alma and Devuan Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0172Hejd12i4aYikYW9vgpZs --- .../com/neodesktop/dmodem/bridge/Bridges.kt | 2 ++ .../neodesktop/dmodem/local/LinuxSystem.kt | 6 +++++- .../dmodem/transfer/AndroidFiles.kt | 8 +++++--- .../neodesktop/dmodem/local/DistrosTest.kt | 6 ++++++ .../dmodem/local/LinuxSystemTest.kt | 20 +++++++++++++++++-- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/neodesktop/dmodem/bridge/Bridges.kt b/app/src/main/java/com/neodesktop/dmodem/bridge/Bridges.kt index 0a5470f..0f06116 100644 --- a/app/src/main/java/com/neodesktop/dmodem/bridge/Bridges.kt +++ b/app/src/main/java/com/neodesktop/dmodem/bridge/Bridges.kt @@ -22,6 +22,8 @@ import kotlinx.coroutines.launch * as the settings have them, one client on the modem at a time between * them; the modem's lines (DSR, DCD, RI) from its state. */ +// (the Bluetooth bridge holds the application's context, which lives as long as the process) +@android.annotation.SuppressLint("StaticFieldLeak") object Bridges { private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO) private val signals = MutableStateFlow(LineSignals()) diff --git a/app/src/main/java/com/neodesktop/dmodem/local/LinuxSystem.kt b/app/src/main/java/com/neodesktop/dmodem/local/LinuxSystem.kt index a96cdbd..49e7fde 100644 --- a/app/src/main/java/com/neodesktop/dmodem/local/LinuxSystem.kt +++ b/app/src/main/java/com/neodesktop/dmodem/local/LinuxSystem.kt @@ -192,7 +192,11 @@ class LinuxSystem( fun loginShell(): String { val passwd = File(rootfs, "etc/passwd") val shell = runCatching { passwd.readLines().firstOrNull { it.startsWith("root:") }?.split(':')?.getOrNull(6) }.getOrNull() - return shell?.takeIf { it.startsWith("/") && existsInside(it) } ?: "/bin/sh" + val sh = shell?.takeIf { it.startsWith("/") && existsInside(it) } ?: "/bin/sh" + // (root's plain sh, as Void has it, while bash is there: bash, whose prompt the + // system's profile is written for, else it's shown as it's written, \u@\h and all) + if ((sh == "/bin/sh" || sh == "/usr/bin/sh") && existsInside("/bin/bash")) return "/bin/bash" + return sh } /** [path] is in the system: its links followed as the system sees them (an absolute one from its own root) */ diff --git a/app/src/main/java/com/neodesktop/dmodem/transfer/AndroidFiles.kt b/app/src/main/java/com/neodesktop/dmodem/transfer/AndroidFiles.kt index b68a64c..3ef2b4f 100644 --- a/app/src/main/java/com/neodesktop/dmodem/transfer/AndroidFiles.kt +++ b/app/src/main/java/com/neodesktop/dmodem/transfer/AndroidFiles.kt @@ -23,8 +23,10 @@ class DownloadsIncoming(context: Context) : Incoming { private val folder: FolderIncoming? = if (Build.VERSION.SDK_INT < 29) FolderIncoming(ctx.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS) ?: ctx.filesDir) else null + // (the stream is the caller's to close) + @android.annotation.SuppressLint("Recycle") override fun create(name: String, size: Long): Pair { - folder?.let { return it.create(name, size) } + if (Build.VERSION.SDK_INT < 29) return folder!!.create(name, size) val safe = FolderIncoming.safeName(name) val v = ContentValues().apply { put(MediaStore.MediaColumns.DISPLAY_NAME, safe) @@ -43,7 +45,7 @@ class DownloadsIncoming(context: Context) : Incoming { } override fun done(name: String, mtime: Long) { - folder?.let { return it.done(name, mtime) } + if (Build.VERSION.SDK_INT < 29) return folder!!.done(name, mtime) val uri = synchronized(pending) { pending.remove(name) } ?: return val v = ContentValues().apply { put(MediaStore.MediaColumns.IS_PENDING, 0) @@ -53,7 +55,7 @@ class DownloadsIncoming(context: Context) : Incoming { } override fun abandon(name: String) { - folder?.let { return it.abandon(name) } + if (Build.VERSION.SDK_INT < 29) return folder!!.abandon(name) val uri = synchronized(pending) { pending.remove(name) } ?: return runCatching { ctx.contentResolver.delete(uri, null, null) } } diff --git a/app/src/test/java/com/neodesktop/dmodem/local/DistrosTest.kt b/app/src/test/java/com/neodesktop/dmodem/local/DistrosTest.kt index 48499dc..165481a 100644 --- a/app/src/test/java/com/neodesktop/dmodem/local/DistrosTest.kt +++ b/app/src/test/java/com/neodesktop/dmodem/local/DistrosTest.kt @@ -184,6 +184,12 @@ class DistrosTest { assertTrue(sys.command().takeLast(2) == listOf("/bin/bash", "-l")) assertTrue(sys.existsInside("/usr/bin/../bin/env")) assertFalse(sys.existsInside("/bin/zsh")) + // root's plain sh (Void's) with bash there: bash, the shell the profile's prompt is for + val passwd = File(etc, "passwd") + val before = passwd.readText() + passwd.writeText("root:x:0:0:root:/root:/bin/sh\n") + assertEquals("/bin/bash", sys.loginShell()) + passwd.writeText(before) // an absolute link: resolved inside, not on the host Files.createSymbolicLink(File(sys.rootfs, "usr/bin/sh").toPath(), Paths.get("/usr/bin/bash")) assertTrue(sys.existsInside("/bin/sh")) diff --git a/app/src/test/java/com/neodesktop/dmodem/local/LinuxSystemTest.kt b/app/src/test/java/com/neodesktop/dmodem/local/LinuxSystemTest.kt index ed4fec2..de3cb00 100644 --- a/app/src/test/java/com/neodesktop/dmodem/local/LinuxSystemTest.kt +++ b/app/src/test/java/com/neodesktop/dmodem/local/LinuxSystemTest.kt @@ -62,10 +62,23 @@ class LinuxSystemTest { for (d in dirs) { val f = File(sys.rootfs, d) val files = if (f.isDirectory) f.listFiles()?.toList() ?: emptyList() else listOf(f) - for (x in files) if (x.isFile && !Files.isSymbolicLink(x.toPath())) x.writeText(x.readText().replace("http://", "https://")) + for (x in files) if (x.isFile && !Files.isSymbolicLink(x.toPath())) x.writeText(https(x.readText())) } } + /** + * a repository list's mirrors on https: http:// made https://; Devuan's round-robin name (its + * mirrors' certificates are their own) as its main mirror; a yum mirror list (which hands out + * http mirrors) replaced by the repository's own baseurl, where it has a real one + */ + private fun https(t: String): String { + var out = t.replace("http://", "https://").replace("deb.devuan.org", "pkgmaster.devuan.org") + if (Regex("(?m)^#\\s*baseurl=").containsMatchIn(out) && !out.contains("download.example")) { + out = out.replace(Regex("(?m)^(mirrorlist|metalink)="), "#$1=").replace(Regex("(?m)^#\\s*baseurl="), "baseurl=") + } + return out + } + /** behind a proxy that re-signs TLS: its CA added to the system's own bundles (the test's doing, not the app's) */ private fun trustHostCa(sys: LinuxSystem) { val ca = File("/etc/ssl/certs/ca-certificates.crt") @@ -123,7 +136,10 @@ class LinuxSystemTest { if (t.contains("\u001b[6n")) link.write("\u001b[1;1R".toByteArray()) synchronized(sb) { sb.append(t) } } - val text get() = synchronized(sb) { sb.toString().replace(Regex("\u001b\\[[0-9;?]*[A-Za-z]|\u001b\\][^\u0007]*\u0007"), "") } + // (CSI; OSC to BEL or to ST, as systemd's prompt marks end; charset and other two-character escapes) + val text get() = synchronized(sb) { + sb.toString().replace(Regex("\u001b\\[[0-9;?]*[A-Za-z]|\u001b\\][^\u0007\u001b]*(\u0007|\u001b\\\\)|\u001b[()#][0-9A-Za-z]|\u001b[=>78]"), "") + } } private fun shell(sys: LinuxSystem): Pair {