diff --git a/Makefile b/Makefile index fa28272..f02c105 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/cbattery b/cbattery index a8a856f..eca2610 100755 --- a/cbattery +++ b/cbattery @@ -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