Move visudo installation to cbattery script
This commit is contained in:
parent
6b037c1778
commit
1c56899fab
14
Makefile
14
Makefile
|
@ -16,22 +16,10 @@ uninstall:
|
|||
@$(DESTDIR)/cbattery revert || (echo "Reverting cbattery configurations 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 visudo help
|
||||
.PHONY: all install uninstall help
|
||||
|
|
28
cbattery
28
cbattery
|
@ -9,6 +9,7 @@ usage: ${0##*/} [command]
|
|||
adapter [on|off] - Toggle adapter connection
|
||||
status - Get status information
|
||||
revert - Revert to default settings
|
||||
visudo - Run the script without password
|
||||
help - Display this help message
|
||||
EOF
|
||||
}
|
||||
|
@ -49,23 +50,15 @@ function get_smc_charging_status() {
|
|||
fi
|
||||
}
|
||||
|
||||
function get_smc_discharging_status() {
|
||||
hex_status=$(smc -k CH0I -r | awk '{print $4}' | sed 's:\)::')
|
||||
if [[ "$hex_status" == "0" ]]; then
|
||||
echo "not discharging"
|
||||
else
|
||||
echo "discharging"
|
||||
fi
|
||||
}
|
||||
|
||||
function get_battery_percentage() {
|
||||
battery_percentage=$(pmset -g batt | tail -n1 | awk '{print $3}' | sed 's:%\;::')
|
||||
echo "$battery_percentage"
|
||||
}
|
||||
|
||||
function get_remaining_time() {
|
||||
time_remaining=$(pmset -g batt | tail -n1 | awk '{print $5}')
|
||||
echo "$time_remaining"
|
||||
function install_visudo_file() {
|
||||
sudoers_file=/private/etc/sudoers.d/cbattery
|
||||
sudo cp "$1" "$sudoers_file"
|
||||
sudo chmod 440 "$sudoers_file"
|
||||
}
|
||||
|
||||
action=$1
|
||||
|
@ -106,7 +99,16 @@ if [[ "$action" == "status" ]]; then
|
|||
if [[ "$setting" == "charging" ]]; then
|
||||
exit "$(get_smc_charging_hex)"
|
||||
else
|
||||
echo "Battery at $(get_battery_percentage)% ($(get_remaining_time) remaining), smc charging $(get_smc_charging_status)"
|
||||
echo "Battery at $(get_battery_percentage)%, smc charging $(get_smc_charging_status)"
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$action" == "visudo" ]]; then
|
||||
if [[ -n "$setting" ]]; then
|
||||
install_visudo "$setting"
|
||||
else
|
||||
install_visudo ".visudo"
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue