summarylogtreecommitdiffstats
path: root/lenovo-ice-mode
blob: 5fdf1f792d207f8a8f8a93eee97f1353970e7a4e (plain)
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
#!/bin/bash
#Script to apply desired Lenovo bios System Cooling mode using acpi_call

clrarr=( "$(tput bold ; tput setaf 5)" "$(tput bold ; tput setaf 6)" "$(tput bold ; tput setaf 4)" "$(tput bold ; tput setaf 1)" "$(tput setab 5 ; tput bold ; tput setaf 6)" "$(tput setab 1)" "$(tput sgr0)" )
pnk=0 ; lcn=1 ; lbl=2 ; lrd=3 ; purbg=4 ; redbg=5 ; noc=6  #no color

if [ -a /proc/acpi/call ]; then
    curcoolmode() {
        echo '\_SB.PCI0.LPC0.EC0.FCMO' > /proc/acpi/call
        cat /proc/acpi/call | cut -d '' -f1
    }

    hcoolmodearr=( "${clrarr[$pnk]}Intelligent Cooling${clrarr[$noc]}" "${clrarr[$lrd]}Extreme Performance${clrarr[$noc]}" "${clrarr[$lcn]}Battery Saving${clrarr[$noc]}" )
    hcoolmodei=0 ; hcoolmodep=1 ; hcoolmodeb=2

    modepusharr=( "0x000FB001" "0x0012B001" "0x0013B001" )
    modepushi=0 ; modepushp=1 ; modepushb=2

    noticetext="${clrarr[$purbg]}Notice:${clrarr[$noc]}"

    helptext="$hcurrmode \n$noticetext ${clrarr[$lbl]}Provide a case insensitive option to set system cooling mode:\n\n ${clrarr[$pnk]}[-i${clrarr[$pnk]}] ${clrarr[$lbl]}for "${hcoolmodearr[$hcoolmodei]}" \n ${clrarr[$lrd]}[-p${clrarr[$lrd]}] ${clrarr[$lbl]}for "${hcoolmodearr[$hcoolmodep]}" \n ${clrarr[$lcn]}[-b${clrarr[$lcn]}] ${clrarr[$lbl]}for "${hcoolmodearr[$hcoolmodeb]}" ${clrarr[$noc]} \n "

    case `curcoolmode` in
        0x0)
            coolmodei="${hcoolmodearr[$hcoolmodei]}"
            coolmode="$coolmodei"
            ;;
        0x1)
            coolmodep="${hcoolmodearr[$hcoolmodep]}"
            coolmode="$coolmodep"
            ;;
        0x2)
            coolmodeb="${hcoolmodearr[$hcoolmodeb]}"
            coolmode="$coolmodeb"
            ;;
    esac

    hcurrmode="\n$noticetext ${clrarr[$lbl]}Current cooling mode is set as $coolmode ${clrarr[$noc]}\n"

    [ $# -eq 0 ] && { echo -e "$hcurrmode"; echo -e "$helptext"; exit 1; }

    while getopts ':[iI][pP][bB]' optgiv
    do
        case "$optgiv" in
            [iI] )
                modepush="${modepusharr[$modepushi]}"
                hmodepush="${hcoolmodearr[$hcoolmodei]}"
                ;;
            [pP] )
                modepush="${modepusharr[$modepushp]}"
                hmodepush="${hcoolmodearr[$hcoolmodep]}"
                ;;
            [bB] )
                modepush="${modepusharr[$modepushb]}"
                hmodepush="${hcoolmodearr[$hcoolmodeb]}"
                ;;
            \? )
                echo -e "$hcurrmode"
                echo -e "$helptext"
                exit;;
        esac

        echo "\_SB.PCI0.LPC0.EC0.VPC0.DYTC $modepush" > /proc/acpi/call
        echo -e "\n$noticetext ${clrarr[$lbl]}Successfully updated system cooling from $coolmode ${clrarr[$lbl]}to $hmodepush ${clrarr[$lbl]}mode.${clrarr[$noc]}\n"
        exit
    done
else
    echo -e "\n${clrarr[$redbg]}ERROR: No /proc/acpi/call found! Please make sure acpi_call is installed and has been modprobed. ${clrarr[$noc]}\n"
fi