|
#!/bin/bash |
|
# |
|
# Notify of Homebrew updates via Notification Center on Mac OS X |
|
# Requires: terminal-notifier. Install with: |
|
# brew install terminal-notifier |
|
|
|
BREW_EXEC='/opt/homebrew/bin/brew' |
|
TERMINAL_NOTIFIER='/opt/homebrew/bin/terminal-notifier' |
|
NOTIF_ARGS="-activate com.apple.Terminal" |
|
GIT='/usr/bin/git' |
|
TR='/usr/bin/tr' |
|
AUTO=true |
|
NONINTERACTIVE=1 |
|
|
|
# update brew itself |
|
cd "$($BREW_EXEC --repo)" && $GIT fetch && $GIT reset --hard origin/master && $BREW_EXEC update |
|
|
|
{ $BREW_EXEC update > /dev/null; } 2>&1 |
|
outdated=$($BREW_EXEC outdated | $TR ' ' '\n') |
|
outdated_cask=$($BREW_EXEC outdated --cask | $TR ' ' '\n') |
|
|
|
if [ -n "$outdated" ] && [ -n "$outdated_cask" ] ; then |
|
# Nofity via Notification Center |
|
if [ -e "$TERMINAL_NOTIFIER" ]; then |
|
message="The following formulae are outdated:"$'\n'"$outdated"$'\n'"$outdated_cask" |
|
# Send to the Nofication Center |
|
$TERMINAL_NOTIFIER "$NOTIF_ARGS" -title "Homebrew Update(s) Available" -message "$message" |
|
fi |
|
|
|
# Automatically update |
|
if ( $AUTO ); then |
|
for app in ${outdated_cask//\\n/} |
|
do |
|
if $BREW_EXEC upgrade --cask "$app"; then |
|
$TERMINAL_NOTIFIER "$NOTIF_ARGS" -title "Homebrew Updater" -message "The $app cask app was successfully updated" |
|
else |
|
$TERMINAL_NOTIFIER "$NOTIF_ARGS" -title "Homebrew Updater" -message "Something went wrong with the $app cask app" |
|
fi |
|
done |
|
for app in ${outdated//\\n/} |
|
do |
|
if $BREW_EXEC upgrade "$app"; then |
|
$TERMINAL_NOTIFIER "$NOTIF_ARGS" -title "Homebrew Updater" -message "The $app app was successfully updated" |
|
else |
|
$TERMINAL_NOTIFIER "$NOTIF_ARGS" -title "Homebrew Updater" -message "Something went wrong with the $app app" |
|
fi |
|
done |
|
if $BREW_EXEC doctor; then |
|
$TERMINAL_NOTIFIER "$NOTIF_ARGS" -title "Homebrew Updater" -message "Doctor found some issues pls run 'brew doctor'" |
|
fi |
|
if $BREW_EXEC missing; then |
|
$TERMINAL_NOTIFIER "$NOTIF_ARGS" -title "Homebrew Updater" -message "Some apps have missing dependencies pls run 'brew missing'" |
|
fi |
|
$BREW_EXEC cleanup -s |
|
fi |
|
fi |
|
|
|
|
|
|
|
# Install Homebrew. |
|
# Install terminal-notifier. Execute brew install terminal-notifier. |
|
# copy the homebrew-upgrade.sh file to /usr/local/bin don't forget about chmod +x |
|
# Copy the homebrew-upgrade.plist file in this gist into ~/Library/LaunchAgents/. |
|
# Execute launchctl load ~/Library/LaunchAgents/homebrew-upgrade.plist. Do not run this command with superuser privileges. |
|
|
|
# ~/Library/LaunchAgents/homebrew-upgrade.plist |
|
|
|
# <?xml version="1.0" encoding="UTF-8"?> |
|
# <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
|
# <plist version="1.0"> |
|
# <dict> |
|
# <key>Disabled</key> |
|
# <false/> |
|
# <key>EnvironmentVariables</key> |
|
# <dict> |
|
# <key>PATH</key> |
|
# <string>$PATH:/Users/nkunashko/.bin</string> |
|
# </dict> |
|
# <key>Label</key> |
|
# <string>homebrewupdate</string> |
|
# <key>LowPriorityIO</key> |
|
# <true/> |
|
# <key>ProgramArguments</key> |
|
# <array> |
|
# <string>/bin/bash</string> |
|
# <string>-c</string> |
|
# <string>homebrew-upgrade.sh</string> |
|
# </array> |
|
# <key>RunAtLoad</key> |
|
# <true/> |
|
# <key>StandardErrorPath</key> |
|
# <string>/Users/nkunashko/.bin/homebrew-upgrade.log</string> |
|
# <key>StandardOutPath</key> |
|
# <string>/Users/nkunashko/.bin/homebrew-upgrade.log</string> |
|
# <key>StartInterval</key> |
|
# <integer>60</integer> |
|
# </dict> |
|
# </plist> |