2023-02-04 13:16:51 +08:00
|
|
|
#!/bin/sh
|
|
|
|
set -eux
|
2022-12-10 22:43:21 +07:00
|
|
|
|
|
|
|
GKI_ROOT=$(pwd)
|
|
|
|
|
|
|
|
echo "[+] GKI_ROOT: $GKI_ROOT"
|
|
|
|
|
2023-01-12 17:09:55 +08:00
|
|
|
if test -d "$GKI_ROOT/common/drivers"; then
|
|
|
|
DRIVER_DIR="$GKI_ROOT/common/drivers"
|
|
|
|
elif test -d "$GKI_ROOT/drivers"; then
|
|
|
|
DRIVER_DIR="$GKI_ROOT/drivers"
|
|
|
|
else
|
2023-02-04 13:16:51 +08:00
|
|
|
echo '[ERROR] "drivers/" directory is not found.'
|
2023-05-16 17:12:16 +07:00
|
|
|
echo '[+] You should modify this script by yourself.'
|
2023-01-12 17:09:55 +08:00
|
|
|
exit 127
|
|
|
|
fi
|
|
|
|
|
|
|
|
test -d "$GKI_ROOT/KernelSU" || git clone https://github.com/tiann/KernelSU
|
|
|
|
cd "$GKI_ROOT/KernelSU"
|
2023-04-14 15:31:30 +08:00
|
|
|
git stash
|
|
|
|
if [ "$(git status | grep -Po 'v\d+(\.\d+)*' | head -n1)" ]; then
|
|
|
|
git checkout main
|
|
|
|
fi
|
|
|
|
git pull
|
2023-04-13 22:15:17 +08:00
|
|
|
if [ -z "${1-}" ]; then
|
2023-04-13 14:40:56 +08:00
|
|
|
git checkout "$(git describe --abbrev=0 --tags)"
|
|
|
|
else
|
|
|
|
git checkout "$1"
|
|
|
|
fi
|
2023-01-12 17:09:55 +08:00
|
|
|
cd "$GKI_ROOT"
|
|
|
|
|
|
|
|
echo "[+] GKI_ROOT: $GKI_ROOT"
|
|
|
|
echo "[+] Copy kernel su driver to $DRIVER_DIR"
|
|
|
|
|
2023-05-03 21:05:36 +07:00
|
|
|
cd "$DRIVER_DIR"
|
|
|
|
if test -d "$GKI_ROOT/common/drivers"; then
|
|
|
|
ln -sf "../../KernelSU/kernel" "kernelsu"
|
|
|
|
elif test -d "$GKI_ROOT/drivers"; then
|
|
|
|
ln -sf "../KernelSU/kernel" "kernelsu"
|
|
|
|
fi
|
|
|
|
cd "$GKI_ROOT"
|
2022-12-10 22:43:21 +07:00
|
|
|
|
2023-02-04 13:16:51 +08:00
|
|
|
echo '[+] Add kernel su driver to Makefile'
|
2022-12-10 22:43:21 +07:00
|
|
|
|
2023-01-12 17:09:55 +08:00
|
|
|
DRIVER_MAKEFILE=$DRIVER_DIR/Makefile
|
2023-06-06 12:12:27 +08:00
|
|
|
DRIVER_KCONFIG=$DRIVER_DIR/Kconfig
|
2024-02-23 16:55:22 +08:00
|
|
|
grep -q "kernelsu" "$DRIVER_MAKEFILE" || printf "\nobj-\$(CONFIG_KSU) += kernelsu/\n" >> "$DRIVER_MAKEFILE"
|
2023-06-06 12:12:27 +08:00
|
|
|
grep -q "kernelsu" "$DRIVER_KCONFIG" || sed -i "/endmenu/i\\source \"drivers/kernelsu/Kconfig\"" "$DRIVER_KCONFIG"
|
2022-12-10 22:43:21 +07:00
|
|
|
|
2024-02-23 16:55:22 +08:00
|
|
|
echo '[+] Done.'
|