Fix more bugs

This commit is contained in:
Santiago Lo Coco 2024-03-17 15:48:33 +01:00
parent ed316bb564
commit 1ef1a7825b
2 changed files with 16 additions and 7 deletions

View File

@ -1,7 +1,7 @@
Cmnd_Alias BATTERYOFF = /usr/local/bin/smc -k CH0B -w 02, /usr/local/bin/smc -k CH0C -w 02, /usr/local/bin/smc -k CH0B -r, /usr/local/bin/smc -k CH0C -r Cmnd_Alias BATTERYOFF = smc -k CH0B -w 02, smc -k CH0C -w 02, smc -k CH0B -r, smc -k CH0C -r
Cmnd_Alias BATTERYON = /usr/local/bin/smc -k CH0B -w 00, /usr/local/bin/smc -k CH0C -w 00 Cmnd_Alias BATTERYON = smc -k CH0B -w 00, smc -k CH0C -w 00
Cmnd_Alias DISCHARGEOFF = /usr/local/bin/smc -k CH0I -w 00, /usr/local/bin/smc -k CH0I -r Cmnd_Alias DISCHARGEOFF = smc -k CH0I -w 00, smc -k CH0I -r
Cmnd_Alias DISCHARGEON = /usr/local/bin/smc -k CH0I -w 01 Cmnd_Alias DISCHARGEON = smc -k CH0I -w 01
ALL ALL = NOPASSWD: BATTERYOFF ALL ALL = NOPASSWD: BATTERYOFF
ALL ALL = NOPASSWD: BATTERYON ALL ALL = NOPASSWD: BATTERYON

View File

@ -56,8 +56,17 @@ function get_battery_percentage() {
} }
function install_visudo_file() { function install_visudo_file() {
sudoers_file=/private/etc/sudoers.d/cbattery sudoers_file="/private/etc/sudoers.d/cbattery"
sudo cp ".visudo" "$sudoers_file" if ! smc_loc="$(command -v smc)"; then
echo "'smc' is required but not found."
exit 1
fi
sed "s:smc:$smc_loc:g" ".visudo" | sudo tee "$sudoers_file" > /dev/null
if ! sudo visudo -c -f "$sudoers_file"; then
echo "Failed to check sudoers file syntax."
sudo rm "$sudoers_file"
exit 1
fi
sudo chmod 440 "$sudoers_file" sudo chmod 440 "$sudoers_file"
} }
@ -105,7 +114,7 @@ if [[ "$action" == "status" ]]; then
fi fi
if [[ "$action" == "visudo" ]]; then if [[ "$action" == "visudo" ]]; then
install_visudo install_visudo_file
exit 0 exit 0
fi fi