Created
November 15, 2017 17:26
-
-
Save ryangreenberg/214dc44b1df61e286a1e81ed3de72a0c to your computer and use it in GitHub Desktop.
install_homebrew, script to install packages on a new machine (extracted from private dotfiles)
This file contains hidden or 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
1password | |
divvy | |
dropbox | |
google-chrome | |
nvalt | |
screenflow | |
skitch | |
spotify | |
sublime-text |
This file contains hidden or 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
# Stored in `homebrew/` relative to the installation script | |
ack | |
autossh | |
cloc | |
coreutils | |
diff-so-fancy | |
git | |
gnu-sed | |
gnu-tar | |
grep | |
htop | |
imagemagick | |
jq | |
mas | |
netcat | |
pandoc | |
parallel | |
pcre | |
pstree | |
pv | |
rbenv | |
readline | |
ruby-build | |
socat | |
sqlite | |
the_silver_searcher | |
tig | |
tmux | |
tree | |
watch |
This file contains hidden or 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 | |
# Installs homebrew packages from groups in homebrew directory | |
require 'io/console' | |
# Assumes installation somewhere in a user's home directory | |
current_dir = File.dirname(File.expand_path(__FILE__)) | |
HOMEBREW_PATH = File.join(current_dir, 'homebrew') | |
def homebrew_installed? | |
system("hash brew") | |
end | |
def installed_packages(list_cmd) | |
`#{list_cmd}`.split("\n").map {|ea| ea.strip } | |
end | |
def load_groups | |
Dir.glob("#{HOMEBREW_PATH}/*").map {|ea| File.basename(ea) } | |
end | |
def load_packages(group_name) | |
File.read(File.join(HOMEBREW_PATH, group_name)).split("\n") | |
end | |
# output a command for display and run it | |
def systemv(cmd) | |
warn cmd | |
system cmd | |
end | |
# Prompt the user to enter Y/n | |
def yes? | |
input = STDIN.getch | |
abort if input == "\u0003" # ctrl-c | |
["y", "\n", "\r"].include?(input) | |
end | |
def main | |
unless homebrew_installed? | |
warn "Homebrew not installed." | |
warn "Install from instructions at https://brew.sh/" | |
abort | |
end | |
# Any group that starts with "cask" will be installed using | |
# `brew cask` instead of plain `brew` | |
# | |
# Prioritize any group named core | |
groups = load_groups.sort_by {|ea| ea == "core" ? " " : ea } | |
puts "Found #{groups.size} groups: #{groups.join(", ")}" | |
groups.each do |group| | |
is_cask = group.start_with?("cask") | |
list_cmd = is_cask ? "brew cask list" : "brew list" | |
install_cmd = is_cask ? "brew cask install --force" : "brew install" | |
current_packages = installed_packages(list_cmd) | |
group_packages = load_packages(group) | |
puts "" | |
puts "#{group.upcase} (#{group_packages.size} packages)" | |
group_packages.sort.each do |pkg| | |
char = current_packages.include?(pkg) ? "✔︎" : "✘" | |
puts "#{char} #{pkg}" | |
end | |
missing_packages = group_packages - current_packages | |
if missing_packages.empty? | |
puts "All packages installed" | |
else | |
puts "The following packages are missing from the #{group} group: #{missing_packages.join(", ")}" | |
print "Install? [Y/n] " | |
if yes? | |
puts "Installing..." | |
systemv "#{install_cmd} #{missing_packages.join(' ')}" | |
end | |
end | |
puts "" | |
end | |
end | |
main if $PROGRAM_NAME == __FILE__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment