From fdced04a677a2f3d7c38d33daae77e92eae6aefe Mon Sep 17 00:00:00 2001 From: base47 Date: Wed, 25 Feb 2026 02:00:33 +0100 Subject: [PATCH] Address the second set of comments from Copilot --- app/modules/battery.js | 2 +- app/modules/helpers.js | 2 +- battery.sh | 23 +++++++++++------------ setup.sh | 26 +++++++++++++------------- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/app/modules/battery.js b/app/modules/battery.js index 94fba93..5a8763e 100644 --- a/app/modules/battery.js +++ b/app/modules/battery.js @@ -133,7 +133,7 @@ const enable_battery_limiter = async () => { try { const status = await get_battery_status() const allow_force_discharge = get_force_discharge_setting() - // 'batery maintain' creates a child process, so when the command exits exec_async does not return. + // 'battery maintain' creates a child process, so when the command exits exec_async does not return. // That's why here we use a timeout and wait for some time. await exec_async( `${ battery } maintain ${ status?.maintain_percentage || 80 }${ allow_force_discharge ? ' --force-discharge' : '' }`, diff --git a/app/modules/helpers.js b/app/modules/helpers.js index 878307a..cae7ad1 100644 --- a/app/modules/helpers.js +++ b/app/modules/helpers.js @@ -1,6 +1,6 @@ const { promises: fs } = require( 'fs' ) const { HOME } = process.env -const util = require("util"); +const util = require( 'util' ) let has_alerted_user_no_home = false diff --git a/battery.sh b/battery.sh index 9e5fd44..2bbc109 100755 --- a/battery.sh +++ b/battery.sh @@ -494,7 +494,7 @@ function ensure_owner() { local cur_owner=$(stat -f '%Su' "$path") local cur_group=$(stat -f '%Sg' "$path") if [[ $cur_owner != "$owner" || $cur_group != "$group" ]]; then - sudo chown "${owner}:${group}" "$path" + sudo chown -h "${owner}:${group}" "$path" fi } @@ -503,7 +503,7 @@ function ensure_owner_mode() { ensure_owner "$owner" "$group" "$path" || return local cur_mode=$(stat -f '%Lp' "$path") if [[ $cur_mode != "${mode#0}" ]]; then - sudo chmod "$mode" "$path" + sudo chmod -h "$mode" "$path" fi } @@ -512,13 +512,6 @@ function ensure_owner_mode() { function fixup_installation_owner_mode() { local username=$1 - ensure_owner_mode root wheel 755 "$visudo_folder" - ensure_owner_mode root wheel 440 "$visudo_file" - - ensure_owner_mode root wheel 755 "$binfolder" - ensure_owner_mode root wheel 755 "$battery_binary" - ensure_owner_mode root wheel 755 "$smc_binary" - ensure_owner_mode $username staff 755 "$(dirname "$daemon_path")" ensure_owner_mode $username staff 644 "$daemon_path" @@ -529,6 +522,13 @@ function fixup_installation_owner_mode() { ensure_owner_mode $username staff 644 "$maintain_voltage_tracker_file" ensure_owner_mode $username staff 644 "$calibrate_pidfile" + ensure_owner_mode root wheel 755 "$visudo_folder" + ensure_owner_mode root wheel 440 "$visudo_file" + + ensure_owner_mode root wheel 755 "$binfolder" + ensure_owner_mode root wheel 755 "$battery_binary" + ensure_owner_mode root wheel 755 "$smc_binary" + # Do some cleanup after previous versions sudo rm -f "$configfolder/visudo.tmp" } @@ -696,13 +696,12 @@ if [[ "$action" == "update" ]]; then sudo -n "$battery_binary" update_silent is_enabled >/dev/null 2>&1 ) - version_before="$($battery_binary version)" - if ! check_installation_integrity; then + version_before="0" # Force restart maintenance process echo -e "‼️ The battery installation seems to be broken. Forcing reinstall...\n" $battery_binary reinstall silent - version_before="0" # Force restart maintenance process else + version_before="$($battery_binary version)" sudo $battery_binary update_silent fi diff --git a/setup.sh b/setup.sh index ebb30bf..4927597 100755 --- a/setup.sh +++ b/setup.sh @@ -91,35 +91,35 @@ echo "[ 7 ] Make sure the PATH environment variable includes '$binfolder'" if ! grep -qF "$binfolder" $path_configfile 2>/dev/null; then printf '%s\n' "$binfolder" | sudo tee "$path_configfile" >/dev/null fi -sudo chown root:wheel $path_configfile -sudo chmod 644 $path_configfile +sudo chown -h root:wheel $path_configfile +sudo chmod -h 644 $path_configfile # Create a symlink for rare shells that do not initialize PATH from /etc/paths.d (including the current one) sudo mkdir -p /usr/local/bin sudo ln -sf "$binfolder/battery" /usr/local/bin/battery -sudo chown root:wheel /usr/local/bin/battery +sudo chown -h root:wheel /usr/local/bin/battery # Create a link to smc as well to silence older GUI apps running with updated background executables # (consider removing in the next releases) sudo ln -sf "$binfolder/smc" /usr/local/bin/smc -sudo chown root:wheel /usr/local/bin/smc +sudo chown -h root:wheel /usr/local/bin/smc echo "[ 8 ] Set ownership and permissions for $configfolder" mkdir -p $configfolder -sudo chown -R $calling_user $configfolder -sudo chmod 755 $configfolder +sudo chown -hRP $calling_user $configfolder +sudo chmod -h 755 $configfolder touch $logfile -sudo chown $calling_user $logfile -sudo chmod 644 $logfile +sudo chown -h $calling_user $logfile +sudo chmod -h 644 $logfile touch $pidfile -sudo chown $calling_user $pidfile -sudo chmod 644 $pidfile +sudo chown -h $calling_user $pidfile +sudo chmod -h 644 $pidfile # Fix permissions for 'create_daemon' action echo "[ 9 ] Fix ownership and permissions for $(dirname "$launch_agent_plist")" -sudo chown $calling_user "$(dirname "$launch_agent_plist")" -sudo chmod 755 "$(dirname "$launch_agent_plist")" -sudo chown -f $calling_user "$launch_agent_plist" 2>/dev/null +sudo chown -h $calling_user "$(dirname "$launch_agent_plist")" +sudo chmod -h 755 "$(dirname "$launch_agent_plist")" +sudo chown -hf $calling_user "$launch_agent_plist" 2>/dev/null echo "[ 10 ] Setup visudo configuration" sudo $binfolder/battery visudo