-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tsu was no longer developed (as last commit is 15th August 2020) this causes su binary of newer root solutions not reconized, instead use our own simple_sudo that up to date with newer root solutions. Signed-off-by: Rem01Gaming <Rem01_Gaming@proton.me>
- Loading branch information
1 parent
d6f66e6
commit 3c28fc0
Showing
4 changed files
with
118 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#!/data/data/com.termux/files/usr/bin/bash | ||
# Simple Sudo is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Simple Sudo is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with Simple Sudo. If not, see <https://www.gnu.org/licenses/>. | ||
# | ||
# Copyright (C) 2024-2025 Rem01Gaming | ||
|
||
show_usage_sudo() { | ||
cat <<"EOF" | ||
sudo - run commands as root or another user | ||
usage: sudo command | ||
usage: sudo [-E] [-u USER] command | ||
Options: | ||
-E Preserve environment variables from the current shell. | ||
-u USER Switch to USER instead of root.. | ||
EOF | ||
} | ||
|
||
_is_pos() { | ||
for e in -u --user -E --preserve-enviroment; do [[ "$e" == "$1" ]] && return 1; done | ||
return 0 | ||
} | ||
|
||
for arg in "$@"; do | ||
# It is important to break as soon as we see a positional args | ||
# Otherwise `sudo id -u` or `sudo some_cmd -E` wont work as expected | ||
|
||
if _is_pos "$arg"; then break; fi | ||
|
||
case $arg in | ||
-u | --user) | ||
SWITCH_USER="$2" | ||
shift | ||
shift | ||
;; | ||
-E | --preserve-enviroment) | ||
ENVIRONMENT_PRESERVE=true | ||
shift | ||
;; | ||
esac | ||
done | ||
|
||
STARTUP_SCRIPT="$@" | ||
|
||
# Print help if no arguments passed | ||
if [ -z "$1" ]; then | ||
show_usage_sudo | ||
exit 0 | ||
fi | ||
|
||
# Handle case if people do `sudo su` | ||
if [[ "$1" == "su" ]]; then | ||
echo "You can't call SuperUser on sudo!" | ||
exit 1 | ||
fi | ||
|
||
# Prevent executable not found by using Termux's $PATH | ||
TERMUX_PATH="/data/data/com.termux/files/usr/bin" | ||
|
||
# Unset all Termux LD_* enviroment variables to prevent symbols missing , dlopen()ing of wrong libs. | ||
unset LD_LIBRARY_PATH LD_PRELOAD | ||
|
||
# Add your path of su binary | ||
SEARCH_SU_BINARY=( | ||
"/debug_ramdisk/su" | ||
"/sbin/su" | ||
"/system/sbin/su" | ||
"/system/bin/su" | ||
"/system/xbin/su" | ||
"/su/bin/su" | ||
"/magisk/.core/bin/su" | ||
"/apex/com.android.runtime/bin/su" | ||
) | ||
|
||
SU_ARGS=() | ||
|
||
if [ ! -z $SWITCH_USER ]; then | ||
SU_ARGS+=("$SWITCH_USER") | ||
fi | ||
|
||
if [ ! -z $ENVIRONMENT_PRESERVE ]; then | ||
SU_ARGS+=("--preserve-environment") | ||
SU_CMDLINE="LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so PATH=/data/data/com.termux/files/usr/bin:/debug_ramdisk:/sbin:/sbin/su:/su/bin:/su/xbin:/system/bin:/system/xbin" | ||
else | ||
SU_CMDLINE="$TERMUX_PATH/env -i SUDO_GID=$(id -g) SUDO_USER=$(id -u) PREFIX=/data/data/com.termux/files/usr LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so HOME=/data/data/com.termux/files/home/.suroot TMPDIR=/data/data/com.termux/files/home/.suroot/.tmp ANDROID_DATA=/data TERM=xterm-256color ANDROID_ROOT=/system PATH=/data/data/com.termux/files/usr/bin:/debug_ramdisk:/sbin:/sbin/su:/su/bin:/su/xbin:/system/bin:/system/xbin" | ||
fi | ||
|
||
# Execute command | ||
for su in ${SEARCH_SU_BINARY[@]}; do | ||
if [ -x $su ]; then | ||
SU_ARGS+=("-c") | ||
exec $su ${SU_ARGS[@]} "$SU_CMDLINE $STARTUP_SCRIPT" | ||
IS_SU_EXECUTED="1" | ||
break | ||
fi | ||
done | ||
|
||
# We didn't find any SuperUser binary | ||
if [ -z "$IS_SU_EXECUTED" ]; then | ||
echo "Can't find any SuperUser binary!" | ||
echo "Make sure you're rooted and allow Termux for SuperUser access." | ||
fi |