Fix PATH bugs
This commit is contained in:
parent
12f40d39e1
commit
75871c1618
21
Makefile
21
Makefile
|
@ -1,20 +1,39 @@
|
||||||
PREFIX ?= /usr/local
|
PREFIX ?= /usr/local
|
||||||
DESTDIR = $(PREFIX)/bin
|
DESTDIR = $(PREFIX)/bin
|
||||||
INSTALL_PATH = $(DESTDIR)/cbattery
|
INSTALL_PATH = $(DESTDIR)/cbattery
|
||||||
|
SHAREDIR = $(PREFIX)/share/cbattery
|
||||||
|
DAEMON_PATH = $(SHAREDIR)/cbattery.plist
|
||||||
|
VISUDO_PATH = $(SHAREDIR)/.visudo
|
||||||
|
|
||||||
all: install
|
all: install
|
||||||
|
|
||||||
install: $(INSTALL_PATH)
|
install: $(INSTALL_PATH) $(DAEMON_PATH) $(VISUDO_PATH)
|
||||||
|
|
||||||
$(INSTALL_PATH): cbattery
|
$(INSTALL_PATH): cbattery
|
||||||
@echo "Installing cbattery to $(DESTDIR)"
|
@echo "Installing cbattery to $(DESTDIR)"
|
||||||
@install -d $(DESTDIR)
|
@install -d $(DESTDIR)
|
||||||
@install -m 755 $< $(DESTDIR)
|
@install -m 755 $< $(DESTDIR)
|
||||||
|
|
||||||
|
$(DAEMON_PATH): cbattery.plist
|
||||||
|
@echo "Installing cbattery.plist to $(DAEMON_PATH)"
|
||||||
|
@install -d $(SHAREDIR)
|
||||||
|
@install -m 644 $< $(DAEMON_PATH)
|
||||||
|
|
||||||
|
$(VISUDO_PATH): .visudo
|
||||||
|
@echo "Installing .visudo to $(VISUDO_PATH)"
|
||||||
|
@install -d $(SHAREDIR)
|
||||||
|
@install -m 644 $< $(VISUDO_PATH)
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
@echo "Removing cbattery from $(DESTDIR)"
|
@echo "Removing cbattery from $(DESTDIR)"
|
||||||
@$(DESTDIR)/cbattery revert || (echo "Reverting cbattery configurations failed"; exit 1)
|
@$(DESTDIR)/cbattery revert || (echo "Reverting cbattery configurations failed"; exit 1)
|
||||||
@rm -f $(INSTALL_PATH)
|
@rm -f $(INSTALL_PATH)
|
||||||
|
@echo "Removing cbattery.plist from $(DAEMON_PATH)"
|
||||||
|
@rm -f $(DAEMON_PATH)
|
||||||
|
@echo "Removing .visudo from $(VISUDO_PATH)"
|
||||||
|
@rm -f $(VISUDO_PATH)
|
||||||
|
@echo "Removing $(SHAREDIR)"
|
||||||
|
@rmdir $(SHAREDIR) || true
|
||||||
|
|
||||||
help:
|
help:
|
||||||
@echo "Available targets:"
|
@echo "Available targets:"
|
||||||
|
|
13
cbattery
13
cbattery
|
@ -3,6 +3,7 @@
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
CACHE_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/cbattery.status"
|
CACHE_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/cbattery.status"
|
||||||
|
SHARE_DIR=/usr/local/share/cbattery
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat << EOF
|
cat << EOF
|
||||||
|
@ -66,7 +67,7 @@ install_visudo_file() {
|
||||||
echo "'smc' is required but not found."
|
echo "'smc' is required but not found."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
sed "s:smc:$smc_loc:g" ".visudo" | sudo tee "$sudoers_file" > /dev/null
|
sed "s:smc:$smc_loc:g" "$SHARE_DIR/.visudo" | sudo tee "$sudoers_file" > /dev/null
|
||||||
if ! sudo visudo -c -f "$sudoers_file"; then
|
if ! sudo visudo -c -f "$sudoers_file"; then
|
||||||
echo "Failed to check sudoers file syntax."
|
echo "Failed to check sudoers file syntax."
|
||||||
sudo rm "$sudoers_file"
|
sudo rm "$sudoers_file"
|
||||||
|
@ -75,6 +76,13 @@ install_visudo_file() {
|
||||||
sudo chmod 440 "$sudoers_file"
|
sudo chmod 440 "$sudoers_file"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
install_launch_daemon() {
|
||||||
|
launch_daemon=/Library/LaunchDaemons/cbattery.plist
|
||||||
|
sudo cp "$SHARE_DIR"/cbattery.plist "$launch_daemon"
|
||||||
|
sudo chown root:wheel "$launch_daemon"
|
||||||
|
sudo launchctl load "$launch_daemon"
|
||||||
|
}
|
||||||
|
|
||||||
get_cached_status() {
|
get_cached_status() {
|
||||||
set +e
|
set +e
|
||||||
read_cache_result=$(read_cache)
|
read_cache_result=$(read_cache)
|
||||||
|
@ -127,6 +135,9 @@ runScript() {
|
||||||
"visudo")
|
"visudo")
|
||||||
install_visudo_file
|
install_visudo_file
|
||||||
;;
|
;;
|
||||||
|
"daemon")
|
||||||
|
install_launch_daemon
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Invalid command: $action"
|
echo "Invalid command: $action"
|
||||||
usage
|
usage
|
||||||
|
|
Loading…
Reference in New Issue