DomT4 / homebrew-autoupdate

:tropical_drink: An easy, convenient way to automatically update Homebrew.
BSD 2-Clause "Simplified" License
987 stars 54 forks source link

homebrew-autoupdate is not working with `sudo -uH` or `su -` #47

Closed snetwork-dev closed 3 years ago

snetwork-dev commented 3 years ago

homebrew-autoupdate is not working with sudo -uH admin or su - admin

Homebrew is installed within an administrator account (not root). For daily use I granted a normal user to manage homebrew via sudoers-entry.

So things like sudo -Hu admin brew install/update/etc or su - admin and afterwards brew install/update/etc are working flawlessly.

The only thing which is not working is homebrew-autoupdate.

If I were logged in as admin - everything is fine. But if I was logged in as a normal user, sudo -Hu admin brew autoupdate --start 7200 --upgrade --cleanup --enable-notification --debug or first su - admin and afterwards the previous brew autoupdate command, results in:

Warning: Please note if you use Casks that require `sudo` to upgrade there
are known issues with that use case and this command unless using
`SUDO_ASKPASS`.

  https://github.com/Homebrew/homebrew-autoupdate/issues/40

/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/terminal-notifier.rb
Homebrew will now automatically update every 2 hours, or on system boot.
/usr/local/Homebrew/Library/Homebrew/brew.rb:125:in `exit'
/usr/local/Homebrew/Library/Homebrew/brew.rb:125:in `<main>'

sudo -Hu admin brew autoupdate --status reports:

Autoupdate is installed but stopped.

Autoupdate was initialised on 04/18/21.

Also if I log in first as admin, run brew autoupdate --start 7200 --upgrade --cleanup --enable-notification --debug, log out and log in afterwards as a normal user sudo -Hu admin brew autoupdate --status reports the same:

Autoupdate is installed but stopped.

Autoupdate was initialised on 04/18/21.

What is more, even if the setup works with a local admin account logon - as soon as the admin user is logged out, the launch daemon application.com.github.domt4.homebrew-autoupdate.autoupdater.42866421.42866425 is no longer running.

DomT4 commented 3 years ago

I don't have a particularly easy way to test this without messing around with my local system, but my initial very vague suspicion would be that this tool uses things like File.expand_path("~/Library/LaunchAgents/#{name}.plist") instead of ENV["USER"], leaving the daemon being launched from the wrong user, essentially.

Can you check if the logs/etc exist in either the admin or normal user's ~/Library/LaunchAgents and ~/Library/Logs/com.github.domt4.homebrew-autoupdate?

snetwork-dev commented 3 years ago

You're right. Both, the LaunchAgent /Users/admin/Library/LaunchAgents/com.github.domt4.homebrew-autoupdate.plist and the log file /Users/admin/Library/Logs/com.github.domt4.homebrew-autoupdate exist at the admin user (which is called with sudo).

Since the admin user is hardly or not logged in at all, the homebrew-autoupdate LaunchAgent is never started either. Is there a way to rebuild the script so that homebrew-autoupdate is executed under the logged-in user?

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

DomT4 commented 3 years ago

Is there a way to rebuild the script so that homebrew-autoupdate is executed under the logged-in user?

I'd be happy to review a PR that attempts this in a sensible way, but I don't have the time to do so myself now I'm back to working full-time sadly. Happy to come back to this in future if I can.