Skip to content

Instantly share code, notes, and snippets.

@dwerbam
Created November 5, 2017 11:51
Show Gist options
  • Save dwerbam/00a1df2ce4158111299853c8502d1f17 to your computer and use it in GitHub Desktop.
Save dwerbam/00a1df2ce4158111299853c8502d1f17 to your computer and use it in GitHub Desktop.
ubuntu change lid action: ignore, suspend, hibernate
#!/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