From afd6bee7c03d7635130a4e2e82a9444f4973efe1 Mon Sep 17 00:00:00 2001 From: sakrecoer Date: Wed, 20 Nov 2024 16:35:57 +0100 Subject: [PATCH] add battery control for syncthing --- lowbat.sh | 10 ++++++++++ onbat.sh | 10 ++++++++++ onpower.sh | 14 ++++++++++++++ 3 files changed, 34 insertions(+) create mode 100755 lowbat.sh create mode 100755 onbat.sh create mode 100755 onpower.sh diff --git a/lowbat.sh b/lowbat.sh new file mode 100755 index 0000000..b8808e9 --- /dev/null +++ b/lowbat.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +SERVICE="syncthing" +if pgrep -x "$SERVICE" >/dev/null +then + ## notify user that syncthing is stopping + notify-send -a $SERVICE -h "string:desktop-entry:org.kde.konsole" "Lowbatts, terminating $SERVICE to save power." "Recharge before using $SERVICE." --icon=dialog-information + ## kill syncthing + syncthing cli operations shutdown +fi diff --git a/onbat.sh b/onbat.sh new file mode 100755 index 0000000..6710e5b --- /dev/null +++ b/onbat.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +SERVICE="syncthing" +if pgrep -x "$SERVICE" >/dev/null +then + ## notify user that syncthing is stopping + notify-send -a $SERVICE -h "string:desktop-entry:org.kde.konsole" "Terminating to save power." "Restart manually if you need $SERVICE." --icon=dialog-information + ## kill syncthing + syncthing cli operations shutdown +fi diff --git a/onpower.sh b/onpower.sh new file mode 100755 index 0000000..232581d --- /dev/null +++ b/onpower.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +SERVICE="syncthing" +if pgrep -x "$SERVICE" >/dev/null +then + notify-send -a $SERVICE -h "string:desktop-entry:org.kde.konsole" "We're already up and running" --icon=dialog-information + +else + ## notify user that syncthing is restarting + notify-send -a $SERVICE -h "string:desktop-entry:org.kde.konsole" "Starting up because power is back!" --icon=dialog-information + ## start syncthing + /usr/bin/syncthing serve --no-browser --logfile=default +fi +