Created
April 24, 2021 22:14
-
-
Save adamwhitakerwilson/64eca65cf8478ca328ed151ce588af64 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require 'pathname' | |
class << ENV | |
def path | |
@path ||= self['PATH'].split(':').map{ |d| Pathname.new(d) } | |
end | |
def which(cmd) | |
cmd = cmd.to_s | |
self.path.lazy.map{ |d| d + cmd }.find{ |e| e.file? && e.executable? } | |
end | |
end | |
COLORS = { | |
green: "\e[32m", | |
yellow: "\e[33m", | |
reset: "\e[0m" | |
} | |
def colorize(str, color) | |
COLORS[color] + str + COLORS[:reset] | |
end | |
def run_cmd(cmd) | |
puts("=> " + colorize(cmd.join(' '), :green)) | |
system(*cmd) | |
end | |
def read_from_cmd(cmd) | |
puts("** " + colorize(cmd.join(' '), :yellow)) | |
IO.popen(cmd){ |f| f.read.split("\n").map{ |ln| ln.strip } } | |
end | |
if ENV.which('softwareupdate') | |
su_commands = [ | |
['--download'] | |
] | |
su_commands.each do |cmd| | |
cmd = ['softwareupdate'] + cmd | |
run_cmd(cmd) | |
end | |
end | |
if ENV.which('mas') | |
mas_commands = [ | |
['upgrade'] | |
] | |
mas_commands.each do |cmd| | |
cmd = ['mas'] + cmd | |
run_cmd(cmd) | |
end | |
end | |
if ENV.which('qlmanage') | |
run_cmd(['qlmanage', '-r', 'cache']) | |
end | |
if ENV.which('apt-get') | |
apt_commands = [ | |
['update'], | |
['dist-upgrade'], | |
['autoremove', '--purge'], | |
['clean'] | |
] | |
apt_commands.each do |cmd| | |
cmd = ['sudo', 'apt-get'] + cmd | |
run_cmd(cmd) | |
end | |
end | |
if ENV.which('brew') | |
brew_commands = [ | |
['update'], | |
['upgrade'], | |
['cleanup'], | |
] | |
brew_commands.each do |cmd| | |
next unless cmd | |
cmd = ['brew'] + cmd | |
run_cmd(cmd) | |
end | |
end | |
['pip', 'pip3'].each do |pip_cmd| | |
next | |
next unless ENV.which(pip_cmd) | |
wheel_lns = read_from_cmd([pip_cmd, 'list', '--outdated'])[2..-1] || [] | |
wheels = wheel_lns.map{ |ln| ln.split(' ').first } | |
pip_blacklist = ['pip', 'setuptools'] | |
wheels -= pip_blacklist | |
unless wheels.empty? | |
run_cmd([pip_cmd, 'install', '--upgrade'] + wheels) | |
end | |
end | |
if ENV.which('gem') | |
run_cmd(['gem', 'update']) | |
run_cmd(['gem', 'cleanup']) | |
end | |
if ENV.which('npm') | |
run_cmd(['npm', 'update', '-g']) | |
end | |
if ENV.which('rustup') | |
run_cmd(['rustup', 'update']) | |
end | |
if ENV.which('gcloud') | |
run_cmd(['gcloud', 'components', 'update', '--quiet']) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment