diff --git a/app/.DS_Store b/app/.DS_Store index 563238f..062e8f6 100644 Binary files a/app/.DS_Store and b/app/.DS_Store differ diff --git a/app/modules/battery.js b/app/modules/battery.js index 9f29b26..c70140c 100644 --- a/app/modules/battery.js +++ b/app/modules/battery.js @@ -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 diff --git a/app/package.json b/app/package.json index 870060c..0ed4158 100644 --- a/app/package.json +++ b/app/package.json @@ -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": { diff --git a/battery.sh b/battery.sh index 791420e..35f16df 100755 --- a/battery.sh +++ b/battery.sh @@ -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 @@ -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 @@ -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 diff --git a/setup.sh b/setup.sh index dce9f9d..adca09e 100755 --- a/setup.sh +++ b/setup.sh @@ -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." @@ -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 @@ -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 ../..