g_it/macupdater
Archived
1
0
Fork 0
This repository has been archived on 2026-03-15. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
macupdater/macupdater.sh
2018-06-30 19:57:54 +02:00

64 lines
No EOL
2.8 KiB
Bash
Executable file

#!/bin/sh
# This script updates brew, brew cask apps, ruby gems, rvm, npm packages and macOS (including system software) Apps.
# Version 6.0 (30 June, 2018)
# Function: Reviews the last command for errors. Then prints update complete to log or shows error dialog. Takes section variable.
catcher () {
if [ "$?" = "0" ]; then
printf "$1 updates complete." >> ~/Projects/Programming/macupdater/macupdater-log.txt # If no error, print update complete to file.
printf "" >> ~/Projects/Programming/macupdater/macupdater-log.txt # Add a line to file.
else # If error, show a dialog stating the section where the error occured.
osascript -e 'display notification "'$1': Script encountered errors." with title "MacUpdater"'
fi
}
# Function: Creates a horizontal line in the text file.
line () {
echo "" >> ~/Projects/Programming/macupdater/macupdater-log.txt # Starts the horizontal line on its own fresh line.
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' - >> ~/Projects/Programming/macupdater/macupdater-log.txt # Prints line
}
# Writes the header for the log file: Program, Version number, Date and Line.
{ echo "macupdater 6.0"; echo "Log: " `date`; line; } > ~/Projects/Programming/macupdater/macupdater-log.txt
# Brew update commands.
{ echo "Brew"; echo ""; brew update; brew upgrade; brew cleanup; brew prune; } >> ~/Projects/Programming/macupdater/macupdater-log.txt
catcher Brew
line
# Brew-cask update commands.
{ echo "Brew Cask"; echo ""; brew cu -ay --cleanup; brew cask cleanup; } >> ~/Projects/Programming/macupdater/macupdater-log.txt
catcher Brew-cask
line
# Node update commands.
{ echo "Node"; echo ""; npm install npm@latest -g --silent; npm update --silent; npm prune --silent; } >> ~/Projects/Programming/macupdater/macupdater-log.txt
catcher Node
line
# Ruby update commands. Commented out RVM update.
# { rvm get latest; } >> ~/Projects/Programming/macupdater/macupdater-log.txt
{ echo "Ruby"; echo ""; rvm cleanup all; gem update --system; gem update; gem cleanup; } >> ~/Projects/Programming/macupdater/macupdater-log.txt
catcher Ruby
line
# Perl update commands.
{ echo "Perl"; echo ""; perlbrew upgrade-perl; perlbrew self-upgrade --silent; perlbrew clean; } >> ~/Projects/Programming/macupdater/macupdater-log.txt
catcher Perl
line
# System software update commads.
{ echo "macOS"; echo ""; softwareupdate -ia; } >> ~/Projects/Programming/macupdater/macupdater-log.txt
catcher macOS
line
# App Store update commands.
{ echo "Apps"; echo ""; mas upgrade; } >> ~/Projects/Programming/macupdater/macupdater-log.txt
catcher Apps
echo "" >> ~/Projects/Programming/macupdater/macupdater-log.txt
line
# Prints and shows dialog box confirming all updates are done.
printf "All updates complete. END" >> ~/Projects/Programming/macupdater/macupdater-log.txt
osascript -e 'display notification "All updates completed." with title "MacUpdater"'