Skip to content

Instantly share code, notes, and snippets.

@kennethho
Last active October 16, 2021 05:26
Show Gist options
  • Save kennethho/bc7502dcf6c0b4a53ef85758f797fc8b to your computer and use it in GitHub Desktop.
Save kennethho/bc7502dcf6c0b4a53ef85758f797fc8b to your computer and use it in GitHub Desktop.
Sudo for Termux
#!/data/data/com.termux/files/usr/bin/bash
#set -x
SUDO_SH=/data/data/com.termux/files/usr/bin/sh
QUOTED_SUDO_ARGS=$(printf '%q' $"$(printf '%q ' "$@")")
#QUOTED_SUDO_ARGS=$(printf '%q ' \"$@\")
printf '%s\n' "$QUOTED_SUDO_ARGS"
SU_C_ARGS=("LD_LIBRARY_PATH=$PREFIX/lib" "$SUDO_SH" "-c" "$QUOTED_SUDO_ARGS")
for su in /system/xbin/su /su/bin/su
do
if [ -x $su ]; then
# The su tool may require programs in PATH:
PATH=$PATH:/su/bin:/su/xbin:/system/bin:/system/xbin \
exec $su \
--preserve-environment \
-c "${SU_C_ARGS[@]}"
fi
done
echo "There is no su program on this device. Termux"
echo "does not supply tools for rooting, see e.g."
echo "http://www.androidcentral.com/root for"
echo "information about rooting Android."
exit 1
@lifeModder19135
Copy link

I don't know why they write that at the bottom. Do they not realize that the command sudo bash is the same thing as su.

Thank goodness, I don't think having to deal with running sh from that deep-a** bin directory I would be worth it. Even for root privilege.. every single time you type the command, you'd have to type that super long string first. You could try to build your own path variable, but you would probably fill up the phones storage with ANSI character codes before it finished writing! XD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment