#StackBounty: Ubuntu Mate pernament CPU governor state?

Bounty: 50

I’m changing Rpi3 with Ubuntu Mate governor on user login to ‘performance’ but it seems like the kernel is changing the state back to original value after some time (ALSO THE 7″ LCD SCREEN BRIGHTNESS).

How do I save my changes I set up at login to stay permanent (until next reboot)?

I could make this script run as service and check the value and adjust, but let’s try not going that route.

I’m pretty sure It’s not the script fault, but take a look:

#!/bin/bash

file='/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor'

init_file_read() {
    if [ $# -eq 2 ]; then
        file="$1"
        line="$2"

        if init_file_check "$file"; then
            echo "$(sed -n ${line}p $file)"
        fi
    fi
}

init_file_write() {
    if [ $# -eq 3 ]; then
        action="$1"
        file="$2"
        string="$3"

        if init_file_check "$file"; then
            # append
            if [ "$action" == "append" ]; then
                echo -e $(printf '%q' "$string") >> "$file"
            fi

            if [ "$action" == "write" ]; then
                echo -e $(printf '%q' "$string") > "$file"
            fi
        fi
    fi
}

init_file_check() { 
    if [ $# -eq 1 ]; then
        if [ -f "$1" ]; then
            return 0 # true
        fi

        return 1 # false
    fi

    return 1 # false
}

content="$( init_file_read "$file" 1 )"

if [ "$content" == "performance" ]; then
    echo "Performance on: performance"
else
    echo "Changing governor to: performance"

    init_file_write 'write' "$file" "performance"
fi

exit 0


Get this bounty!!!

Leave a Reply