#!/bin/sh # v6.3 # Copyright © 2025 Stouthart. All rights reserved. { # shellcheck disable=SC3028 case "$HOSTNAME" in DX340 | DX180) ;; *) echo 'Your device is not compatible with this version.' >&2 exit 1 ;; esac url=https://raw.githubusercontent.com/Stouthart/DX340/refs/heads/main/custom.rc file=/etc/init/${url##*/} [ -w "${file%/*}" ] || { echo 'Read-only file system. Try "adb remount" first.' >&2 exit 1 } echo '[ Advanced Tweaking ]' echo "> Downloading template..." curl -sSfo "$file" $url || { echo 'Failed to download template.' >&2 exit 2 } chmod 0644 "$file" chcon u:object_r:system_file:s0 "$file" # Helper functions _replace() { sed -i "s,### $1\$,$2," "$file" } _execbkg() { _replace "$1" "exec_background -- /bin/sh -c \"sleep 2; $2\"" } _minfreq() { _execbkg minfreq "echo $1 >/sys/devices/system/cpu/cpufreq/policy4/scaling_min_freq" } _sedregx() { sed -i -E "s,($1) [0-9]+$,\1 $2," "$file" } _stboost() { _sedregx "stune/${1}schedtune.boost" "$2" } # Performance/power modes if [ "${pmax:-0}" -eq 1 ]; then echo '> Applying "Performance MAX"...' _replace tmrmig 'write /proc/sys/kernel/timer_migration 0' _minfreq 1401600 _stboost '' 20 _stboost foreground/ 30 _stboost top-app/ 40 # Scheduler tuning by Whitigir elif [ "${psave:-0}" -eq 1 ]; then echo '> Applying "Power SAVE"...' _minfreq 652800 _stboost '' 8 _stboost foreground/ 12 fi # RAM tuning awk '/MemTotal/ { exit ($2 <= 4194304) }' /proc/meminfo && { echo '> Tuning for > 4GB RAM...' _sedregx sda/queue/nr_requests 256 _execbkg tdswap 'echo 10 >/proc/sys/vm/swappiness' [ "${nozram:-0}" -eq 1 ] && { echo '> Disabling zRAM...' _execbkg nozram 'swapoff /dev/block/zram0; echo 1 >/sys/block/zram0/reset' } } # Debugging & testing [ -x /etc/rc.local ] && _execbkg rclocal /etc/rc.local echo '> Final cleanup & tweaks' sed -i -E 's,### [a-z]+$,# N/A,g' "$file" # Reduce logging (logcat) & tracing (perfetto.rc) setprop persist.log.tag W # I setprop persist.traced.enable 0 # 1 echo '> Done!' [ "${noboot:-0}" -eq 1 ] || { echo "> Rebooting..." reboot } }