バージョン1

バージョン1

バージョン1

以下のバージョン2に直接進んでください。

Debianではフォローしていますこのガイドノートブックカバーを閉じるときの動作を定義します。

だから、次のように修正しました。

#!/bin/sh

# Disable sleep on lead (do noting)
echo 'HandleLidSwitch=ignore' | tee --append /etc/systemd/logind.conf
echo 'HandleLidSwitchDocked=ignore' | tee --append /etc/systemd/logind.conf
sudo service systemd-logind restart


# Disable screen on lid close/etc/acpi/events
mkdir -r /etc/acpi/events
echo 'event=button/lid.*' | tee --append /etc/acpi/events/lm_lid
echo 'action=/etc/acpi/lid.sh' | tee --append /etc/acpi/events/lm_lid
# The lid.sh should be in the same directory
mv ./lid.sh /etc/acpi/lid.sh
chmod +x /etc/acpi/lid.sh

# Restarting service to take effect
/etc/init.d/acpid restart

/etc/acpi/lid.sh次に、デフォルトの動作の代わりにキャップを閉じるたびにアクティブになるアクションを作成します。

lid.shこれはこれです:

#!/bin/bash
#
# Lid closing event script


grep -q close /proc/acpi/button/lid/*/state
if [ $? = 0 ]; then
        echo close>>/tmp/screen.lid
     # main user
    USER=fauve
    # Remaining percent of battry
    REMAININGBAT=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep percentage | sed "s/ *percentage: *\(.*\)%/\1/")

    # Test battry remaining percentage
    if [ $REMAININGBAT -gt 10 ]; then
        # If the percentage is higher than 10
        TIMEBEFORELOCK="1m"
        TIMEBEFORESUSPENSION="9m"
        TIMEBEFORESHUTDOWN="5 minutes"
    else
        # If the percentage is less than 10
        TIMEBEFORELOCK="1m"
        TIMEBEFORESUSPENSION="2m"
        TIMEBEFORESHUTDOWN="4 minutes"
    fi

    # Do noting a ${TIMEBEFORELOCK} time
    # In case if a quick shifting from a room to another
    echo "$(date): Waiting ${TIMEBEFORELOCK} before lock"
    sleep ${TIMEBEFORELOCK}

    # set screensaver for ${TIMEBEFORESUSPENSION} time
    echo "$(date): Lock now"
    su -c  "DISPLAY=:0.0 /home/$USER/.local/bin/screenlock" - $USER &
    echo "$(date): Waiting ${TIMEBEFORESUSPENSION} before suspension"
    sleep ${TIMEBEFORESUSPENSION}

    # Set a wake up at given time
    echo "$(date): Seting time before waking up to ${TIMEBEFORESHUTDOWN}"
    echo `date '+%s' -d "+ ${TIMEBEFORESHUTDOWN}"` > /sys/class/rtc/rtc0/wakealarm

    # Suspend for ${TIMEBEFORESHUTDOWN} time
    echo "$(date): Starting suspention for ${TIMEBEFORESHUTDOWN}"
    systemctl suspend
    echo "$(date): Wake up"

    # Wait 5s to ensure the next command will take effect
    sleep 5s

    # shutdown
    #echo "$(date): Shutdown"
    #shutdown +0
fi
grep -q open /proc/acpi/button/lid/*/state
if [ $? = 0 ]; then
    echo open>>/tmp/screen.lid
fi

このスクリプトは、カバーを開かない限り実行され続けます。ただし、蓋が開いたら中断する必要があります(最後の行にまだ達していない場合)。

それでは、蓋が開いたときにACPI割り込みをどのように作成できますか?


バージョン2

だから私は次のようにスクリプトを更新しました。

#!/bin/bash
#
# Lid closing event script

PIDFILE=/tmp/lidpid

grep -q close /proc/acpi/button/lid/*/state
if [ $? = 0 ]; then
    echo $$ > $PIDFILE
    echo "$(date) close">>/tmp/screen.lid
     # main user
    USER=fauve
    # Remaining percent of battry
    REMAININGBAT=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep percentage | sed "s/ *percentage: *\(.*\)%/\1/")

    # Test battry remaining percentage
    if [ $REMAININGBAT -gt 10 ]; then
        # If the percentage is higher than 10
        TIMEBEFORELOCK="1m"
        TIMEBEFORESUSPENSION="9m"
        TIMEBEFORESHUTDOWN="5 minutes"
    else
        # If the percentage is less than 10
        TIMEBEFORELOCK="1m"
        TIMEBEFORESUSPENSION="2m"
        TIMEBEFORESHUTDOWN="4 minutes"
    fi

    # Do noting a ${TIMEBEFORELOCK} time
    # In case if a quick shifting from a room to another
    echo "$(date): Waiting ${TIMEBEFORELOCK} before lock"
    sleep ${TIMEBEFORELOCK}

    # set screensaver for ${TIMEBEFORESUSPENSION} time
    echo "$(date): Lock now"
    su -c  "DISPLAY=:0.0 /home/$USER/.local/bin/screenlock" - $USER &
    echo "$(date): Waiting ${TIMEBEFORESUSPENSION} before suspension"
    sleep ${TIMEBEFORESUSPENSION}

    # Set a wake up at given time
    echo "$(date): Seting time before waking up to ${TIMEBEFORESHUTDOWN}"
    echo `date '+%s' -d "+ ${TIMEBEFORESHUTDOWN}"` > /sys/class/rtc/rtc0/wakealarm

    # Suspend for ${TIMEBEFORESHUTDOWN} time
    echo "$(date): Starting suspention for ${TIMEBEFORESHUTDOWN}"
    systemctl suspend
    echo "$(date): Wake up"

    # Wait 5s to ensure the next command will take effect
    sleep 5s

    echo "Going to shutdown"
    # shutdown
    #echo "$(date): Shutdown"
    shutdown +0
fi


# Wait 5s to ensure the next command will take effect
sleep 5s
grep -q open /proc/acpi/button/lid/*/state
if [ $? = 0 ]; then
    echo "$(date) open">>/tmp/screen.lid
    if [ -e $PIDFILE ] ; then
        kill -9 $(cat $PIDFILE)
    fi
fi

しかし、今の問題は、ACPIがカバーが開いているかどうかを検出するのが難しいことです。ふたを閉じて開けると/tmp/screen.lid「閉じる」と表示されますが、「開く」とは表示されません。 「open」フラグは後で表示され、ランダムに表示されます。

ベストアンサー1

さて、スクリプトにはいくつかの問題があります。

私が見た最初の問題は、ガイドのように/proc/acpi/button/lid/*/stateでカバーの状態を確認しないことです。開いたり閉じたりするときにスクリプトが実行されるため、直接スキャンを追加する必要があります。

次に、カバーが開いたときにすでに実行されているスクリプトインスタンスを停止するメカニズムが必要です。

おすすめ記事