-
-
Save guiambros/166039459a8579638b57f7d135505ab1 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
set -e | |
# See https://wrgms.com/disable-mouse-battery-low-spam-notification/ | |
# for instructions on how to use it | |
# | |
# TL;DR: run with "--keyboard" if you want to patch upower to ignore both | |
# mice and keyboard notifications (by default it ignores only mice) | |
# Check distro and upower version in use, and install required libraries | |
# | |
echo | |
echo "---------------------------------------------------------------------------" | |
upower --version | |
echo "---------------------------------------------------------------------------" | |
echo | |
UPOWER_ORIG_VER=`upower --version` | |
OS=`awk -F= '/^ID=/{print $2}' /etc/os-release` | |
OS_VER=`awk -F= '/^VERSION_ID=/{print $2}' /etc/os-release | cut -d "\"" -f 2` | |
OS_VER_MAJOR=`echo ${OS_VER} | awk -F. '{print $1}'` | |
PATCH_LEGACY_URL="https://gist.githubusercontent.com/guiambros/f2bf07f1cc085f8f0b0a9e04c0a767b4/raw/73efac967c8fc9539802e7aa8eeba5492f8ae3b1/up-device-legacy.patch" | |
PATCH_CURRENT_URL="https://gist.githubusercontent.com/guiambros/f2bf07f1cc085f8f0b0a9e04c0a767b4/raw/73efac967c8fc9539802e7aa8eeba5492f8ae3b1/up-device-current-0.99.12p.patch" | |
PATCH_NAME="up-device.patch" | |
PATCH_URL=${PATCH_CURRENT_URL} | |
if [ "$OS" == "manjaro" ] | |
then | |
echo "-- Manjaro detected; installing required libraries" | |
sudo pacman -S base-devel gtk-doc gobject-introspection git | |
PATH_UPOWERD="/usr/lib" | |
PATH_UPOWER="/usr/bin" | |
elif [ "$OS" == "ubuntu" ] | |
then | |
echo "-- Ubuntu detected; installing required libraries" | |
sudo apt install -y git gtk-doc-tools gobject-introspection libgudev-1.0-dev libusb-1.0-0-dev autoconf libtool autopoint | |
PATH_UPOWER="/usr/bin" | |
if [ "${OS_VER}" == "20.10" ] | |
then | |
echo "--- Ubuntu version 20.10 (Groovy Gorilla) detected" | |
PATH_UPOWERD="/usr/libexec" | |
UPOWER_BRANCH="UPOWER_0_99_11" | |
PATCH_URL=${PATCH_LEGACY_URL} | |
elif [ ${OS_VER_MAJOR} -ge 21 ] | |
then | |
echo "--- Ubuntu version 21 or above detected" | |
PATH_UPOWERD="/usr/libexec" | |
UPOWER_BRANCH="UPOWER_0_99_11" | |
PATCH_URL=${PATCH_LEGACY_URL} | |
elif [ ${OS_VER_MAJOR} -le 20 ] | |
then | |
echo "--- Ubuntu version 20.04 or lower detected" | |
PATH_UPOWERD="/usr/lib/upower" | |
UPOWER_BRANCH="UPOWER_0_99_11" | |
PATCH_URL=${PATCH_LEGACY_URL} | |
fi | |
else | |
echo "-- Unknown system; this script was only tested on ubuntu and manjaro." | |
exit 1 | |
fi | |
echo "---------------------------------------------------------------------------" | |
echo | |
# Download upowerd source and selects the proper branch | |
# | |
cd ~ | |
git clone https://gitlab.freedesktop.org/upower/upower | |
if [ -z ${UPOWER_BRANCH} ] | |
then | |
echo "-- Using latest master branch (0.99.12 or above)" | |
cd upower/src | |
else | |
echo "-- Using branch ${UPOWER_BRANCH} (latest compatible with your distro)" | |
cd upower | |
git fetch --all --tags | |
git checkout tags/${UPOWER_BRANCH} -b ${UPOWER_BRANCH} | |
cd src | |
fi | |
# Download and patch upowerd | |
# | |
wget ${PATCH_URL} -O ${PATCH_NAME} | |
if [ "$1" == "-keyboard" ] || [ "$1" == "--keyboard" ]; then | |
SILENCE_KEYBOARD="+ if ((type == UP_DEVICE_KIND_MOUSE || type == UP_DEVICE_KIND_KEYBOARD) && state == UP_DEVICE_STATE_DISCHARGING) {" | |
sed -i "/UP_DEVICE_KIND_MOUSE/c${SILENCE_KEYBOARD}" ${PATCH_NAME} | |
fi | |
patch -F 1 < ${PATCH_NAME} | |
# Compile upowerd | |
# | |
cd .. | |
./autogen.sh | |
./configure | |
make | |
# Install upowerd | |
# | |
CUR_DATETIME=`date +%Y-%m-%d-%H%M%S` | |
pushd . | |
cd src/.libs | |
strip upowerd | |
sudo chown root.root upowerd | |
sudo mv upowerd ${PATH_UPOWERD}/upowerd-silent | |
cd ${PATH_UPOWERD} | |
sudo mv upowerd upowerd-original-${CUR_DATETIME} | |
sudo ln -s upowerd-silent upowerd | |
popd | |
# Install upower | |
# | |
pushd . | |
cd tools/.libs | |
strip upower | |
sudo chown root.root upower | |
sudo mv upower ${PATH_UPOWER}/upower-silent | |
cd ${PATH_UPOWER} | |
sudo mv upower upower-original-${CUR_DATETIME} | |
sudo ln -s upower-silent upower | |
popd | |
# Restart upowerd | |
# | |
sudo systemctl restart upower | |
# Compare versions before/after (they will likely be different, but it depends on what your distro packages by default) | |
# | |
echo | |
echo "---------------------------------------------------------------------------" | |
echo "upower version BEFORE the update:" | |
echo "${UPOWER_ORIG_VER}" | |
echo "-------------------------------------" | |
echo "upower version AFTER the update:" | |
upower --version |
Thanks for the script! I ran with:
wget -O - https://gist.githubusercontent.com/guiambros/166039459a8579638b57f7d135505ab1/raw/733b8dd3ac3280bb76f48ba3dc04655df6d69025/silent-mouse.sh | bash
It prints a bunch of commands, detects correctly that I'm on Ubuntu 18, but then it seems to run into a upower
error. I've pasted the last few lines of the command line.
make[3]: Leaving directory '/home/seita/upower/po'
test ! -f ./upower.pot || \
test -z "fr.gmo it.gmo sv.gmo pl.gmo" || make fr.gmo it.gmo sv.gmo pl.gmo
make[3]: Entering directory '/home/seita/upower/po'
rm -f fr.gmo && /usr/bin/msgfmt -c --statistics --verbose -o fr.gmo fr.po
fr.po:7: warning: header field 'Language' missing in header
fr.po: 26 translated messages.
rm -f it.gmo && /usr/bin/msgfmt -c --statistics --verbose -o it.gmo it.po
it.po:8: warning: header field 'Language' missing in header
it.po: 19 translated messages.
rm -f sv.gmo && /usr/bin/msgfmt -c --statistics --verbose -o sv.gmo sv.po
sv.po:7: warning: header field 'Language' missing in header
sv.po: 19 translated messages.
rm -f pl.gmo && /usr/bin/msgfmt -c --statistics --verbose -o pl.gmo pl.po
pl.po:5: warning: header field 'Language' missing in header
pl.po: 26 translated messages.
make[3]: Leaving directory '/home/seita/upower/po'
touch stamp-po
make[2]: Leaving directory '/home/seita/upower/po'
Making all in rules
make[2]: Entering directory '/home/seita/upower/rules'
GEN .gitignore
make[2]: Leaving directory '/home/seita/upower/rules'
make[2]: Entering directory '/home/seita/upower'
make[2]: Leaving directory '/home/seita/upower'
make[1]: Leaving directory '/home/seita/upower'
~/upower ~/upower
~/upower
~/upower ~/upower
~/upower
---------------------------------------------------------------------------
upower version BEFORE the update:
UPower client version 0.99.7
UPower daemon version 0.99.7
-------------------------------------
upower version AFTER the update:
upower: symbol lookup error: upower: undefined symbol: up_client_get_devices2
seita@starship:~ $
Is this error critical?
Thanks for your work on this.
I have ubuntu 20.04 and ran the script but got stuck in some dependencies, specifically:
The following packages have unmet dependencies:
gobject-introspection : Depends: libgirepository-1.0-1 (= 1.64.0-2) but 1.64.1-1~ubuntu20.04.1 is to be installed
I already had gobject-introspection installed, version 1.64.1-1~ubuntu20.04.1. (despite the above message) so
I downgraded the libgirepository-1.0-1 package from 1.64.1-1~ubuntu20.04.1 to v 1.64.0-2; ran the script again and it worked.
@skorasaurus -- thanks for sharing your experience!
This thread is quite old at this point. I'm also using 20.04, and haven't had to mess with upowerd for a while. Curious if you were still experiencing it.
It seems the frequent notifications were fixed upstream in gnome-settings-daemon. I haven't tracked the exact changes in gsd, but at least I haven't seen it nearly as frequently as before.
The folks from upower argue the issue should be fixed upstream (in this case gnome-settings-daemon).
@guiambros I still experience this issue, with marathon mouse/performance plus m705 on Ubuntu 23.10 with gnome 45.0, I also encountered this issue on Ubuntu 23.04 with gnome 44.
At this point, I was seeing this (or similar, I think at the beginning it was yellow, not orange) message for three months:
It appears on the login screen and after logging in despite "Do Not Disturb" turned on. It stays on the screen till I click on it.
I tested this script in Pop!_OS 21.10 and it works well, for those who were wondering. I changed
ubuntu
in line 35 topop
to make it work.