From 9415f719294c6622be02558c94681c08d57073ec Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Tue, 24 Mar 2020 07:14:42 +0100 Subject: [PATCH] termux-tools: add termux-change-repo script (#5069) * termux-tools: add termux-change-repo script Simplifies changing repositories to a mirror, useful when Bintray downloads hit the roof * *-repo: add etc/apt/sources.list.d/* to TERMUX_PKG_CONFFILES --- packages/game-repo/build.sh | 3 +- packages/root-repo/build.sh | 3 +- packages/science-repo/build.sh | 3 +- packages/termux-tools/build.sh | 6 +- packages/termux-tools/termux-change-repo | 125 +++++++++++++++++++++++ packages/unstable-repo/build.sh | 3 +- packages/x11-repo/build.sh | 3 +- 7 files changed, 138 insertions(+), 8 deletions(-) create mode 100644 packages/termux-tools/termux-change-repo diff --git a/packages/game-repo/build.sh b/packages/game-repo/build.sh index 0909d45a9..01b114a9e 100644 --- a/packages/game-repo/build.sh +++ b/packages/game-repo/build.sh @@ -2,10 +2,11 @@ TERMUX_PKG_HOMEPAGE=https://github.com/termux/game-packages TERMUX_PKG_DESCRIPTION="Package repository containing games for termux" TERMUX_PKG_LICENSE="Apache-2.0" TERMUX_PKG_MAINTAINER="Henrik Grimler @Grimler91" -TERMUX_PKG_VERSION=1.1 +TERMUX_PKG_VERSION=1.2 TERMUX_PKG_DEPENDS="termux-keyring" TERMUX_PKG_SKIP_SRC_EXTRACT=true TERMUX_PKG_PLATFORM_INDEPENDENT=true +TERMUX_PKG_CONFFILES="etc/apt/sources.list.d/game.list" termux_step_make_install() { mkdir -p $TERMUX_PREFIX/etc/apt/sources.list.d diff --git a/packages/root-repo/build.sh b/packages/root-repo/build.sh index 2e9dffee3..8208e14fc 100644 --- a/packages/root-repo/build.sh +++ b/packages/root-repo/build.sh @@ -2,10 +2,11 @@ TERMUX_PKG_HOMEPAGE=https://github.com/termux/termux-root-packages TERMUX_PKG_DESCRIPTION="Package repository containing programs for rooted devices" TERMUX_PKG_LICENSE="Apache-2.0" TERMUX_PKG_MAINTAINER="Henrik Grimler @Grimler91" -TERMUX_PKG_VERSION=1.5 +TERMUX_PKG_VERSION=1.6 TERMUX_PKG_DEPENDS="termux-keyring" TERMUX_PKG_SKIP_SRC_EXTRACT=true TERMUX_PKG_PLATFORM_INDEPENDENT=true +TERMUX_PKG_CONFFILES="etc/apt/sources.list.d/root.list" termux_step_make_install() { mkdir -p $TERMUX_PREFIX/etc/apt/sources.list.d diff --git a/packages/science-repo/build.sh b/packages/science-repo/build.sh index 03fe7cf34..69868641a 100644 --- a/packages/science-repo/build.sh +++ b/packages/science-repo/build.sh @@ -2,10 +2,11 @@ TERMUX_PKG_HOMEPAGE=https://github.com/termux/science-packages TERMUX_PKG_DESCRIPTION="Package repository containing science software" TERMUX_PKG_LICENSE="Apache-2.0" TERMUX_PKG_MAINTAINER="Henrik Grimler @Grimler91" -TERMUX_PKG_VERSION=1.0 +TERMUX_PKG_VERSION=1.1 TERMUX_PKG_DEPENDS="termux-keyring" TERMUX_PKG_SKIP_SRC_EXTRACT=true TERMUX_PKG_PLATFORM_INDEPENDENT=true +TERMUX_PKG_CONFFILES="etc/apt/sources.list.d/science.list" termux_step_make_install() { mkdir -p $TERMUX_PREFIX/etc/apt/sources.list.d diff --git a/packages/termux-tools/build.sh b/packages/termux-tools/build.sh index a1ec47c8e..6d9a231bb 100644 --- a/packages/termux-tools/build.sh +++ b/packages/termux-tools/build.sh @@ -1,7 +1,7 @@ TERMUX_PKG_HOMEPAGE=https://termux.com/ TERMUX_PKG_DESCRIPTION="Basic system tools for Termux" TERMUX_PKG_LICENSE="GPL-3.0" -TERMUX_PKG_VERSION=0.74 +TERMUX_PKG_VERSION=0.75 TERMUX_PKG_SKIP_SRC_EXTRACT=true TERMUX_PKG_PLATFORM_INDEPENDENT=true TERMUX_PKG_ESSENTIAL=true @@ -12,7 +12,7 @@ TERMUX_PKG_CONFFILES="etc/motd" # Some of these packages are not dependencies and used only to ensure # that core packages are installed after upgrading (we removed busybox # from essentials). -TERMUX_PKG_DEPENDS="bzip2, coreutils, curl, dash, diffutils, findutils, gawk, grep, gzip, less, procps, psmisc, sed, tar, termux-am, termux-exec, xz-utils" +TERMUX_PKG_DEPENDS="bzip2, coreutils, curl, dash, diffutils, findutils, gawk, grep, gzip, less, procps, psmisc, sed, tar, termux-am, termux-exec, xz-utils, dialog" # Optional packages that are distributed as part of bootstrap archives. TERMUX_PKG_RECOMMENDS="ed, dos2unix, inetutils, net-tools, patch, unzip, util-linux" @@ -34,7 +34,7 @@ termux_step_make_install() { for script in chsh dalvikvm login pkg su termux-fix-shebang termux-info \ termux-open termux-open-url termux-reload-settings termux-setup-storage \ - termux-wake-lock termux-wake-unlock; do + termux-wake-lock termux-wake-unlock termux-change-repo; do install -Dm700 $TERMUX_PKG_BUILDER_DIR/$script $TERMUX_PREFIX/bin/$script perl -p -i -e "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" $TERMUX_PREFIX/bin/$script done diff --git a/packages/termux-tools/termux-change-repo b/packages/termux-tools/termux-change-repo new file mode 100644 index 000000000..317c1d534 --- /dev/null +++ b/packages/termux-tools/termux-change-repo @@ -0,0 +1,125 @@ +#!@TERMUX_PREFIX@/bin/bash + +if [ "$1" == "--help" ] || [ "$1" == "-help" ]; then + echo "Script for redirecting subscribed repositories to mirrors." + echo "You can choose between mirrors listed at" + echo "https://github.com/termux/termux-packages/wiki/Mirrors" + exit 0 +fi + +select_repository() { + if [ "$1" == "Official repositories" ]; then + echo "[*] Official repositories selected" + MAIN="https://termux.org/packages/" + ROOT="https://dl.bintray.com/grimler/termux-root-packages-24" + GAME="https://dl.bintray.com/grimler/game-packages-24" + SCIENCE="https://dl.bintray.com/grimler/science-packages-24" + UNSTABLE="https://dl.bintray.com/xeffyr/unstable-packages" + X11="https://dl.bintray.com/xeffyr/unstable-packages" + + elif [ "$1" == "Mirrors by Xeffyr" ]; then + echo "[*] Xeffyr's mirrors selected" + MAIN="https://main.termux-mirror.ml" + GAME="https://games.termux-mirror.ml" + ROOT="https://root.termux-mirror.ml" + SCIENCE="https://science.termux-mirror.ml" + UNSTABLE="https://unstable.termux-mirror.ml" + X11="https://x11.termux-mirror.ml" + + elif [ "$1" == "Mirrors by Grimler" ]; then + echo "[*] Grimler's mirrors selected" + MAIN="https://grimler.se/termux-packages-24" + GAME="https://grimler.se/game-packages-24" + ROOT="https://grimler.se/termux-root-packages-24" + SCIENCE="https://grimler.se/science-packages-24" + UNSTABLE="https://grimler.se/unstable-packages" + X11="https://grimler.se/x11-packages" + + elif [ "$1" == "Mirrors by Tsinghua University" ]; then + echo "[*] Tsinghua's mirrors selected" + MAIN="https://mirrors.tuna.tsinghua.edu.cn/termux/termux-packages-24/" + GAME="https://mirrors.tuna.tsinghua.edu.cn/termux/game-packages-24/" + ROOT="https://mirrors.tuna.tsinghua.edu.cn/termux/termux-root-packages-24/" + SCIENCE="https://mirrors.tuna.tsinghua.edu.cn/termux/science-packages-24/" + UNSTABLE="https://mirrors.tuna.tsinghua.edu.cn/termux/unstable-packages/" + X11="https://mirrors.tuna.tsinghua.edu.cn/termux/x11-packages" + + else + echo "[!] Error: unknown repository: '$1'. Exiting" + exit 1 + fi + + replace_repository sources.list $MAIN "stable main" "$2" "Main repository" + replace_repository sources.list.d/game.list $GAME "games stable" "$2" "Game repository" + replace_repository sources.list.d/root.list $ROOT "root stable" "$2" "Root repository" + replace_repository sources.list.d/science.list $SCIENCE "science stable" "$2" "Science repository" + replace_repository sources.list.d/unstable.list $UNSTABLE "unstable stable" "$2" "Unstable repository" + replace_repository sources.list.d/x11.list $X11 "x11 stable" "$2" "X11 repository" +} + +replace_repository() { + if [[ "$4" == *"$5"* ]]; then + SOURCE_FILE="$1" + NEW_URL="$2" + COMPONENT_SUITE="$3" + + TMPFILE="$(mktemp $TMPDIR/$(basename ${SOURCE_FILE}).XXXXXX)" + if [ "$1" == "sources.list" ]; then + echo "# The main termux repository:" >> "$TMPFILE" + fi + echo "deb ${NEW_URL} ${COMPONENT_SUITE}" >> "$TMPFILE" + echo " Changing ${5,,}" #${,,} converts to lower case + mv "$TMPFILE" "$PREFIX/etc/apt/${SOURCE_FILE}" + fi +} + +TEMPFILE="$(mktemp $PREFIX/tmp/mirror.XXXXXX)" + +REPOSITORIES=() +REPOSITORIES+=("Main repository" "termux-packages" "on") +if [ -f "$PREFIX/etc/apt/sources.list.d/game.list" ]; then + REPOSITORIES+=("Game repository" "game-packages" "off") +fi +if [ -f "$PREFIX/etc/apt/sources.list.d/root.list" ]; then + REPOSITORIES+=("Root repository" "termux-root-packages" "off") +fi +if [ -f "$PREFIX/etc/apt/sources.list.d/science.list" ]; then + REPOSITORIES+=("Science repository" "science-packages" "off") +fi +if [ -f "$PREFIX/etc/apt/sources.list.d/unstable.list" ]; then + REPOSITORIES+=("Unstable repository" "unstable-packages" "off") +fi +if [ -f "$PREFIX/etc/apt/sources.list.d/x11.list" ]; then + REPOSITORIES+=("X11 repository" "x11-packages" "off") +fi + +dialog \ + --title "termux-change-repo" --clear \ + --checklist "Which repositories do you want to edit? Select with space." 0 0 0 \ + "${REPOSITORIES[@]}" --and-widget \ + --title "termux-change-repo" --clear \ + --radiolist "Which mirror do you want to use?" 0 0 0 \ + "Official repositories" "Hosted on Bintray" on \ + "Mirrors by Xeffyr" "Hosted on termux-mirror.ml" off \ + "Mirrors by Grimler" "Hosted on grimler.se" off \ + "Mirrors by Tsinghua University" "Hosted on mirrors.tuna.tsinghua.edu.cn" off \ + 2> "$TEMPFILE" +retval=$? +clear + +case $retval in + 0) + IFS=$'\t' read REPOSITORIES MIRROR <<< "$(more $TEMPFILE)" + select_repository "$MIRROR" "$REPOSITORIES" + ;; + 1) + # Cancel pressed + exit + ;; + 255) + # Esc pressed + exit + ;; +esac + +rm "$TEMPFILE" diff --git a/packages/unstable-repo/build.sh b/packages/unstable-repo/build.sh index dd2d2c1d3..eaff82d6e 100644 --- a/packages/unstable-repo/build.sh +++ b/packages/unstable-repo/build.sh @@ -2,10 +2,11 @@ TERMUX_PKG_HOMEPAGE=https://github.com/termux/unstable-packages TERMUX_PKG_DESCRIPTION="Package repository containing new/unstable programs and libraries." TERMUX_PKG_LICENSE="Apache-2.0" TERMUX_PKG_MAINTAINER="Leonid Plyushch " -TERMUX_PKG_VERSION=3.0 +TERMUX_PKG_VERSION=4.0 TERMUX_PKG_DEPENDS="termux-keyring" TERMUX_PKG_SKIP_SRC_EXTRACT=true TERMUX_PKG_PLATFORM_INDEPENDENT=true +TERMUX_PKG_CONFFILES="etc/apt/sources.list.d/unstable.list" termux_step_make_install() { mkdir -p $TERMUX_PREFIX/etc/apt/sources.list.d diff --git a/packages/x11-repo/build.sh b/packages/x11-repo/build.sh index dc5a70f7d..f3e316cbf 100644 --- a/packages/x11-repo/build.sh +++ b/packages/x11-repo/build.sh @@ -2,10 +2,11 @@ TERMUX_PKG_HOMEPAGE=https://github.com/termux/x11-packages TERMUX_PKG_DESCRIPTION="Package repository containing X11 programs and libraries" TERMUX_PKG_LICENSE="Apache-2.0" TERMUX_PKG_MAINTAINER="Leonid Plyushch " -TERMUX_PKG_VERSION=3.0 +TERMUX_PKG_VERSION=4.0 TERMUX_PKG_DEPENDS="termux-keyring" TERMUX_PKG_SKIP_SRC_EXTRACT=true TERMUX_PKG_PLATFORM_INDEPENDENT=true +TERMUX_PKG_CONFFILES="etc/apt/sources.list.d/x11.list" termux_step_make_install() { mkdir -p $TERMUX_PREFIX/etc/apt/sources.list.d