Skip to content

Commit 28ca844

Browse files
changed(scripts|main/termux-tools): Use TERMUX_APP_PACKAGE_MANAGER instead of TERMUX_MAIN_PACKAGE_FORMAT
Make changes as per new design implemented in termux/termux-app@b950efec and termux/termux-app#2740 The package build and termux-tools scripts use current package manager for custom logic. The `termux-tools/termux-setup-package-manager` script has been added that will now be used to provide backward compatibility for termux-app `< 0.119.0` (when its released) and validate the package manager. It will also ensure the variable in not unset to prevent `unbound variable` errors if `set -u` is being used by calling scripts. Closes #10782
1 parent 82f2127 commit 28ca844

File tree

5 files changed

+52
-19
lines changed

5 files changed

+52
-19
lines changed

packages/termux-tools/build.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ termux_step_make_install() {
4040
for script in chsh dalvikvm login pkg su termux-fix-shebang termux-backup \
4141
termux-info termux-open termux-open-url termux-reload-settings \
4242
termux-reset termux-restore termux-setup-storage termux-wake-lock \
43-
termux-wake-unlock termux-change-repo; do
43+
termux-wake-unlock termux-change-repo termux-setup-package-manager; do
4444
install -Dm700 $TERMUX_PKG_BUILDER_DIR/$script $TERMUX_PREFIX/bin/$script
4545
sed -i -e "s%\@TERMUX_APP_PACKAGE\@%${TERMUX_APP_PACKAGE}%g" \
4646
-e "s%\@TERMUX_BASE_DIR\@%${TERMUX_BASE_DIR}%g" \
@@ -49,6 +49,7 @@ termux_step_make_install() {
4949
-e "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" \
5050
-e "s%\@PACKAGE_VERSION\@%${TERMUX_PKG_VERSION}%g" \
5151
-e "s%\@TERMUX_PACKAGE_FORMAT\@%${TERMUX_PACKAGE_FORMAT}%g" \
52+
-e "s%\@TERMUX_PACKAGE_MANAGER\@%${TERMUX_PACKAGE_MANAGER}%g" \
5253
$TERMUX_PREFIX/bin/$script
5354
done
5455

packages/termux-tools/login

+8-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ else
2323
done
2424
fi
2525

26-
# for the correct operation of scripts that work with the package manager
27-
export TERMUX_MAIN_PACKAGE_FORMAT="@TERMUX_PACKAGE_FORMAT@"
26+
# TERMUX_APP_PACKAGE_MANAGER should be exported by termux-app v0.119.0+ itself
27+
if [ -z "${TERMUX_APP_PACKAGE_MANAGER-}" ]; then
28+
if { [ -n "$(command -v dpkg)" ] && dpkg --compare-versions "$TERMUX_VERSION" lt 0.119.0; } || # apt
29+
{ [ -n "$(command -v vercmp)" ] && [ "$(vercmp "$TERMUX_VERSION" 0.119.0)" = "-1" ]; }; then # pacman
30+
# For the correct operation of scripts that work with the package manager
31+
export TERMUX_MAIN_PACKAGE_FORMAT="@TERMUX_PACKAGE_FORMAT@"
32+
fi
33+
fi
2834

2935
if [ -f @TERMUX_PREFIX@/lib/libtermux-exec.so ]; then
3036
export LD_PRELOAD=@TERMUX_PREFIX@/lib/libtermux-exec.so

packages/termux-tools/pkg

+9-6
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
set -eu
33

44
declare -A commands_pkg=(
5-
["debian"]="dpkg -L|apt show|select_mirror; update_apt_cache; apt install|apt autoclean|apt clean|apt list|apt list --installed|apt install --reinstall|select_mirror; update_apt_cache; apt search|apt remove|select_mirror; apt update; apt full-upgrade"
5+
["apt"]="dpkg -L|apt show|select_mirror; update_apt_cache; apt install|apt autoclean|apt clean|apt list|apt list --installed|apt install --reinstall|select_mirror; update_apt_cache; apt search|apt remove|select_mirror; apt update; apt full-upgrade"
66
["pacman"]="pacman -Ql|pacman -Qi|pacman -Sy --needed|pacman -Sc|pacman -Scc|pacman -Sl|pacman -Q|pacman -S|pacman -Sys|pacman -Rcns|pacman -Syu"
77
)
88

9+
# Setup TERMUX_APP_PACKAGE_MANAGER
10+
source "@TERMUX_PREFIX@/bin/termux-setup-package-manager" || exit 1
11+
912
show_help() {
1013
local cache_size
1114
local cache_dir=""
12-
if [ "$TERMUX_MAIN_PACKAGE_FORMAT" = "debian" ]; then
15+
if [ "$TERMUX_APP_PACKAGE_MANAGER" = "apt" ]; then
1316
cache_dir="@TERMUX_CACHE_DIR@/apt/archives"
14-
elif [ "$TERMUX_MAIN_PACKAGE_FORMAT" = "pacman" ]; then
17+
elif [ "$TERMUX_APP_PACKAGE_MANAGER" = "pacman" ]; then
1518
cache_dir="@TERMUX_PREFIX@/var/cache/pacman/pkg"
1619
fi
1720
cache_size=$(du -sh "$cache_dir" 2>/dev/null | cut -f1)
@@ -194,9 +197,9 @@ if [ $# = 0 ]; then
194197
show_help
195198
fi
196199

197-
case "$TERMUX_MAIN_PACKAGE_FORMAT" in
198-
debian|pacman) IFS="|" pkg_cmd=(${commands_pkg["$TERMUX_MAIN_PACKAGE_FORMAT"]});;
199-
*) echo "Error: pkg is not supported with '$TERMUX_MAIN_PACKAGE_FORMAT' package manager format"; exit 1;;
200+
case "${TERMUX_APP_PACKAGE_MANAGER-}" in
201+
apt|pacman) IFS="|" pkg_cmd=(${commands_pkg["$TERMUX_APP_PACKAGE_MANAGER"]});;
202+
*) echo "Error: pkg is not supported with '${TERMUX_APP_PACKAGE_MANAGER-}' package manager"; exit 1;;
200203
esac
201204

