Skip to content

Commit

Permalink
Add generic Makefile.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rouven Spreckels committed Jun 7, 2019
1 parent 5f35311 commit da048fe
Show file tree
Hide file tree
Showing 27 changed files with 229 additions and 68 deletions.
48 changes: 0 additions & 48 deletions Makefile

This file was deleted.

24 changes: 4 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
34 changes: 34 additions & 0 deletions common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) 2019 Rouven Spreckels <[email protected]>
#
# 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
4 changes: 4 additions & 0 deletions .gitignore → debian/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
77 changes: 77 additions & 0 deletions debian/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright (c) 2019 Rouven Spreckels <[email protected]>
#
# 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:;
27 changes: 27 additions & 0 deletions debian/README.md
Original file line number Diff line number Diff line change
@@ -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`
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions generic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
users
67 changes: 67 additions & 0 deletions generic/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright (c) 2019 Rouven Spreckels <[email protected]>
#
# 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:;
15 changes: 15 additions & 0 deletions generic/README.md
Original file line number Diff line number Diff line change
@@ -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`
File renamed without changes.
File renamed without changes.

0 comments on commit da048fe

Please sign in to comment.