mirror of
https://github.com/D-Modem/app.git
synced 2026-11-28 17:38:05 -08:00
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0172Hejd12i4aYikYW9vgpZs
This commit is contained in:
5 files changed
+36
-6
No files matched your search
@@ -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())
|
||||
|
||||
@@ -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) */
|
||||
|
||||
@@ -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<OutputStream, String> {
|
||||
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) }
|
||||
}
|
||||
|
||||
@@ -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"))
|
||||
|
||||
@@ -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<LocalLink, Screen> {
|
||||
|
||||
Reference in new issue
Block a user