From da048feb5670dd22bb5b48546f1fa94178919823 Mon Sep 17 00:00:00 2001 From: Rouven Spreckels Date: Fri, 7 Jun 2019 13:29:40 +0200 Subject: [PATCH] Add generic Makefile. --- Makefile | 48 ------------ README.md | 24 +----- common.mk | 34 ++++++++ .gitignore => debian/.gitignore | 4 + debian/Makefile | 77 +++++++++++++++++++ debian/README.md | 27 +++++++ .../huawei-wmi-0.1.0}/debian/changelog | 0 .../huawei-wmi-0.1.0}/debian/compat | 0 .../huawei-wmi-0.1.0}/debian/config | 0 .../huawei-wmi-0.1.0}/debian/control | 0 .../huawei-wmi-0.1.0}/debian/copyright | 0 .../debian/huawei-wmi.lintian-overrides | 0 .../huawei-wmi-0.1.0}/debian/install | 0 .../huawei-wmi-0.1.0}/debian/po/POTFILES.in | 0 .../huawei-wmi-0.1.0}/debian/po/templates.pot | 0 .../huawei-wmi-0.1.0}/debian/postinst | 0 .../huawei-wmi-0.1.0}/debian/prerm | 0 .../huawei-wmi-0.1.0}/debian/rules | 0 .../huawei-wmi-0.1.0}/debian/source/format | 0 .../huawei-wmi-0.1.0}/debian/templates | 0 generic/.gitignore | 1 + generic/Makefile | 67 ++++++++++++++++ generic/README.md | 15 ++++ .../huawei-wmi-0.1.0}/10-huawei-wmi.rules | 0 .../huawei-wmi-0.1.0}/README.md | 0 .../huawei-wmi-privilege.service | 0 .../huawei-wmi-reinstate.service | 0 27 files changed, 229 insertions(+), 68 deletions(-) delete mode 100644 Makefile create mode 100644 common.mk rename .gitignore => debian/.gitignore (64%) create mode 100644 debian/Makefile create mode 100644 debian/README.md rename {huawei-wmi-0.1.0 => debian/huawei-wmi-0.1.0}/debian/changelog (100%) rename {huawei-wmi-0.1.0 => debian/huawei-wmi-0.1.0}/debian/compat (100%) rename {huawei-wmi-0.1.0 => debian/huawei-wmi-0.1.0}/debian/config (100%) rename {huawei-wmi-0.1.0 => debian/huawei-wmi-0.1.0}/debian/control (100%) rename {huawei-wmi-0.1.0 => debian/huawei-wmi-0.1.0}/debian/copyright (100%) rename {huawei-wmi-0.1.0 => debian/huawei-wmi-0.1.0}/debian/huawei-wmi.lintian-overrides (100%) rename {huawei-wmi-0.1.0 => debian/huawei-wmi-0.1.0}/debian/install (100%) rename {huawei-wmi-0.1.0 => debian/huawei-wmi-0.1.0}/debian/po/POTFILES.in (100%) rename {huawei-wmi-0.1.0 => debian/huawei-wmi-0.1.0}/debian/po/templates.pot (100%) rename {huawei-wmi-0.1.0 => debian/huawei-wmi-0.1.0}/debian/postinst (100%) rename {huawei-wmi-0.1.0 => debian/huawei-wmi-0.1.0}/debian/prerm (100%) rename {huawei-wmi-0.1.0 => debian/huawei-wmi-0.1.0}/debian/rules (100%) rename {huawei-wmi-0.1.0 => debian/huawei-wmi-0.1.0}/debian/source/format (100%) rename {huawei-wmi-0.1.0 => debian/huawei-wmi-0.1.0}/debian/templates (100%) create mode 100644 generic/.gitignore create mode 100644 generic/Makefile create mode 100644 generic/README.md rename {huawei-wmi-0.1.0 => generic/huawei-wmi-0.1.0}/10-huawei-wmi.rules (100%) rename {huawei-wmi-0.1.0 => generic/huawei-wmi-0.1.0}/README.md (100%) rename {huawei-wmi-0.1.0/debian => generic/huawei-wmi-0.1.0}/huawei-wmi-privilege.service (100%) rename {huawei-wmi-0.1.0/debian => generic/huawei-wmi-0.1.0}/huawei-wmi-reinstate.service (100%) diff --git a/Makefile b/Makefile deleted file mode 100644 index 873af51..0000000 --- a/Makefile +++ /dev/null @@ -1,48 +0,0 @@ -PKG := huawei-wmi -VER := 0.1.0 -SRC := $(PKG)-$(VER)/ -DSC := $(PKG)_$(VER).dsc -DEB := $(PKG)_$(VER)_all.deb - -.PHONY: all -all: $(DEB) - -.PHONY: install -install: $(DEB) - dpkg --install $(DEB) - -.PHONY: remove -remove: - dpkg --remove $(PKG) - -.PHONY: purge -purge: - dpkg --purge $(PKG) - -.PHONY: reconfigure -reconfigure: - dpkg-reconfigure $(PKG) - -.PHONY: clean -clean: - cd $(SRC) && dpkg-buildpackage --no-sign --post-clean - -.PHONY: distclean -distclean: clean - rm --force *.deb - rm --force *.buildinfo - rm --force *.changes - rm --force *.dsc - rm --force *.xz - -.PHONY: translate -translate: - cd $(SRC) && debconf-updatepo - -$(DEB): $(shell find $(SRC) | grep -vFf .gitignore) - cd $(SRC) && dpkg-buildpackage --no-sign - touch $@ - lintian $(DSC) - lintian $(DEB) - -Makefile:; diff --git a/README.md b/README.md index 8ddd90c..6b2965d 100644 --- a/README.md +++ b/README.md @@ -2,26 +2,10 @@ Sets group write privileges and reinstates battery charging-thresholds. -## Debian Package +## Makefile -Tested on Debian Buster. +[Generic](generic) -Requirements: +## Packages - * `build-essential` - * `devscripts` - * `debhelper` - -Build package: `make` - -Install package: `sudo make install` - -Remove package: `sudo make remove` - -Reconfigure installed package: `sudo make reconfigure` - -Clean package directory: `make clean` - -Clean all: `make distclean` - -Translate templates: `make translate` +[Debian](debian) diff --git a/common.mk b/common.mk new file mode 100644 index 0000000..12221df --- /dev/null +++ b/common.mk @@ -0,0 +1,34 @@ +# Copyright (c) 2019 Rouven Spreckels +# +# Usage of the works is permitted provided that +# this instrument is retained with the works, so that +# any entity that uses the works is notified of this instrument. +# +# DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY. + +ETC := /etc/default/huawei-wmi/ +SYS := /sys/devices/platform/huawei-wmi/ + +.PHONY: off +off: + @echo 0 100 | tee $(ETC)charge_thresholds $(SYS)charge_thresholds + +.PHONY: travel +travel: + @echo 95 100 | tee $(ETC)charge_thresholds $(SYS)charge_thresholds + +.PHONY: office +office: + @echo 70 90 | tee $(ETC)charge_thresholds $(SYS)charge_thresholds + +.PHONY: home +home: + @echo 40 70 | tee $(ETC)charge_thresholds $(SYS)charge_thresholds + +.PHONY: lock +lock: + @echo 0 | tee $(SYS)fn_lock_state + +.PHONY: unlock +unlock: + @echo 1 | tee $(SYS)fn_lock_state diff --git a/.gitignore b/debian/.gitignore similarity index 64% rename from .gitignore rename to debian/.gitignore index 958702e..e8d7f74 100644 --- a/.gitignore +++ b/debian/.gitignore @@ -12,3 +12,7 @@ *.deb *.buildinfo *.changes +huawei-wmi-0.1.0/10-huawei-wmi.rules +huawei-wmi-0.1.0/README.md +huawei-wmi-0.1.0/debian/huawei-wmi-privilege.service +huawei-wmi-0.1.0/debian/huawei-wmi-reinstate.service diff --git a/debian/Makefile b/debian/Makefile new file mode 100644 index 0000000..ef952ec --- /dev/null +++ b/debian/Makefile @@ -0,0 +1,77 @@ +# Copyright (c) 2019 Rouven Spreckels +# +# Usage of the works is permitted provided that +# this instrument is retained with the works, so that +# any entity that uses the works is notified of this instrument. +# +# DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY. + +include ../common.mk + +PKG := huawei-wmi +VER := 0.1.0 +GEN := ../generic/huawei-wmi-0.1.0/ +SRC := $(PKG)-$(VER)/ +DSC := $(PKG)_$(VER).dsc +DEB := $(PKG)_$(VER)_all.deb + +.PHONY: all +all: $(DEB) + +.PHONY: install +install: $(DEB) + dpkg --install $(DEB) + +.PHONY: remove +remove: + dpkg --remove $(PKG) + +.PHONY: purge +purge: + dpkg --purge $(PKG) + +.PHONY: reconfigure +reconfigure: + dpkg-reconfigure $(PKG) + +.PHONY: clean +clean: + cd $(SRC) && dpkg-buildpackage --no-sign --post-clean + rm --force $(CPY) + +.PHONY: distclean +distclean: clean + rm --force *.deb + rm --force *.buildinfo + rm --force *.changes + rm --force *.dsc + rm --force *.xz + +.PHONY: translate +translate: + cd $(SRC) && debconf-updatepo + +CPY := $(SRC)README.md +CPY += $(SRC)10-huawei-wmi.rules +CPY += $(SRC)debian/huawei-wmi-privilege.service +CPY += $(SRC)debian/huawei-wmi-reinstate.service + +$(DEB): $(CPY) $(shell find $(SRC) | grep -vFf .gitignore) + cd $(SRC) && dpkg-buildpackage --no-sign + touch $@ + lintian $(DSC) + lintian $(DEB) + +$(SRC)README.md: $(GEN)README.md + cp -a $< $@ + +$(SRC)10-huawei-wmi.rules: $(GEN)10-huawei-wmi.rules + cp -a $< $@ + +$(SRC)debian/huawei-wmi-privilege.service: $(GEN)huawei-wmi-privilege.service + cp -a $< $@ + +$(SRC)debian/huawei-wmi-reinstate.service: $(GEN)huawei-wmi-reinstate.service + cp -a $< $@ + +Makefile:; diff --git a/debian/README.md b/debian/README.md new file mode 100644 index 0000000..8ddd90c --- /dev/null +++ b/debian/README.md @@ -0,0 +1,27 @@ +# huawei-wmi + +Sets group write privileges and reinstates battery charging-thresholds. + +## Debian Package + +Tested on Debian Buster. + +Requirements: + + * `build-essential` + * `devscripts` + * `debhelper` + +Build package: `make` + +Install package: `sudo make install` + +Remove package: `sudo make remove` + +Reconfigure installed package: `sudo make reconfigure` + +Clean package directory: `make clean` + +Clean all: `make distclean` + +Translate templates: `make translate` diff --git a/huawei-wmi-0.1.0/debian/changelog b/debian/huawei-wmi-0.1.0/debian/changelog similarity index 100% rename from huawei-wmi-0.1.0/debian/changelog rename to debian/huawei-wmi-0.1.0/debian/changelog diff --git a/huawei-wmi-0.1.0/debian/compat b/debian/huawei-wmi-0.1.0/debian/compat similarity index 100% rename from huawei-wmi-0.1.0/debian/compat rename to debian/huawei-wmi-0.1.0/debian/compat diff --git a/huawei-wmi-0.1.0/debian/config b/debian/huawei-wmi-0.1.0/debian/config similarity index 100% rename from huawei-wmi-0.1.0/debian/config rename to debian/huawei-wmi-0.1.0/debian/config diff --git a/huawei-wmi-0.1.0/debian/control b/debian/huawei-wmi-0.1.0/debian/control similarity index 100% rename from huawei-wmi-0.1.0/debian/control rename to debian/huawei-wmi-0.1.0/debian/control diff --git a/huawei-wmi-0.1.0/debian/copyright b/debian/huawei-wmi-0.1.0/debian/copyright similarity index 100% rename from huawei-wmi-0.1.0/debian/copyright rename to debian/huawei-wmi-0.1.0/debian/copyright diff --git a/huawei-wmi-0.1.0/debian/huawei-wmi.lintian-overrides b/debian/huawei-wmi-0.1.0/debian/huawei-wmi.lintian-overrides similarity index 100% rename from huawei-wmi-0.1.0/debian/huawei-wmi.lintian-overrides rename to debian/huawei-wmi-0.1.0/debian/huawei-wmi.lintian-overrides diff --git a/huawei-wmi-0.1.0/debian/install b/debian/huawei-wmi-0.1.0/debian/install similarity index 100% rename from huawei-wmi-0.1.0/debian/install rename to debian/huawei-wmi-0.1.0/debian/install diff --git a/huawei-wmi-0.1.0/debian/po/POTFILES.in b/debian/huawei-wmi-0.1.0/debian/po/POTFILES.in similarity index 100% rename from huawei-wmi-0.1.0/debian/po/POTFILES.in rename to debian/huawei-wmi-0.1.0/debian/po/POTFILES.in diff --git a/huawei-wmi-0.1.0/debian/po/templates.pot b/debian/huawei-wmi-0.1.0/debian/po/templates.pot similarity index 100% rename from huawei-wmi-0.1.0/debian/po/templates.pot rename to debian/huawei-wmi-0.1.0/debian/po/templates.pot diff --git a/huawei-wmi-0.1.0/debian/postinst b/debian/huawei-wmi-0.1.0/debian/postinst similarity index 100% rename from huawei-wmi-0.1.0/debian/postinst rename to debian/huawei-wmi-0.1.0/debian/postinst diff --git a/huawei-wmi-0.1.0/debian/prerm b/debian/huawei-wmi-0.1.0/debian/prerm similarity index 100% rename from huawei-wmi-0.1.0/debian/prerm rename to debian/huawei-wmi-0.1.0/debian/prerm diff --git a/huawei-wmi-0.1.0/debian/rules b/debian/huawei-wmi-0.1.0/debian/rules similarity index 100% rename from huawei-wmi-0.1.0/debian/rules rename to debian/huawei-wmi-0.1.0/debian/rules diff --git a/huawei-wmi-0.1.0/debian/source/format b/debian/huawei-wmi-0.1.0/debian/source/format similarity index 100% rename from huawei-wmi-0.1.0/debian/source/format rename to debian/huawei-wmi-0.1.0/debian/source/format diff --git a/huawei-wmi-0.1.0/debian/templates b/debian/huawei-wmi-0.1.0/debian/templates similarity index 100% rename from huawei-wmi-0.1.0/debian/templates rename to debian/huawei-wmi-0.1.0/debian/templates diff --git a/generic/.gitignore b/generic/.gitignore new file mode 100644 index 0000000..ae22583 --- /dev/null +++ b/generic/.gitignore @@ -0,0 +1 @@ +users diff --git a/generic/Makefile b/generic/Makefile new file mode 100644 index 0000000..742c9b4 --- /dev/null +++ b/generic/Makefile @@ -0,0 +1,67 @@ +# Copyright (c) 2019 Rouven Spreckels +# +# Usage of the works is permitted provided that +# this instrument is retained with the works, so that +# any entity that uses the works is notified of this instrument. +# +# DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY. + +include ../common.mk + +SRC := huawei-wmi-0.1.0/ + +UDEV := /lib/udev/rules.d/ +SYSTEMD := /lib/systemd/system/ + +SHELL := /bin/sh + +.PHONY: all +all: + +.PHONY: install +install: users + groupadd --system huawei-wmi 2> /dev/null || true + for user in $$(cat $<); do \ + usermod --append --groups huawei-wmi "$$user"; \ + done + install -d $(ETC) + install $(SRC)README.md $(ETC) + chmod g+s $(ETC) + chgrp huawei-wmi $(ETC) + [ -e $(ETC)/charge_thresholds ] || { \ + cat $(SYS)/charge_thresholds 2> /dev/null || echo 0 100; \ + } > $(ETC)/charge_thresholds + chmod g=u $(ETC)charge_thresholds + install $(SRC)10-huawei-wmi.rules $(UDEV) + install $(SRC)huawei-wmi-privilege.service $(SYSTEMD) + install $(SRC)huawei-wmi-reinstate.service $(SYSTEMD) + systemctl daemon-reload + systemctl enable huawei-wmi-privilege huawei-wmi-reinstate + udevadm control --reload-rules && udevadm trigger --action=add || true + +.PHONY: reconfigure +reconfigure: clean install + +users: + @echo "Please list the users who are allowed to change WMI settings, such" + @echo "as the battery charge-thresholds and the Fn-lock state. You probably" + @echo "want to to list your desktop users." + @echo + @read -p "List of users separated by space: " users; echo "$$users" > $@ + +.PHONY: remove +remove: + systemctl disable huawei-wmi-reinstate huawei-wmi-privilege || true + rm --force $(ETC)README.md + rm --force $(ETC)charge_thresholds + rmdir $(ETC) || true + rm --force $(UDEV)10-huawei-wmi.rules + rm --force $(SYSTEMD)huawei-wmi-privilege.service + rm --force $(SYSTEMD)huawei-wmi-reinstate.service + groupdel huawei-wmi || true + +.PHONY: clean +clean: + @rm --force users + +Makefile:; diff --git a/generic/README.md b/generic/README.md new file mode 100644 index 0000000..293fa5b --- /dev/null +++ b/generic/README.md @@ -0,0 +1,15 @@ +# huawei-wmi + +Sets group write privileges and reinstates battery charging-thresholds. + +## Generic Makefile + +Tested on Debian Buster. + +Install: `sudo make install` + +Remove: `sudo make remove` + +Reconfigure then install: `sudo make reconfigure` + +Clean users: `make clean` diff --git a/huawei-wmi-0.1.0/10-huawei-wmi.rules b/generic/huawei-wmi-0.1.0/10-huawei-wmi.rules similarity index 100% rename from huawei-wmi-0.1.0/10-huawei-wmi.rules rename to generic/huawei-wmi-0.1.0/10-huawei-wmi.rules diff --git a/huawei-wmi-0.1.0/README.md b/generic/huawei-wmi-0.1.0/README.md similarity index 100% rename from huawei-wmi-0.1.0/README.md rename to generic/huawei-wmi-0.1.0/README.md diff --git a/huawei-wmi-0.1.0/debian/huawei-wmi-privilege.service b/generic/huawei-wmi-0.1.0/huawei-wmi-privilege.service similarity index 100% rename from huawei-wmi-0.1.0/debian/huawei-wmi-privilege.service rename to generic/huawei-wmi-0.1.0/huawei-wmi-privilege.service diff --git a/huawei-wmi-0.1.0/debian/huawei-wmi-reinstate.service b/generic/huawei-wmi-0.1.0/huawei-wmi-reinstate.service similarity index 100% rename from huawei-wmi-0.1.0/debian/huawei-wmi-reinstate.service rename to generic/huawei-wmi-0.1.0/huawei-wmi-reinstate.service