Skip to content

Commit

Permalink
Add apply previous settings feature
Browse files Browse the repository at this point in the history
Signed-off-by: Rem01Gaming <Rem01_Gaming@proton.me>
  • Loading branch information
Rem01Gaming committed Jun 19, 2024
1 parent c740854 commit 5652d16
Show file tree
Hide file tree
Showing 25 changed files with 870 additions and 295 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ install:
@printf " ノノ㇏ V ノ|ノ\n"
@printf " ⠁⠁\n"
@printf "\033[1;38;2;254;228;208m[+] origami-kernel installed, run with 'okm'\033[0m\n"

uninstall:
rm -f $(PREFIX)/bin/okm $(PREFIX)/bin/origami-sudo
rm -rf $(PREFIX)/share/origami-kernel
Expand All @@ -49,7 +49,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 jq -y
@apt install fzf fzy git jq sqlite -y

pack-deb:
@mkdir -v $(O)
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.1.0
Homepage: https://github.com/Rem01Gaming/origami_kernel_manager
Depends: fzf, fzy, jq, curl
Depends: fzf, fzy, jq, curl, sqlite
Description: Yet another kernel manager.
53 changes: 53 additions & 0 deletions share/database_util.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/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
# 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.
#
# Origami Kernel Manager 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 Origami Kernel Manager. If not, see <https://www.gnu.org/licenses/>.
#
# Copyright (C) 2023-2024 Rem01Gaming

database_path="/data/origami-kernel/okm.db"

sql_query() {
echo "$1" | sqlite3 $database_path
}

if [ ! -f $database_path ]; then
sql_query "CREATE TABLE tb_storecmd (id TEXT PRIMARY KEY, command TEXT NOT NULL, risky BOOLEAN NOT NULL);"
sql_query "CREATE TABLE tb_info (risk_acceptence BOOLEAN NOT NULL, execstoredcmd BOOLEAN NOT NULL, execstoredcmd_risky BOOLEAN NOT NULL);"
sql_query "INSERT INTO tb_info (risk_acceptence, execstoredcmd, execstoredcmd_risky) VALUES (FALSE, FALSE, FALSE);"
sql_query "PRAGMA auto_vacuum = FULL;"
fi

risk_acceptence() {
sql_query "SELECT risk_acceptence FROM tb_info;"
}

accept_risk() {
sql_query "UPDATE tb_info SET risk_acceptence = TRUE;"
}

execstoredcmd_db() {
sql_query "UPDATE tb_info SET execstoredcmd = $1;"
}

execstoredcmd_risky_db() {
sql_query "UPDATE tb_info SET execstoredcmd_risky = $1;"
}

# usage: command2db "identifier" "command" "risky (boolean)"
command2db() {
if [ -f /dev/okm-execstoredcmd ]; then
sql_query "INSERT INTO tb_storecmd (id, command, risky) VALUES ('$1', '$2', $3) ON CONFLICT(id) DO UPDATE SET command='$2', risky=$3;"
fi
}
39 changes: 39 additions & 0 deletions share/exec_storedcmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/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
# 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.
#
# Origami Kernel Manager 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 Origami Kernel Manager. If not, see <https://www.gnu.org/licenses/>.
#
# Copyright (C) 2023-2024 Rem01Gaming

execstoredcmd_allow_risky="$(sql_query "SELECT execstoredcmd_risky FROM tb_info;")"

execstoredcmd() {
while IFS='|' read -r command risky; do
if [ "$risky" -eq 1 ] && [ "$execstoredcmd_allow_risky" -eq 1 ]; then
eval "$command"
elif [ "$risky" -eq 0 ]; then
eval "$command"
fi
done < <(sql_query "SELECT command, risky FROM tb_storecmd;")
}

