From 7e3a3f5260f9f30857f91eec1869c60846f3be54 Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Sat, 12 Jul 2025 11:03:08 +0800 Subject: [PATCH] Add `Termux` bootstrapper --- bootstrap/README.md | 2 +- bootstrap/Termux.bash | 55 ++++++++++++++++++++++++++++++++++++++ src/recipe/os/APT/Termux.c | 26 +++++++++--------- 3 files changed, 70 insertions(+), 13 deletions(-) create mode 100644 bootstrap/Termux.bash diff --git a/bootstrap/README.md b/bootstrap/README.md index 619617d..1c7bd84 100644 --- a/bootstrap/README.md +++ b/bootstrap/README.md @@ -30,7 +30,7 @@ end ## `chsrc-bootstrap` to the Rescue -`chsrc-bootstrap` 是一组使用原生脚本语言的脚本,用来完成两件事情: +`chsrc-bootstrap` 是一组使用原生脚本语言的脚本,每个脚本称为 `bootstrapper`,用来完成两件事情: 1. 帮助用户进行最基本的换源,让用户能够立即开始使用该系统安装其他软件 diff --git a/bootstrap/Termux.bash b/bootstrap/Termux.bash new file mode 100644 index 0000000..384a352 --- /dev/null +++ b/bootstrap/Termux.bash @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +# --------------------------------------------------------------- +# File Name : Termux.bash +# File Authors : Aoran Zeng +# Contributors : Nul None +# Created On : <2025-07-12> +# Last Modified : <2025-07-12> +# +# Termux: +# +# Bootstrap Termux: https://github.com/RubyMetric/chsrc/issues/173 +# +# @consult https://help.mirrors.cernet.edu.cn/termux/ +# +# 我们默认采用校园网联合镜像站提供的源 +# --------------------------------------------------------------- + +bs_echo() { + echo "[chsrc-bootstrap] $*" +} + +if command -v termux-change-repo &>/dev/null; then + termux-change-repo +else + # HELP: $PREFIX 有值吗? 是 "/data/data/com.termux/files/usr" 吗? + # 必要的 + sed -i 's@^\(deb.*stable main\)$@#\1\ndeb https://mirrors.cernet.edu.cn/termux/apt/termux-main stable main@' $PREFIX/etc/apt/sources.list + apt update + + # x11-repo + sed -i 's@^\(deb.*x11 main\)$@#\1\ndeb https://mirrors.cernet.edu.cn/termux/apt/termux-x11 x11 main @' $PREFIX/etc/apt/sources.list.d/x11.list + + # root-repo + sed -i 's@^\(deb.*root main\)$@#\1\ndeb https://mirrors.cernet.edu.cn/termux/apt/termux-root root main @' $PREFIX/etc/apt/sources.list.d/root.list +fi + +# 立即更新测试换源状态 +apt update && apt upgrade + +bs_echo "基础换源已完成" + +read -p "是否需要安装 chsrc ? (y/n): " need_install_chsrc + +if [[ $need_install_chsrc == "y" || $need_install_chsrc == "Y" ]]; then + bs_echo "正在安装依赖项..." + apt-get install -y gcc make git + git clone https://gitee.com/RubyMetric/chsrc.git --depth 1 + bs_echo "依赖安装完成!" + + bs_echo "正在开始编译和安装" + cd chsrc + make build-in-release-mode + make install + bs_echo "chsrc 安装完成!" +fi diff --git a/src/recipe/os/APT/Termux.c b/src/recipe/os/APT/Termux.c index f3985d6..d0a7b19 100644 --- a/src/recipe/os/APT/Termux.c +++ b/src/recipe/os/APT/Termux.c @@ -5,6 +5,8 @@ * Contributors : Nul None * Created On : <2025-03-04> * Last Modified : <2025-03-04> + * + * 该 recipe 存在对应的 bootstrapper * ------------------------------------------------------------*/ /** @@ -13,18 +15,18 @@ static Source_t os_termux_sources[] = { {&UpstreamProvider, NULL}, - {&Ustc, "https://mirrors.ustc.edu.cn/termux/"}, - {&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn/termux/"}, - {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/termux/"}, - {&Bfsu, "https://mirrors.bfsu.edu.cn/termux/"}, - {&Pku, "https://mirrors.pku.edu.cn/termux/"}, - {&Nyist, "https://mirror.nyist.edu.cn/termux/"}, - {&Nju, "https://mirror.nju.edu.cn/termux/"}, - {&Sustech, "https://mirrors.sustech.edu.cn/termux/"}, - {&Iscas, "https://mirror.iscas.ac.cn/termux/"}, - {&Zju, "https://mirrors.zju.edu.cn/termux/"}, - {&Sdu, "https://mirrors.sdu.edu.cn/termux/"}, - {&Cqupt, "https://mirrors.cqupt.edu.cn/termux/"} + {&Ustc, "https://mirrors.ustc.edu.cn/termux/", NULL}, + {&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn/termux/", NULL}, + {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/termux/", NULL}, + {&Bfsu, "https://mirrors.bfsu.edu.cn/termux/", NULL}, + {&Pku, "https://mirrors.pku.edu.cn/termux/", NULL}, + {&Nyist, "https://mirror.nyist.edu.cn/termux/", NULL}, + {&Nju, "https://mirror.nju.edu.cn/termux/", NULL}, + {&Sustech, "https://mirrors.sustech.edu.cn/termux/", NULL}, + {&Iscas, "https://mirror.iscas.ac.cn/termux/", NULL}, + {&Zju, "https://mirrors.zju.edu.cn/termux/", NULL}, + {&Sdu, "https://mirrors.sdu.edu.cn/termux/", NULL}, + {&Cqupt, "https://mirrors.cqupt.edu.cn/termux/", NULL} }; def_sources_n(os_termux);