Skip to content

Instantly share code, notes, and snippets.

@cswl
Last active April 20, 2024 03:17
Show Gist options
  • Star 39 You must be signed in to star a gist
  • Fork 18 You must be signed in to fork a gist
  • Save cswl/cd13971e644dc5ced7b2 to your computer and use it in GitHub Desktop.
Save cswl/cd13971e644dc5ced7b2 to your computer and use it in GitHub Desktop.
DEPRECATED: Use https://github.com/cswl/tsu instead.
#!/data/data/com.termux/files/usr/bin/sh
# sudo for Termux
# For security reasons some environent variables are reset by su
# So we need to set LD_LIBRARY_PATH
# Root's HOME is set to 'termux's home/.suroot'.
# Startup files and other stuffs can be added there.
ROOT_HOME=$HOME/.suroot
case "$1" in
'-')
# check if user has set shell
if test -x "$HOME/.termux/shell" ; then
ROOT_SHELL=$HOME/.termux/shell
# has installed bash?
elif test -x "$PREFIX/bin/bash" ; then
ROOT_SHELL="$PREFIX/bin/bash"
# no..fallback to default ash.
else
ROOT_SHELL="$PREFIX/bin/ash"
fi
exec su -c "LD_LIBRARY_PATH=$PREFIX/lib HOME=$ROOT_HOME $ROOT_SHELL"
;;
''|'--help')
echo 'Sets up environment to allow termux programs to run with root access'
echo 'Not the sudo as found in other *nixes'
echo
echo 'Usage: sudo [-|cmd args]'
echo '- : Try to start a shell of termux as root shell. su by default runs /system/bin/sh.'
echo 'cmd : Run termux program with args as root.'
;;
*)
exec su -c "LD_LIBRARY_PATH=$PREFIX/lib HOME=$ROOT_HOME ${@}";
;;
esac
@Seliniux777
Copy link

fix usaage

Copy link

ghost commented Sep 16, 2022

@DreamBoy65
Copy link

hello, i tried installing it but it says sudo requires su

@shubhamsharmaw
Copy link

No such file or directory

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