Fix more bugs
This commit is contained in:
parent
ed316bb564
commit
1ef1a7825b
8
.visudo
8
.visudo
|
@ -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
|
||||||
|
|
15
cbattery
15
cbattery
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue