mac_setup 0.8.0 → 0.8.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: 05b25fd9b18c84ceab8c35345f58607111782d0c
4
- data.tar.gz: 3683dd0949e472f501f9624145ed97f695450f9b
3
+ metadata.gz: 9c4e9c261b3d1a91265e2aedd53b1a45d6e91340
4
+ data.tar.gz: de0dc8873cf819ea49ebfe1573fb53807b7e177c
5
5
  SHA512:
6
- metadata.gz: 81bd2abe212ca77282c59023e5d1505f6e803715da8791ee94caa9f1046690b7469d152c0a96ef4f2111d177f01cbd5044cd0b712e2f7f5f684a54cb772a48ba
7
- data.tar.gz: a61fad4936463e8d1e737feb2069f11209733847af307e638e80c9f85169f9376b9d65a9aa3ada6503baa0e5e2a528e143840f80e6787692b0b69d47520dbcfc
6
+ metadata.gz: 7392b6f59c7398bd6efabf67cf1c497fd92ce404ccc031e2f98697d61e1dd775313d4e077f8392431557551add773a4704f5ab216bc2c4c2370b06edbea3c3e2
7
+ data.tar.gz: 10051992c38e779f7924750d6e846a8c5012a27f2c93b6afbcad79432fa2524549837af094b7c583ac0243243e1035d4e883d35d62a65d0226a10ca940bee671
data/exe/mac_setup CHANGED
@@ -3,8 +3,8 @@
3
3
  require "mac_setup"
4
4
 
5
5
  command = ARGV.shift
6
- options = ARGV.select { |arg| arg.start_with?("--") }
7
- config_path = (ARGV - options).first || File.expand_path(DEFAULT_CONFIG_PATH)
6
+ # options = ARGV.select { |arg| arg.start_with?("--") }
7
+ # config_path = (ARGV - options).first || File.expand_path(DEFAULT_CONFIG_PATH)
8
8
 
9
9
  case command
10
10
  when "bootstrap"
@@ -4,7 +4,7 @@ require "set"
4
4
  module MacSetup
5
5
  class Configuration
6
6
  InvalidConfigError = Class.new(StandardError)
7
- DEFAULT_KEYS = [:plugins, :git_repos, :symlinks, :brews, :fonts, :casks, :quicklook, :mas]
7
+ DEFAULT_KEYS = [:repo, :plugins, :git_repos, :symlinks, :brews, :fonts, :casks, :quicklook, :mas]
8
8
 
9
9
  def initialize(config_path)
10
10
  @config_path = config_path
@@ -32,7 +32,7 @@ module MacSetup
32
32
  when Set
33
33
  collection << value.to_s
34
34
  when Hash
35
- collection.merge(value) do |key, oldval, newval|
35
+ collection.merge!(value) do |key, oldval, newval|
36
36
  raise InvalidConfigError, "#{key} is defined twice!: #{oldval}, #{newval}"
37
37
  end
38
38
  end
@@ -44,11 +44,11 @@ module MacSetup
44
44
  end
45
45
 
46
46
  def validate!
47
- extra_keys = @config.keys.map(&:to_i) - allowed_keys
47
+ extra_keys = @config.keys.map(&:to_sym) - allowed_keys.to_a
48
48
 
49
49
  return if extra_keys.none?
50
50
 
51
- raise InvalidConfigError, "Extra keys in config: #{extra_keys.join(", ")}"
51
+ raise InvalidConfigError, "Extra keys in config: #{extra_keys.join(', ')}"
52
52
  end
53
53
 
54
54
  def dotfiles_repo
@@ -64,7 +64,7 @@ module MacSetup
64
64
  end
65
65
 
66
66
  def brews
67
- @brews ||= (@config["brews"] || []).reduce({}) do |merged, item|
67
+ @brews ||= (@config["brews"] || []).each_with_object({}) do |item, merged|
68
68
  add_brews(item, merged)
69
69
  end
70
70
  end
@@ -88,7 +88,7 @@ module MacSetup
88
88
  private
89
89
 
90
90
  def add_brews(item, existing_brews = brews)
