Skip to content

Commit

Permalink
🐛 permissions bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
actuallymentor committed Jun 28, 2024
1 parent 6e3a640 commit affb7f0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
Binary file modified app/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion app/modules/battery.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const initialize_battery = async () => {
exec_async( `${ path_fix } sudo -n /usr/local/bin/smc -k CH0C -r` ).catch( () => false ),
exec_async( `${ path_fix } sudo -n /usr/local/bin/smc -k CH0I -r` ).catch( () => false ),
exec_async( `${ path_fix } sudo -n /usr/local/bin/smc -k ACLC -r` ).catch( () => false ),
exec_async( `${ path_fix } sudo -n /usr/local/bin/smc -k ACLC -w 01` ).catch( () => false )
exec_async( `${ path_fix } sudo -n /usr/local/bin/smc -k ACLC -w 02` ).catch( () => false )
] )

const visudo_complete = charging_in_visudo && discharging_in_visudo && magsafe_led_in_visudo && additional_magsafe_led_in_visudo
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "battery",
"version": "1.1.8",
"version": "1.2.2",
"description": "A battery charge limiter for Apple silicon Mac devices",
"main": "main.js",
"build": {
Expand Down
14 changes: 10 additions & 4 deletions battery.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## Update management
## variables are used by this binary as well at the update script
## ###############
BATTERY_CLI_VERSION="v1.2.3"
BATTERY_CLI_VERSION="v1.2.4"

# Path fixes for unexpected environments
PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Expand Down Expand Up @@ -113,7 +113,7 @@ Cmnd_Alias BATTERYOFF = $binfolder/smc -k CH0B -w 02, $binfolder/smc -k CH0
Cmnd_Alias BATTERYON = $binfolder/smc -k CH0B -w 00, $binfolder/smc -k CH0C -w 00
Cmnd_Alias DISCHARGEOFF = $binfolder/smc -k CH0I -w 00, $binfolder/smc -k CH0I -r
Cmnd_Alias DISCHARGEON = $binfolder/smc -k CH0I -w 01
Cmnd_Alias LEDCONTROL = $binfolder/smc -k ACLC -w 04, $binfolder/smc -k ACLC -w 03, $binfolder/smc -k ACLC -w 01, $binfolder/smc -k ACLC -w 00, $binfolder/smc -k ACLC -r
Cmnd_Alias LEDCONTROL = $binfolder/smc -k ACLC -w 04, $binfolder/smc -k ACLC -w 03, $binfolder/smc -k ACLC -w 02, $binfolder/smc -k ACLC -w 01, $binfolder/smc -k ACLC -w 00, $binfolder/smc -k ACLC -r
ALL ALL = NOPASSWD: BATTERYOFF
ALL ALL = NOPASSWD: BATTERYON
ALL ALL = NOPASSWD: DISCHARGEOFF
Expand Down Expand Up @@ -291,12 +291,18 @@ fi
# Visudo message
if [[ "$action" == "visudo" ]]; then

# User to set folder ownership to is $setting if it is defined and $USER otherwise
if [[ -z "$setting" ]]; then
setting=$USER
fi

# Set visudo tempfile ownership to current user
log "Setting visudo file permissions to $USER"
sudo chown -R $USER $configfolder
log "Setting visudo file permissions to $setting"
sudo chown -R $setting $configfolder

# Write the visudo file to a tempfile
visudo_tmpfile="$configfolder/visudo.tmp"
sudo rm visudo_tmpfile 2>/dev/null
echo -e "$visudoconfig" >$visudo_tmpfile

# If the visudo file is the same (no error, exit code 0), set the permissions just
Expand Down
10 changes: 5 additions & 5 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ configfolder=/Users/$calling_user/.battery
pidfile=$configfolder/battery.pid
logfile=$configfolder/battery.log


# Ask for sudo once, in most systems this will cache the permissions for a bit
sudo echo "🔋 Starting battery installation"
echo -e "[ 1 ] Superuser permissions acquired."
Expand Down Expand Up @@ -45,15 +44,15 @@ sudo chmod +x $binfolder/smc
echo "[ 4 ] Writing script to $binfolder/battery for user $calling_user"
sudo cp $batteryfolder/battery.sh $binfolder/battery

echo "[ 5 ] Setting correct file permissions"
echo "[ 5 ] Setting correct file permissions for $calling_user"
# Set permissions for battery executables
sudo chown $calling_user $binfolder/battery
sudo chown -R $calling_user $binfolder/battery
sudo chmod 755 $binfolder/battery
sudo chmod +x $binfolder/battery

# Set permissions for logfiles
mkdir -p $configfolder
sudo chown $calling_user $configfolder
sudo chown -R $calling_user $configfolder

touch $logfile
sudo chown $calling_user $logfile
Expand All @@ -66,7 +65,8 @@ sudo chmod 755 $pidfile
sudo chown $calling_user $binfolder/battery

echo "[ 6 ] Setting up visudo declarations"
sudo bash $batteryfolder/battery.sh visudo
sudo $batteryfolder/battery.sh visudo $USER
sudo chown -R $calling_user $configfolder

# Remove tempfiles
cd ../..
Expand Down

0 comments on commit affb7f0

Please sign in to comment.