From e2fd640045e53d38097999ddde7122558771f238 Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Tue, 4 Mar 2025 05:16:41 +0800 Subject: [PATCH] Support `Termux` [GitHub #173] --- src/chsrc-main.c | 1 + src/recipe/menu.c | 3 +- src/recipe/os/APT/Termux.c | 103 +++++++++++++++++++++++++++++++++++ src/recipe/os/APT/Trisquel.c | 4 +- src/recipe/os/APT/common.h | 3 + 5 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 src/recipe/os/APT/Termux.c diff --git a/src/chsrc-main.c b/src/chsrc-main.c index d7f96c5..2666e50 100644 --- a/src/chsrc-main.c +++ b/src/chsrc-main.c @@ -89,6 +89,7 @@ #include "recipe/os/APT/Armbian.c" // Independent #include "recipe/os/APT/ROS.c" +#include "recipe/os/APT/Termux.c" #include "recipe/os/APT/openKylin.c" #include "recipe/os/APT/deepin.c" diff --git a/src/recipe/menu.c b/src/recipe/menu.c index 1285368..3194dbb 100644 --- a/src/recipe/menu.c +++ b/src/recipe/menu.c @@ -90,6 +90,7 @@ static const char *os_raspberrypi[] = {"raspi", "raspberrypi",NULL, t(&os_raspberrypi_target)}, *os_armbian [] = {"armbian", NULL, t(&os_armbian_target)}, *os_openwrt [] = {"openwrt", "opkg", "LEDE", NULL, t(&os_openwrt_target)}, +*os_termux [] = {"termux", NULL, t(&os_termux_target)}, *os_openkylin [] = {"openkylin", NULL, t(&os_openkylin_target)}, *os_openeuler [] = {"openeuler", NULL, t(&os_openeuler_target)}, @@ -103,7 +104,7 @@ static const char **os_systems[] = { os_debian, os_ubuntu, os_linuxmint, os_kali, - os_trisquel, os_linuxlite, os_raspberrypi, os_armbian, os_openwrt, + os_trisquel, os_linuxlite, os_raspberrypi, os_armbian, os_openwrt, os_termux, os_deepin, os_openkylin, os_ros, os_fedora, os_rockylinux, os_almalinux, os_openeuler, os_anolis, diff --git a/src/recipe/os/APT/Termux.c b/src/recipe/os/APT/Termux.c new file mode 100644 index 0000000..cfe1b29 --- /dev/null +++ b/src/recipe/os/APT/Termux.c @@ -0,0 +1,103 @@ +/** ------------------------------------------------------------ + * SPDX-License-Identifier: GPL-3.0-or-later + * ------------------------------------------------------------- + * File Authors : Aoran Zeng + * Contributors : Nul None + * Created On : <2025-03-04> + * Last Modified : <2025-03-04> + * ------------------------------------------------------------*/ + +/** + * @update 2025-03-04 + */ +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/"} + +}; +def_sources_n(os_termux); + + +/** + * chsrc get termux + */ +void +os_termux_getsrc (char *option) +{ + chsrc_view_file (OS_Termux_SourceList); +} + + +/** + * @consult https://help.mirrors.cernet.edu.cn/termux/ + * + * chsrc set termux + */ +void +os_termux_setsrc (char *option) +{ + + // chsrc_ensure_root (); Termux下禁止使用root + + chsrc_yield_source_and_confirm (os_termux); + + char *cmd = xy_strjoin (3, "sed -i 's@^\\(deb.*stable main\\)$@#\\1\\ndeb ", + source.url, "apt/termux-main stable main@' " OS_Termux_SourceList); + + chsrc_run (cmd, RunOpt_Default); + + chsrc_run ("apt update", RunOpt_Default); + chsrc_run ("apt upgrade", RunOpt_Default); + + ProgMode_ChgType = ChgType_Auto; + chsrc_conclude (&source); +} + + +/** + * chsrc reset termux + * + * 暂时缺乏原地址 + */ +void +os_termux_resetsrc (char *option) +{ + os_termux_setsrc (option); +} + + +/** + * chsrc ls termux + */ +Feature_t +os_termux_feat (char *option) +{ + Feature_t f = {0}; + + f.can_get = true; + f.can_reset = false; + + f.cap_locally = CanNot; + f.cap_locally_explain = NULL; + + f.can_english = false; + f.can_user_define = false; + + f.note = NULL; + return f; +} + + +def_target_gsf(os_termux); diff --git a/src/recipe/os/APT/Trisquel.c b/src/recipe/os/APT/Trisquel.c index e6bdba6..5214e33 100644 --- a/src/recipe/os/APT/Trisquel.c +++ b/src/recipe/os/APT/Trisquel.c @@ -30,8 +30,9 @@ os_trisquel_getsrc (char *option) chsrc_view_file (OS_Apt_SourceList); } + /** - * 参考: https://help.mirrors.cernet.edu.cn/trisquel/ + * @consult: https://help.mirrors.cernet.edu.cn/trisquel/ */ void os_trisquel_setsrc (char *option) @@ -51,4 +52,5 @@ os_trisquel_setsrc (char *option) chsrc_conclude (&source); } + def_target(os_trisquel); diff --git a/src/recipe/os/APT/common.h b/src/recipe/os/APT/common.h index 28aa8e7..3b487ed 100644 --- a/src/recipe/os/APT/common.h +++ b/src/recipe/os/APT/common.h @@ -30,6 +30,9 @@ // independent #define OS_ROS_SourceList OS_Apt_SourceList_D "ros-latest.list" +#define OS_Termux_SourceList "/data/data/com.termux/files/usr" OS_Apt_SourceList + + // Ubuntu based #define OS_LinuxMint_SourceList OS_Apt_SourceList_D "official-package-repositories.list"