mac_setup 0.8.2 → 0.8.3

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: 958d74da43b6b9b23c98203dfce55023ae821ead
4
- data.tar.gz: f593796bcc578be1cc5db12693e9e0a9ef3f9955
3
+ metadata.gz: 85c82751d2edcd5b3f2c05031c7471d47950e176
4
+ data.tar.gz: 913750c0d4590db473ee9e37992e57f1ee1b5766
5
5
  SHA512:
6
- metadata.gz: adf67dfc0fab520beeec3e627f922f4e8b356fd137847e69d2152bcab9de337fece85057ab21e3b7e3b6248de4228c85d4081465c2cff696aa01c227f44bba52
7
- data.tar.gz: 03b4895bfe6074bf8aa1ca9cfa3d239e53419e26be06c90fcb22a975a9d2e12ba3e611af5dd16d09e4870c10f273e10f2d5bcb445d199cc83913e6b058d8725b
6
+ metadata.gz: 0bcb6cfa1933a948ba1e764ff6d50e3e45ec93d5ad12a84142725c3aa45b56497b35712c82aa08f22fa3202fc104b8ed9755c54eb24589acd29418f5e8b624dd
7
+ data.tar.gz: d871cb41042b844deccc7508c2e8d4d2b9db19bac52ecfc420c43f045850d3b43bb4adc2a9ca9d6f7899e98ce678703e98860d59c45945070c09f896b95f2702
@@ -4,7 +4,7 @@ require "set"
4
4
  module MacSetup
5
5
  class Configuration
6
6
  InvalidConfigError = Class.new(StandardError)
7
- DEFAULT_KEYS = [:repo, :plugins, :git_repos, :symlinks, :brews, :fonts, :casks, :quicklook, :mas]
7
+ DEFAULT_KEYS = [:repo, :plugins, :git_repos, :symlinks, :taps, :brews, :fonts, :casks, :quicklook, :mas]
8
8
 
9
9
  def initialize(config_path)
10
10
  @config_path = config_path
@@ -63,6 +63,10 @@ module MacSetup
63
63
  @symlinks ||= @config["symlinks"] || {}
64
64
  end
65
65
 
66
+ def taps
67
+ @taps ||= (@config["taps"] || []).map { |item| item.split(/\s+/) }.to_set
68
+ end
69
+
66
70
  def brews
67
71
  @brews ||= (@config["brews"] || []).each_with_object({}) do |item, merged|
68
72
  add_brews(item, merged)
@@ -38,17 +38,20 @@ module MacSetup
38
38
  private
39
39
 
40
40
  def install
41
- clone_repo
42
- track_install
41
+ in_install_path do
42
+ clone_repo
43
+ track_install
44
+ end
43
45
  end
44
46
 
45
47
  def update
46
- unless can_update?
47
- MacSetup.log "Can't update. Unstaged changes in #{install_path}"
48
- return
49
- end
50
-
51
48
  in_install_path do
49
+ unless can_update?
50
+ MacSetup.log "Can't update. Unstaged changes in #{install_path}"
51
+ MacSetup.log Shell.run("git status --porcelain")
52
+ return
53
+ end
54
+
52
55
  Shell.run("git fetch")
53
56
  track_update
54
57
  Shell.run("git merge origin && git submodule update --init --recursive")
@@ -66,9 +69,7 @@ module MacSetup
66
69
  def track_install
67
70
  return unless tracking_key
68
71
 
69
- in_install_path do
70
- status.git_changes(tracking_key, Shell.run("git ls-files").split("\n"))
71
- end
72
+ status.git_changes(tracking_key, Shell.run("git ls-files").split("\n"))
72
73
  end
73
74
 
74
75
  def track_update
@@ -9,7 +9,7 @@ module MacSetup
9
9
  MacSetup.log "Homebrew already installed. Skipping..."
10
10
  else
11
11
  MacSetup.log "Installing Homebrew" do
