mac_setup 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/.gitignore +1 -0
 - data/exe/mac_setup +14 -4
 - data/lib/mac_setup/command_line_tools_installer.rb +30 -0
 - data/lib/mac_setup/configuration.rb +13 -5
 - data/lib/mac_setup/git_repo_installer.rb +48 -0
 - data/lib/mac_setup/homebrew_installer.rb +11 -3
 - data/lib/mac_setup/launch_agent_installer.rb +2 -0
 - data/lib/mac_setup/script_installer.rb +12 -0
 - data/lib/mac_setup/version.rb +1 -1
 - data/lib/mac_setup.rb +14 -2
 - metadata +5 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 88a72378f58d4b1c3fa3f47860839882d22a0381
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: af193618f6af8eb24972eb463646a6eeddbe4297
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 9c369085f19136ccf79b3228e7746aecf07724f2c256633a1fa61c6750431409b0460d892d5ab4de6f1689e288e22b5f1fb1e33c6de06b60cafae720bea30ec1
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 4ddf0256be709a839815a7d1fdee92e7d0adcb0a3e48b1937f68f8fe09aa40f07c854294ba301abefa84caff09b9fa9bac13a2caeeafe0cddffda51a84b840cb
         
     | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/exe/mac_setup
    CHANGED
    
    | 
         @@ -4,10 +4,20 @@ require 'mac_setup' 
     | 
|
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            DEFAULT_CONFIG_PATH = '~/.mac_setup.yml'
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
            command = ARGV.shift
         
     | 
| 
      
 8 
     | 
    
         
            +
            options = ARGV.select { |arg| arg.start_with?('--') }
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
      
 10 
     | 
    
         
            +
            case command
         
     | 
| 
      
 11 
     | 
    
         
            +
            when 'bootstrap'
         
     | 
| 
      
 12 
     | 
    
         
            +
              MacSetup.bootstrap(ARGV[0])
         
     | 
| 
      
 13 
     | 
    
         
            +
            when 'install'
         
     | 
| 
      
 14 
     | 
    
         
            +
              config_path = (ARGV - options)[0] || File.expand_path(DEFAULT_CONFIG_PATH)
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              if File.exist?(config_path)
         
     | 
| 
      
 17 
     | 
    
         
            +
                MacSetup.install(config_path, options)
         
     | 
| 
      
 18 
     | 
    
         
            +
              else
         
     | 
| 
      
 19 
     | 
    
         
            +
                puts "You must specify a path to config file or create one at #{DEFAULT_CONFIG_PATH}"
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
       11 
21 
     | 
    
         
             
            else
         
     | 
| 
       12 
     | 
    
         
            -
              puts " 
     | 
| 
      
 22 
     | 
    
         
            +
              puts "Unknown command: #{command}"
         
     | 
| 
       13 
23 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,30 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'fileutils'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative 'shell'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            module MacSetup
         
     | 
| 
      
 6 
     | 
    
         
            +
              class CommandLineToolsInstaller
         
     | 
| 
      
 7 
     | 
    
         
            +
                BIN_PATH = '/Library/Developer/CommandLineTools/usr/bin/clang'
         
     | 
| 
      
 8 
     | 
    
         
            +
                TMP_FILE = '/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress'
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                def self.run
         
     | 
| 
      
 11 
     | 
    
         
            +
                  if File.exist?(BIN_PATH)
         
     | 
| 
      
 12 
     | 
    
         
            +
                    puts 'Command Line Tools already installed. Skipping...'
         
     | 
| 
      
 13 
     | 
    
         
            +
                  else
         
     | 
| 
      
 14 
     | 
    
         
            +
                    install_clts
         
     | 
| 
      
 15 
     | 
    
         
            +
                  end
         
     | 
| 
      
 16 
     | 
    
         
            +
                end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                def self.install_clts
         
     | 
| 
      
 19 
     | 
    
         
            +
                  puts 'Installing Command Line Tools...'
         
     | 
| 
      
 20 
     | 
    
         
            +
                  FileUtils.touch(TMP_FILE)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  Shell.run(%(softwareupdate -i "#{package_name}" -v))
         
     | 
| 
      
 22 
     | 
    
         
            +
                  FileUtils.rm_f(TMP_FILE)
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                def self.package_name
         
     | 
