DomT4 / homebrew-autoupdate

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

Updated notifier/notifier.scpt to use /usr/bin/tail, in case users have coreutils installed and GNU tail in their PATH #92

Closed ndbroadbent closed 1 year ago

ndbroadbent commented 1 year ago

Fixes #37

GNU tail doesn't support the -r flag, so that's why it was failing for me and running the "on error" section:

try
    set tailLog to do shell script "tail -r ~/Library/Logs/com.github.domt4.homebrew-autoupdate/*.out | grep -E -m1 'taps|date'"
on error
    set tailLog to "Logs not found; cannot show summary!"
end try

Can be fixed by using /usr/bin/tail -r, which is the default tail that comes with macOS.

Before:

Screen Shot 2022-10-08 at 1 22 48 PM

After:

cp notifier/notifier.scpt /usr/local/Homebrew/Library/Taps/homebrew/homebrew-autoupdate/notifier/brew-autoupdate.app/Contents/Resources/Scripts/main.scpt
launchctl start com.github.domt4.homebrew-autoupdate
Screen Shot 2022-10-08 at 1 25 48 PM
ndbroadbent commented 1 year ago

I also just noticed there's a bug with the log parsing. grep -E -m1 'taps|date'" is matching the first line in the logs: or list them with brew outdated.

 $ /usr/bin/tail -r ~/Library/Logs/com.github.domt4.homebrew-autoupdate/*.out
or list them with brew outdated.
You can upgrade them with brew upgrade
You have 178 outdated formulae and 13 outdated casks installed.

virtualbox
rescuetime
qbittorrent
postico

EDIT: Can filter out this line with | grep -Ev 'with brew outdated' | so that it matches on the correct one:

# Before:
$ /usr/bin/tail -r ~/Library/Logs/com.github.domt4.homebrew-autoupdate/*.out | grep -E -m1 'taps|date'
or list them with brew outdated.

# After:
$ /usr/bin/tail -r ~/Library/Logs/com.github.domt4.homebrew-autoupdate/*.out | grep -Ev 'with brew outdated' | grep -E -m1 'taps|date'
You have 178 outdated formulae and 13 outdated casks installed.

Have included this change in the PR as well

Screen Shot 2022-10-08 at 1 37 45 PM
troyfisher commented 1 year ago

Also confirming this fixes the specific scenario of GNU coreutils installed (tested locally), great work @ndbroadbent. Can the PR be expedited?

troyfisher commented 1 year ago

Alternatively, if this is not a desirable change perhaps using tac rather than tail -r could be considered. The same reversed output of the log is created by tac natively whether using native MacOS binaries or GNU Coreutils.

github-actions[bot] commented 1 year ago

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

ndbroadbent commented 1 year ago

@troyfisher Thanks for the tip about tac, I didn't know about that! I will update to use that

EDIT: Oh actually it's not available on Mac by default: https://unix.stackexchange.com/questions/114041/how-can-i-get-the-tac-command-on-os-x Might be better to stick to /usr/bin/tail -r since this will use the default tail command on all macOS systems

github-actions[bot] commented 1 year ago

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