Created
November 5, 2017 11:51
-
-
Save dwerbam/00a1df2ce4158111299853c8502d1f17 to your computer and use it in GitHub Desktop.
ubuntu change lid action: ignore, suspend, hibernate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root" | |
exit 1 | |
fi | |
replace_var_in_file() { | |
VAR=$1 | |
VALUE=$2 | |
FILENAME=$3 | |
grep -q "^$VAR=" ${FILENAME} && sed -i 's/^$VAR=.*$/$VAR=$VALUE/' $FILENAME || echo "$VAR=$1" >> $FILENAME | |
} | |
PARAM=$1 | |
case $PARAM in | |
ignore | suspend | hibernate ) | |
echo "changing lid to $PARAM" | |
;; | |
*) | |
echo $"Usage: $0 {ignore|suspend|hibernate}" | |
exit 1 | |
esac | |
replace_var_in_file "HandleLidSwitch" $PARAM "/etc/systemd/logind.conf" | |
service systemd-logind restart | |
echo "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment