• # petit fix

    Posté par . En réponse au journal Petit script pour gerer cpu_freq au demarrage de mon laptop.. Évalué à 1.

    Cette version fixe une petite erreur. En effet, Lorsque la batterie n'est pas inseré, la variable $CHARGING_STATE se retrouvait vide et donc le if renvoyait une erreur concernant les arguments.

    version corrigée :


    #!/bin/sh
    #
    ###############################################################################
    # Copyright (C) 2005 Francois COJEAN

    # This program 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 2
    # of the License, or (at your option) any later version.

    # This program 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 this program; if not, write to the Free Software
    # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
    ###############################################################################

    # This script tests if a battery is plugged or not, set
    # the cpufreq scaling_governor depending on the state of the battery, and
    # the trip_points file to avoid the "critical temperature reached" error.
    # Note : this script need to be run as root.

    # Set up the different variables
    # Edit all this variable to value which fit to your computer

    BATTERY_NAME="BAT0"
    BATTERY_ACPI_PATH="/proc/acpi/battery"
    BATTERY_STATE_FILE="state"
    POWERSAVE_SCALING_GOVERNOR="powersave"
    CONSERVATIVE_SCALING_GOVERNOR="conservative"
    CPU_FREQ_PATH="/sys/devices/system/cpu/cpu0/cpufreq"
    SCALING_GOVERNOR_FILE="scaling_governor"
    TEMPERATURE_ACPI_PATH="/proc/acpi/thermal_zone/THRS"
    TEMPERATURE_TRIP_POINTS_FILE="trip_points"
    # Becarefull, choose special values related to your processor.
    # The value are organised like that :
    # critical:hot:passive:active0:...:activeX
    # where critical, hot, passive, active0..x is a value in Celsius for the
    # corresponding trip point. x is between 0 and 9 and depends on your
    # platform.
    # See : http://acpi.sourceforge.net/documentation/thermal.html
    TEMPERATURE_VALUE="95:0:75:0:0"


    # Get the state of the battery
    PRESENT="`cat $BATTERY_ACPI_PATH/$BATTERY_NAME/$BATTERY_STATE_FILE | grep present: | cut -f2 -d:`"

    if [ $PRESENT = "yes" ]; then
    CHARGING_STATE="`cat $BATTERY_ACPI_PATH/$BATTERY_NAME/$BATTERY_STATE_FILE | grep "charging state:" | cut -f2 -d:`"
    else
    CHARGING_STATE="empty"
    fi

    # Check the state of the battery
    if [ $PRESENT = "yes" -a $CHARGING_STATE = "discharging" ]; then
    # Set cpu_freq scaling_governor to powersave.
    # This command need to be run as root.
    echo "$POWERSAVE_SCALING_GOVERNOR" > $CPU_FREQ_PATH/$SCALING_GOVERNOR_FILE
    echo "CPU_FREQ : $POWERSAVE_SCALING_GOVERNOR enable"
    else
    # Set cpu_freq scaling_governor to conservative.
    # This command need to be run as root.
    echo "$CONSERVATIVE_SCALING_GOVERNOR" > $CPU_FREQ_PATH/$SCALING_GOVERNOR_FILE
    echo "CPU_FREQ : $CONSERVATIVE_SCALING_GOVERNOR enable"
    fi

    # Modification of the critical temperature value
    # This command need to be run as root.
    echo -n "$TEMPERATURE_VALUE" > $TEMPERATURE_ACPI_PATH/$TEMPERATURE_TRIP_POINTS_FILE
    echo "ACPI : trip_points change to $TEMPERATURE_VALUE"