12
- Shell.run(%{/usr/bin/ruby -e "$(curl -fsSL #{BREW_INSTALL_URL})"})
12
+ Shell.raw(%{/usr/bin/ruby -e "$(curl -fsSL #{BREW_INSTALL_URL})"})
13
13
  end
14
14
  end
15
15
  end
@@ -1,15 +1,17 @@
1
+ require "tempfile"
2
+
1
3
  module MacSetup
2
4
  class HomebrewRunner
3
5
  def self.run(config, _status)
4
- brewfile = build_brewfile(config)
5
-
6
- cmd = [
7
- "echo << EOF | brew bundle install --file=-",
8
- brewfile,
9
- "EOF"
10
- ]
11
-
12
- Shell.run(cmd.join("\n"))
6
+ MacSetup.log("Installing Homebrew brews and casks") do
7
+ Tempfile.create("Brewfile") do |brewfile|
8
+ write_brewfile(config, brewfile)
9
+ File.chmod(0644, brewfile)
10
+ brewfile.rewind
11
+
12
+ Shell.raw("brew bundle install --file=#{brewfile.path}")
13
+ end
14
+ end
13
15
  end
14
16
 
15
17
  def self.install_brew(formula)
@@ -20,16 +22,18 @@ module MacSetup
20
22
  Shell.run("brew cask install #{cask}")
21
23
  end
22
24
 