202205
CMD="$1"

packages/termux-tools/termux-info

+13-10
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ updates() {
1212
if [ "$(id -u)" = "0" ]; then
1313
echo "Running as root. Cannot check package updates."
1414
else
15-
if [ "$TERMUX_MAIN_PACKAGE_FORMAT" = "pacman" ]; then
16-
pacman -Sy >/dev/null 2>&1
17-
updatable=$(pacman -Qu)
18-
else
15+
if [ "$TERMUX_APP_PACKAGE_MANAGER" = "apt" ]; then
1916
apt update >/dev/null 2>&1
2017
updatable=$(apt list --upgradable 2>/dev/null | tail -n +2)
18+
elif [ "$TERMUX_APP_PACKAGE_MANAGER" = "pacman" ]; then
19+
pacman -Sy >/dev/null 2>&1
20+
updatable=$(pacman -Qu)
2121
fi
2222

2323
if [ -z "$updatable" ];then
@@ -69,6 +69,9 @@ repo_subscriptions_pacman() {
6969
fi
7070
}
7171

72+
# Setup TERMUX_APP_PACKAGE_MANAGER
73+
source "@TERMUX_PREFIX@/bin/termux-setup-package-manager" || exit 1
74+
7275
output=""
7376

7477
if [ -n "$TERMUX_VERSION" ]; then
@@ -84,18 +87,18 @@ fi
8487
8588
output+="Packages CPU architecture:
8689
$(
87-
if [ "$TERMUX_MAIN_PACKAGE_FORMAT" = "pacman" ]; then
88-
pacman-conf | grep Architecture | sed 's/Architecture = //g'
89-
else
90+
if [ "$TERMUX_APP_PACKAGE_MANAGER" = "apt" ]; then
9091
dpkg --print-architecture
92+
elif [ "$TERMUX_APP_PACKAGE_MANAGER" = "pacman" ]; then
93+
pacman-conf | grep Architecture | sed 's/Architecture = //g'
9194
fi
9295
)
9396
Subscribed repositories:
9497
$(
95-
if [ "$TERMUX_MAIN_PACKAGE_FORMAT" = "pacman" ]; then
96-
repo_subscriptions_pacman
97-
else
98+
if [ "$TERMUX_APP_PACKAGE_MANAGER" = "apt" ]; then
9899
repo_subscriptions_apt
100+
elif [ "$TERMUX_APP_PACKAGE_MANAGER" = "pacman" ]; then
101+
repo_subscriptions_pacman
99102
fi
100103
)
101104
Updatable packages:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
# TERMUX_APP_PACKAGE_MANAGER should be exported by termux-app v0.119.0+
4+
# itself and should contain "apt" or "pacman".
5+
# TERMUX_MAIN_PACKAGE_FORMAT should be exported by login script in
6+
# termux-tools v0.161+ if termux-app version is less than 0.119.0 and
7+
# should contain "debian" or "pacman".
8+
if [ -z "${TERMUX_APP_PACKAGE_MANAGER-}" ]; then
9+
if [ -n "${TERMUX_MAIN_PACKAGE_FORMAT-}" ]; then
10+
TERMUX_APP_PACKAGE_MANAGER="$([ "${TERMUX_MAIN_PACKAGE_FORMAT-}" = "debian" ] && echo "apt" || echo "${TERMUX_MAIN_PACKAGE_FORMAT-}")"
11+
else
12+
TERMUX_APP_PACKAGE_MANAGER="@TERMUX_PACKAGE_MANAGER@"
13+
fi
14+
fi
15+
16+
case "${TERMUX_APP_PACKAGE_MANAGER-}" in
17+
apt|pacman) :;;
18+
*) echo "Unsupported package manager \"${TERMUX_APP_PACKAGE_MANAGER-}\". Only 'apt' and 'pacman' managers are supported" 1>&2; exit 1;;
19+
esac
20+
export TERMUX_APP_PACKAGE_MANAGER

0 commit comments

Comments
 (0)