Last active
January 29, 2017 03:16
-
-
Save leipert/8a2b2d5bc6154e8ec135 to your computer and use it in GitHub Desktop.
Full brew and brew cask upgrade cycle in https://github.com/benjaminoakes/maid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Full brew and brew cask upgrade cycle in https://github.com/benjaminoakes/maid | |
# | |
Maid.rules do | |
### Homebrew: | |
rule 'Updating brew formulas' do | |
log(`brew update`) | |
end | |
rule 'Upgrading installed brew formulas' do | |
log(`brew upgrade -all`) | |
end | |
rule 'Cleaning brew' do | |
log(`brew cleanup`) | |
end | |
#Get all installed brew casks | |
installedCasks = (`brew cask list`).split() | |
# Upgrade casks, that have a version number other than latest | |
# Inspiration from https://github.com/caskroom/homebrew-cask/issues/4678#issuecomment-77692503 | |
rule 'Update brew casks' do | |
updateHappened = false | |
installedCasks.each do |cask| | |
needToInstall = system("brew cask info #{cask} |grep -qF 'Not installed'") | |
if needToInstall | |
updateHappened = true | |
log("New Version of homebrew cask #{cask}, will install it") | |
log(`brew cask install #{cask}`) | |
end | |
end | |
log('No brew cask updated') unless updateHappened | |
end | |
# Delete old cask versions | |
# Inspiration from https://gist.github.com/orangeudav/26a8752ae54a169b8516 | |
rule 'Clean brew casks' do | |
log(`brew cask cleanup`) | |
installedCasks.each do |cask| | |
# Get installed version folders for each installed cask | |
versions = dir("/opt/homebrew-cask/Caskroom/#{cask}/*") | |
# Jump to next if only one version is installed | |
next if versions.size == 1 | |
# Sort version folders by creation date | |
versions.sort_by! do |item| | |
created_at(item) | |
end | |
# Remove newest version folder from list | |
currVer = versions.pop | |
log("We won't delete newest version (#{currVer}) of #{cask}") | |
# Trash all remaining versions | |
versions.each do |version| | |
trash(version) | |
end | |
end | |
end | |
end |
Hi! Thanks for putting together this awesome script. I've just installed maid and used it for the first time this morning, and the two seem to work really well together and did exactly the job they advertised :-)
I added two flags to allow the user to choose whether this script should upgrade the software before clean-up or not. Within the scientific community we typically retain older versions of software for quite some time until we're sure that an upgrade won't cause any compatibility issues or break any core functionality. That is to say that full manual control over upgrades is a must for me (and probably many others). Feel free to merge my fork if you desire.
This script periodically removes the cask-installed Firefox.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do you deal with upgrades that need sudo privileges (and prompt for password)?