Update Makefile and cbattery

This commit is contained in:
Santiago Lo Coco 2024-03-17 14:31:10 +01:00
parent b379f3bc79
commit 205318dd24
2 changed files with 20 additions and 18 deletions

View File

@ -1,34 +1,36 @@
SUDOERSDIR = /private/etc/sudoers.d
INSTALL_PATH_CBATTERY = $(DESTDIR)/cbattery
INSTALL_PATH_VISUDO = $(SUDOERSDIR)/cbattery
PREFIX ?= /usr/local
DESTDIR = $(PREFIX)/bin
INSTALL_PATH = $(DESTDIR)/cbattery
all: install
install: $(INSTALL_PATH_CBATTERY) $(INSTALL_PATH_VISUDO)
install: $(INSTALL_PATH)
$(INSTALL_PATH_VISUDO): .visudo
@echo "Installing visudo file to $(SUDOERSDIR)"
@if ! test -d "$(SUDOERSDIR)"; then \
sudo mkdir -p "$(SUDOERSDIR)"; \
fi
@sudo cp $< $(SUDOERSDIR)/cbattery
@sudo chmod 440 $(SUDOERSDIR)/cbattery
$(INSTALL_PATH_CBATTERY): cbattery
$(INSTALL_PATH): cbattery
@echo "Installing cbattery to $(DESTDIR)"
@install -m 755 $< $(DESTDIR)
uninstall:
@echo "Removing cbattery from $(DESTDIR)"
@cbattery uninstall || (echo "Uninstalling cbattery failed"; exit 1)
@rm -f $(INSTALL_PATH_CBATTERY) $(INSTALL_PATH_SMC)
@$(DESTDIR)/cbattery uninstall || (echo "Uninstalling cbattery failed"; exit 1)
@rm -f $(INSTALL_PATH)
SUDOERSDIR = /private/etc/sudoers.d/cbattery
visudo: .visudo
@echo "Installing visudo file to $(SUDOERSDIR)"
@if ! test -d "$(SUDOERSDIR)"; then \
mkdir -p "$(SUDOERSDIR)"; \
fi
@cp $< $(SUDOERSDIR)/cbattery
@chmod 440 $(SUDOERSDIR)/cbattery
help:
@echo "Available targets:"
@echo " make install - Install cbattery to $(DESTDIR)"
@echo " make uninstall - Remove cbattery from $(DESTDIR)"
@echo " make visudo - Install visudo file to $(SUDOERSDIR)"
@echo " make help - Show this help message"
.PHONY: all install uninstall help
.PHONY: all install uninstall visudo help

View File

@ -8,7 +8,7 @@ usage: ${0##*/} [command]
charging [on|off] - Toggle charging
adapter [on|off] - Toggle adapter connection
status - Get status information
uninstall - Revert to default settings
revert - Revert to default settings
help - Display this help message
EOF
}
@ -76,7 +76,7 @@ if [ -z "$action" ] || [[ "$action" == "help" ]]; then
exit 0
fi
if [[ "$action" == "uninstall" ]]; then
if [[ "$action" == "revert" ]]; then
enable_charging
disable_discharging
exit 0