| 
      
 26 
     | 
    
         
            +
                  response = Shell.run('softwareupdate -l')
         
     | 
| 
      
 27 
     | 
    
         
            +
                  response.match(/(Command.*$)/)[1]
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -2,7 +2,7 @@ require 'yaml' 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module MacSetup
         
     | 
| 
       4 
4 
     | 
    
         
             
              class Configuration
         
     | 
| 
       5 
     | 
    
         
            -
                 
     | 
| 
      
 5 
     | 
    
         
            +
                CASK_FORMULA = 'caskroom/cask/brew-cask'
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
                attr_reader :config
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
         @@ -11,11 +11,11 @@ module MacSetup 
     | 
|
| 
       11 
11 
     | 
    
         
             
                end
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
                def taps
         
     | 
| 
       14 
     | 
    
         
            -
                   
     | 
| 
      
 14 
     | 
    
         
            +
                  (@config['taps'] || []).uniq
         
     | 
| 
       15 
15 
     | 
    
         
             
                end
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
                def formulas
         
     | 
| 
       18 
     | 
    
         
            -
                  (@config['formulas'] || []).uniq
         
     | 
| 
      
 18 
     | 
    
         
            +
                  add_cask(@config['formulas'] || []).uniq
         
     | 
| 
       19 
19 
     | 
    
         
             
                end
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
21 
     | 
    
         
             
                def casks
         
     | 
| 
         @@ -26,10 +26,18 @@ module MacSetup 
     | 
|
| 
       26 
26 
     | 
    
         
             
                  (@config['launch_agents'] || []).uniq
         
     | 
| 
       27 
27 
     | 
    
         
             
                end
         
     | 
| 
       28 
28 
     | 
    
         | 
| 
      
 29 
     | 
    
         
            +
                def git_repos
         
     | 
| 
      
 30 
     | 
    
         
            +
                  (@config['git_repos'] || []).uniq
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                def scripts
         
     | 
| 
      
 34 
     | 
    
         
            +
                  (@config['scripts'] || []).uniq
         
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
       29 
37 
     | 
    
         
             
                private
         
     | 
| 
       30 
38 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
                def  
     | 
| 
       32 
     | 
    
         
            -
                  casks.any? ?  
     | 
| 
      
 39 
     | 
    
         
            +
                def add_cask(specified_formulas)
         
     | 
| 
      
 40 
     | 
    
         
            +
                  casks.any? ? specified_formulas << CASK_FORMULA : specified_formulas
         
     | 
| 
       33 
41 
     | 
    
         
             
                end
         
     | 
| 
       34 
42 
     | 
    
         
             
              end
         
     | 
| 
       35 
43 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,48 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require_relative 'shell'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module MacSetup
         
     | 
| 
      
 4 
     | 
    
         
            +
              class GitRepoInstaller
         
     | 
| 
      
 5 
     | 
    
         
            +
                def self.run(config)
         
     | 
| 
      
 6 
     | 
    
         
            +
                  repos = config.git_repos
         
     | 
| 
      
 7 
     | 
    
         
            +
                  return if repos.none?
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                  puts 'Installing Git Repos...'
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                  repos.each do |repo_and_path|
         
     | 
| 
      
 12 
     | 
    
         
            +
                    repo, install_path = repo_and_path.to_a.flatten
         
     | 
| 
      
 13 
     | 
    
         
            +
                    install_repo(repo, File.expand_path(install_path))
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                def self.install_repo(repo, install_path)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  if Dir.exist?(install_path)
         
     | 
| 
      
 19 
     | 
    
         
            +
                    print "#{repo} Already Installed. Updating..."
         
     | 
| 
      
 20 
     | 
    
         
            +
                    update_repo(install_path)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  else
         
     | 
| 
      
 22 
     | 
    
         
            +
                    print "Installing #{repo}..."
         
     | 
| 
      
 23 
     | 
    
         
            +
                    url = expand_url(repo)
         
     | 
