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
This commit is contained in:
agnostic-apollo 2022-05-22 23:00:24 +05:00
parent ee224d779e
commit 0275d9bff3
20 changed files with 105 additions and 53 deletions

View File

@ -313,10 +313,13 @@ source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_finish_build.sh"
. "$TERMUX_SCRIPTDIR/scripts/properties.sh" . "$TERMUX_SCRIPTDIR/scripts/properties.sh"
if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then
# Setup TERMUX_APP_PACKAGE_MANAGER
source "$TERMUX_PREFIX/bin/termux-setup-package-manager"
# For on device builds cross compiling is not supported. # For on device builds cross compiling is not supported.
# Target architecture must be same as for environment used currently. # Target architecture must be same as for environment used currently.
case "$TERMUX_MAIN_PACKAGE_FORMAT" in case "$TERMUX_APP_PACKAGE_MANAGER" in
"debian") TERMUX_ARCH=$(dpkg --print-architecture);; "apt") TERMUX_ARCH=$(dpkg --print-architecture);;
"pacman") TERMUX_ARCH=$(pacman-conf | grep Architecture | sed 's/Architecture = //g');; "pacman") TERMUX_ARCH=$(pacman-conf | grep Architecture | sed 's/Architecture = //g');;
esac esac
export TERMUX_ARCH export TERMUX_ARCH
@ -360,11 +363,7 @@ while (($# >= 1)); do
if [ -z "$1" ]; then if [ -z "$1" ]; then
termux_error_exit "./build-package.sh: argument to '--format' should not be empty" termux_error_exit "./build-package.sh: argument to '--format' should not be empty"
fi fi
TERMUX_PACKAGE_FORMAT="$1"
case "$1" in
debian|pacman) TERMUX_PACKAGE_FORMAT="$1";;
*) termux_error_exit "./build-package.sh: only 'debian' and 'pacman' formats are supported";;
esac
else else
termux_error_exit "./build-package.sh: option '--format' requires an argument" termux_error_exit "./build-package.sh: option '--format' requires an argument"
fi fi
@ -416,6 +415,13 @@ while (($# >= 1)); do
done done
unset -f _show_usage unset -f _show_usage
if [ -n "${TERMUX_PACKAGE_FORMAT-}" ]; then
case "${TERMUX_PACKAGE_FORMAT-}" in
debian|pacman) :;;
*) termux_error_exit "Unsupported package format \"${TERMUX_PACKAGE_FORMAT-}\". Only 'debian' and 'pacman' formats are supported";;
esac
fi
if [ "${TERMUX_INSTALL_DEPS-false}" = "true" ]; then if [ "${TERMUX_INSTALL_DEPS-false}" = "true" ]; then
# Setup PGP keys for verifying integrity of dependencies. # Setup PGP keys for verifying integrity of dependencies.
# Keys are obtained from our keyring package. # Keys are obtained from our keyring package.

View File

