Move to using a Brewfile and be smarter about cleaning up Casks.
This commit is contained in:
parent
6e2ad13953
commit
45c3dae58d
39
Brewfile
Normal file
39
Brewfile
Normal file
|
@ -0,0 +1,39 @@
|
|||
brew "ack"
|
||||
brew "archey"
|
||||
brew "bash-completion"
|
||||
brew "git"
|
||||
brew "coreutils"
|
||||
brew "htop-osx"
|
||||
brew "mosh"
|
||||
brew "nmap"
|
||||
brew "p7zip"
|
||||
brew "pv"
|
||||
brew "python3"
|
||||
brew "rename"
|
||||
brew "vim"
|
||||
|
||||
cask "1password"
|
||||
cask "alfred"
|
||||
cask "bbc-iplayer-downloads"
|
||||
cask "beardedspice"
|
||||
cask "bittorrent-sync"
|
||||
cask "cleanmymac"
|
||||
cask "day-o"
|
||||
cask "dropbox"
|
||||
cask "firefox"
|
||||
cask "flux"
|
||||
cask "gitx"
|
||||
cask "gpgtools"
|
||||
cask "google-chrome"
|
||||
cask "google-drive"
|
||||
cask "google-hangouts"
|
||||
cask "handbrake"
|
||||
cask "iterm2"
|
||||
cask "sonos"
|
||||
cask "textmate"
|
||||
cask "vlc"
|
||||
cask "vmware-fusion"
|
||||
cask "wireshark"
|
||||
cask "xquartz"
|
||||
cask "yubikey-neo-manager"
|
||||
cask "yubikey-personalization-gui"
|
146
bin/cask-upgrade
Executable file
146
bin/cask-upgrade
Executable file
|
@ -0,0 +1,146 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
# A workaround to upgrade installed casks
|
||||
# Update Homebrew Cask and verify installed applications versions with Casks to perform an upgrade
|
||||
# The app prompts you to update only if the Cask contain a version number and the installed app version can be retrieved.
|
||||
# Therefore casks that use "latest" will not be updated
|
||||
#
|
||||
# NOTE: THIS SCRIPT COMPLETELY REMOVES OUT-OF-DATE CASKS & ADDS THE LATEST VERSION.
|
||||
#
|
||||
# Usage :
|
||||
# cask-upgrade : prompt each time it encouter an update to install it
|
||||
# cask-upgrade auto : will upgrade applications automatically
|
||||
# cask-upgrade atom : will search for an application called atom and upgrade it
|
||||
|
||||
class String
|
||||
def black; "\e[30m#{self}\e[0m" end
|
||||
def red; "\e[31m#{self}\e[0m" end
|
||||
def green; "\e[32m#{self}\e[0m" end
|
||||
def brown; "\e[33m#{self}\e[0m" end
|
||||
def blue; "\e[34m#{self}\e[0m" end
|
||||
def magenta; "\e[35m#{self}\e[0m" end
|
||||
def cyan; "\e[36m#{self}\e[0m" end
|
||||
def gray; "\e[1;30m#{self}\e[0m" end
|
||||
|
||||
def bg_black; "\e[40m#{self}\e[0m" end
|
||||
def bg_red; "\e[41m#{self}\e[0m" end
|
||||
def bg_green; "\e[42m#{self}\e[0m" end
|
||||
def bg_brown; "\e[43m#{self}\e[0m" end
|
||||
def bg_blue; "\e[44m#{self}\e[0m" end
|
||||
def bg_magenta; "\e[45m#{self}\e[0m" end
|
||||
def bg_cyan; "\e[46m#{self}\e[0m" end
|
||||
def bg_gray; "\e[47m#{self}\e[0m" end
|
||||
|
||||
def bold; "\e[1m#{self}\e[22m" end
|
||||
def italic; "\e[3m#{self}\e[23m" end
|
||||
def underline; "\e[4m#{self}\e[24m" end
|
||||
def blink; "\e[5m#{self}\e[25m" end
|
||||
def reverse_color; "\e[7m#{self}\e[27m" end
|
||||
end
|
||||
|
||||
option = ARGV[0]
|
||||
auto = (option == 'auto') ? true : false
|
||||
# this is where you want to install casks
|
||||
appdir = '/Applications'
|
||||
|
||||
system('clear')
|
||||
|
||||
# CHANGE APP FOLDER
|
||||
CASK_OPTIONS = `echo $HOMEBREW_CASK_OPTS`.freeze
|
||||
if appdiropt = CASK_OPTIONS.match(/--appdir=(\S+)\s+/)
|
||||
appdir = appdiropt[1] if File.exist?(appdiropt[1])
|
||||
end
|
||||
puts "Application directory: #{appdir}"
|
||||
|
||||
# UPGRADE SPECIFIC APP
|
||||
if !option.nil? && !option.empty? && option != 'auto'
|
||||
app = option.chomp
|
||||
if system("brew cask info #{app} &>/dev/null")
|
||||
print "Do you want to reinstall #{app}? " + '[ y/N ] '.gray
|
||||
update = STDIN.gets.strip
|
||||
if update =~ /[yY]/
|
||||
puts "closing any open instances of #{app}".cyan
|
||||
system("osascript -e \'quit app \"#{app}\"\' && sleep 1")
|
||||
puts "Upgrading #{app}".green
|
||||
system("brew cask uninstall #{app} --force && sleep 1 && brew cask install #{app} --force")
|
||||
else
|
||||
puts 'Canceling update...'.brown
|
||||
end
|
||||
else
|
||||
puts 'Unknow app to update'.red
|
||||
end
|
||||
exit!
|
||||
end
|
||||
|
||||
# UPDATE HOMEBREW
|
||||
puts 'Updating homebrew cask, please wait...'.cyan
|
||||
system('brew cask update')
|
||||
if $CHILD_STATUS == 1
|
||||
puts 'Cask update failed'.red
|
||||
exit!
|
||||
end
|
||||
system('clear')
|
||||
|
||||
# BREW CASK LIST
|
||||
# IO.popen("echo atom") { |apps|
|
||||
IO.popen('brew cask list') do |apps|
|
||||
apps.each do |app|
|
||||
app.chomp!
|
||||
puts '+-------------------------------------------------------------------+'
|
||||
infosstr = app.upcase
|
||||
infos = `brew cask info #{app}`
|
||||
if vmatch = /: ([0-9\._]+)/.match(infos.lines.first)
|
||||
version, build = vmatch[1].split(/[_-]/)
|
||||
infosstr += " version #{version}".gray
|
||||
infosstr += " (#{build})".gray if build
|
||||
|
||||
print infosstr.to_s
|
||||
column1length = 69 - infosstr.gsub(/\e\[[0-9;]+[m]?/, '').length
|
||||
|
||||
if appname = /(.*) \(app\)/.match(infos)
|
||||
# APPLICATION FILENAME
|
||||
appname = appname[1].strip
|
||||
if File.exist?("#{appdir}/#{appname}")
|
||||
# GET APPLICATION VERSION WITH SPOTLIGHT
|
||||
if currentmatch = /([0-9\.]+)/.match(`mdls "#{appdir}/#{appname}" -name kMDItemVersion -raw`)
|
||||
current = currentmatch[1].chomp
|
||||
# COMPARE INSTALLED VERSION WITH CASK VERSION
|
||||
if Gem::Version.new(version) <= Gem::Version.new(current)
|
||||
puts 'up-to-date'.rjust(column1length).green
|
||||
elsif current != '(null)' && version != 'latest'
|
||||
puts 'update available'.rjust(column1length).cyan
|
||||
print "Do you want to update #{app} to version #{version.green} (current #{current.green})? " + '[ y/N ] '.gray
|
||||
if auto
|
||||
puts 'auto'.cyan
|
||||
update = 'y'
|
||||
else
|
||||
update = STDIN.gets.strip
|
||||
end
|
||||
# UPDATE CURRENT APPLICAION
|
||||
if update =~ /[yY]/
|
||||
puts "Updating #{app} to version #{version}".green
|
||||
puts "Closing any open instances of #{app}".cyan
|
||||
system("osascript -e \'quit app \"#{app}\"\' && sleep 1")
|
||||
system("brew cask uninstall #{app} --force && sleep 1 && brew cask install #{app} --force")
|
||||
else
|
||||
puts 'Cancel update...'.brown
|
||||
end
|
||||
else
|
||||
puts 'update undefined...'.rjust(column1length)
|
||||
end
|
||||
else
|
||||
puts 'unknown installed version'.rjust(column1length).brown
|
||||
end
|
||||
else
|
||||
puts 'not found'.rjust(column1length)
|
||||
end
|
||||
else
|
||||
puts 'unknown app'.rjust(column1length).brown
|
||||
end
|
||||
else
|
||||
print infosstr.to_s
|
||||
column1length = 69 - infosstr.length
|
||||
puts 'unknown version'.rjust(column1length).brown
|
||||
end
|
||||
end
|
||||
end
|
|
@ -38,72 +38,49 @@ function install_osx_software {
|
|||
fi
|
||||
#-------------------------------
|
||||
|
||||
#-------------------------------
|
||||
# Update Brew formulae if older than 24 hours
|
||||
#-------------------------------
|
||||
find /usr/local/.git -name FETCH_HEAD -mtime +0 -exec brew update \;
|
||||
|
||||
# Install homebrew/bundle tap if we don't have it
|
||||
[ -d /usr/local/Library/Taps/homebrew/homebrew-bundle ] || brew tap homebrew/bundle
|
||||
|
||||
#-------------------------------
|
||||
# Run brew bundle if there's a newer version of Brewfile
|
||||
#-------------------------------
|
||||
if [ ~/Brewfile -nt ~/.Brewfile.updated ]; then
|
||||
brew bundle && touch ~/.Brewfile.updated
|
||||
fi
|
||||
#-------------------------------
|
||||
|
||||
#-------------------------------
|
||||
# Install the basics
|
||||
#-------------------------------
|
||||
xargs brew install <<-EOF
|
||||
ack
|
||||
archey
|
||||
bash-completion
|
||||
git
|
||||
coreutils
|
||||
htop-osx
|
||||
mosh
|
||||
nmap
|
||||
p7zip
|
||||
pv
|
||||
python3
|
||||
rename
|
||||
vim
|
||||
EOF
|
||||
#-------------------------------
|
||||
|
||||
#-------------------------------
|
||||
# Install Casks
|
||||
#-------------------------------
|
||||
xargs brew cask install <<-EOF
|
||||
1password
|
||||
alfred
|
||||
bbc-iplayer-downloads
|
||||
beardedspice
|
||||
bittorrent-sync
|
||||
cleanmymac
|
||||
day-o
|
||||
dropbox
|
||||
firefox
|
||||
flux
|
||||
gitx
|
||||
gpgtools
|
||||
google-chrome
|
||||
google-drive
|
||||
google-hangouts
|
||||
handbrake
|
||||
iterm2
|
||||
sonos
|
||||
textmate
|
||||
vlc
|
||||
vmware-fusion
|
||||
wireshark
|
||||
xquartz
|
||||
yubikey-neo-manager
|
||||
yubikey-personalization-gui
|
||||
EOF
|
||||
#-------------------------------
|
||||
|
||||
#-------------------------------
|
||||
# Clean up
|
||||
# Upgrade and clean
|
||||
#-------------------------------
|
||||
brew upgrade
|
||||
brew cleanup
|
||||
brew bundle check || ( cask-upgrade auto && cask-tidy )
|
||||
brew cask cleanup
|
||||
#-------------------------------
|
||||
}
|
||||
|
||||
function __remove-cask {
|
||||
caskBasePath="/opt/homebrew-cask/Caskroom"
|
||||
local cask="$1"
|
||||
local caskDirectory="$caskBasePath/$cask"
|
||||
local versionsToRemove="$(ls -r $caskDirectory | sed 1,1d)"
|
||||
if [[ -n $versionsToRemove ]]; then
|
||||
while read versionToRemove ; do
|
||||
echo "Removing $cask $versionToRemove..."
|
||||
rm -rf "$caskDirectory/$versionToRemove"
|
||||
done <<< "$versionsToRemove"
|
||||
fi
|
||||
}
|
||||
|
||||
function cask-tidy {
|
||||
while read cask; do
|
||||
__remove-cask "$cask"
|
||||
done <<< "$(brew cask list)"
|
||||
}
|
||||
|
||||
echo "#-------------------------------"
|
||||
echo "# START: $(date)"
|
||||
echo "#-------------------------------"
|
||||
|
|
Loading…
Reference in a new issue