Overhauled notification system using Alerter. Added logs popup when there is an error.
This commit is contained in:
parent
1bb6feab1b
commit
2edbc43453
1 changed files with 53 additions and 64 deletions
125
macupdater.sh
125
macupdater.sh
|
|
@ -1,30 +1,35 @@
|
||||||
#!/Users/gugulethu/brew/bin/zsh
|
#!/Users/gugulethu/brew/bin/zsh
|
||||||
|
|
||||||
# This script updates brew, brew cask apps, atom packages, ruby gems, node packages and macOS (including system software) Apps.
|
# This script updates brew, brew cask apps, ruby gems, node packages and macOS (including system software) Apps.
|
||||||
# Version 9.1 (30 October 2019)
|
# Version 10.0 (18 January 2020)
|
||||||
|
|
||||||
# The below are Platypus features for managing UI
|
# Open an alert that requires the user the click RUN to start the process.
|
||||||
echo "PROGRESS:0" # Show the progress bar at 0%
|
ANSWER=$(./alerter -message "Run an update?" -actions Run -title macupdater -timeout 10 -sound default)
|
||||||
echo "Script starting" # Show this message above the progress bar
|
|
||||||
|
# Check the response from the alert and close if it is anything but RUN.
|
||||||
|
if [ $ANSWER = "@TIMEOUT" ]; then
|
||||||
|
echo "NOTIFICATION: Update process exited."
|
||||||
|
exit
|
||||||
|
elif [ $ANSWER = "@CLOSED" ]; then
|
||||||
|
exit
|
||||||
|
else
|
||||||
|
echo "NOTIFICATION: Updater starting..." # Send a notification (with logo)
|
||||||
|
fi
|
||||||
|
|
||||||
# Set the path to the log file
|
# Set the path to the log file
|
||||||
export LOG=~/Projects/Programming/push/macupdater/macupdater-log.txt
|
export LOG=~/Projects/Programming/push/macupdater/macupdater-log.txt
|
||||||
|
|
||||||
echo "NOTIFICATION:Updater starting..." # Send a notification (with logo)
|
|
||||||
|
|
||||||
# Export paths for appification.
|
# Export paths for appification.
|
||||||
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/$"
|
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/$"
|
||||||
|
|
||||||
# Clear the brew cache
|
|
||||||
trash -rf $(brew --cache)
|
|
||||||
|
|
||||||
# Function: Reviews the last command for errors. Then prints update complete to log or shows error dialog. Takes section variable.
|
# Function: Reviews the last command for errors. Then prints update complete to log or shows error dialog. Takes section variable.
|
||||||
catcher () {
|
catcher () {
|
||||||
if [ "$?" = "0" ]; then
|
if [ "$?" = "0" ]; then
|
||||||
printf "$1 updates complete." >> $LOG # If no error, print update complete to file.
|
printf "$1 updates complete." >> $LOG # If no error, print update complete to file.
|
||||||
printf "" >> $LOG # Add a line to file.
|
printf "" >> $LOG # Add a line to file.
|
||||||
else # If error, show a dialog stating the section where the error occured.
|
else # If error, show a dialog stating the section where the error occured.
|
||||||
echo "NOTIFICATION:'$1': Updates failed." # Send a notification (with logo)
|
echo "NOTIFICATION: '$1' updates failed."
|
||||||
|
ERROR=1 # Sets variable for error in script to 1.
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,82 +39,66 @@ echo "" >> $LOG # Starts the horizontal line on its own fresh line.
|
||||||
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' - >> $LOG # Prints line
|
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' - >> $LOG # Prints line
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function: If there has been an error in the script open the log file.
|
||||||
|
verify () {
|
||||||
|
if [ $ERROR = 1 ]; then
|
||||||
|
open $LOG
|
||||||
|
echo "NOTIFICATION: Updates completed with some errors."
|
||||||
|
else
|
||||||
|
echo "NOTIFICATION: Updates completed."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Writes the header for the log file: Program, Version number, Date and Line.
|
# Writes the header for the log file: Program, Version number, Date and Line.
|
||||||
{ echo "macupdater 9.1"; echo "Log: " `date`; line; } > $LOG
|
{ echo "macupdater 10.0"; echo "Log: " `date`; line; } > $LOG
|
||||||
|
|
||||||
# Brew update commands.
|
# Brew update commands.
|
||||||
{ echo "Brew"; echo ""; brew update; brew upgrade; brew cleanup; } >> $LOG
|
{ trash -rf $(brew --cache); echo "Brew"; echo ""; brew update; brew upgrade; brew cleanup; } >> $LOG
|
||||||
catcher Brew
|
catcher Brew
|
||||||
line
|
line
|
||||||
|
|
||||||
echo "PROGRESS:10" # Show the progress bar at 10%
|
|
||||||
echo "Brew updates complete" # Show this message above the progress bar
|
|
||||||
|
|
||||||
# App Store update commands.
|
|
||||||
{ echo "Apps"; echo ""; mas upgrade; } >> $LOG
|
|
||||||
catcher Apps
|
|
||||||
|
|
||||||
echo "PROGRESS:30" # Show the progress bar at 30%
|
|
||||||
echo "Mac app store updates complete" # Show this message above the progress bar
|
|
||||||
|
|
||||||
# Node update commands.
|
|
||||||
{ echo "Node"; echo ""; npm install npm@latest -g --silent; npm update --silent; npm prune --silent; } >> $LOG
|
|
||||||
catcher Node
|
|
||||||
line
|
|
||||||
|
|
||||||
echo "PROGRESS:40" # Show the progress bar at 40%
|
|
||||||
echo "Node package updates complete" # Show this message above the progress bar
|
|
||||||
|
|
||||||
# Ruby update commands. Commented out all as they only work in admin.
|
|
||||||
{ echo "Ruby"; echo ""; gem update --system; gem update; gem cleanup; } >> $LOG
|
|
||||||
catcher Ruby
|
|
||||||
line
|
|
||||||
|
|
||||||
# Perl update commands. Commented out (don't need updated Perl at the moment)
|
|
||||||
# { echo "Perl"; echo ""; perlbrew upgrade-perl; perlbrew self-upgrade --silent; perlbrew clean; } >> $LOG
|
|
||||||
# catcher Perl
|
|
||||||
# line
|
|
||||||
|
|
||||||
# System software update commads.
|
|
||||||
{ echo "macOS"; echo ""; softwareupdate -ia; } >> $LOG
|
|
||||||
catcher macOS
|
|
||||||
line
|
|
||||||
|
|
||||||
echo "PROGRESS:60" # Show the progress bar at 60%
|
|
||||||
echo "macOS updates complete" # Show this message above the progress bar
|
|
||||||
|
|
||||||
# Brew-cask update commands.
|
# Brew-cask update commands.
|
||||||
{ echo "Brew Cask"; echo ""; brew cu -ayf --cleanup; } >> $LOG
|
{ echo "Brew Cask"; echo ""; brew cu -ayf --cleanup; } >> $LOG
|
||||||
catcher Brew-cask
|
catcher Brew-cask
|
||||||
line
|
line
|
||||||
|
|
||||||
echo "PROGRESS:70" # Show the progress bar at 70%
|
# Push and pull all git remotes.
|
||||||
echo "Brew cask updates complete" # Show this message above the progress bar
|
|
||||||
|
|
||||||
# echo "NOTIFICATION:All local updates complete."
|
|
||||||
|
|
||||||
{ cd Projects/Programming/push/ find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} push \; cd Projects/Programming/pull/; find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} pull origin master \; } >> $LOG
|
{ cd Projects/Programming/push/ find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} push \; cd Projects/Programming/pull/; find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} pull origin master \; } >> $LOG
|
||||||
catcher Git-remote
|
catcher Git-remote
|
||||||
line
|
line
|
||||||
echo "PROGRESS:90" # Show the progress bar at 90%
|
|
||||||
|
|
||||||
# echo "Local updates complete" # Show this message above the progress bar
|
# Node update commands.
|
||||||
|
{ echo "Node"; echo ""; npm install npm@latest -g; npm update; npm prune; } >> $LOG
|
||||||
# Sets the password variable for the admin account
|
catcher Node
|
||||||
# PASSWD="$(osascript -e 'text returned of (display dialog "Please enter a password to continue" default answer "" with icon stop buttons {"Cancel", "Continue"} default button "Continue" with hidden answer)')"
|
|
||||||
|
|
||||||
# An expect script to log into the admin account and run brew updates
|
|
||||||
# /usr/bin/expect -c "spawn login; expect \"Login:\"; send \"mlungisi\r\"; expect \"Password:\"; send \"$PASSWD\r\"; expect \"g:~ mlungisi$\"; send \"{ brew update; brew upgrade; brew cleanup; brew cu -ayf --cleanup; }\r\"; expect eof; end"
|
|
||||||
# catcher Admin
|
|
||||||
|
|
||||||
echo "" >> $LOG
|
|
||||||
line
|
line
|
||||||
|
|
||||||
echo "PROGRESS:100" # Show the progress bar at 100%
|
# Ruby update commands.
|
||||||
echo "Script complete" # Show this message above the progress bar
|
{ echo "Ruby"; echo ""; gem update --system; gem cleanup; } >> $LOG
|
||||||
echo "NOTIFICATION:All updates are complete"
|
catcher Ruby
|
||||||
|
line
|
||||||
|
|
||||||
|
# Perl update commands.
|
||||||
|
# { echo "Perl"; echo ""; perlbrew self-upgrade; perlbrew upgrade-perl; perlbrew clean; } >> $LOG
|
||||||
|
# catcher Perl
|
||||||
|
# line
|
||||||
|
|
||||||
|
# Python update commands.
|
||||||
|
{ echo "Python"; echo ""; pip install -U pip; } >> $LOG
|
||||||
|
catcher Python
|
||||||
|
line
|
||||||
|
|
||||||
|
# App Store update commands.
|
||||||
|
{ echo "Apps"; echo ""; mas upgrade; } >> $LOG
|
||||||
|
catcher Apps
|
||||||
|
line
|
||||||
|
|
||||||
|
# System software update commads.
|
||||||
|
{ echo "macOS"; echo ""; softwareupdate -ia; } >> $LOG
|
||||||
|
catcher macOS
|
||||||
|
line
|
||||||
|
|
||||||
# Prints and shows dialog box confirming all updates are done.
|
# Prints and shows dialog box confirming all updates are done.
|
||||||
printf "All updates complete. END" >> $LOG
|
printf "All updates complete. END" >> $LOG
|
||||||
|
verify $ERROR
|
||||||
|
|
||||||
echo "QUITAPP"
|
echo "QUITAPP"
|
||||||
Reference in a new issue