203 lines
8.6 KiB
Bash
Executable File
203 lines
8.6 KiB
Bash
Executable File
#!@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" == "Default repositories" ]; then
|
|
echo "[*] Termux primary host (USA) selected"
|
|
MAIN="https://packages.termux.org/apt/termux-main"
|
|
GAME="https://packages.termux.org/apt/termux-games"
|
|
ROOT="https://packages.termux.org/apt/termux-root"
|
|
SCIENCE="https://packages.termux.org/apt/termux-science"
|
|
X11="https://packages.termux.org/apt/termux-x11"
|
|
|
|
elif [ "$1" == "Default repositories (CF)" ]; then
|
|
echo "[*] Termux primary host (worldwide) selected"
|
|
MAIN="https://packages-cf.termux.org/apt/termux-main"
|
|
GAME="https://packages-cf.termux.org/apt/termux-games"
|
|
ROOT="https://packages-cf.termux.org/apt/termux-root"
|
|
SCIENCE="https://packages-cf.termux.org/apt/termux-science"
|
|
X11="https://packages-cf.termux.org/apt/termux-x11"
|
|
|
|
elif [ "$1" == "GH Mirrors by Kcubeterm" ]; then
|
|
echo "[*] GH mirrors selected"
|
|
MAIN="https://deb.kcubeterm.me/termux-main"
|
|
GAME="https://deb.kcubeterm.me/termux-games"
|
|
ROOT="https://deb.kcubeterm.me/termux-root"
|
|
SCIENCE="https://deb.kcubeterm.me/termux-science"
|
|
X11="https://deb.kcubeterm.me/termux-x11"
|
|
|
|
elif [ "$1" == "Mirrors by A1batross" ]; then
|
|
echo "[*] A1batross mirrors selected"
|
|
MAIN="https://termux.mentality.rip/termux-main"
|
|
GAME="https://termux.mentality.rip/termux-games"
|
|
ROOT="https://termux.mentality.rip/termux-root"
|
|
SCIENCE="https://termux.mentality.rip/termux-science"
|
|
X11="https://termux.mentality.rip/termux-x11"
|
|
|
|
elif [ "$1" == "Mirrors by Astra ISP" ]; then
|
|
echo "[*] Astra ISP (UA) mirrors selected"
|
|
MAIN="https://termux.astra.in.ua/apt/termux-main"
|
|
GAME="https://termux.astra.in.ua/apt/termux-games"
|
|
ROOT="https://termux.astra.in.ua/apt/termux-root"
|
|
SCIENCE="https://termux.astra.in.ua/apt/termux-science"
|
|
X11="https://termux.astra.in.ua/apt/termux-x11"
|
|
|
|
elif [ "$1" == "Mirrors by Bardia Moshiri" ]; then
|
|
echo "[*] Bardia Moshiri (Iran) mirrors selected"
|
|
MAIN="https://mirror.bardia.tech/termux/termux-packages-24/"
|
|
GAME="https://mirror.bardia.tech/termux/game-packages-24/"
|
|
ROOT="https://mirror.bardia.tech/termux/termux-root-packages-24/"
|
|
SCIENCE="https://mirror.bardia.tech/termux/science-packages-24/"
|
|
X11="https://mirror.bardia.tech/termux/x11-packages/"
|
|
|
|
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"
|
|
X11="https://grimler.se/x11-packages"
|
|
|
|
elif [ "$1" == "Mirrors by Kcubeterm" ]; then
|
|
echo "[*] Kcubeterm's mirrors selected"
|
|
MAIN="https://dl.kcubeterm.me/termux-packages-24"
|
|
GAME="https://dl.kcubeterm.me/game-packages-24"
|
|
ROOT="https://dl.kcubeterm.me/termux-root-packages-24"
|
|
SCIENCE="https://dl.kcubeterm.me/science-packages-24"
|
|
X11="https://dl.kcubeterm.me/x11-packages"
|
|
|
|
elif [ "$1" == "Mirrors by Librehat" ]; then
|
|
echo "[*] Librehat's mirrors selected"
|
|
MAIN="https://termux.librehat.com/apt/termux-main"
|
|
GAME="https://termux.librehat.com/apt/termux-games"
|
|
ROOT="https://termux.librehat.com/apt/termux-root"
|
|
SCIENCE="https://termux.librehat.com/apt/termux-science"
|
|
X11="https://termux.librehat.com/apt/termux-x11"
|
|
|
|
elif [ "$1" == "Mirrors by Tsinghua University" ]; then
|
|
echo "[*] Tsinghua's (CN) mirrors selected"
|
|
MAIN="https://mirrors.tuna.tsinghua.edu.cn/termux/apt/termux-main"
|
|
GAME="https://mirrors.tuna.tsinghua.edu.cn/termux/apt/termux-games"
|
|
ROOT="https://mirrors.tuna.tsinghua.edu.cn/termux/apt/termux-root"
|
|
SCIENCE="https://mirrors.tuna.tsinghua.edu.cn/termux/apt/termux-science"
|
|
X11="https://mirrors.tuna.tsinghua.edu.cn/termux/apt/termux-x11"
|
|
|
|
elif [ "$1" == "Mirrors by BFSU" ]; then
|
|
echo "[*] BFSU (CN) mirrors selected"
|
|
MAIN="https://mirrors.bfsu.edu.cn/termux/apt/termux-main"
|
|
GAME="https://mirrors.bfsu.edu.cn/termux/apt/termux-games"
|
|
ROOT="https://mirrors.bfsu.edu.cn/termux/apt/termux-root"
|
|
SCIENCE="https://mirrors.bfsu.edu.cn/termux/apt/termux-science"
|
|
X11="https://mirrors.bfsu.edu.cn/termux/apt/termux-x11"
|
|
|
|
elif [ "$1" == "Mirrors by NJU" ]; then
|
|
echo "[*] NJU (CN) mirrors selected"
|
|
MAIN="https://mirror.nju.edu.cn/termux/apt/termux-main"
|
|
GAME="https://mirror.nju.edu.cn/termux/apt/termux-games"
|
|
ROOT="https://mirror.nju.edu.cn/termux/apt/termux-root"
|
|
SCIENCE="https://mirror.nju.edu.cn/termux/apt/termux-science"
|
|
X11="https://mirror.nju.edu.cn/termux/apt/termux-x11"
|
|
|
|
elif [ "$1" == "Mirrors by USTC" ]; then
|
|
echo "[*] USTC (CN) mirrors selected"
|
|
MAIN="https://mirrors.ustc.edu.cn/termux/apt/termux-main"
|
|
GAME="https://mirrors.ustc.edu.cn/termux/apt/termux-games"
|
|
ROOT="https://mirrors.ustc.edu.cn/termux/apt/termux-root"
|
|
SCIENCE="https://mirrors.ustc.edu.cn/termux/apt/termux-science"
|
|
X11="https://mirrors.ustc.edu.cn/termux/apt/termux-x11"
|
|
|
|
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/x11.list $X11 "x11 main" "$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" "@TERMUX_PREFIX@/etc/apt/${SOURCE_FILE}"
|
|
fi
|
|
}
|
|
|
|
TEMPFILE="$(mktemp @TERMUX_PREFIX@/tmp/mirror.XXXXXX)"
|
|
|
|
REPOSITORIES=()
|
|
REPOSITORIES+=("Main repository" "termux-packages" "on")
|
|
if [ -f "@TERMUX_PREFIX@/etc/apt/sources.list.d/game.list" ]; then
|
|
REPOSITORIES+=("Game repository" "game-packages" "off")
|
|
fi
|
|
if [ -f "@TERMUX_PREFIX@/etc/apt/sources.list.d/root.list" ]; then
|
|
REPOSITORIES+=("Root repository" "termux-root-packages" "off")
|
|
fi
|
|
if [ -f "@TERMUX_PREFIX@/etc/apt/sources.list.d/science.list" ]; then
|
|
REPOSITORIES+=("Science repository" "science-packages" "off")
|
|
fi
|
|
if [ -f "@TERMUX_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 \
|
|
"Default repositories" "Default host" on \
|
|
"Default repositories (CF)" "Default host with CloudFlare endpoint" on \
|
|
"GH Mirrors by Kcubeterm" "Hosted on Github Release" off \
|
|
"Mirrors by A1batross" "Hosted on termux.mentality.rip" off \
|
|
"Mirrors by Astra ISP" "Hosted on termux.astra.in.ua" off \
|
|
"Mirrors by Bardia Moshiri" "Hosted on mirror.bardia.tech" off \
|
|
"Mirrors by Grimler" "Hosted on grimler.se" off \
|
|
"Mirrors by Kcubeterm" "Hosted on dl.kcubeterm.me" off \
|
|
"Mirrors by Librehat" "Hosted on termux.librehat.com" off \
|
|
"Mirrors by Tsinghua University" "Hosted on mirrors.tuna.tsinghua.edu.cn" off \
|
|
"Mirrors by BFSU" "Hosted on mirrors.bfsu.edu.cn" off \
|
|
"Mirrors by NJU" "Hosted on mirror.nju.edu.cn" off \
|
|
"Mirrors by USTC" "Hosted on mirrors.ustc.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"
|
|
|
|
echo "[*] Running apt update"
|
|
apt update
|