23
- def self.build_brewfile(config)
25
+ def self.write_brewfile(config, brewfile)
26
+ taps = config.taps.map { |parts| %(tap #{quote_args(parts)}) }
27
+
24
28
  brews = config.brews.map do |name, opts|
25
29
  [%(brew "#{name}"), print_args(opts)].compact.join(", ")
26
30
  end
27
31
 
28
32
  casks = (config.fonts + config.casks + config.quicklook).map do |name|
29
- "cask #{name}"
33
+ %(cask "#{name}")
30
34
  end
31
35
 
32
- (brews + casks).join("\n")
36
+ brewfile.write((taps + brews + casks).join("\n"))
33
37
  end
34
38
 
35
39
  def self.print_args(opts)
@@ -37,8 +41,11 @@ module MacSetup
37
41
 
38
42
  return unless args
39
43
 
40
- args_str = args.sort.map { |arg| %("#{arg}") }.join(", ")
41
- "args: [#{args_str}]"
44
+ "args: [#{quote_args(args.sort)}]"
45
+ end
46
+
47
+ def self.quote_args(args)
48
+ args.map { |arg| %("#{arg}") }.join(", ")
42
49
  end
43
50
  end
44
51
  end
@@ -29,14 +29,15 @@ module MacSetup
29
29
  # TODO: Investigate making this work with kext permissions
30
30
  def install_volume
31
31
  Shell.run("keybase install --components=fuse")
32
- Shell.ask("Allow the extension in system preferences")
32
+ Shell.ask("Allow the extension in system preferences and then hit Return")
33
33
  Shell.run("keybase install --components=helper,fuse,mountdir,kbfs")
34
34
  end
35
35
 
36
36
  def add_private_dotfiles(config)
37
- dotfiles_dir = Pathname.new("/keybase/private/#{config.keybase}/dotfiles")
37
+ keybase_dir = Dir.entries("/Volumes").find { |dir| dir.start_with?("Keybase") }
38
+ dotfiles_dir = "/Volumes/#{keybase_dir}/private/#{config.keybase}/dotfiles"
38
39
 
39
- return unless dotfiles_dir.exist?
40
+ return unless Dir.exist?(dotfiles_dir)
40
41
 
41
42
  SymlinkPathBuilder.paths_for(dotfiles_dir) do |source, target|
42
43
  config.add(:symlinks, source => target)
@@ -11,9 +11,9 @@ module MacSetup
11
11
  def link
12
12
  return if Secrets.encrypted?(source_path)
13
13
 
14
- short_sorce_path = MacSetup.shorten_path(source_path)
14
+ short_source_path = MacSetup.shorten_path(source_path)
15
15
  short_target_path = MacSetup.shorten_path(target_path)
16
- MacSetup.log "Linking #{short_sorce_path} to #{short_target_path}..."
16
+ MacSetup.log "Linking #{short_source_path} to #{short_target_path}..."
17
17
 
18
18
  return unless source_exists
19
19
 
@@ -25,8 +25,8 @@ module MacSetup
25
25
  def source_exists
26
26
  File.exist?(source_path).tap do |exists|
27
27
  unless exists
28
- short_sorce_path = MacSetup.shorten_path(source_path)
29
- MacSetup.log "WARNING: Source doesn’t exist at #{short_sorce_path}. Skipping."
28
+ short_source_path = MacSetup.shorten_path(source_path)
29
+ MacSetup.log "WARNING: Source doesn’t exist at #{short_source_path}. Skipping."
30
30
  end
31
31
  end
32
32
  end
@@ -100,38 +100,54 @@ module MacSetup
100
100
  config.symlinks.each do |source_path, target_path|
101
101
  # source = Symlink.new(source_path: File.expand_path(source_path))
102
102
  # source.link
103
- source = Pathname.new(source_path)
104
- short_source_path = source.to_s
105
- # MacSetup.shorten_path(source_path)
103
+ source = Pathname.new(source_path).expand_path
104
+ short_source_path = MacSetup.shorten_path(source.to_s)
106
105
 
107
106
  unless source.exist?
108
107
  MacSetup.log "#{short_source_path} doesn't exist. Skipping."
109
108
  next
110
109
  end
111
110
 
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)
111
+ target = Pathname.new(target_path).expand_path
112
+ short_target_path = MacSetup.shorten_path(target.to_s)
117
113
 
118
- MacSetup.log "Linking #{short_sorce_path} to #{short_target_path}..."
114
+ MacSetup.log "Linking #{short_source_path} to #{short_target_path}..."
119
115
 
120
116
  home = Pathname.new(ENV.fetch("HOME"))
121
117
 
122
118
  if target.directory?
123
119
  filename = target == home ? ".#{source.basename}" : source.basename
124
120
  full_target = target.join(filename)
125
- File.symlink(source, full_target)
121
+ link(source, full_target)
126
122
  elsif target.to_s.end_with?("/")
127
123
  target.mkpath
128
124
  full_target = target.join(source.basename)
129
- File.symlink(source, full_target)
125
+ link(source, full_target)
130
126
  else
131
127
  target.dirname.mkpath
132
- File.symlink(source, target)
128
+ link(source, target)
133
129
  end
134
130
  end
135
131
  end
132
+
133
+ def self.link(source, target)
134
+ if File.exist?(target)
135
+ if File.symlink?(target)
136
+ existing_link = File.readlink(target)
137
+
138
+ if existing_link == source.to_s
139
+ MacSetup.log "Already linked. Skipping."
140
+ else
141
+ print "Replacing existing symlink at #{MacSetup.shorten_path(target)}. "
142
+ puts "Originally linked to #{MacSetup.shorten_path(existing_link)}..."
143
+ FileUtils.ln_sf(source, target)
144
+ end
145
+ else
146
+ MacSetup.log "WARNING: File already exists at #{MacSetup.shorten_path(target)}. Skipping."
147
+ end
148
+ else
149
+ FileUtils.ln_s(source, target)
150
+ end
151
+ end
136
152
  end
137
153
  end
@@ -26,7 +26,7 @@ module MacSetup
26
26
  end
27
27
 
28
28
  def relative_path(path, base, replacement = "~/")
29
- path.to_s.sub(%r{^#{base}\/}, replacement)
29
+ path.to_s.sub(%r{^#{Regexp.escape(base.to_s)}\/}, replacement)
30
30
  end
31
31
  end
32
32
  end
@@ -1,3 +1,3 @@
1
1
  module MacSetup
2
- VERSION = "0.8.2"
2
+ VERSION = "0.8.3"
3
3
  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.8.2
4
+ version: 0.8.3
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-07 00:00:00.000000000 Z
11
+ date: 2018-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler