/
brew_full_upgrade
executable file
·84 lines (70 loc) · 2.86 KB
/
brew_full_upgrade
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env bash
### Dependencies ###
### brew install mas
### brew tap buo/cask-upgrade
# Ctrl-C trap. Catches INT signal. This is necessary to ensure that we kill all the children
trap "kill ${$}" INT
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
echo "Updating brew database..."
brew update
echo "Upgrading brew apps..."
brew upgrade
echo "Cleaning brew cache..."
brew cleanup
echo "Upgrading brew cask apps..."
casks=( $(brew outdated --cask | awk '{ print $1 }') )
if [ -z "${casks}" ] ; then
echo "Yay! No casks to upgrade!"
else
echo -n "The following casks are going to be upgraded: "
echo ${casks[*]} | sed -e "s/[[:space:]]/, /g" # Replace spaces and newlines with comma space
problematic=()
successful=()
for cask in ${casks[@]}
do
echo "${red}${cask}${reset} requires ${red}update${reset}."
brew fetch --cask ${cask}
exit_status=${?}
# If we can't download the new release (hash problems, website unavailibility, aliens...) we don't want to uninstall the current version!
if [ ${exit_status} -eq 0 ] ; then
brew uninstall --cask ${cask}
exit_status=${?}
if [ ${exit_status} -ne 0 ] ; then
echo "${red}${cask}${reset} encountered an error during the uninstallation (${exit_status}). ${red}PLEASE CHECK THE LOGS.${reset}"
problematic+=("${cask}")
# Skip to the next application to upgrade
continue
fi
brew install --cask ${cask}
exit_status=${?}
if [ ${exit_status} -eq 0 ] ; then
successful+=("${cask}")
echo "now ${red}${cask}${reset} is ${green}up-to-date!${reset}"
else
echo "${red}${cask}${reset} encountered an error during the installation (${exit_status}). ${red}PLEASE CHECK THE LOGS.${reset}"
problematic+=("${cask}")
fi
else
echo "${red}${cask}${reset} encountered an error during the download (${exit_status}). ${red}PLEASE CHECK THE LOGS.${reset}"
problematic+=("${cask}")
# Skip to the next application to upgrade
continue
fi
done
if [ ${#problematic[@]} -eq 0 ] ; then
echo "Cleaning brew cask cache..."
brew cleanup # Brew cask cleanup has been deprecated and disabled on 2018-09-30
if [ ${#successful[@]} -eq 0 ] ; then echo "${green}${successful[*]}${reset}have been successfully upgraded." ; fi;
echo "${green}Congratulations, your system is clean and up-to-date!${reset}"
else
echo "We encountered problems upgrading the following packages: ${red}${problematic[*]}${reset}. Some of these packages could be ${red}UNINSTALLED FROM YOUR SYSTEM${reset}, please check the logs. Not proceeding with the cask cleanup process."
fi
fi
# "Upgrading remaining brew cask apps..."
brew cu -a -y
# "Upgrading AppStore packages..."
mas upgrade
# "Upgrading MacOS internal packages..."
sudo softwareupdate -i -a