Skip to content

Getting termux-tools ready for apt 3.0.0 #165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chore(scripts/pkg): support deb822 sources format
  • Loading branch information
TomJo2000 committed Apr 24, 2025
commit 8caa6829cc5feea2a211653fcea956923705a389
55 changes: 33 additions & 22 deletions scripts/pkg.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if [[ "$(id -u)" == "0" ]]; then
fi

# Setup TERMUX_APP_PACKAGE_MANAGER
# shellcheck source=/dev/null
source "@TERMUX_PREFIX@/bin/termux-setup-package-manager" || exit 1

MIRROR_BASE_DIR="@TERMUX_PREFIX@/etc/termux/mirrors"
Expand Down Expand Up @@ -112,10 +113,10 @@ has_repo() {
# Check if root-repo or x11-repo are installed
repo="$1"

if [ -f "@TERMUX_PREFIX@/etc/apt/sources.list.d/$repo.list" ]; then
echo true
else
echo false
if [[ -f "@TERMUX_PREFIX@/etc/apt/sources.list.d/$repo.sources" ]]; then
echo deb822
elif [[ -f "@TERMUX_PREFIX@/etc/apt/sources.list.d/$repo.list" ]]; then
echo legacy
fi
}

Expand All @@ -132,6 +133,7 @@ get_mirror_url() {
local -r _has_repo_root="$3"

unset_mirror_variables
# shellcheck source=/dev/null
source "$_mirror"

if [[ -z "${MAIN:-}" ]]; then
Expand Down Expand Up @@ -339,24 +341,33 @@ select_mirror() {
selected_mirror="${weighted_mirrors[${random_weight}]}"
fi

if [ -n "$selected_mirror" ]; then
(
unset_mirror_variables
source "$selected_mirror"
echo "deb $MAIN stable main" > @TERMUX_PREFIX@/etc/apt/sources.list
if [[ "$has_repo_x11" == "true" ]]; then
echo "deb $X11 x11 main" > @TERMUX_PREFIX@/etc/apt/sources.list.d/x11.list
fi
if [[ "$has_repo_root" == "true" ]]; then
echo "deb $ROOT root stable" > @TERMUX_PREFIX@/etc/apt/sources.list.d/root.list
fi
)
else
[[ -z "$selected_mirror" ]] && {
# Should not happen unless there is some issue with
# the script, or the mirror files
echo "Error: None of the mirrors are accessible"
exit 1
fi
}

(
unset_mirror_variables
# shellcheck source=/dev/null
source "$selected_mirror"

case "$(has_repo main)" in
'deb822') sed -ni -e "s|URIs:.*|URIs: $MAIN|" "@TERMUX_PREFIX@/etc/apt/sources.list.d/main.sources";;
'legacy') echo "deb $MAIN stable main" > @TERMUX_PREFIX@/etc/apt/sources.list;;
esac

case "${has_repo_x11:-}" in
'deb822') sed -ni -e "s|URIs:.*|URIs: $X11|" "@TERMUX_PREFIX@/etc/apt/sources.list.d/x11.sources";;
'legacy') echo "deb $X11 x11 main" > @TERMUX_PREFIX@/etc/apt/sources.list.d/x11.list;;
esac

case "${has_repo_root:-}" in
'deb822') sed -ni -e "s|URIs:.*|URIs: $ROOT|" "@TERMUX_PREFIX@/etc/apt/sources.list.d/root.sources";;
'legacy') echo "deb $ROOT root stable" > @TERMUX_PREFIX@/etc/apt/sources.list.d/root.list;;
esac
)
}

update_apt_cache() {
Expand Down Expand Up @@ -394,8 +405,8 @@ update_apt_cache() {

force_check_mirror=false
if [ "${1-}" = "--check-mirror" ]; then
force_check_mirror=true
shift 1
force_check_mirror=true
shift 1
fi

if [[ $# = 0 || $(echo "$1" | grep "^h") ]]; then
Expand All @@ -419,7 +430,7 @@ case "$TERMUX_APP_PACKAGE_MANAGER" in
rei*) apt install --reinstall "$@";;
se*) select_mirror; update_apt_cache; apt search "$@";;
un*|rem*|rm|del*) apt remove "$@";;
upd*) select_mirror; apt update;;
upd*) select_mirror; apt update;;
up|upg*) select_mirror; apt update; apt full-upgrade "$@";;
*) ERROR=true;;
esac;;
Expand All @@ -435,7 +446,7 @@ case "$TERMUX_APP_PACKAGE_MANAGER" in
rei*) pacman -S "$@";;
se*) pacman -Sys "$@";;
un*|rem*|rm|del*) pacman -Rcns "$@";;
upd*) pacman -Sy "$@";;
upd*) pacman -Sy "$@";;
up|upg*) pacman -Syu "$@";;
*) ERROR=true;;
esac;;
Expand Down