User Tools

Site Tools


general:linux:systemd_sleep_script

put script in /lib/systemd/system-sleep

root@asu-laptop:/lib/systemd/system-sleep# cat sleep_switcheroo.sh 
#!/bin/sh

switch=/sys/kernel/debug/vgaswitcheroo/switch

switch_off () {
    if [ -f $switch ]; then
        if ! grep -qE 'DIS:.*Off' $switch; then
            echo -n "Switching off DIS vga ..."
            echo "OFF" > $switch
            if grep -qE 'DIS:.*Off' $switch; then
                echo " done"
            else
                echo " ERROR"
                exit 1
            fi
        fi
    fi
    exit 0
}

switch_on () {
    if [ -f $switch ]; then
        if grep -qE 'DIS:.*Off' $switch; then
            echo -n "Switching on DIS vga ..."
            echo "ON" > $switch
            if ! grep -qE 'DIS:.*Off' $switch; then
                echo " done"
            else
                echo " ERROR"
                exit 1
            fi
        fi
    fi
    exit 0
}

case "$2" in
    suspend|hibernate|hybrid-sleep)
        continue
        ;;
    *)
        echo "no"
        exit 0
        ;;
esac

case "$1" in
    pre)
        switch_on
        ;;
    post)
        switch_off
        ;;
esac
general/linux/systemd_sleep_script.txt · Last modified: 2020/11/17 20:45 by