File: setDefaultTrippoints.sh

package info (click to toggle)
powersave 0.14.0-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,764 kB
  • ctags: 999
  • sloc: sh: 11,357; cpp: 8,103; ansic: 2,631; makefile: 388
file content (94 lines) | stat: -rw-r--r-- 2,341 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
#
# what does this script do?
#
#set -x

usage(){
    echo "SetDefaultTrippoints [CONFIG_FILE]"
}

set_trip_points(){
    local FILE="$1"

    grep "THERMAL_TRIP_POINTS AUTOMATICALLY CREATED - DO NOT EDIT THIS LINE" $FILE >/dev/null
    if [ $? -eq 0 ];then
	# Trip points already written
	return
    fi
    
    echo $'\n' >> $FILE
    echo "## Path:		System/Powermanagement/Powersave/Thermal"$'\n'\
"## Type:		integer(0:150)"$'\n'\
"#"$'\n'\
"# THERMAL_TRIP_POINTS AUTOMATICALLY CREATED - DO NOT EDIT THIS LINE"$'\n'\
"# Set trip points for critical, hot, passive and active limits"$'\n'\
"# also see the ENABLE_THERMAL_MANAGEMENT variable in the thermal file"$'\n'\
"# to activate these settings. Per default only thermal zones that define"$'\n'\
"# a passive trip point are managed with these settings."$'\n'\
"# The intitial default values are exported from BIOS."$'\n' >>$FILE


    n=0
    for x in `sed -n -e 's/^Critical: \([0-9]\+\)/\1/p' < <(cat $THERMAL_TRIPPOINTS_FILE)`; do
        echo "THERMAL_CRITICAL_$n=\"$x\"" >> $FILE
        n=$(($n+1))
    done

    n=0
    for x in `sed -n -e 's/^Hot: \([0-9]\+\)/\1/p' < <(cat $THERMAL_TRIPPOINTS_FILE)`; do
        echo "THERMAL_HOT_$n=\"$x\"" >> $FILE
        n=$(($n+1))
    done

    n=0
    for x in `sed -n -e 's/^Passive: \([0-9]\+\)/\1/p' < <(cat $THERMAL_TRIPPOINTS_FILE)`; do
        echo "THERMAL_PASSIVE_$n=\"$x\"" >> $FILE
        n=$(($n+1))
    done
}

if [ $# -gt 1 ];then
    echo usage
    exit 1
fi

CONFIG_FILE=""

if [ -n "$1" ];then
    if [ -w "$1" ];then
	CONFIG_FILE="$1"
    else
	echo "Cannot access config file $1"
	exit 1
    fi
fi

if [ -d /dev/shm ] && [ -w /dev/shm ] && [ -x /dev/shm ];then
    THERMAL_TRIPPOINTS_FILE="/dev/shm/thermal_trippoints_file"
    /usr/local/bin/powersave -T > $THERMAL_TRIPPOINTS_FILE
    if [ $? != 0 ];then
	exit 1
    fi
elif [ -d /tmp ] && [ -w /tmp ] && [ -x /tmp ];then
    THERMAL_TRIPPOINTS_FILE="/tmp/thermal_trippoints_file"
    /usr/local/bin/powersave -T > $THERMAL_TRIPPOINTS_FILE
    if [ $? != 0 ];then
	exit 1
    fi
else
    # No temp directory
    return
fi

if [ "$CONFIG_FILE" = "" ];then
    for y in /usr/local/etc/powersave/scheme_*; do
	if [ ! -w "$y" ];then
	    echo "Cannot access config file $y"
	    exit 1
	fi
	set_trip_points $y
    done
else
    set_trip_points $CONFIG_FILE
fi