release v2.0.23:生成 apt.conf 重设全部 Dir::/Acquire::https(apt 一路撞出来的编译死路径)
This commit is contained in:
@@ -30,8 +30,8 @@ android {
|
||||
* versionCode 每次发版 +1(Android 靠它判断"能不能覆盖安装",
|
||||
* 改小了会装不上)。
|
||||
*/
|
||||
versionCode = 222
|
||||
versionName = "2.0.22"
|
||||
versionCode = 223
|
||||
versionName = "2.0.23"
|
||||
|
||||
ndk {
|
||||
// Chaquopy 只支持这两个;Termux bootstrap 也只准备了这两份
|
||||
|
||||
@@ -48,7 +48,7 @@ object TermuxInstaller {
|
||||
* 把戳的值带上版本号,**对不上就只重跑修正式步骤**(不重新解压,
|
||||
* 解压要几十秒)。以后再加这类"装完之后要修一下"的逻辑,把这里 +1。
|
||||
*/
|
||||
private const val STAMP_VALUE = "ok:7"
|
||||
private const val STAMP_VALUE = "ok:12"
|
||||
|
||||
/**
|
||||
* 安装日志。
|
||||
@@ -88,6 +88,10 @@ 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)
|
||||
// ★ 顺手把源也重设一次。两个原因:
|
||||
// 1. 老设备上 bootstrap 自带的是俄罗斯源,国内连不上
|
||||
// 2. v2.0.20 之前只写了 sources.list,而 **pkg 不认那个文件** ——
|
||||
@@ -137,6 +141,7 @@ object TermuxInstaller {
|
||||
home(context).mkdirs()
|
||||
writeBashRc(context)
|
||||
|
||||
writeAptConf(context)
|
||||
progress("正在改写写死的 com.termux 路径…")
|
||||
val fixed = rewritePrefixes(context)
|
||||
trace(context, "改写了 $fixed 个文件里的硬编码路径")
|
||||
@@ -475,6 +480,100 @@ 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";
|
||||
DPkg::options:: "--force-confnew";
|
||||
// ★★ 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
|
||||
|
||||
@@ -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",
|
||||
"国内经常连不上,镜像挂了才用它",
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user