91
- existing_brews.merge(brew_value(item)) do |key, oldval, newval|
91
+ existing_brews.merge!(brew_value(item)) do |key, oldval, newval|
92
92
  raise InvalidConfigError, "#{key} is defined twice!: #{oldval}, #{newval}"
93
93
  end
94
94
  end
@@ -12,6 +12,10 @@ module MacSetup
12
12
  Shell.run(cmd.join("\n"))
13
13
  end
14
14
 
15
+ def self.install_brew(formula)
16
+ Shell.run("brew install #{formula}")
17
+ end
18
+
15
19
  def self.install_cask(cask)
16
20
  Shell.run("brew cask install #{cask}")
17
21
  end
@@ -1,17 +1,20 @@
1
1
  module MacSetup
2
2
  class Plugin
3
- def self.add_requirements(_config)
4
- end
5
-
6
- def self.run(_config, _status)
7
- end
3
+ class << self
4
+ def add_requirements(_config)
5
+ end
8
6
 
9
- def self.load(plugin_name)
7
+ def run(_config, _status)
8
+ end
10
9
 
11
- end
10
+ def load(_plugin_name)
11
+ end
12
12
 
13
- def self.bootstrap
13
+ def get_status(_status)
14
+ end
14
15
 
16
+ def bootstrap
17
+ end
15
18
  end
16
19
  end
17
20
  end
@@ -0,0 +1,13 @@
1
+ module MacSetup
2
+ module Plugins
3
+ class Dotfiles < MacSetup::Plugin
4
+ class << self
5
+ def add_requirements(config)
6
+ SymlinkPathBuilder.paths_for(MacSetup.dotfiles_path) do |source, target|
7
+ config.add(:symlinks, source => target)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,31 +1,44 @@
1
1
  module MacSetup
2
2
  module Plugins
3
3
  class Keybase < MacSetup::Plugin
4
- def self.bootstrap(config)
5
- add_requirements(config)
6
- install
7
- login(config.keybase)
8
- install_volume
9
- end
4
+ class << self
5
+ def bootstrap(config)
6
+ add_requirements(config)
7
+ install
8
+ log_in(config.keybase)
9
+ install_volume
10
+ end
10
11
 
11
- def self.add_requirements(config)
12
- config.require_value(:keybase)
13
- config.add(:casks, :keybase)
14
- end
12
+ def add_requirements(config)
13
+ config.require_value(:keybase)
14
+ config.add(:casks, :keybase)
15
+ add_private_dotfiles(config)
16
+ end
15
17
 
16
- private
18
+ private
17
19
 
18
- def self.install
19
- HomebrewRunner.install_cask(:keybase)
20
- end
20
+ def install
21
+ HomebrewRunner.install_cask(:keybase)
22
+ end
21
23
 
22
- def self.login(username)
23
- Shell.run("keybase login #{username}")
24
- end
24
+ def log_in(username)
25
+ Shell.run("keybase login #{username}")
26
+ end
27
+
28
+ # TODO: Investigate making this work with kext permissions
29
+ def install_volume
30
+ Shell.run("keybase install --components=helper,fuse,mountdir,kbfs")
31
+ end
32
+
33
+ def add_private_dotfiles(config)
34
+ dotfiles_dir = Pathname.new("/keybase/private/#{config.keybase}/dotfiles")
35
+
36
+ return unless dotfiles_dir.exist?
25
37
 
26
- # TODO: Investigate making this work with kext permissions
27
- def self.install_volume
28
- Shell.run("keybase install --components=helper,fuse,mountdir,kbfs")
38
+ SymlinkPathBuilder.paths_for(dotfiles_dir) do |source, target|
39
+ config.add(:symlinks, source => target)
40
+ end
41
+ end
29
42
  end
30
43
  end
31
44
  end
@@ -1,75 +1,46 @@
1
1
  module MacSetup
2
2
  module Plugins
3
3
  class MacAppStore < MacSetup::Plugin
4
- attr_reader :config, :status
5
-
6
- def self.add_requirements(config)
7
- config.add(:brews, :mas)
8
- end
9
-
10
- def self.get_status(status)
11
-
12
- end
13
-
14
- def self.run(config, status)
15
- new(config, status).run
16
- end
17
-
18
- def initialize(config, status)
19
- @config = config
20
- @status = status
21
- end
4
+ class << self
5
+ def bootstrap(config)
6
+ add_requirements(config)
7
+ install
8
+ log_in
9
+ end
22
10
 
23
- def run
24
- set_up_mas
25
- install_brewfile
26
- end
11
+ def add_requirements(config)
12
+ config.add(:brews, :mas)
13
+ end
27
14
 
28
- private
15
+ def run(config, _status)
16
+ log_in
29
17
 
30
- def set_up_mas
31
- return unless brewfile.read =~ /^mas /
18
+ config.mas.each do |_name, id|
19
+ Shell.run("mas install #{id}")
20
+ end
21
+ end
32
22
 
33
- install_mas
34
- sign_in_to_mas
35
- end
23
+ private
36
24
 
37
- def install_mas
38
- MacSetup.log "Installing mas" do
39
- Shell.run("brew install mas")
25
+ def install
26
+ MacSetup.log "Installing mas" do
27
+ HomebrewRunner.install_brew(:mas)
28
+ end
40
29
  end
41
- end
42
30
 
43
- def sign_in_to_mas
44
- if mas_signed_in?
45
- MacSetup.log "Already signed into Mac App Store. Skipping."
46
- else
47
- apple_id = Shell.ask("What is your Apple ID?")
48
- Shell.run("mas signin --dialog #{apple_id}")
31
+ def log_in
32
+ if mas_signed_in?
33
+ MacSetup.log "Already signed into Mac App Store. Skipping."
34
+ else
35
+ apple_id = Shell.ask("What is your Apple ID?")
36
+ Shell.run("mas signin #{apple_id}")
37
+ end
49
38
  end
50
- end
51
-
52
- def mas_signed_in?
53
- Shell.success?("mas account")
54
- end
55
39
 
56
- def install_brewfile
57
- MacSetup.log "Installing Brewfile" do
58
- Shell.run("brew bundle --global")
40
+ def mas_signed_in?
41
+ Shell.success?("mas account")
59
42
  end
60
43
  end
61
-
62
- def mas_installed?
63
- Shell.command_present?("mas")
64
- end
65
-
66
- def bundle_already_tapped?
67
- status.installed_taps.include?(BUNDLE_TAP)
68
- end
69
-
70
- def brewfile
71
- @brewfile ||= Pathname.new("~/.Brewfile").expand_path
72
- end
73
44
  end
74
45
  end
75
46
  end
@@ -1,3 +1,5 @@
1
+ require "fileutils"
2
+
1
3
  module MacSetup
2
4
  class Symlink
3
5
  def initialize(options)
@@ -91,33 +93,45 @@ module MacSetup
91
93
 
92
94
  class SymlinkInstaller
93
95
  def self.run(config, _status)
94
- install_dotfiles
95
96
  install_symlinks(config)
96
97
  end
97
98
 
98
- def self.install_dotfiles
99
- dotfiles.each do |file_name|
100
- source = Symlink.new(name: file_name)
101
- source.link
102
- end
103
- end
104
-
105
99
  def self.install_symlinks(config)