@ -40,7 +40,7 @@ termux_step_make_install() {
for script in chsh dalvikvm login pkg su termux-fix-shebang termux-backup \ for script in chsh dalvikvm login pkg su termux-fix-shebang termux-backup \
termux-info termux-open termux-open-url termux-reload-settings \ termux-info termux-open termux-open-url termux-reload-settings \
termux-reset termux-restore termux-setup-storage termux-wake-lock \ termux-reset termux-restore termux-setup-storage termux-wake-lock \
termux-wake-unlock termux-change-repo; do termux-wake-unlock termux-change-repo termux-setup-package-manager; do
install -Dm700 $TERMUX_PKG_BUILDER_DIR/$script $TERMUX_PREFIX/bin/$script install -Dm700 $TERMUX_PKG_BUILDER_DIR/$script $TERMUX_PREFIX/bin/$script
sed -i -e "s%\@TERMUX_APP_PACKAGE\@%${TERMUX_APP_PACKAGE}%g" \ sed -i -e "s%\@TERMUX_APP_PACKAGE\@%${TERMUX_APP_PACKAGE}%g" \
-e "s%\@TERMUX_BASE_DIR\@%${TERMUX_BASE_DIR}%g" \ -e "s%\@TERMUX_BASE_DIR\@%${TERMUX_BASE_DIR}%g" \
@ -49,6 +49,7 @@ termux_step_make_install() {
-e "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" \ -e "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" \
-e "s%\@PACKAGE_VERSION\@%${TERMUX_PKG_VERSION}%g" \ -e "s%\@PACKAGE_VERSION\@%${TERMUX_PKG_VERSION}%g" \
-e "s%\@TERMUX_PACKAGE_FORMAT\@%${TERMUX_PACKAGE_FORMAT}%g" \ -e "s%\@TERMUX_PACKAGE_FORMAT\@%${TERMUX_PACKAGE_FORMAT}%g" \
-e "s%\@TERMUX_PACKAGE_MANAGER\@%${TERMUX_PACKAGE_MANAGER}%g" \
$TERMUX_PREFIX/bin/$script $TERMUX_PREFIX/bin/$script
done done

View File

@ -23,8 +23,14 @@ else
done done
fi fi
# for the correct operation of scripts that work with the package manager # TERMUX_APP_PACKAGE_MANAGER should be exported by termux-app v0.119.0+ itself
export TERMUX_MAIN_PACKAGE_FORMAT="@TERMUX_PACKAGE_FORMAT@" if [ -z "${TERMUX_APP_PACKAGE_MANAGER-}" ]; then
if { [ -n "$(command -v dpkg)" ] && dpkg --compare-versions "$TERMUX_VERSION" lt 0.119.0; } || # apt
{ [ -n "$(command -v vercmp)" ] && [ "$(vercmp "$TERMUX_VERSION" 0.119.0)" = "-1" ]; }; then # pacman
# For the correct operation of scripts that work with the package manager
export TERMUX_MAIN_PACKAGE_FORMAT="@TERMUX_PACKAGE_FORMAT@"
fi
fi
if [ -f @TERMUX_PREFIX@/lib/libtermux-exec.so ]; then if [ -f @TERMUX_PREFIX@/lib/libtermux-exec.so ]; then
export LD_PRELOAD=@TERMUX_PREFIX@/lib/libtermux-exec.so export LD_PRELOAD=@TERMUX_PREFIX@/lib/libtermux-exec.so

View File

@ -2,16 +2,19 @@
set -eu set -eu
declare -A commands_pkg=( declare -A commands_pkg=(
["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" ["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"
["pacman"]="pacman -Ql|pacman -Qi|pacman -Sy --needed|pacman -Sc|pacman -Scc|pacman -Sl|pacman -Q|pacman -S|pacman -Sys|pacman -Rcns|pacman -Syu" ["pacman"]="pacman -Ql|pacman -Qi|pacman -Sy --needed|pacman -Sc|pacman -Scc|pacman -Sl|pacman -Q|pacman -S|pacman -Sys|pacman -Rcns|pacman -Syu"
) )
# Setup TERMUX_APP_PACKAGE_MANAGER
source "@TERMUX_PREFIX@/bin/termux-setup-package-manager" || exit 1
show_help() { show_help() {
local cache_size local cache_size
local cache_dir="" local cache_dir=""
if [ "$TERMUX_MAIN_PACKAGE_FORMAT" = "debian" ]; then if [ "$TERMUX_APP_PACKAGE_MANAGER" = "apt" ]; then
cache_dir="@TERMUX_CACHE_DIR@/apt/archives" cache_dir="@TERMUX_CACHE_DIR@/apt/archives"
elif [ "$TERMUX_MAIN_PACKAGE_FORMAT" = "pacman" ]; then elif [ "$TERMUX_APP_PACKAGE_MANAGER" = "pacman" ]; then
cache_dir="@TERMUX_PREFIX@/var/cache/pacman/pkg" cache_dir="@TERMUX_PREFIX@/var/cache/pacman/pkg"
fi fi
cache_size=$(du -sh "$cache_dir" 2>/dev/null | cut -f1) cache_size=$(du -sh "$cache_dir" 2>/dev/null | cut -f1)
@ -194,9 +197,9 @@ if [ $# = 0 ]; then
show_help show_help
fi fi
case "$TERMUX_MAIN_PACKAGE_FORMAT" in case "${TERMUX_APP_PACKAGE_MANAGER-}" in
debian|pacman) IFS="|" pkg_cmd=(${commands_pkg["$TERMUX_MAIN_PACKAGE_FORMAT"]});; apt|pacman) IFS="|" pkg_cmd=(${commands_pkg["$TERMUX_APP_PACKAGE_MANAGER"]});;
*) echo "Error: pkg is not supported with '$TERMUX_MAIN_PACKAGE_FORMAT' package manager format"; exit 1;; *) echo "Error: pkg is not supported with '${TERMUX_APP_PACKAGE_MANAGER-}' package manager"; exit 1;;
esac esac
CMD="$1" CMD="$1"

View File

@ -12,12 +12,12 @@ updates() {
if [ "$(id -u)" = "0" ]; then if [ "$(id -u)" = "0" ]; then
echo "Running as root. Cannot check package updates." echo "Running as root. Cannot check package updates."
else else
if [ "$TERMUX_MAIN_PACKAGE_FORMAT" = "pacman" ]; then if [ "$TERMUX_APP_PACKAGE_MANAGER" = "apt" ]; then
pacman -Sy >/dev/null 2>&1
updatable=$(pacman -Qu)
else
apt update >/dev/null 2>&1 apt update >/dev/null 2>&1
updatable=$(apt list --upgradable 2>/dev/null | tail -n +2) updatable=$(apt list --upgradable 2>/dev/null | tail -n +2)
elif [ "$TERMUX_APP_PACKAGE_MANAGER" = "pacman" ]; then
pacman -Sy >/dev/null 2>&1
updatable=$(pacman -Qu)
fi fi
if [ -z "$updatable" ];then if [ -z "$updatable" ];then
@ -69,6 +69,9 @@ repo_subscriptions_pacman() {
fi fi
} }
# Setup TERMUX_APP_PACKAGE_MANAGER
source "@TERMUX_PREFIX@/bin/termux-setup-package-manager" || exit 1
output="" output=""
if [ -n "$TERMUX_VERSION" ]; then if [ -n "$TERMUX_VERSION" ]; then
@ -84,18 +87,18 @@ fi
output+="Packages CPU architecture: output+="Packages CPU architecture:
$( $(
if [ "$TERMUX_MAIN_PACKAGE_FORMAT" = "pacman" ]; then if [ "$TERMUX_APP_PACKAGE_MANAGER" = "apt" ]; then
pacman-conf | grep Architecture | sed 's/Architecture = //g'
else
dpkg --print-architecture dpkg --print-architecture
elif [ "$TERMUX_APP_PACKAGE_MANAGER" = "pacman" ]; then
pacman-conf | grep Architecture | sed 's/Architecture = //g'
fi fi
) )
Subscribed repositories: Subscribed repositories:
$( $(
if [ "$TERMUX_MAIN_PACKAGE_FORMAT" = "pacman" ]; then if [ "$TERMUX_APP_PACKAGE_MANAGER" = "apt" ]; then
repo_subscriptions_pacman
else
repo_subscriptions_apt repo_subscriptions_apt
elif [ "$TERMUX_APP_PACKAGE_MANAGER" = "pacman" ]; then
repo_subscriptions_pacman
fi fi
) )
Updatable packages: Updatable packages:

View File

@ -0,0 +1,20 @@
#!/bin/bash
# TERMUX_APP_PACKAGE_MANAGER should be exported by termux-app v0.119.0+
# itself and should contain "apt" or "pacman".
# TERMUX_MAIN_PACKAGE_FORMAT should be exported by login script in
# termux-tools v0.161+ if termux-app version is less than 0.119.0 and
# should contain "debian" or "pacman".
if [ -z "${TERMUX_APP_PACKAGE_MANAGER-}" ]; then
if [ -n "${TERMUX_MAIN_PACKAGE_FORMAT-}" ]; then
TERMUX_APP_PACKAGE_MANAGER="$([ "${TERMUX_MAIN_PACKAGE_FORMAT-}" = "debian" ] && echo "apt" || echo "${TERMUX_MAIN_PACKAGE_FORMAT-}")"
else
TERMUX_APP_PACKAGE_MANAGER="@TERMUX_PACKAGE_MANAGER@"
fi
fi
case "${TERMUX_APP_PACKAGE_MANAGER-}" in
apt|pacman) :;;
*) echo "Unsupported package manager \"${TERMUX_APP_PACKAGE_MANAGER-}\". Only 'apt' and 'pacman' managers are supported" 1>&2; exit 1;;
esac
export TERMUX_APP_PACKAGE_MANAGER

View File

@ -27,8 +27,8 @@ termux_setup_cabal() {
cabal update cabal update
else else
if [[ "${TERMUX_MAIN_PACKAGE_FORMAT}" == "debian" ]] && "$(dpkg-query -W -f '${db:Status-Status}\n' cabal-install 2>/dev/null)" != "installed" || if [[ "${TERMUX_APP_PACKAGE_MANAGER}" == "apt" ]] && "$(dpkg-query -W -f '${db:Status-Status}\n' cabal-install 2>/dev/null)" != "installed" ||
[[ "${TERMUX_MAIN_PACKAGE_FORMAT}" == "pacman" ]] && ! "$(pacman -Q cabal-install 2>/dev/null)"; then [[ "${TERMUX_APP_PACKAGE_MANAGER}" == "pacman" ]] && ! "$(pacman -Q cabal-install 2>/dev/null)"; then
echo "Package 'cabal-install' is not installed." echo "Package 'cabal-install' is not installed."
exit 1 exit 1
fi fi

View File

@ -25,8 +25,8 @@ termux_setup_cmake() {
export PATH=$TERMUX_CMAKE_FOLDER/bin:$PATH export PATH=$TERMUX_CMAKE_FOLDER/bin:$PATH
else else
if [[ "$TERMUX_MAIN_PACKAGE_FORMAT" = "debian" && "$(dpkg-query -W -f '${db:Status-Status}\n' cmake 2>/dev/null)" != "installed" ]] || if [[ "$TERMUX_APP_PACKAGE_MANAGER" = "apt" && "$(dpkg-query -W -f '${db:Status-Status}\n' cmake 2>/dev/null)" != "installed" ]] ||
[[ "$TERMUX_MAIN_PACKAGE_FORMAT" = "pacman" && ! "$(pacman -Q cmake 2>/dev/null)" ]]; then [[ "$TERMUX_APP_PACKAGE_MANAGER" = "pacman" && ! "$(pacman -Q cmake 2>/dev/null)" ]]; then
echo "Package 'cmake' is not installed." echo "Package 'cmake' is not installed."
echo "You can install it with" echo "You can install it with"
echo echo

View File

@ -58,8 +58,8 @@ termux_setup_ghc() {
) )
rm -Rf "$TERMUX_GHC_TEMP_FOLDER" "$TERMUX_GHC_TAR" rm -Rf "$TERMUX_GHC_TEMP_FOLDER" "$TERMUX_GHC_TAR"
else else
if [[ "$TERMUX_MAIN_PACKAGE_FORMAT" = "debian" && "$(dpkg-query -W -f '${db:Status-Status}\n' ghc 2>/dev/null)" != "installed" ]] || if [[ "$TERMUX_APP_PACKAGE_MANAGER" = "apt" && "$(dpkg-query -W -f '${db:Status-Status}\n' ghc 2>/dev/null)" != "installed" ]] ||
[[ "$TERMUX_MAIN_PACKAGE_FORMAT" = "pacman" && ! "$(pacman -Q ghc 2>/dev/null)" ]]; then [[ "$TERMUX_APP_PACKAGE_MANAGER" = "pacman" && ! "$(pacman -Q ghc 2>/dev/null)" ]]; then
echo "Package 'ghc' is not installed." echo "Package 'ghc' is not installed."
exit 1 exit 1
fi fi

View File

@ -124,8 +124,8 @@ termux_setup_ghc_cross_compiler() {
rm "${TERMUX_GHC_TAR}" rm "${TERMUX_GHC_TAR}"
else else
if [[ "${TERMUX_MAIN_PACKAGE_FORMAT}" == "debian" ]] && "$(dpkg-query -W -f '${db:Status-Status}\n' ghc 2>/dev/null)" != "installed" || if [[ "${TERMUX_APP_PACKAGE_MANAGER}" == "apt" ]] && "$(dpkg-query -W -f '${db:Status-Status}\n' ghc 2>/dev/null)" != "installed" ||
[[ "${TERMUX_MAIN_PACKAGE_FORMAT}" == "pacman" ]] && ! "$(pacman -Q ghc 2>/dev/null)"; then [[ "${TERMUX_APP_PACKAGE_MANAGER}" == "pacman" ]] && ! "$(pacman -Q ghc 2>/dev/null)"; then
echo "Package 'ghc' is not installed." echo "Package 'ghc' is not installed."
exit 1 exit 1
else else

View File

@ -40,8 +40,8 @@ termux_setup_gn() {
fi fi
export PATH=$GN_FOLDER/out:$PATH export PATH=$GN_FOLDER/out:$PATH
else else
if [[ "$TERMUX_MAIN_PACKAGE_FORMAT" = "debian" && "$(dpkg-query -W -f '${db:Status-Status}\n' gn 2>/dev/null)" != "installed" ]] || if [[ "$TERMUX_APP_PACKAGE_MANAGER" = "apt" && "$(dpkg-query -W -f '${db:Status-Status}\n' gn 2>/dev/null)" != "installed" ]] ||
[[ "$TERMUX_MAIN_PACKAGE_FORMAT" = "pacman" && ! "$(pacman -Q gn 2>/dev/null)" ]]; then [[ "$TERMUX_APP_PACKAGE_MANAGER" = "pacman" && ! "$(pacman -Q gn 2>/dev/null)" ]]; then
echo "Package 'gn' is not installed." echo "Package 'gn' is not installed."
echo "You can install it with" echo "You can install it with"
echo echo

View File

@ -26,8 +26,8 @@ termux_setup_golang() {
( cd "$TERMUX_BUILDGO_FOLDER"; . ${TERMUX_SCRIPTDIR}/packages/golang/fix-hardcoded-etc-resolv-conf.sh ) ( cd "$TERMUX_BUILDGO_FOLDER"; . ${TERMUX_SCRIPTDIR}/packages/golang/fix-hardcoded-etc-resolv-conf.sh )
else else
if [[ "$TERMUX_MAIN_PACKAGE_FORMAT" = "debian" && "$(dpkg-query -W -f '${db:Status-Status}\n' golang 2>/dev/null)" != "installed" ]] || if [[ "$TERMUX_APP_PACKAGE_MANAGER" = "apt" && "$(dpkg-query -W -f '${db:Status-Status}\n' golang 2>/dev/null)" != "installed" ]] ||
[[ "$TERMUX_MAIN_PACKAGE_FORMAT" = "pacman" && ! "$(pacman -Q golang 2>/dev/null)" ]]; then [[ "$TERMUX_APP_PACKAGE_MANAGER" = "pacman" && ! "$(pacman -Q golang 2>/dev/null)" ]]; then
echo "Package 'golang' is not installed." echo "Package 'golang' is not installed."
echo "You can install it with" echo "You can install it with"
echo echo

View File

@ -26,8 +26,8 @@ termux_setup_jailbreak_cabal() {
rm "${TERMUX_JAILBREAK_TAR}" rm "${TERMUX_JAILBREAK_TAR}"
else else
if [[ "${TERMUX_MAIN_PACKAGE_FORMAT}" == "debian" ]] && "$(dpkg-query -W -f '${db:Status-Status}\n' jailbreak-cabal 2>/dev/null)" != "installed" || if [[ "${TERMUX_APP_PACKAGE_MANAGER}" == "apt" ]] && "$(dpkg-query -W -f '${db:Status-Status}\n' jailbreak-cabal 2>/dev/null)" != "installed" ||
[[ "${TERMUX_MAIN_PACKAGE_FORMAT}" = "pacman" ]] && ! "$(pacman -Q jailbreak-cabal 2>/dev/null)"; then [[ "${TERMUX_APP_PACKAGE_MANAGER}" = "pacman" ]] && ! "$(pacman -Q jailbreak-cabal 2>/dev/null)"; then
echo "Package 'jailbreak-cabal' is not installed." echo "Package 'jailbreak-cabal' is not installed."
exit 1 exit 1
fi fi

View File

@ -23,8 +23,8 @@ termux_setup_ninja() {
local NINJA_PKG_VERSION=$(bash -c ". $TERMUX_SCRIPTDIR/packages/ninja/build.sh; echo \$TERMUX_PKG_VERSION") local NINJA_PKG_VERSION=$(bash -c ". $TERMUX_SCRIPTDIR/packages/ninja/build.sh; echo \$TERMUX_PKG_VERSION")
if ([ ! -e "$TERMUX_BUILT_PACKAGES_DIRECTORY/ninja" ] || if ([ ! -e "$TERMUX_BUILT_PACKAGES_DIRECTORY/ninja" ] ||
[ "$(cat "$TERMUX_BUILT_PACKAGES_DIRECTORY/ninja")" != "$NINJA_PKG_VERSION" ]) && [ "$(cat "$TERMUX_BUILT_PACKAGES_DIRECTORY/ninja")" != "$NINJA_PKG_VERSION" ]) &&
([[ "$TERMUX_MAIN_PACKAGE_FORMAT" = "debian" && "$(dpkg-query -W -f '${db:Status-Status}\n' ninja 2>/dev/null)" != "installed" ]] || ([[ "$TERMUX_APP_PACKAGE_MANAGER" = "apt" && "$(dpkg-query -W -f '${db:Status-Status}\n' ninja 2>/dev/null)" != "installed" ]] ||
[[ "$TERMUX_MAIN_PACKAGE_FORMAT" = "pacman" && ! "$(pacman -Q ninja 2>/dev/null)" ]]); then [[ "$TERMUX_APP_PACKAGE_MANAGER" = "pacman" && ! "$(pacman -Q ninja 2>/dev/null)" ]]); then
echo "Package 'ninja' is not installed." echo "Package 'ninja' is not installed."
echo "You can install it with" echo "You can install it with"
echo echo

View File

@ -23,8 +23,8 @@ termux_setup_nodejs() {
local NODEJS_PKG_VERSION=$(bash -c ". $TERMUX_SCRIPTDIR/packages/nodejs/build.sh; echo \$TERMUX_PKG_VERSION") local NODEJS_PKG_VERSION=$(bash -c ". $TERMUX_SCRIPTDIR/packages/nodejs/build.sh; echo \$TERMUX_PKG_VERSION")
if ([ ! -e "$TERMUX_BUILT_PACKAGES_DIRECTORY/nodejs" ] || if ([ ! -e "$TERMUX_BUILT_PACKAGES_DIRECTORY/nodejs" ] ||
[ "$(cat "$TERMUX_BUILT_PACKAGES_DIRECTORY/nodejs")" != "$NODEJS_PKG_VERSION" ]) && [ "$(cat "$TERMUX_BUILT_PACKAGES_DIRECTORY/nodejs")" != "$NODEJS_PKG_VERSION" ]) &&
([[ "$TERMUX_MAIN_PACKAGE_FORMAT" = "debian" && "$(dpkg-query -W -f '${db:Status-Status}\n' nodejs 2>/dev/null)" != "installed" ]] || ([[ "$TERMUX_APP_PACKAGE_MANAGER" = "apt" && "$(dpkg-query -W -f '${db:Status-Status}\n' nodejs 2>/dev/null)" != "installed" ]] ||
[[ "$TERMUX_MAIN_PACKAGE_FORMAT" = "pacman" && ! "$(pacman -Q nodejs 2>/dev/null)" ]]); then [[ "$TERMUX_APP_PACKAGE_MANAGER" = "pacman" && ! "$(pacman -Q nodejs 2>/dev/null)" ]]); then
echo "Package 'nodejs' is not installed." echo "Package 'nodejs' is not installed."
echo "You can install it with" echo "You can install it with"
echo echo

View File

@ -6,8 +6,8 @@ termux_setup_rust() {
fi fi
if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then
if [[ "$TERMUX_MAIN_PACKAGE_FORMAT" = "debian" && "$(dpkg-query -W -f '${db:Status-Status}\n' rust 2>/dev/null)" != "installed" ]] || if [[ "$TERMUX_APP_PACKAGE_MANAGER" = "apt" && "$(dpkg-query -W -f '${db:Status-Status}\n' rust 2>/dev/null)" != "installed" ]] ||
[[ "$TERMUX_MAIN_PACKAGE_FORMAT" = "pacman" && ! "$(pacman -Q rust 2>/dev/null)" ]]; then [[ "$TERMUX_APP_PACKAGE_MANAGER" = "pacman" && ! "$(pacman -Q rust 2>/dev/null)" ]]; then
echo "Package 'rust' is not installed." echo "Package 'rust' is not installed."
echo "You can install it with" echo "You can install it with"
echo echo

View File

@ -5,8 +5,8 @@ termux_download_deb_pac() {
local VERSION_PACMAN=$4 local VERSION_PACMAN=$4
if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then
case "$TERMUX_MAIN_PACKAGE_FORMAT" in case "$TERMUX_APP_PACKAGE_MANAGER" in
"debian") apt install -y "${PACKAGE}=${VERSION}";; "apt") apt install -y "${PACKAGE}=${VERSION}";;
"pacman") pacman -S "${PACKAGE}=${VERSION_PACMAN}" --needed --noconfirm;; "pacman") pacman -S "${PACKAGE}=${VERSION_PACMAN}" --needed --noconfirm;;
esac esac
return "$?" return "$?"

View File

@ -5,8 +5,8 @@ termux_step_get_dependencies() {
# When doing build on device, ensure that apt lists are up-to-date. # When doing build on device, ensure that apt lists are up-to-date.
if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then
case "$TERMUX_MAIN_PACKAGE_FORMAT" in case "$TERMUX_APP_PACKAGE_MANAGER" in
"debian") apt update;; "apt") apt update;;
"pacman") pacman -Sy;; "pacman") pacman -Sy;;
esac esac
fi fi

View File

@ -1,5 +1,4 @@
termux_step_setup_variables() { termux_step_setup_variables() {
: "${TERMUX_PACKAGE_FORMAT:="$([ ! -z "${TERMUX_MAIN_PACKAGE_FORMAT+x}" ] && echo "$TERMUX_MAIN_PACKAGE_FORMAT" || echo "debian")"}" # debian, pacman
: "${TERMUX_ARCH:="aarch64"}" # arm, aarch64, i686 or x86_64. : "${TERMUX_ARCH:="aarch64"}" # arm, aarch64, i686 or x86_64.
: "${TERMUX_OUTPUT_DIR:="${TERMUX_SCRIPTDIR}/output"}" : "${TERMUX_OUTPUT_DIR:="${TERMUX_SCRIPTDIR}/output"}"
: "${TERMUX_DEBUG_BUILD:="false"}" : "${TERMUX_DEBUG_BUILD:="false"}"
@ -14,6 +13,20 @@ termux_step_setup_variables() {
: "${TERMUX_TOPDIR:="$HOME/.termux-build"}" : "${TERMUX_TOPDIR:="$HOME/.termux-build"}"
: "${TERMUX_PACMAN_PACKAGE_COMPRESSION:="xz"}" : "${TERMUX_PACMAN_PACKAGE_COMPRESSION:="xz"}"
if [ -z "${TERMUX_PACKAGE_FORMAT-}" ]; then
if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ] && [ -n "${TERMUX_APP_PACKAGE_MANAGER-}" ]; then
TERMUX_PACKAGE_FORMAT="$([ "${TERMUX_APP_PACKAGE_MANAGER-}" = "apt" ] && echo "debian" || echo "${TERMUX_APP_PACKAGE_MANAGER-}")"
else
TERMUX_PACKAGE_FORMAT="debian"
fi
fi
case "${TERMUX_PACKAGE_FORMAT-}" in
debian) TERMUX_PACKAGE_MANAGER="apt";;
pacman) TERMUX_PACKAGE_MANAGER="pacman";;
*) termux_error_exit "Unsupported package format \"${TERMUX_PACKAGE_FORMAT-}\". Only 'debian' and 'pacman' formats are supported";;
esac
if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then
# For on-device builds cross-compiling is not supported so we can # For on-device builds cross-compiling is not supported so we can
# store information about built packages under $TERMUX_TOPDIR. # store information about built packages under $TERMUX_TOPDIR.

View File

@ -55,8 +55,8 @@ termux_step_start_build() {
echo "$TERMUX_PKG_NAME@$TERMUX_PKG_FULLVERSION built - skipping (rm $TERMUX_BUILT_PACKAGES_DIRECTORY/$TERMUX_PKG_NAME to force rebuild)" echo "$TERMUX_PKG_NAME@$TERMUX_PKG_FULLVERSION built - skipping (rm $TERMUX_BUILT_PACKAGES_DIRECTORY/$TERMUX_PKG_NAME to force rebuild)"
exit 0 exit 0
elif [ "$TERMUX_ON_DEVICE_BUILD" = "true" ] && elif [ "$TERMUX_ON_DEVICE_BUILD" = "true" ] &&
([[ "$TERMUX_MAIN_PACKAGE_FORMAT" = "debian" && "$(dpkg-query -W -f '${db:Status-Status} ${Version}\n' "$TERMUX_PKG_NAME" 2>/dev/null)" = "installed $TERMUX_PKG_FULLVERSION" ]] || ([[ "$TERMUX_APP_PACKAGE_MANAGER" = "apt" && "$(dpkg-query -W -f '${db:Status-Status} ${Version}\n' "$TERMUX_PKG_NAME" 2>/dev/null)" = "installed $TERMUX_PKG_FULLVERSION" ]] ||
[[ "$TERMUX_MAIN_PACKAGE_FORMAT" = "pacman" && "$(pacman -Q $TERMUX_PKG_NAME 2>/dev/null)" = "$TERMUX_PKG_NAME $TERMUX_PKG_FULLVERSION_FOR_PACMAN" ]]); then [[ "$TERMUX_APP_PACKAGE_MANAGER" = "pacman" && "$(pacman -Q $TERMUX_PKG_NAME 2>/dev/null)" = "$TERMUX_PKG_NAME $TERMUX_PKG_FULLVERSION_FOR_PACMAN" ]]); then
echo "$TERMUX_PKG_NAME@$TERMUX_PKG_FULLVERSION installed - skipping" echo "$TERMUX_PKG_NAME@$TERMUX_PKG_FULLVERSION installed - skipping"
exit 0 exit 0
fi fi