Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 85238013a1 | |||
| 97793231c1 | |||
| 59e12a7261 | |||
| dd7bce574e | |||
| 71703c173c | |||
| ed97ec6c63 |
@@ -30,8 +30,8 @@ android {
|
||||
* versionCode 每次发版 +1(Android 靠它判断"能不能覆盖安装",
|
||||
* 改小了会装不上)。
|
||||
*/
|
||||
versionCode = 222
|
||||
versionName = "2.0.22"
|
||||
versionCode = 228
|
||||
versionName = "2.0.28"
|
||||
|
||||
ndk {
|
||||
// Chaquopy 只支持这两个;Termux bootstrap 也只准备了这两份
|
||||
|
||||
@@ -48,7 +48,7 @@ object TermuxInstaller {
|
||||
* 把戳的值带上版本号,**对不上就只重跑修正式步骤**(不重新解压,
|
||||
* 解压要几十秒)。以后再加这类"装完之后要修一下"的逻辑,把这里 +1。
|
||||
*/
|
||||
private const val STAMP_VALUE = "ok:7"
|
||||
private const val STAMP_VALUE = "ok:20"
|
||||
|
||||
/**
|
||||
* 安装日志。
|
||||
@@ -67,6 +67,56 @@ object TermuxInstaller {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ★★ 把内置 Termux 环境**整个重置**(删掉重装)。
|
||||
*
|
||||
* 为什么需要这个功能:
|
||||
*
|
||||
* 1. **装坏了自己救不回来**。dpkg 的数据库和真实文件一旦不一致
|
||||
* (比如在修好 apt 路径之前试着装过包),后面 `pkg install` 会一直报
|
||||
* `E: Internal Error, No file name for ...` 或者
|
||||
* `1 not fully installed or removed` —— **用户在界面上没有任何办法恢复**,
|
||||
* 只能清 App 数据(那会把会议、设置、自定义节点全丢掉)。
|
||||
*
|
||||
* 2. 排查问题时也需要一个"从干净状态重来"的入口。
|
||||
*
|
||||
* 删的是:`files/usr`(整个 prefix)、`files/home`、安装标记、安装日志。
|
||||
* **不碰** `files/kernel-data`(会议/设置/智能体)和 `nodes/`(自定义节点)——
|
||||
* 那些是用户的东西,跟 Termux 环境无关。
|
||||
*
|
||||
* 要在**后台线程**调用。progress 报告阶段。
|
||||
*
|
||||
* @return 重置后重新安装是否成功
|
||||
*/
|
||||
fun reset(context: Context, progress: (String) -> Unit): Boolean {
|
||||
trace(context, "===== 开始重置 Termux 环境 =====")
|
||||
progress("正在删除旧的运行环境…")
|
||||
try {
|
||||
val p = prefix(context)
|
||||
if (p.exists()) {
|
||||
val ok = p.deleteRecursively()
|
||||
trace(context, "删除 prefix:$ok($p)")
|
||||
}
|
||||
val h = home(context)
|
||||
if (h.exists()) {
|
||||
val ok = h.deleteRecursively()
|
||||
trace(context, "删除 home:$ok($h)")
|
||||
}
|
||||
// 安装标记也要删 —— 不然 install() 会走"已装好"的快速路径
|
||||
stampFile(context).delete()
|
||||
trace(context, "已删除安装标记")
|
||||
} catch (t: Throwable) {
|
||||
trace(context, "删除时出错:${t.javaClass.simpleName}: ${t.message}")
|
||||
progress("删除旧的运行环境失败:${t.message}")
|
||||
return false
|
||||
}
|
||||
|
||||
progress("正在重新解压运行环境(约 95 MB,要等一会儿)…")
|
||||
val ok = install(context, progress)
|
||||
trace(context, "===== 重置结束,结果=$ok =====")
|
||||
return ok
|
||||
}
|
||||
|
||||
/**
|
||||
* 安装(幂等)。要在后台线程调用。progress 会报告阶段,给界面显示。
|
||||
* @return true 表示装好(或本来就装好了)
|
||||
@@ -88,6 +138,12 @@ object TermuxInstaller {
|
||||
progress("正在修正内置环境(升级后的一次性修复)…")
|
||||
val fixed = rewritePrefixes(context)
|
||||
trace(context, "补跑改写:$fixed 个文件")
|
||||
// ★ apt.conf 是新增的,老设备上肯定没有 → 必须补写。
|
||||
// 不写的话 apt 会去 /data/data/com.termux/... 找 apt.conf.d,
|
||||
// 报 "Unable to determine a suitable packaging system type"。
|
||||
writeAptConf(context)
|
||||
fixBrokenSymlinks(context).let { trace(context, "修了 $it 个断链") }
|
||||
installDpkgWrapper(context)
|
||||
// ★ 顺手把源也重设一次。两个原因:
|
||||
// 1. 老设备上 bootstrap 自带的是俄罗斯源,国内连不上
|
||||
// 2. v2.0.20 之前只写了 sources.list,而 **pkg 不认那个文件** ——
|
||||
@@ -137,6 +193,9 @@ object TermuxInstaller {
|
||||
home(context).mkdirs()
|
||||
writeBashRc(context)
|
||||
|
||||
writeAptConf(context)
|
||||
fixBrokenSymlinks(context).let { trace(context, "修了 $it 个断链") }
|
||||
installDpkgWrapper(context)
|
||||
progress("正在改写写死的 com.termux 路径…")
|
||||
val fixed = rewritePrefixes(context)
|
||||
trace(context, "改写了 $fixed 个文件里的硬编码路径")
|
||||
@@ -411,6 +470,14 @@ object TermuxInstaller {
|
||||
File(prefix, "libexec/termux-am"),
|
||||
File(prefix, "etc"),
|
||||
File(prefix, "share"),
|
||||
// ★★ dpkg 装完包会把每个包的**安装脚本**放在这里
|
||||
// (xxx.postinst / xxx.prerm ...),它们的 shebang 也是
|
||||
// 按真 Termux 的包名写的。不改写的话装到配置阶段就报:
|
||||
// dpkg: unable to execute .../var/lib/dpkg/info/openssh.postinst:
|
||||
// No such file or directory
|
||||
// —— 看着像文件不存在,其实是 shebang 里的解释器找不到。
|
||||
File(prefix, "var/lib/dpkg/info"),
|
||||
File(prefix, "var/lib/dpkg/updates"),
|
||||
)
|
||||
for (dir in dirs) {
|
||||
// etc/ 往下还有子目录(dpkg、apt 的配置)
|
||||
@@ -475,6 +542,127 @@ object TermuxInstaller {
|
||||
"-i",
|
||||
)
|
||||
|
||||
/**
|
||||
* ★★ 写一份 `etc/apt/apt.conf`,把所有 `Dir::` 指到我们自己的 prefix。
|
||||
*
|
||||
* 为什么必须写:`apt` **二进制里编译死**了这些路径(都是真 Termux 的包名):
|
||||
*
|
||||
* Dir::Etc::parts = /data/data/com.termux/files/usr/etc/apt/apt.conf.d/
|
||||
* Dir::Etc::sourcelist = /data/data/com.termux/files/usr/etc/apt/sources.list
|
||||
* Dir::State = /data/data/com.termux/files/usr/var/lib/apt
|
||||
* …
|
||||
*
|
||||
* 读不到 `apt.conf.d` 它就直接罢工:
|
||||
*
|
||||
* W: Unable to read /data/data/com.termux/files/usr/etc/apt/apt.conf.d/
|
||||
* E: Unable to determine a suitable packaging system type
|
||||
*
|
||||
* —— `pkg update` 到此为止,什么都装不了。
|
||||
*
|
||||
* **`LD_PRELOAD=libtermux-exec.so` 也救不了**(实测带不带一模一样):
|
||||
* termux-exec 改写的是它认识的那些路径,apt 这套 `Dir::` 不在里面。
|
||||
*
|
||||
* 正路是 apt 自己的机制:环境变量 `APT_CONFIG` 指定主配置文件的**绝对路径**
|
||||
* (见 environment() 里那一项),apt 会先读它,里面重设 `Dir::` 就覆盖了
|
||||
* 编译死的默认值。
|
||||
*
|
||||
* ★ 有个坑:`APT_CONFIG` 指向的文件**必须存在**,否则 apt 只打个警告就
|
||||
* 回退到编译死的路径 —— 我第一版就是这样,白试了一轮。
|
||||
*/
|
||||
private fun writeAptConf(context: Context) {
|
||||
val prefix = prefix(context).absolutePath
|
||||
val conf = File(prefix, "etc/apt/apt.conf")
|
||||
conf.parentFile?.mkdirs()
|
||||
conf.writeText(
|
||||
"""
|
||||
// 由豆包 App 生成 —— 把 apt 的目录全部指到我们自己的 prefix。
|
||||
//
|
||||
// 不写这份文件的话,apt 会去 /data/data/com.termux/... (真 Termux 的包名)
|
||||
// 找 apt.conf.d,读不到就报 "Unable to determine a suitable packaging
|
||||
// system type" 然后拒绝工作。
|
||||
Dir::Etc::parts "$prefix/etc/apt/apt.conf.d";
|
||||
Dir::Etc::main "$prefix/etc/apt/apt.conf";
|
||||
Dir::Etc::sourcelist "$prefix/etc/apt/sources.list";
|
||||
Dir::Etc::sourceparts "$prefix/etc/apt/sources.list.d";
|
||||
Dir::Etc::preferences "$prefix/etc/apt/preferences";
|
||||
Dir::Etc::preferencesparts "$prefix/etc/apt/preferences.d";
|
||||
Dir::Etc::trusted "$prefix/etc/apt/trusted.gpg";
|
||||
Dir::Etc::trustedparts "$prefix/etc/apt/trusted.gpg.d";
|
||||
Dir::State "$prefix/var/lib/apt";
|
||||
Dir::State::status "$prefix/var/lib/dpkg/status";
|
||||
Dir::State::lists "$prefix/var/lib/apt/lists";
|
||||
Dir::Cache "$prefix/var/cache/apt";
|
||||
Dir::Cache::archives "$prefix/var/cache/apt/archives";
|
||||
// ★ `Dir::Bin::*` 也全是编译死的路径,一个都不能漏。
|
||||
// 漏了 methods 的话 apt 能读索引了,但一取包就报:
|
||||
// E: The method driver /data/data/com.termux/files/usr/lib/apt/methods/https
|
||||
// could not be found.
|
||||
Dir::Bin::methods "$prefix/lib/apt/methods";
|
||||
Dir::Bin::solvers "$prefix/lib/apt/solvers";
|
||||
Dir::Bin::dpkg "$prefix/bin/dpkg";
|
||||
// ★★ 验签用的那几个可执行文件,路径也是编译死的。
|
||||
//
|
||||
// 漏了 apt-key 的话 apt 能下载索引、能读证书,但一验签就报:
|
||||
// Err:1 ...: Couldn't execute
|
||||
// /data/data/com.termux/files/usr/bin/apt-key to check .../InRelease
|
||||
// E: The repository ... is not signed.
|
||||
// —— 看着像"源没签名",其实是找不到 apt-key 这个程序。
|
||||
Dir::Bin::apt-key "$prefix/bin/apt-key";
|
||||
Dir::Bin::gpg "$prefix/bin/gpg";
|
||||
Dir::Bin::gpgv "$prefix/bin/gpgv";
|
||||
Dir::Bin::apt-get "$prefix/bin/apt-get";
|
||||
Dir::Bin::apt-cache "$prefix/bin/apt-cache";
|
||||
Dir::Bin::apt-config "$prefix/bin/apt-config";
|
||||
DPkg::options:: "--force-confnew";
|
||||
// ★ dpkg 的**安装根**也是编译死的(= 真 Termux 的 prefix)。
|
||||
// 不指定的话它会去创建 /data/data/com.termux/... :
|
||||
// dpkg: error: creating directory './data/data/com.termux':
|
||||
// Permission denied
|
||||
DPkg::options:: "--instdir=$prefix";
|
||||
DPkg::options:: "--admindir=$prefix/var/lib/dpkg";
|
||||
// ★ Android 应用**不能 chroot**(没 CAP_SYS_CHROOT),
|
||||
// 而 dpkg 跑 maintainer script 时默认要 chroot 进去。
|
||||
// 不加这个开关的话包能装上,但配置阶段直接失败:
|
||||
// dpkg (subprocess): failed to chroot to ...: Operation not permitted
|
||||
// dpkg: error processing package openssh (--configure)
|
||||
// dpkg 为这种情况提供了 --force-script-chrootless。
|
||||
DPkg::options:: "--force-script-chrootless";
|
||||
|
||||
// ★★ apt 的 HTTPS 要单独告诉它证书在哪。
|
||||
//
|
||||
// `SSL_CERT_FILE` / `CURL_CA_BUNDLE` 管的是 **curl**;
|
||||
// apt 走自己的 https method(GnuTLS),不看那两个变量,
|
||||
// 只认 apt 自己的 `Acquire::https::CaInfo`。
|
||||
//
|
||||
// 不加这两行的话 apt 能读索引、能建依赖树,但一取包就报:
|
||||
// W: ...: No system certificates available. Try installing ca-certificates.
|
||||
// W: Failed to fetch ...: Certificate verification failed:
|
||||
// The certificate is NOT trusted. The certificate issuer is unknown.
|
||||
Acquire::https::CaInfo "$prefix/etc/tls/cert.pem";
|
||||
Acquire::https::Verify-Peer "true";
|
||||
Acquire::https::Verify-Host "true";
|
||||
// ★★ 临时目录也必须重设。
|
||||
//
|
||||
// 漏了它的话 apt 能下载索引,但验证签名时建不了临时文件:
|
||||
// Err:1 ...: Couldn't create temporary file
|
||||
// /data/data/com.termux/files/usr/tmp/apt.conf.XXXX for passing config to apt-key
|
||||
// E: The repository ... is not signed.
|
||||
// —— 看起来像签名问题,其实是临时目录路径错了。
|
||||
Dir::Temp "$prefix/tmp";
|
||||
Dir::Log "$prefix/var/log/apt";
|
||||
Dir::Log::Terminal "$prefix/var/log/apt/term.log";
|
||||
Dir::Log::History "$prefix/var/log/apt/history.log";
|
||||
Dir::Media::MountPath "$prefix/media";
|
||||
""".trimIndent() + "\n",
|
||||
Charsets.UTF_8,
|
||||
)
|
||||
// apt 要往这些目录写东西,先建好
|
||||
for (d in listOf("var/lib/apt/lists", "var/cache/apt/archives", "etc/apt/sources.list.d")) {
|
||||
File(prefix, d).mkdirs()
|
||||
}
|
||||
trace(context, "已写入 apt.conf(Dir:: 全指向 $prefix)")
|
||||
}
|
||||
|
||||
/** 装完之后给内核/工具用的环境变量(Termux 的标准一套) */
|
||||
fun environment(context: Context): Map<String, String> {
|
||||
val prefix = prefix(context).absolutePath
|
||||
@@ -485,7 +673,14 @@ object TermuxInstaller {
|
||||
"PREFIX" to prefix,
|
||||
"HOME" to home,
|
||||
"TMPDIR" to "$prefix/tmp",
|
||||
"PATH" to "$prefix/bin:$prefix/bin/applets:/system/bin:/system/xbin",
|
||||
// ★ PATH 里多带一条 /data/data/<包名>/files/usr/bin。
|
||||
//
|
||||
// dpkg 是 Termux 编译出来的,内部有一份"预期程序"清单
|
||||
// (sh / rm / tar / diff / dpkg-deb / start-stop-daemon),
|
||||
// 路径来自**编译时的 $PREFIX**。Android 上
|
||||
// /data/data/<包名> 是指向 /data/user/0/<包名> 的符号链接,
|
||||
// 所以这条路径真实存在 —— 多带一条,成本为零。
|
||||
"PATH" to "$prefix/bin:$prefix/bin/applets:$legacy/usr/bin:/system/bin:/system/xbin",
|
||||
/**
|
||||
* ★★ 证书路径 —— 不设这个,**所有 HTTPS 都连不上**。
|
||||
*
|
||||
@@ -522,6 +717,20 @@ object TermuxInstaller {
|
||||
* 那个文件的目录去找 `apt.conf.d/`,绕开编译死的路径。
|
||||
*/
|
||||
"APT_CONFIG" to "$prefix/etc/apt/apt.conf",
|
||||
/**
|
||||
* ★★ dpkg 的数据库目录也得告诉它。
|
||||
*
|
||||
* dpkg 二进制里编译死了 admindir(真 Termux 的包名),
|
||||
* 装包时直接拒绝:
|
||||
*
|
||||
* dpkg: error: cannot create the dpkg database directory
|
||||
* /data/data/com.termux/files/usr/var/lib/dpkg: Permission denied
|
||||
* E: Sub-process .../bin/dpkg returned an error code (2)
|
||||
*
|
||||
* —— 包都下载完了,卡在最后一步,很冤。
|
||||
* dpkg 认 DPKG_ADMINDIR 这个环境变量,指过去就行。
|
||||
*/
|
||||
"DPKG_ADMINDIR" to "$prefix/var/lib/dpkg",
|
||||
"LD_LIBRARY_PATH" to "$prefix/lib",
|
||||
// ★ 这个 LD_PRELOAD 是 Termux 能在 Android 上正常跑命令的关键:
|
||||
// 它把二进制里写死的 /data/data/com.termux/files/usr 重写到我们自己的 prefix。
|
||||
@@ -551,4 +760,116 @@ object TermuxInstaller {
|
||||
"TERMUX_MAIN_PACKAGE_FORMAT" to "debian",
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* ★★ 修**断掉的符号链接**(链接目标和路径改写无关,得单独处理)。
|
||||
*
|
||||
* bootstrap 的 SYMLINKS.txt 里有一部分链接是**绝对路径**,指向真 Termux 的包名:
|
||||
*
|
||||
* etc/apt/trusted.gpg.d/termux-autobuilds.gpg
|
||||
* -> /data/data/com.termux/files/usr/share/termux-keyring/termux-autobuilds.gpg
|
||||
*
|
||||
* 我们建出来就是**断链**。apt 读钥匙串时找不到公钥:
|
||||
*
|
||||
* Err:1 ...: The following signatures could not be verified because
|
||||
* the public key is not available: NO_PUBKEY 5A897D96E57CF20C
|
||||
* E: The repository ... is not signed.
|
||||
*
|
||||
* rewritePrefixes 救不了 —— 它改的是**文件内容**,链接目标存在 inode 里。
|
||||
* 这里扫一遍:凡是「软链 + 当前是断的 + 目标含 com.termux」的,
|
||||
* 把目标里的包名换成我们的,重建链接。
|
||||
*/
|
||||
private fun fixBrokenSymlinks(context: Context): Int {
|
||||
val prefix = prefix(context)
|
||||
val oldPkg = "/data/data/com.termux"
|
||||
val newPkg = context.applicationInfo.dataDir
|
||||
var fixed = 0
|
||||
val all = try {
|
||||
prefix.walkTopDown().toList()
|
||||
} catch (t: Throwable) {
|
||||
trace(context, "遍历 prefix 失败:${t.message}")
|
||||
return 0
|
||||
}
|
||||
for (entry in all) {
|
||||
val path = entry.toPath()
|
||||
val isLink = try {
|
||||
java.nio.file.Files.isSymbolicLink(path)
|
||||
} catch (_: Throwable) {
|
||||
false
|
||||
}
|
||||
if (!isLink) continue
|
||||
if (entry.exists()) continue // 还好的链接不动
|
||||
val target = try {
|
||||
java.nio.file.Files.readSymbolicLink(path).toString()
|
||||
} catch (_: Throwable) {
|
||||
continue
|
||||
}
|
||||
if (!target.contains(oldPkg)) continue
|
||||
val newTarget = target.replace(oldPkg, newPkg)
|
||||
try {
|
||||
entry.delete()
|
||||
java.nio.file.Files.createSymbolicLink(
|
||||
entry.toPath(), java.io.File(newTarget).toPath(),
|
||||
)
|
||||
fixed += 1
|
||||
} catch (t: Throwable) {
|
||||
trace(context, "修链接失败 ${entry.name}:${t.message}")
|
||||
}
|
||||
}
|
||||
return fixed
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ★★ 给 `$PREFIX/bin/dpkg` 套一层 wrapper。
|
||||
*
|
||||
* 为什么需要:`apt` 调 `dpkg` 时给的是**清洗过的环境** ——
|
||||
* 实测直接跑 dpkg 一切正常,apt 一调就报:
|
||||
*
|
||||
* dpkg: warning: 'sh' not found in PATH or not executable
|
||||
* dpkg: error: 6 expected programs not found in PATH or not executable
|
||||
*
|
||||
* 那 6 个程序都在、PATH 也对 —— 因为 PATH 根本没传进 dpkg。
|
||||
* apt 怎么派生 dpkg 我们控制不了,但**可以控制 dpkg 这个入口**:
|
||||
* 把原来的 dpkg 改名成 dpkg.real,原地放一个脚本,谁来调都先补齐环境。
|
||||
*
|
||||
* 顺带把 `--instdir` / `--admindir` 也带上(dpkg 的安装根同样是
|
||||
* 编译死的,不指定它会去创建 /data/data/com.termux/... 然后失败)。
|
||||
*/
|
||||
private fun installDpkgWrapper(context: Context) {
|
||||
val prefix = prefix(context).absolutePath
|
||||
val real = File(prefix, "bin/dpkg.real")
|
||||
val wrapper = File(prefix, "bin/dpkg")
|
||||
// 已经包过就别再包一层
|
||||
if (real.exists()) return
|
||||
if (!wrapper.exists()) {
|
||||
trace(context, "没有 bin/dpkg,跳过 wrapper")
|
||||
return
|
||||
}
|
||||
try {
|
||||
if (!wrapper.renameTo(real)) {
|
||||
trace(context, "dpkg 改名失败,跳过 wrapper")
|
||||
return
|
||||
}
|
||||
wrapper.writeText(
|
||||
"#!/data/user/0/" + context.packageName + "/files/usr/bin/sh\n" +
|
||||
"# 由豆包 App 生成:补全环境再调真正的 dpkg。\n" +
|
||||
"# apt 派生子进程时会清洗环境,PATH 传不进来,这里补上。\n" +
|
||||
"P=" + prefix + "\n" +
|
||||
"export PATH=\$P/bin:\$P/bin/applets:/system/bin:/system/xbin\n" +
|
||||
"export LD_LIBRARY_PATH=\$P/lib\n" +
|
||||
"export TMPDIR=\$P/tmp\n" +
|
||||
"export DPKG_ADMINDIR=\$P/var/lib/dpkg\n" +
|
||||
"export TERMUX__PREFIX=\$P\n" +
|
||||
"exec \$P/bin/dpkg.real --instdir=\$P --admindir=\$P/var/lib/dpkg --force-script-chrootless \"\$@\"\n",
|
||||
Charsets.UTF_8,
|
||||
)
|
||||
wrapper.setExecutable(true, false)
|
||||
real.setExecutable(true, false)
|
||||
trace(context, "已给 dpkg 套上 wrapper")
|
||||
} catch (t: Throwable) {
|
||||
trace(context, "套 wrapper 失败:${t.message}")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,23 +33,23 @@ object TermuxMirror {
|
||||
*/
|
||||
val MIRRORS = listOf(
|
||||
Mirror(
|
||||
"tuna", "清华 TUNA", "https://mirrors.tuna.tsinghua.edu.cn/termux",
|
||||
"tuna", "清华 TUNA", "http://mirrors.tuna.tsinghua.edu.cn/termux",
|
||||
"国内最快最稳的一个,推荐",
|
||||
),
|
||||
Mirror(
|
||||
"ustc", "中科大 USTC", "https://mirrors.ustc.edu.cn/termux",
|
||||
"ustc", "中科大 USTC", "http://mirrors.ustc.edu.cn/termux",
|
||||
"同样完整同步,教育网更快",
|
||||
),
|
||||
Mirror(
|
||||
"aliyun", "阿里云", "https://mirrors.aliyun.com/termux",
|
||||
"aliyun", "阿里云", "http://mirrors.aliyun.com/termux",
|
||||
"公网覆盖好,偶尔缺 science 仓库",
|
||||
),
|
||||
Mirror(
|
||||
"bfsu", "北外 BFSU", "https://mirrors.bfsu.edu.cn/termux",
|
||||
"bfsu", "北外 BFSU", "http://mirrors.bfsu.edu.cn/termux",
|
||||
"清华的备份站",
|
||||
),
|
||||
Mirror(
|
||||
"official", "官方源", "https://packages.termux.dev/apt",
|
||||
"official", "官方源", "http://packages.termux.dev/apt",
|
||||
"国内经常连不上,镜像挂了才用它",
|
||||
),
|
||||
)
|
||||
|
||||
@@ -82,6 +82,21 @@ fun TerminalScreen(
|
||||
// 换了起法之后新会话**永远接不上** —— 表现是"屏幕停在旧会话的
|
||||
// [Process completed],打字没反应"。(真踩到了:修语法时把 key() 去掉,订阅也丢了。)
|
||||
val tickNow = sessionTick
|
||||
|
||||
/**
|
||||
* 重置 Termux 环境。
|
||||
*
|
||||
* ★ 为什么需要:装坏了自己救不回来。dpkg 的数据库和真实文件一旦不一致
|
||||
* (比如在修好 apt 路径之前试着装过包),后面 `pkg install` 会一直报
|
||||
* `E: Internal Error, No file name for ...` 或 `1 not fully installed or removed`,
|
||||
* **用户在界面上没有任何办法恢复**,只能清 App 数据 —— 那会把会议、设置、
|
||||
* 自定义节点全丢掉。有了这个,重置的代价只是"重下一次运行环境"。
|
||||
*
|
||||
* 删的是 `files/usr` + `files/home`;**不碰** kernel-data 和 nodes。
|
||||
*/
|
||||
var showResetConfirm by remember { mutableStateOf(false) }
|
||||
var resetting by remember { mutableStateOf(false) }
|
||||
var resetMsg by remember { mutableStateOf("") }
|
||||
val onSessionExit = {
|
||||
val quick = startedAt > 0 && System.currentTimeMillis() - startedAt < 900
|
||||
if (quick) {
|
||||
@@ -129,6 +144,47 @@ fun TerminalScreen(
|
||||
TextButton(onClick = { showMirror = true }) {
|
||||
Text("源", color = Color(0xFF9BE7B4), fontSize = 13.sp)
|
||||
}
|
||||
// 重置环境:装坏了(dpkg 数据库和文件不一致)时的唯一自救入口。
|
||||
// 放在换源旁边 —— 出问题时这两个是最先要点的。
|
||||
TextButton(onClick = { showResetConfirm = true }) {
|
||||
Text("重置", color = Color(0xFFFFB4A9), fontSize = 13.sp)
|
||||
}
|
||||
|
||||
// ---------------- 重置确认 + 进度 ----------------
|
||||
if (showResetConfirm) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { showResetConfirm = false },
|
||||
title = { Text("重置 Termux 环境?") },
|
||||
text = {
|
||||
Text(
|
||||
"会把内置运行环境(约 95MB)删掉重新解压。\n\n" +
|
||||
"什么时候需要:pkg install 报 Internal Error、\n" +
|
||||
"not fully installed,或者终端起不来又查不出原因。\n\n" +
|
||||
"**会议、设置、智能体、自定义节点都不会动**," +
|
||||
"只有装在 Termux 里的包(python 之类)会没。",
|
||||
fontSize = 13.sp,
|
||||
lineHeight = 19.sp,
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
showResetConfirm = false
|
||||
resetting = true
|
||||
resetMsg = "正在准备…"
|
||||
Thread {
|
||||
val ok = TermuxInstaller.reset(context) { msg ->
|
||||
resetMsg = msg
|
||||
}
|
||||
resetting = false
|
||||
resetMsg = if (ok) "重置完成,重新打开终端即可" else "重置失败,看看 termux-install.log"
|
||||
}.start()
|
||||
}) { Text("重置", color = Color(0xFFD93025)) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { showResetConfirm = false }) { Text("取消") }
|
||||
},
|
||||
)
|
||||
}
|
||||
IconButton(onClick = {
|
||||
// 发一个 Ctrl+C,终止前台进程(手机上没键盘,这是最常用的逃生键)
|
||||
terminal.session?.write("\u0003".toByteArray(), 0, 1)
|
||||
|
||||
Reference in New Issue
Block a user