| 
      
 24 
     | 
    
         
            +
                    Shell.run(%(git clone --recursive #{url} "#{install_path}"))
         
     | 
| 
      
 25 
     | 
    
         
            +
                    puts 'Ok'
         
     | 
| 
      
 26 
     | 
    
         
            +
                  end
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                def self.update_repo(install_path)
         
     | 
| 
      
 30 
     | 
    
         
            +
                  Dir.chdir(install_path) do
         
     | 
| 
      
 31 
     | 
    
         
            +
                    if can_update?
         
     | 
| 
      
 32 
     | 
    
         
            +
                      Shell.run('git pull && git submodule update --init --recursive')
         
     | 
| 
      
 33 
     | 
    
         
            +
                      puts 'Ok'
         
     | 
| 
      
 34 
     | 
    
         
            +
                    else
         
     | 
| 
      
 35 
     | 
    
         
            +
                      puts "\nCan't update. Unstaged changes in #{install_path}"
         
     | 
| 
      
 36 
     | 
    
         
            +
                    end
         
     | 
| 
      
 37 
     | 
    
         
            +
                  end
         
     | 
| 
      
 38 
     | 
    
         
            +
                end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                def self.can_update?
         
     | 
| 
      
 41 
     | 
    
         
            +
                  Shell.run('git status --porcelain').empty?
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                def self.expand_url(repo)
         
     | 
| 
      
 45 
     | 
    
         
            +
                  repo =~ %r{^[^/]+/[^/]+$} ? "https://github.com/#{repo}.git" : repo
         
     | 
| 
      
 46 
     | 
    
         
            +
                end
         
     | 
| 
      
 47 
     | 
    
         
            +
              end
         
     | 
| 
      
 48 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -4,7 +4,7 @@ module MacSetup 
     | 
|
| 
       4 
4 
     | 
    
         
             
              class HomebrewInstaller
         
     | 
| 
       5 
5 
     | 
    
         
             
                BREW_INSTALL_URL = 'https://raw.githubusercontent.com/Homebrew/install/master/install'
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
                def self.run
         
     | 
| 
      
 7 
     | 
    
         
            +
                def self.run(options = [])
         
     | 
| 
       8 
8 
     | 
    
         
             
                  if homebrew_missing?
         
     | 
| 
       9 
9 
     | 
    
         
             
                    puts 'Installing Homebrew...'
         
     | 
| 
       10 
10 
     | 
    
         
             
                    Shell.run("curl -fsS '#{BREW_INSTALL_URL}' | ruby")
         
     | 
| 
         @@ -12,12 +12,20 @@ module MacSetup 
     | 
|
| 
       12 
12 
     | 
    
         
             
                    puts 'Homebrew already installed...'
         
     | 
| 
       13 
13 
     | 
    
         
             
                  end
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
                   
     | 
| 
       16 
     | 
    
         
            -
                  Shell.run('brew update')
         
     | 
| 
      
 15 
     | 
    
         
            +
                  update_homebrew(options)
         
     | 
| 
       17 
16 
     | 
    
         
             
                end
         
     | 
| 
       18 
17 
     | 
    
         | 
| 
       19 
18 
     | 
    
         
             
                def self.homebrew_missing?
         
     | 
| 
       20 
19 
     | 
    
         
             
                  Shell.run('which brew').empty?
         
     | 
| 
       21 
20 
     | 
    
         
             
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                def self.update_homebrew(options)
         
     | 
| 
      
 23 
     | 
    
         
            +
                  if options.include?('--skip-brew-update')
         
     | 
| 
      
 24 
     | 
    
         
            +
                    puts 'Skipping Homebrew Update...'
         
     | 
| 
      
 25 
     | 
    
         
            +
                  else
         
     | 
| 
      
 26 
     | 
    
         
            +
                    puts 'Updating Homebrew...'
         
     | 
| 
      
 27 
     | 
    
         
            +
                    Shell.run('brew update')
         
     | 
| 
      
 28 
     | 
    
         
            +
                  end
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
       22 
30 
     | 
    
         
             
              end
         
     | 
| 
       23 
31 
     | 
    
         
             
            end
         
     | 
    
        data/lib/mac_setup/version.rb
    CHANGED
    
    
    
        data/lib/mac_setup.rb
    CHANGED
    
    | 
         @@ -1,21 +1,33 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'mac_setup/version'
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'mac_setup/configuration'
         
     | 
| 
       3 
3 
     | 
    
         
             
            require 'mac_setup/system_status'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'mac_setup/command_line_tools_installer'
         
     | 
| 
       4 
5 
     | 
    
         
             
            require 'mac_setup/homebrew_installer'
         
     | 
| 
       5 
6 
     | 
    
         
             
            require 'mac_setup/tap_installer'
         
     | 
| 
       6 
7 
     | 
    
         
             
            require 'mac_setup/formula_installer'
         
     | 
| 
       7 
8 
     | 
    
         
             
            require 'mac_setup/cask_installer'
         
     | 
| 
       8 
9 
     | 
    
         
             
            require 'mac_setup/launch_agent_installer'
         
     | 
| 
      
 10 
     | 
    
         
            +
            require 'mac_setup/git_repo_installer'
         
     | 
| 
      
 11 
     | 
    
         
            +
            require 'mac_setup/script_installer'
         
     | 
| 
       9 
12 
     | 
    
         | 
| 
       10 
13 
     | 
    
         
             
            module MacSetup
         
     | 
| 
       11 
     | 
    
         
            -
               
     | 
| 
      
 14 
     | 
    
         
            +
              DOTFILES_PATH = File.expand_path('~/.dotfiles')
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              def self.install(config_path, options)
         
     | 
| 
       12 
17 
     | 
    
         
             
                config = Configuration.new(File.expand_path(config_path))
         
     | 
| 
       13 
18 
     | 
    
         
             
                status = SystemStatus.new
         
     | 
| 
       14 
19 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
                HomebrewInstaller.run
         
     | 
| 
      
 20 
     | 
    
         
            +
                HomebrewInstaller.run(options)
         
     | 
| 
       16 
21 
     | 
    
         
             
                TapInstaller.run(config, status)
         
     | 
| 
       17 
22 
     | 
    
         
             
                FormulaInstaller.run(config, status)
         
     | 
| 
       18 
23 
     | 
    
         
             
                CaskInstaller.run(config, status)
         
     | 
| 
       19 
24 
     | 
    
         
             
                LaunchAgentInstaller.run(config, status)
         
     | 
| 
      
 25 
     | 
    
         
            +
                GitRepoInstaller.run(config)
         
     | 
| 
      
 26 
     | 
    
         
            +
                ScriptInstaller.run(config)
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
              def self.bootstrap(dotfiles_repo)
         
     | 
| 
      
 30 
     | 
    
         
            +
                GitRepoInstaller.install_repo(dotfiles_repo, DOTFILES_PATH)
         
     | 
| 
      
 31 
     | 
    
         
            +
                CommandLineToolsInstaller.run
         
     | 
| 
       20 
32 
     | 
    
         
             
              end
         
     | 
| 
       21 
33 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: mac_setup
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Matt Wean
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2015- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2015-10-01 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -104,10 +104,13 @@ files: 
     | 
|
| 
       104 
104 
     | 
    
         
             
            - exe/mac_setup
         
     | 
| 
       105 
105 
     | 
    
         
             
            - lib/mac_setup.rb
         
     | 
| 
       106 
106 
     | 
    
         
             
            - lib/mac_setup/cask_installer.rb
         
     | 
| 
      
 107 
     | 
    
         
            +
            - lib/mac_setup/command_line_tools_installer.rb
         
     | 
| 
       107 
108 
     | 
    
         
             
            - lib/mac_setup/configuration.rb
         
     | 
| 
       108 
109 
     | 
    
         
             
            - lib/mac_setup/formula_installer.rb
         
     | 
| 
      
 110 
     | 
    
         
            +
            - lib/mac_setup/git_repo_installer.rb
         
     | 
| 
       109 
111 
     | 
    
         
             
            - lib/mac_setup/homebrew_installer.rb
         
     | 
| 
       110 
112 
     | 
    
         
             
            - lib/mac_setup/launch_agent_installer.rb
         
     | 
| 
      
 113 
     | 
    
         
            +
            - lib/mac_setup/script_installer.rb
         
     | 
| 
       111 
114 
     | 
    
         
             
            - lib/mac_setup/shell.rb
         
     | 
| 
       112 
115 
     | 
    
         
             
            - lib/mac_setup/system_status.rb
         
     | 
| 
       113 
116 
     | 
    
         
             
            - lib/mac_setup/tap_installer.rb
         
     |