Skip to content

Instantly share code, notes, and snippets.

@gwenhael-le-moine
Forked from cswl/termux-su
Last active October 23, 2022 11:53
Show Gist options
  • Save gwenhael-le-moine/57409ffed9066ce7f4d4 to your computer and use it in GitHub Desktop.
Save gwenhael-le-moine/57409ffed9066ce7f4d4 to your computer and use it in GitHub Desktop.
run termux programs as root..
#!/data/data/com.termux/files/usr/bin/sh
# sudo for Termux
# For security reasons some environent variables are reset by su
# So need to set LD_LIBRARY_PATH again
# root's HOME is set to termux's home/.suroot. You can add bashrc 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=/data/data/com.termux/files/usr/lib HOME=$ROOT_HOME $ROOT_SHELL"
;;
''|'-h'|'--help')
echo 'Sets up environment to allow termux programs to run with root access. Not the sudo as found in other *nixes'
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=/data/data/com.termux/files/usr/lib HOME=$ROOT_HOME ${@}";
;;
esac
@Abdulaziz959
Copy link

how to run this script

@250416
Copy link

250416 commented Mar 23, 2022

Me too

@gwenhael-le-moine
Copy link
Author

DEPRECATED: Use https://github.com/cswl/tsu instead.

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