-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
= mlm-games
committed
Sep 10, 2024
1 parent
dfd85b2
commit c5af05c
Showing
3 changed files
with
375 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/bin/sh | ||
set -eu | ||
|
||
KERNEL_DIR=$(pwd) | ||
|
||
display_usage() { | ||
echo "Usage: $0 [--cleanup | <commit-or-tag>]" | ||
echo " --cleanup: Cleans up previous modifications made by the script." | ||
echo " <commit-or-tag>: Sets up or updates the KernelSU to specified tag or commit." | ||
echo " -h, --help: Displays this usage information." | ||
echo " (no args): Sets up or updates the KernelSU environment to the latest tagged version." | ||
} | ||
|
||
initialize_variables() { | ||
if test -d "$KERNEL_DIR/common/drivers"; then | ||
DRIVER_DIR="$KERNEL_DIR/common/drivers" | ||
elif test -d "$KERNEL_DIR/drivers"; then | ||
DRIVER_DIR="$KERNEL_DIR/drivers" | ||
else | ||
echo '[ERROR] "drivers/" directory not found.' | ||
exit 127 | ||
fi | ||
|
||
DRIVER_MAKEFILE=$DRIVER_DIR/Makefile | ||
DRIVER_KCONFIG=$DRIVER_DIR/Kconfig | ||
} | ||
|
||
# Reverts modifications made by this script | ||
perform_cleanup() { | ||
echo "[+] Cleaning up..." | ||
[ -L "$DRIVER_DIR/kernelsu" ] && rm "$DRIVER_DIR/kernelsu" && echo "[-] Symlink removed." | ||
grep -q "kernelsu" "$DRIVER_MAKEFILE" && sed -i '/kernelsu/d' "$DRIVER_MAKEFILE" && echo "[-] Makefile reverted." | ||
grep -q "drivers/kernelsu/Kconfig" "$DRIVER_KCONFIG" && sed -i '/drivers\/kernelsu\/Kconfig/d' "$DRIVER_KCONFIG" && echo "[-] Kconfig reverted." | ||
if [ -d "$KERNEL_DIR/KernelSU" ]; then | ||
rm -rf "$KERNEL_DIR/KernelSU" && echo "[-] KernelSU directory deleted." | ||
fi | ||
} | ||
|
||
# Sets up or update KernelSU environment | ||
setup_kernelsu() { | ||
echo "[+] Setting up KernelSU..." | ||
test -d "$KERNEL_DIR/KernelSU" | ||
git submodule add https://github.com/mlm-games/KernelSU-Non-GKI KernelSU | ||
git submodule update --init --recursive | ||
# Add entries in Makefile and Kconfig if not already existing | ||
grep -q "kernelsu" "$DRIVER_MAKEFILE" || printf "\nobj-\$(CONFIG_KSU) += kernelsu/\n" >> "$DRIVER_MAKEFILE" && echo "[+] Modified Makefile." | ||
grep -q "source \"drivers/kernelsu/Kconfig\"" "$DRIVER_KCONFIG" || sed -i "/endmenu/i\source \"drivers/kernelsu/Kconfig\"" "$DRIVER_KCONFIG" && echo "[+] Modified Kconfig." | ||
echo '[+] Done.' | ||
} | ||
|
||
# Process command-line arguments | ||
if [ "$#" -eq 0 ]; then | ||
initialize_variables | ||
setup_kernelsu | ||
elif [ "$1" = "-h" ] || [ "$1" = "--help" ]; then | ||
display_usage | ||
elif [ "$1" = "--cleanup" ]; then | ||
initialize_variables | ||
perform_cleanup | ||
else | ||
initialize_variables | ||
setup_kernelsu "$@" | ||
fi |
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
Oops, something went wrong.