mac_setup 0.7.0 → 0.7.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d138f54b0282d08ae090d9d610449a01ca085ca8
4
- data.tar.gz: e6c8f046d259c1716ddb3c2fa0b93b8ebdccf6aa
3
+ metadata.gz: 32bfd8387f06a6e39a2fe649c573ada644381af0
4
+ data.tar.gz: d81c0672a8f3f4ce45b63c3b031e089d5a8ad38c
5
5
  SHA512:
6
- metadata.gz: aa607f339bdb85eeebebd20ae6e80d4d75dace9979b040d2226ead3947fbc91449785132b304e8caf5c2b768f9aee26bba1b6bdacd80c4fb760d8aedcb8d6783
7
- data.tar.gz: 7652ec93fbfb92e1614ab32b7f5919bbb82b1c56296297b0de8244c7d3a7db19aff3432dc236b6078a9c8612baefd338840f42476046d90a7e8956d7dbc7f5b2
6
+ metadata.gz: c48aca54cefb1d8c2284ecf2e39ae38d30a58784756bed95405077dc38aecd4e6eaf49b514f6e717a50c179cf2919fa620110926d1c83d173fa8fddfaf1e765f
7
+ data.tar.gz: 8c40807b907e4c2d240edc298bae37187b3e6f9e64724cba6afdf8d2b831309a5fd7acc4022542c0fcf970d59ab7b0d82fcdd92cd450d0d67421c840de9e2049
data/exe/mac_setup CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "mac_setup"
4
4
 
5
- DEFAULT_CONFIG_PATH = "~/.mac_setup/config.yml"
5
+ DEFAULT_CONFIG_PATH = "~/.dotfiles/mac_setup/config.yml"
6
6
 
7
7
  command = ARGV.shift
8
8
  options = ARGV.select { |arg| arg.start_with?("--") }
@@ -1,3 +1,4 @@
1
+ require "pathname"
1
2
  require_relative "shell"
2
3
 
3
4
  module MacSetup
@@ -19,7 +20,6 @@ module MacSetup
19
20
  tap_bundle
20
21
  set_up_mas
21
22
  install_brewfile
22
- install_openssl
23
23
  end
24
24
 
25
25
  private
@@ -39,13 +39,22 @@ module MacSetup
39
39
  end
40
40
 
41
41
  def install_mas
42
- Shell.run("brew install mas") unless mas_installed?
42
+ if mas_installed?
43
+ MacSetup.log "mas already installed. Skipping."
44
+ else
45
+ MacSetup.log "Installing mas" do
46
+ Shell.run("brew install mas")
47
+ end
48
+ end
43
49
  end
44
50
 
45
51
  def sign_in_to_mas
46
- return if mas_signed_in?
47
- apple_id = Shell.ask("What is your Apple ID?")
48
- Shell.run("mas signin --dialog #{apple_id}")
52
+ if mas_signed_in?
53
+ MacSetup.log "Already signed into Mac App Store. Skipping."
54
+ else
55
+ apple_id = Shell.ask("What is your Apple ID?")
56
+ Shell.run("mas signin --dialog #{apple_id}")
57
+ end
49
58
  end
50
59
 
51
60
  def mas_signed_in?
@@ -53,18 +62,15 @@ module MacSetup
53
62
  end
54
63
 
55
64
  def install_brewfile
56
- Shell.run("brew bundle --global")
65
+ MacSetup.log "Installing Brewfile" do
66
+ Shell.run("brew bundle --global")
67
+ end
57
68
  end
58
69
 
59
70
  def mas_installed?
60
71
  Shell.success?("which mas")
61
72
  end
62
73
 
63
- def install_openssl
64
- # Needed for encrypted files
65
- Shell.run("brew install openssl")
66
- end
67
-
68
74
  def bundle_already_tapped?
69
75
  status.installed_taps.include?(BUNDLE_TAP)
70
76
  end
@@ -1,30 +1,15 @@
1
- require "fileutils"
2
-
3
1
  require_relative "shell"
4
2
 
5
3
  module MacSetup
6
4
  class CommandLineToolsInstaller
7
5
  BIN_PATH = "/Library/Developer/CommandLineTools/usr/bin/clang"
8
- TMP_FILE = "/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress"
9
6
 
10
7
  def self.run
11
8
  if File.exist?(BIN_PATH)
12
9
  puts "Command Line Tools already installed. Skipping..."
13
10
  else
14
- install_clts
11
+ Shell.run("xcode-select --install")
15
12
  end
16
13
  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
14
  end
30
15
  end
@@ -5,7 +5,16 @@ module MacSetup
5
5
  attr_reader :config
6
6
 
7
7
  def initialize(config_path)
8
- @config = YAML.load_file(config_path)
8
+ @config_path = config_path
9
+ load_config
10
+ end
11
+
12
+ def reload!
13
+ load_config
14
+ end
15
+
16
+ def dotfiles_repo
17
+ @config.fetch("repo")
9
18
  end
10
19
 
11
20
  def services
@@ -13,11 +22,17 @@ module MacSetup
13
22
  end
14
23
 
15
24
  def git_repos
