[FYT Android Head Units] surfer63:
Really impressive script.

I made a few adaptations to the program flow, please have look but you as builder have the final verdict of course.

I separated the "chaining" of functions and changed two

"if [...] || [...]"

to

"if ! [...] && ! [...]"

#!/system/bin/sh

maxfreq=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq`
cpuinfo_cur_freq=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq`

log -t GTX "Welcome to GTX ROM"

#### Define all functions ####
network() {
log -t GTX "Enable ADB and restart service"
setprop service.adb.root 1
setprop service.adb.tcp.port 5555
stop adbd
start adbd

log -t GTX "Setting eth0 to 192.168.65.100 and raise interface"
/system/bin/busybox ifconfig eth0 192.168.65.100
}

mcud() {
log -t GTX "Launching MCUD"
/system/vendor/bin/mcud &
}

preboot_clock() {
log -t GTX "Setting preboot scaling governor to performance"
echo performance | tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

if [ "$maxfreq" == "1200000" ];
then
log -t GTX "Set CPU Scaling Max Frequency to 1200000";
echo 1200000 | tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
echo 1200000 | tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
elif [ "$maxfreq" == "1040000" ];
then
log -t GTX "Set CPU Scaling Max Frequency to 1040000";
echo 1040000 | tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
echo 1040000 | tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
fi

if ! [ "$cpuinfo_cur_freq" == "1040000" ] && ! [ "$cpuinfo_cur_freq" == "1200000" ]
then
sleep 0.2
preboot_clock
fi
}

initialize() {
log -t GTX "Stop uneeded debug services"
/system/bin/stop-services.sh &

log -t GTX "Clearing formatesystem! bootloader flag"

printf '\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00' | busybox dd of=/dev/block/mmcblk0p13 bs=1 seek=1051648 count=16 conv=notrunc
printf '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' | busybox dd of=/dev/block/mmcblk0p13 bs=1 seek=1051664 count=16 conv=notrunc

log -t GTX "Clearing upgrade flag"
rm -f /data/.gtx_upgrade

if [ ! -e "/data/.gtx_first_boot" ]; then
log -t GTX "First Boot = True"
/system/bin/first-boot.sh &
touch /data/.gtx_first_boot
else
log -t GTX "First Boot = False"
fi

log -t GTX "Launch SU daemon"
/system/xbin/su --daemon &
}

animation() {
if [ "`getprop init.svc.bootanim`" != "stopped" ]; then
sleep 0.2
#log -t GTX "Animation still running... waiting."
animation
else
log -t GTX "Stage 1 Boot Complete"

log -t GTX "Fake battery level to 100% and full status"
dumpsys battery set status 5 &
dumpsys battery set level 100 &

log -t GTX "Disable low memory killer"
echo '1' > /sys/module/lowmemorykiller/parameters/minfree
echo '9999' > /sys/module/lowmemorykiller/parameters/adj

log -t GTX "Setting scaling governor to interactive"
echo interactive | tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
log -t GTX "Setting interactive governor option go_highspeed_load"
echo 80 | tee /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load
log -t GTX "Setting max performance level for Mali GPU"
echo 4 | tee /sys/devices/soc0/e0000000.noc/ef010000.l2_noc/e2000000.ahb_per/e2e00000.gpu/pm_max_state
fi
}

clock_max() {

if [ "$maxfreq" == "1200000" ];
then
log -t GTX "Set CPU Scaling Max Frequency to 1200000";
echo 416000 | tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
echo 1200000 | tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
elif [ "$maxfreq" == "1040000" ];
log -t GTX "Set CPU Scaling Max Frequency to 1040000";
echo 416000 | tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
echo 1040000 | tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
fi

if ! [ "$cpuinfo_cur_freq" == "1040000" ] && ! [ "$cpuinfo_cur_freq" == "1200000" ];
then
sleep 0.2
clock_max
fi
}

boot_detect() {
##at this point, we are at the desktop, usable, not waiting for anything else.
if [ "`logcat -d -s us | grep -oh "action : android.intent.action.BOOT_COMPLETED"`" == "action : android.intent.action.BOOT_COMPLETED" ];
then
log -t GTX "Stopping MCUd"
killall -9 mcud

##no need ro re-init sofia server anymore with new MCUd
#log -t GTX "Restart sofia-server"
#pkill com.syu.ms

log -t GTX "Clearing multnoboot property"
rm -f /data/property/persist.sys.multnoboot

log -t GTX "GTX/BOOT_COMPLETED"
exit 0
else
sleep 0.2
boot_detect
fi
}
#### End of functions definition ####

#### main ####
# This is where the script starts executing and the functions get kicked off

network
mcud
preboot_clock
initialize
animation
clock_max
boot_detect