From bb0d596595fc04789cb76f516d3fbad4a8b009b6 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Fri, 22 Mar 2024 00:55:16 +0000 Subject: [PATCH] package: DEFPATH fix for Android/Termux (re: c3fec93f) The standard utilities directory on Android is actually /bin (a symlink to /system/bin). There lives sh (which is dash) and the core utilities (from Toybox). In DEFPATH these should take precedence over whatever is added by termux -- if only because /bin is read-only and therefore more secure; termux utilities are installed by and can be overwrittem by the regular user. --- bin/package | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bin/package b/bin/package index 3354e72f1b29..9960866dd619 100755 --- a/bin/package +++ b/bin/package @@ -1714,6 +1714,15 @@ DEFPATH=$( $CC $CCFLAGS $LDFLAGS -o "$t.exe" "$t.c" 2>/dev/null && "$t.exe" } ) || DEFPATH=/bin:/usr/bin:/sbin:/usr/sbin +# Fix for Android/Termux. The /bin directory exists with standard +# utilities (sh, Toybox utils) but it is not included in _PATH_DEFPATH. +# It should come first because /bin is read-only. +if test -d /data/data/com.termux && test "$(/bin/uname -o 2>/dev/null)" = Android +then case ":$DEFPATH:" in + *:/bin:* ) ;; + * ) DEFPATH=/bin:$DEFPATH ;; + esac +fi # Fix for NixOS. Not all POSIX standard utilities come with the default system, # e.g. 'bc', 'file', 'vi'. The command that NixOS recommends to get missing # utilities, e.g. 'nix-env -iA nixos.bc', installs them in a default profile