16
- ((@config["git_repos"] || []) + [@config["repo"]]).uniq
25
+ (@config["git_repos"] || []).uniq
17
26
  end
18
27
 
19
28
  def symlinks
20
29
  (@config["symlinks"] || []).uniq
21
30
  end
31
+
32
+ private
33
+
34
+ def load_config
35
+ @config = YAML.load_file(@config_path)
36
+ end
22
37
  end
23
38
  end
@@ -6,7 +6,7 @@ module MacSetup
6
6
  repos = config.git_repos
7
7
  return if repos.none?
8
8
 
9
- puts "Installing Git Repos..."
9
+ MacSetup.log "Installing Git Repos..."
10
10
 
11
11
  repos.each do |repo_and_path|
12
12
  repo, install_path = repo_and_path.to_a.flatten
@@ -16,13 +16,14 @@ module MacSetup
16
16
 
17
17
  def self.install_repo(repo, install_path)
18
18
  if Dir.exist?(install_path)
19
- print "#{repo} Already Installed. Updating..."
20
- update_repo(install_path)
19
+ MacSetup.log "#{repo} Already Installed. Updating" do
20
+ update_repo(install_path)
21
+ end
21
22
  else
22
- print "Installing #{repo}..."
23
- url = expand_url(repo)
24
- Shell.run(%(git clone --recursive #{url} "#{install_path}"))
25
- puts "Ok"
23
+ MacSetup.log "Installing #{repo}" do
24
+ url = expand_url(repo)
25
+ Shell.run(%(git clone --recursive #{url} "#{install_path}"))
26
+ end
26
27
  end
27
28
  end
28
29
 
@@ -30,9 +31,9 @@ module MacSetup
30
31
  Dir.chdir(install_path) do
31
32
  if can_update?
32
33
  Shell.run("git pull && git submodule update --init --recursive")
33
- puts "Ok"
34
34
  else
35
35
  puts "\nCan't update. Unstaged changes in #{install_path}"
36
+ exit 1
36
37
  end
37
38
  end
38
39
  end
@@ -6,12 +6,13 @@ module MacSetup
6
6
 
7
7
  def self.run
8
8
  if homebrew_missing?
9
- puts "Installing Homebrew..."
10
- Shell.run(%{/usr/bin/ruby -e "$(curl -fsSL #{BREW_INSTALL_URL})"})
9
+ MacSetup.log "Installing Homebrew" do
10
+ Shell.run(%{/usr/bin/ruby -e "$(curl -fsSL #{BREW_INSTALL_URL})"})
11
+ end
11
12
  else
12
- puts "Homebrew already installed. Updating..."
13
-
14
- Shell.run("brew update")
13
+ MacSetup.log "Homebrew already installed. Updating" do
14
+ Shell.run("brew update")
15
+ end
15
16
  end
16
17
  end
17
18
 
@@ -6,6 +6,7 @@ module MacSetup
6
6
 
7
7
  def self.run(_config, _status)
8
8
  Pathname.new(File.join(DOTFILES_PATH, SCRIPTS_PATH)).each_child do |script|
9
+ MacSetup.log "Running script #{script}..."
9
10
  Shell.run(script.to_s)
10
11
  end
11
12
  end
@@ -21,7 +21,7 @@ module MacSetup
21
21
  def self.strip_extension(file)
22
22
  return file unless file.to_s.end_with?(PLAINTEXT_EXT)
23
23
 
24
- file.sub(/#{PLAINTEXT_EXT}$/, "")
24
+ file.sub(/\.#{PLAINTEXT_EXT}$/, "")
25
25
  end
26
26
 
27
27
  def initialize(dir)
@@ -0,0 +1,21 @@
1
+ module MacSetup
2
+ class SecretsInstaller
3
+ def self.run(_config, status)
4
+ new(status).run
5
+ end
6
+
7
+ def initialize(status)
8
+ @status = status
9
+ end
10
+
11
+ def run
12
+ install_openssl
13
+ Secrets.decrypt(DOTFILES_PATH)
14
+ end
15
+
16
+ def install_openssl
17
+ # Needed for encrypted files
18
+ Shell.run("brew install openssl") unless @status.installed_formulas.include?("openssl")
19
+ end
20
+ end
21
+ end
@@ -22,7 +22,7 @@ module MacSetup
22
22
  def run
23
23
  return if services.none?
24
24
 
25
- puts "Installing services..."
25
+ MacSetup.log "Installing services..."
26
26
 
27
27
  FileUtils.mkdir_p(LAUNCH_AGENTS_PATH)
28
28
  tap_services
@@ -44,11 +44,11 @@ module MacSetup
44
44
 
45
45
  def install_service(service)
46
46
  if running_services.include?(service)
47
- puts "Restarting #{service} service..."
47
+ MacSetup.log "Restarting #{service} service..."
48
48
 
49
49
  Shell.run("brew services restart #{service}")
50
50
  else
51
- puts "Installing #{service} service..."
51
+ MacSetup.log "Installing #{service} service..."
52
52
 
53
53
  Shell.run("brew services start #{service}")
54
54
  end
@@ -11,7 +11,7 @@ module MacSetup
11
11
 
12
12
  short_sorce_path = MacSetup.shorten_path(source_path)
13
13
  short_target_path = MacSetup.shorten_path(target_path)
14
- puts "Linking #{short_sorce_path} to #{short_target_path}..."
14
+ MacSetup.log "Linking #{short_sorce_path} to #{short_target_path}..."
15
15
 
16
16
  return unless source_exists
17
17
 
@@ -24,7 +24,7 @@ module MacSetup
24
24
  File.exist?(source_path).tap do |exists|
25
25
  unless exists
26
26
  short_sorce_path = MacSetup.shorten_path(source_path)
27
- puts "WARNING: Source doesn’t exist at #{short_sorce_path}. Skipping..."
27
+ MacSetup.log "WARNING: Source doesn’t exist at #{short_sorce_path}. Skipping."
28
28
  end
29
29
  end
30
30
  end
@@ -51,12 +51,12 @@ module MacSetup
51
51
  elsif File.directory?(source_path)
52
52
  link_children
53
53
  else
54
- puts "WARNING: File already exists at #{MacSetup.shorten_path(target_path)}. Skipping..."
54
+ MacSetup.log "WARNING: File already exists at #{MacSetup.shorten_path(target_path)}. Skipping."
55
55
  end
56
56
  end
57
57
 
58
58
  def link_children
59
- puts "Linking children..."
59
+ MacSetup.log "Linking children..."
60
60
 
61
61
  children.each do |child|
62
62
  child_source = Symlink.new(
@@ -72,7 +72,7 @@ module MacSetup
72
72
  existing_link = File.readlink(target_path)
73
73
 
74
74
  if existing_link == source_path
75
- puts "Already linked. Skipping..."
75
+ MacSetup.log "Already linked. Skipping."
76
76
  else
77
77
  print "Replacing existing symlink at #{MacSetup.shorten_path(target_path)}. "
78
78
  puts "Originally linked to #{MacSetup.shorten_path(existing_link)}..."
@@ -91,7 +91,6 @@ module MacSetup
91
91
 
92
92
  class SymlinkInstaller
93
93
  def self.run(config, _status)
94
- Secrets.decrypt(DOTFILES_PATH)
95
94
  install_dotfiles
96
95
  install_symlinks(config)
97
96
  end
@@ -6,10 +6,18 @@ module MacSetup
6
6
  @installed_taps ||= get_taps
7
7
  end
8
8
 
9
+ def installed_formulas
10
+ @installed_formulas ||= get_formulas
11
+ end
12
+
9
13
  private
10
14
 
11
15
  def get_taps
12
16
  Shell.run("brew tap").split("\n")
13
17
  end
18
+
19
+ def get_formulas
20
+ Shell.run("brew list -1").split("\n")
21
+ end
14
22
  end
15
23
  end
@@ -1,3 +1,3 @@
1
1
  module MacSetup
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
data/lib/mac_setup.rb CHANGED
@@ -9,15 +9,17 @@ require "mac_setup/script_installer"
9
9
  require "mac_setup/symlink_installer"
10
10
  require "mac_setup/brewfile_installer"
11
11
  require "mac_setup/services_installer"
12
+ require "mac_setup/secrets_installer"
12
13
 
13
14
  module MacSetup
14
15
  DOTFILES_PATH = File.expand_path("~/.dotfiles")
15
16
 
16
17
  INSTALLERS = [
17
18
  GitRepoInstaller,
19
+ SecretsInstaller,
20
+ SymlinkInstaller,
18
21
  BrewfileInstaller,
19
22
  ServicesInstaller,
20
- SymlinkInstaller,
21
23
  ScriptInstaller
22
24
  ]
23
25
 
@@ -25,6 +27,8 @@ module MacSetup
25
27
  config = Configuration.new(File.expand_path(config_path))
26
28
  status = SystemStatus.new
27
29
 
30
+ GitRepoInstaller.install_repo(config.dotfiles_repo, DOTFILES_PATH)
31
+ config.reload!
28
32
  INSTALLERS.each { |installer| installer.run(config, status) }
29
33
  end
30
34
 
@@ -41,4 +45,14 @@ module MacSetup
41
45
  def self.shorten_path(path)
42
46
  path.sub(/#{ENV['HOME']}/, "~")
43
47
  end
48
+
49
+ def self.log(message)
50
+ if block_given?
51
+ print "#{message}..."
52
+ yield
53
+ puts "Ok."
54
+ else
55
+ puts message
56
+ end
57
+ end
44
58
  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.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Wean
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-10 00:00:00.000000000 Z
11
+ date: 2017-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -110,6 +110,7 @@ files:
110
110
  - lib/mac_setup/homebrew_installer.rb
111
111
  - lib/mac_setup/script_installer.rb
112
112
  - lib/mac_setup/secrets.rb
113
+ - lib/mac_setup/secrets_installer.rb
113
114
  - lib/mac_setup/services_installer.rb
114
115
  - lib/mac_setup/shell.rb
115
116
  - lib/mac_setup/symlink_installer.rb