init_execstoredcmd() {
read -r -p "Apply previous settings? [Y/n]: " input
case $input in
[Yy]*)
echo "Applying settings..."
execstoredcmd
;;
esac
}
17 changes: 8 additions & 9 deletions share/init/init_run.sh → share/init_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ gpu=$(dumpsys SurfaceFlinger | grep GLES | awk -F ': ' '{print $2}' | tr -d '\n'

gpu_devfreq_paths_array=(
"$(find /sys/class/devfreq "*.mali" -print -quit 2>/dev/null)"
"/sys/devices/platform/dfrgx/devfreq/dfrgx"
"/sys/class/kgsl/kgsl-3d0/devfreq"
"$(find /sys/class/devfreq "*kgsl-3d0" -print -quit 2>/dev/null)"
)

for path in ${gpu_devfreq_paths_array[@]}; do
Expand All @@ -62,22 +65,18 @@ if [ -d /proc/gpufreq ]; then
gpu_node_id=1
elif [ -d /proc/gpufreqv2 ]; then
gpu_node_id=2
elif [ ! -z $gpu_devfreq_path ]; then
elif [ -d $gpu_devfreq_path ]; then # Compensate for Mediatek devices. Mali devfreq interface still exists on Mediatek devices, it just don't fucking work because they injected gpufreq and ged trash into mali driver.
gpu_node_id=0
elif [ -d /sys/devices/platform/kgsl-2d0.0/kgsl ]; then
gpu_node_id=3
elif [ -d /sys/devices/platform/kgsl-3d0.0/kgsl ]; then
gpu_node_id=4
elif [ -d /sys/class/kgsl/kgsl-3d0 ]; then
gpu_node_id=5
elif [ -d /sys/devices/platform/omap/pvrsrvkm.0 ]; then
gpu_node_id=6
gpu_node_id=5
elif [ -d /sys/kernel/tegra_gpu ]; then
gpu_node_id=7
elif [ -d /sys/devices/platform/dfrgx/devfreq ]; then
gpu_node_id=8
gpu_node_id=6
elif [ -d /sys/kernel/gpu ]; then
gpu_node_id=9
gpu_node_id=7
fi

# DRAM info
Expand Down Expand Up @@ -110,7 +109,7 @@ if [[ $soc == "Qualcomm" ]] && [ -z $dram_devfreq_path ]; then
done
fi

# Check for Mediatek's DRAM gebbrish implementation
# Check for Mediatek's DRAM implementation
if [[ $soc == "Mediatek" ]] && [ -z $dram_devfreq_path ]; then
mtk_dram_paths_array=(
"$(find /sys/devices/platform -name "*.dvfsrc" -print -quit 2>/dev/null)/helio-dvfsrc"
Expand Down
22 changes: 10 additions & 12 deletions share/utils/menu/menu_helper.sh → share/menu_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ fzy_select() {
echo $selected_option
}

apply() {
chmod 644 $2 >/dev/null 2>&1
echo $1 >$2 2>/dev/null
chmod 444 $2 >/dev/null 2>&1
}

color_blocks() {
colors=(
"\e[48;5;0m \e[0m" "\e[48;5;1m \e[0m" "\e[48;5;2m \e[0m" "\e[48;5;3m \e[0m"
Expand All @@ -52,10 +58,10 @@ color_blocks() {
menu_value_tune() {
echo
echo -e "${1}" | fold -s -w ${LINE}
echo -e "\nUse ( ↑ ↓ ) to increase or decrease value\nUse HOME or END to exit\n"
echo -e "\nUse ( ↑ ↓ ) to increase or decrease value\nUse HOME or END to exit.\n"

number=$(cat ${2})
x=${5}
local x=${5}

print_number() {
printf "\r%s%s" "value: " "$number "
Expand All @@ -75,12 +81,10 @@ menu_value_tune() {
((number -= x))
fi
;;
*) break ;;
H | F) break ;;
esac

chmod 644 $2 >/dev/null 2>&1
echo $number >$2 2>/dev/null
chmod 444 $2 >/dev/null 2>&1
apply $number $2
done
}

Expand All @@ -100,9 +104,3 @@ print_existing_folders() {
echo "${existing_folders[*]}"
fi
}

apply() {
chmod 644 $2 >/dev/null 2>&1
echo $1 >$2 2>/dev/null
chmod 444 $2 >/dev/null 2>&1
}
60 changes: 60 additions & 0 deletions share/settings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/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
# 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.
#
# Origami Kernel Manager 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 Origami Kernel Manager. If not, see <https://www.gnu.org/licenses/>.
#
# Copyright (C) 2023-2024 Rem01Gaming

execstoredcmd_switch() {
case $(fzf_select "Enable Disable" "Apply previous settings from last session: ") in
Enable) execstoredcmd_db TRUE ;;
Disable) execstoredcmd_db FALSE ;;
esac
}

execstoredcmd_risky_switch() {
case $(fzf_select "Enable Disable" "Allow risky execution: ") in
Enable) execstoredcmd_risky_db TRUE ;;
Disable) execstoredcmd_risky_db FALSE ;;
esac
}

settings_menu() {
while true; do
clear
echo -e "\e[30;48;2;254;228;208;38;2;0;0;0m Origami Kernel Manager ${VERSION}$(yes " " | sed $(($LINE - 30))'q' | tr -d '\n')\033[0m"
echo -e "\e[38;2;254;228;208m"
echo -e " _________ [] Apply previous settings: $(sql_query "SELECT execstoredcmd FROM tb_info;")"
echo -e " / /\\ [] Allow risky execution: $(sql_query "SELECT execstoredcmd_risky FROM tb_info;")"
echo -e " / / \\ "
echo -e " / / \\ "
echo -e "/________/ \\ "
echo -e "\\ \\ / "
echo -e " \\ \\ / "
echo -e " \\ \\ / "
echo -e " \\________\\/ "
echo -e "\n//////////////"
echo -e "$(yes "" | sed ${LINE}'q' | tr -d '\n')\n"
echo -e "[] OKM Settings\033[0m"

# Hide cursor
tput civis

case $(fzy_select "Apply previous settings\nAllow risky execution\nBack to main menu" "") in
"Apply previous settings") execstoredcmd_switch ;;
"Allow risky execution") execstoredcmd_risky_switch ;;
"Back to main menu") break ;;
esac
done
}
Loading

0 comments on commit 5652d16

Please sign in to comment.