From d15d45ee1f76e582dd6382713242c7eb54c2f6c7 Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Fri, 20 Mar 2020 17:27:38 +0200 Subject: [PATCH] Add systemd service for ensuring write access --- harbour-batterybuddy.pro | 16 +++++++++++++--- rpm/harbour-batterybuddy.spec | 10 ++++++++++ service/clear-write-permissions.sh | 5 +++++ service/harbour-batterybuddy.service | 13 +++++++++++++ service/set-write-permissions.sh | 5 +++++ 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100755 service/clear-write-permissions.sh create mode 100644 service/harbour-batterybuddy.service create mode 100755 service/set-write-permissions.sh diff --git a/harbour-batterybuddy.pro b/harbour-batterybuddy.pro index c06d837..2fe9355 100644 --- a/harbour-batterybuddy.pro +++ b/harbour-batterybuddy.pro @@ -28,6 +28,9 @@ DISTFILES += qml/harbour-batterybuddy.qml \ qml/cover/CoverPage.qml \ rpm/harbour-batterybuddy.spec \ rpm/harbour-batterybuddy.yaml \ + service/clear-write-permissions.sh \ + service/harbour-batterybuddy.service \ + service/set-write-permissions.sh \ translations/*.ts \ harbour-batterybuddy.desktop \ qml/pages/MainPage.qml \ @@ -42,15 +45,22 @@ SAILFISHAPP_ICONS = 86x86 108x108 128x128 172x172 TRANSLATIONS += translations/*.ts +OTHER_FILES += service/clear-write-permissions.sh \ + service/harbour-batterybuddy.service \ + service/set-write-permissions.sh + +service.files = service +service.path = /usr/share/$${TARGET} + +INSTALLS += service + # Begin: include sound files #OTHER_FILES += sounds/upperLimit.ogg \ # sounds/lowerLimit.ogg \ -#DEPLOYMENT_PATH = /usr/share/$${TARGET} - #sounds.files = sounds -#sounds.path = $${DEPLOYMENT_PATH} +#sounds.path = /usr/share/$${TARGET} #INSTALLS += sounds diff --git a/rpm/harbour-batterybuddy.spec b/rpm/harbour-batterybuddy.spec index e5c7abf..d22f769 100644 --- a/rpm/harbour-batterybuddy.spec +++ b/rpm/harbour-batterybuddy.spec @@ -69,3 +69,13 @@ desktop-file-install --delete-original \ %{_datadir}/icons/hicolor/*/apps/%{name}.png # >> files # << files + +%post +cp %{_datadir}/%{name}/service/harbour-batterybuddy.service /etc/systemd/system/ +chmod 755 %{_datadir}/%{name}/service/*.sh +systemctl disable --now harbour-batterybuddy.service +systemctl enable --now harbour-batterybuddy.service + +%postun +systemctl disable --now harbour-batterybuddy.service +rm /etc/systemd/system/harbour-batterybuddy.service diff --git a/service/clear-write-permissions.sh b/service/clear-write-permissions.sh new file mode 100755 index 0000000..9c9e4f6 --- /dev/null +++ b/service/clear-write-permissions.sh @@ -0,0 +1,5 @@ +#!/bin/bash +chmod 644 /sys/class/power_supply/battery/input_suspend 2>/dev/null +chmod 644 /sys/class/power_supply/battery/charging_enabled 2>/dev/null +chmod 644 /sys/class/power_supply/usb/charger_disable 2>/dev/null +exit 0 diff --git a/service/harbour-batterybuddy.service b/service/harbour-batterybuddy.service new file mode 100644 index 0000000..7f62aea --- /dev/null +++ b/service/harbour-batterybuddy.service @@ -0,0 +1,13 @@ +[Unit] +Description=Allow user nemo to write to charging control file +#After=network.target + +[Service] +Type=oneshot +ExecStart=/usr/share/harbour-batterybuddy/service/set-write-permissions.sh +RemainAfterExit=true +ExecStop=/usr/share/harbour-batterybuddy/service/clear-write-permissions.sh +StandardOutput=journal + +[Install] +WantedBy=multi-user.target diff --git a/service/set-write-permissions.sh b/service/set-write-permissions.sh new file mode 100755 index 0000000..3dd0ca0 --- /dev/null +++ b/service/set-write-permissions.sh @@ -0,0 +1,5 @@ +#!/bin/bash +chmod 666 /sys/class/power_supply/battery/input_suspend 2>/dev/null +chmod 666 /sys/class/power_supply/battery/charging_enabled 2>/dev/null +chmod 666 /sys/class/power_supply/usb/charger_disable 2>/dev/null +exit 0