106
- config.symlinks.each do |source_path|
107
- source = Symlink.new(source_path: File.expand_path(source_path))
108
- source.link
109
- end
110
- end
111
-
112
- def self.install_dotfile(name)
113
- dotfile = dotfiles.find { |file| file =~ /#{Regexp.escape(name)}/ }
114
- source = Symlink.new(name: dotfile)
115
-
116
- source.link
117
- end
100
+ config.symlinks.each do |source_path, target_path|
101
+ # source = Symlink.new(source_path: File.expand_path(source_path))
102
+ # source.link
103
+ source = Pathname.new(source_path)
104
+ short_source_path = source.to_s
105
+ # MacSetup.shorten_path(source_path)
106
+
107
+ unless source.exist?
108
+ MacSetup.log "#{short_source_path} doesn't exist. Skipping."
109
+ next
110
+ end
118
111
 
119
- def self.dotfiles
120
- Dir.entries(DOTFILES_PATH).reject { |entry| entry.start_with?(".") }
112
+ target = Pathname.new(target_path)
113
+ short_target_path = target.to_s
114
+ source = source.expand_path
115
+ target = target.expand_path
116
+ # MacSetup.shorten_path(target_path)
117
+
118
+ MacSetup.log "Linking #{short_sorce_path} to #{short_target_path}..."
119
+
120
+ home = Pathname.new(ENV.fetch("HOME"))
121
+
122
+ if target.directory?
123
+ filename = target == home ? ".#{source.basename}" : source.basename
124
+ full_target = target.join(filename)
125
+ File.symlink(source, full_target)
126
+ elsif target.to_s.end_with?("/")
127
+ target.mkpath
128
+ full_target = target.join(source.basename)
129
+ File.symlink(source, full_target)
130
+ else
131
+ target.dirname.mkpath
132
+ File.symlink(source, target)
133
+ end
134
+ end
121
135
  end
122
136
  end
123
137
  end
@@ -0,0 +1,33 @@
1
+ module MacSetup
2
+ class SymlinkPathBuilder
3
+ HOME = ENV.fetch("HOME").freeze
4
+
5
+ class << self
6
+ def paths_for(root_dir)
7
+ root = Pathname.new(root_dir)
8
+
9
+ each_child(root) do |child|
10
+ yield [relative_path(child, HOME), relative_path(child, root, "~/.")]
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def each_child(dir, &block)
17
+ dir.children.each do |child|
18
+ next if child.basename.to_s.start_with?(".")
19
+
20
+ if child.directory?
21
+ each_child(child, &block)
22
+ else
23
+ block.call(child)
24
+ end
25
+ end
26
+ end
27
+
28
+ def relative_path(path, base, replacement = "~/")
29
+ path.to_s.sub(%r{^#{base}\/}, replacement)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module MacSetup
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.1"
3
3
  end
data/lib/mac_setup.rb CHANGED
@@ -8,9 +8,11 @@ require "mac_setup/homebrew_runner"
8
8
  require "mac_setup/secrets"
9
9
  require "mac_setup/homebrew_installer"
10
10
  require "mac_setup/git_repo_installer"
11
+ require "mac_setup/symlink_installer"
11
12
  require "mac_setup/plugin"
12
13
  require "mac_setup/plugins/keybase"
13
14
  require "mac_setup/plugins/mac_app_store"
15
+ require "mac_setup/plugins/dotfiles"
14
16
 
15
17
  module MacSetup
16
18
  DEFAULT_DOTFILES_PATH = File.expand_path("~/.dotfiles")
@@ -24,7 +26,8 @@ module MacSetup
24
26
 
25
27
  DEFAULT_PLUGINS = [
26
28
  Plugins::MacAppStore,
27
- Plugins::Keybase
29
+ Plugins::Keybase,
30
+ Plugins::Dotfiles
28
31
  ]
29
32
 
30
33
  class << self
@@ -55,7 +58,7 @@ module MacSetup
55
58
  end
56
59
 
57
60
  def shorten_path(path)
58
- path.sub(/#{ENV['HOME']}/, "~")
61
+ path.to_s.sub(/#{ENV['HOME']}/, "~")
59
62
  end
60
63
 
61
64
  def log(message)
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.8.0
4
+ version: 0.8.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: 2018-08-06 00:00:00.000000000 Z
11
+ date: 2018-08-07 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/homebrew_runner.rb
112
112
  - lib/mac_setup/plugin.rb
113
+ - lib/mac_setup/plugins/dotfiles.rb
113
114
  - lib/mac_setup/plugins/keybase.rb
114
115
  - lib/mac_setup/plugins/mac_app_store.rb
115
116
  - lib/mac_setup/script_installer.rb
@@ -118,6 +119,7 @@ files:
118
119
  - lib/mac_setup/services_installer.rb
119
120
  - lib/mac_setup/shell.rb
120
121
  - lib/mac_setup/symlink_installer.rb
122
+ - lib/mac_setup/symlink_path_builder.rb
121
123
  - lib/mac_setup/system_status.rb
122
124
  - lib/mac_setup/version.rb
123
125
  - mac_setup.gemspec