Skip to content

Commit

Permalink
Remove dependencies with tsu
Browse files Browse the repository at this point in the history
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
Rem01Gaming committed May 14, 2024
1 parent d6f66e6 commit 3c28fc0
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 5 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ uninstall:
install-dependence:
@echo "\033[1;38;2;254;228;208m[+] Installing dependencines...\033[0m"
@apt install root-repo -y
@apt install fzf fzy git tsu -y
@apt install fzf fzy git -y

pack-deb:
@mkdir -v $(O)
Expand All @@ -57,13 +57,14 @@ pack-deb:
@mkdir -pv $(O)/deb/data/data/com.termux/files/usr/share/origami-kernel/
@mkdir -pv $(O)/deb/data/data/com.termux/files/usr/share/origami-kernel/doc
@cp -rv share/* $(O)/deb/data/data/com.termux/files/usr/share/origami-kernel/
@cp -rv src/origami-kernel $(O)/deb/data/data/com.termux/files/usr/bin/
@cp -rv doc/ $(O)/deb/data/data/com.termux/files/usr/share/origami-kernel/doc
@cp -rv src/* $(O)/deb/data/data/com.termux/files/usr/bin/
@cp -rv doc/* $(O)/deb/data/data/com.termux/files/usr/share/origami-kernel/doc
@cp -rv dpkg-conf $(O)/deb/DEBIAN
@printf "\033[1;38;2;254;228;208m[+] Build packages.\033[0m\n"&&sleep 1s
@chmod -Rv 755 $(O)/deb/DEBIAN
@chmod -Rv 755 $(O)/deb/data/data/com.termux/files/usr/bin
@chmod -Rv 777 $(O)/deb/data/data/com.termux/files/usr/bin/origami-kernel
@chmod -Rv 777 $(O)/deb/data/data/com.termux/files/usr/bin/origami-sudo
@cd $(O)/deb&&dpkg -b . ../../origami-kernel.deb
@printf "\033[1;38;2;254;228;208m .^. .^.\n"
@printf " /⋀\\_ノ_/⋀\\ \n"
Expand Down
2 changes: 1 addition & 1 deletion dpkg-conf/control
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ Maintainer: Rem01Gaming
Installed-Size: 1500
Version: 1.0.7
Homepage: https://github.com/Rem01Gaming/origami_kernel_manager
Depends: tsu, fzf, fzy
Depends: fzf, fzy
Description: Yet another kernel manager.
2 changes: 1 addition & 1 deletion src/origami-kernel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/data/data/com.termux/files/usr/bin/bash
#!/data/data/com.termux/files/usr/bin/origami-sudo bash
# This file is part of Origami Kernel Manager.
#
# Origami Kernel Manager is free software: you can redistribute it and/or modify
Expand Down
112 changes: 112 additions & 0 deletions src/origami-sudo
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

0 comments on commit 3c28fc0

Please sign in to comment.