mac_setup 0.8.4 → 0.8.5
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/lib/mac_setup/configuration.rb +5 -1
- data/lib/mac_setup/defaults_installer.rb +89 -0
- data/lib/mac_setup/git_repo_installer.rb +5 -6
- data/lib/mac_setup/plugins/asdf.rb +41 -0
- data/lib/mac_setup/result.rb +17 -0
- data/lib/mac_setup/script_installer.rb +1 -1
- data/lib/mac_setup/shell.rb +8 -3
- data/lib/mac_setup/system_status.rb +13 -2
- data/lib/mac_setup/version.rb +1 -1
- data/lib/mac_setup.rb +12 -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: 9223c0313ddec740c3975abd57e09bb52b3e3bab
|
4
|
+
data.tar.gz: 7b257be1fee8d0c7e72da35ce49102462a6e7881
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 611da27eed94132d5e9a1af2e7dd62e9c9039656a2203a57345d7fd9bfa80222c7766e7d8d0ba0243e5cf74591469c0993c83ad4e72a37d8b57cbc372fe65cb0
|
7
|
+
data.tar.gz: 09f30dc8cae280977c6b0e3ddf09d352d534bfcbf98b56a91903c420ea38fc15dda67581f30e53b0b4a8331ecf9b58dbd1994c21a531b0d5ca1fbf021d1ef391
|
@@ -93,7 +93,11 @@ module MacSetup
|
|
93
93
|
|
94
94
|
def add_brews(item, existing_brews = brews)
|
95
95
|
existing_brews.merge!(brew_value(item)) do |key, oldval, newval|
|
96
|
-
|
96
|
+
if oldval == newval
|
97
|
+
oldval
|
98
|
+
else
|
99
|
+
raise InvalidConfigError, "#{key} is defined twice!: #{oldval}, #{newval}"
|
100
|
+
end
|
97
101
|
end
|
98
102
|
end
|
99
103
|
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module MacSetup
|
2
|
+
class DefaultsInstaller
|
3
|
+
def self.run(config, status)
|
4
|
+
defaults_file = File.join(MacSetup.dotfiles_path, "mac_setup/defaults.yml")
|
5
|
+
|
6
|
+
if File.exist?(defaults_file)
|
7
|
+
MacSetup.log "Setting defaults..."
|
8
|
+
new(defaults_file, config, status).run
|
9
|
+
else
|
10
|
+
MacSetup.log "No config file at #{MacSetup.shorten_path(defaults_file)}. Skipping..."
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(defaults_file, config, status)
|
15
|
+
@defaults = YAML.load_file(defaults_file)
|
16
|
+
@config = config
|
17
|
+
@status = status
|
18
|
+
end
|
19
|
+
|
20
|
+
def run
|
21
|
+
@defaults.each do |domain, values|
|
22
|
+
MacSetup.log "Setting defaults for domain #{domain}..."
|
23
|
+
set_defaults(domain, values)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def set_defaults(domain, values)
|
30
|
+
values.each do |key, value|
|
31
|
+
existing_value = @status.defaults_value(domain, key)
|
32
|
+
|
33
|
+
if values_equal?(existing_value, value)
|
34
|
+
MacSetup.log "Value for #{domain} #{key} is already set. Skipping..."
|
35
|
+
else
|
36
|
+
MacSetup.log "Changing #{existing_value} to #{value}"
|
37
|
+
set_value(domain, key, value)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def values_equal?(existing, desired)
|
43
|
+
return if existing.nil?
|
44
|
+
|
45
|
+
case desired
|
46
|
+
when Integer
|
47
|
+
existing.to_i == desired
|
48
|
+
when Float
|
49
|
+
existing.to_f == desired
|
50
|
+
when Array
|
51
|
+
extract_array_values(existing) == desired
|
52
|
+
when TrueClass
|
53
|
+
existing == "1"
|
54
|
+
when FalseClass
|
55
|
+
existing == "0"
|
56
|
+
when String
|
57
|
+
existing == desired
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def set_value(domain, key, value)
|
62
|
+
MacSetup.log "Setting #{domain} #{key} to #{value}"
|
63
|
+
qualified_value = qualify_value(value)
|
64
|
+
|
65
|
+
sudo = "sudo " if domain.start_with?("/")
|
66
|
+
Shell.run(%(#{sudo}defaults write #{domain} "#{key}" #{qualified_value}))
|
67
|
+
end
|
68
|
+
|
69
|
+
def extract_array_values(string)
|
70
|
+
string.split("\n")[1..-2].map { |line| line.lstrip.gsub(/(^")|(",?$)/, "") }
|
71
|
+
end
|
72
|
+
|
73
|
+
def qualify_value(value)
|
74
|
+
case value
|
75
|
+
when Integer
|
76
|
+
"-int #{value}"
|
77
|
+
when Float
|
78
|
+
"-float #{value}"
|
79
|
+
when TrueClass, FalseClass
|
80
|
+
"-bool #{value}"
|
81
|
+
when Array
|
82
|
+
values = value.map { |val| "'#{val}'" }.join(" ")
|
83
|
+
"-array #{values}"
|
84
|
+
when String
|
85
|
+
"-string '#{value}'"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -10,8 +10,7 @@ module MacSetup
|
|
10
10
|
|
11
11
|
MacSetup.log "Installing Git Repos..."
|
12
12
|
|
13
|
-
repos.each do |
|
14
|
-
repo, install_path = repo_and_path.to_a.flatten
|
13
|
+
repos.each do |repo, install_path|
|
15
14
|
new(repo, File.expand_path(install_path)).install_or_update
|
16
15
|
end
|
17
16
|
end
|
@@ -46,7 +45,7 @@ module MacSetup
|
|
46
45
|
in_install_path do
|
47
46
|
unless can_update?
|
48
47
|
MacSetup.log "Can't update. Unstaged changes in #{install_path}"
|
49
|
-
MacSetup.log Shell.
|
48
|
+
MacSetup.log Shell.result("git status --porcelain")
|
50
49
|
return
|
51
50
|
end
|
52
51
|
|
@@ -61,21 +60,21 @@ module MacSetup
|
|
61
60
|
end
|
62
61
|
|
63
62
|
def can_update?
|
64
|
-
Shell.
|
63
|
+
Shell.result("git status --porcelain").empty?
|
65
64
|
end
|
66
65
|
|
67
66
|
def track_install
|
68
67
|
return unless tracking_key
|
69
68
|
|
70
69
|
in_install_path do
|
71
|
-
status.git_changes(tracking_key, Shell.
|
70
|
+
status.git_changes(tracking_key, Shell.result("git ls-files").split("\n"))
|
72
71
|
end
|
73
72
|
end
|
74
73
|
|
75
74
|
def track_update
|
76
75
|
return unless tracking_key
|
77
76
|
|
78
|
-
status.git_changes(tracking_key, Shell.
|
77
|
+
status.git_changes(tracking_key, Shell.result("git diff --name-only origin").split("\n"))
|
79
78
|
end
|
80
79
|
|
81
80
|
def in_install_path
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module MacSetup
|
2
|
+
module Plugins
|
3
|
+
class Asdf < MacSetup::Plugin
|
4
|
+
TOOL_VERSIONS_FILE = Pathname.new("~/.tool-versions").expand_path
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def add_requirements(config)
|
8
|
+
config.require_value(:asdf)
|
9
|
+
config.add(:brews, :asdf)
|
10
|
+
end
|
11
|
+
|
12
|
+
def run(config, _status)
|
13
|
+
install_missing_plugins(config)
|
14
|
+
install_missing_versions
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def install_missing_plugins(config)
|
20
|
+
(config.asdf - installed_plugins).each do |plugin|
|
21
|
+
Shell.run("asdf", "plugin-add", plugin)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def install_missing_versions
|
26
|
+
tool_versions = TOOL_VERSIONS_FILE.read.split("\n")
|
27
|
+
|
28
|
+
tool_versions.each do |line|
|
29
|
+
plugin, version = line.split(" ")
|
30
|
+
|
31
|
+
Shell.run("asdf", "install", plugin, version)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def installed_plugins
|
36
|
+
@installed_plugins ||= Shell.result("asdf", "plugin-list").split("\n")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module MacSetup
|
2
|
+
class Result
|
3
|
+
def initialize(stdout, stderr, status)
|
4
|
+
@stdout = stdout
|
5
|
+
@stderr = stderr
|
6
|
+
@status = status
|
7
|
+
end
|
8
|
+
|
9
|
+
def success?
|
10
|
+
@status.success?
|
11
|
+
end
|
12
|
+
|
13
|
+
def output
|
14
|
+
[@stderr, @stdout].join("\n").strip
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -5,7 +5,7 @@ module MacSetup
|
|
5
5
|
SCRIPTS_PATH = "mac_setup/scripts"
|
6
6
|
|
7
7
|
def self.run(_config, _status)
|
8
|
-
Pathname.new(
|
8
|
+
Pathname.new(MacSetup.dotfiles_path).join(SCRIPTS_PATH).each_child do |script|
|
9
9
|
MacSetup.log "Running script #{script}..."
|
10
10
|
Shell.run(script.to_s)
|
11
11
|
end
|
data/lib/mac_setup/shell.rb
CHANGED
@@ -1,11 +1,16 @@
|
|
1
1
|
require "shellwords"
|
2
2
|
require "io/console"
|
3
|
+
require "open3"
|
3
4
|
|
4
5
|
module MacSetup
|
5
6
|
class Shell
|
6
7
|
class << self
|
7
|
-
def
|
8
|
-
|
8
|
+
def result(*command)
|
9
|
+
run(*command).output
|
10
|
+
end
|
11
|
+
|
12
|
+
def run(*command)
|
13
|
+
Result.new(*Open3.capture3(*command))
|
9
14
|
end
|
10
15
|
|
11
16
|
def raw(command)
|
@@ -23,7 +28,7 @@ module MacSetup
|
|
23
28
|
end
|
24
29
|
|
25
30
|
def success?(command)
|
26
|
-
|
31
|
+
run(command).success?
|
27
32
|
end
|
28
33
|
|
29
34
|
def command_present?(command)
|
@@ -4,6 +4,7 @@ module MacSetup
|
|
4
4
|
class SystemStatus
|
5
5
|
def initialize
|
6
6
|
@git_changes = Hash.new { |hash, key| hash[key] = [] }
|
7
|
+
@defaults = Hash.new { |hash, key| hash[key] = {} }
|
7
8
|
end
|
8
9
|
|
9
10
|
def installed_taps
|
@@ -22,14 +23,24 @@ module MacSetup
|
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
26
|
+
def defaults_value(domain, key)
|
27
|
+
@defaults[domain][key] ||= read_defaults_value(domain, key)
|
28
|
+
end
|
29
|
+
|
25
30
|
private
|
26
31
|
|
27
32
|
def get_taps
|
28
|
-
Shell.
|
33
|
+
Shell.result("brew tap").split("\n")
|
29
34
|
end
|
30
35
|
|
31
36
|
def get_formulas
|
32
|
-
Shell.
|
37
|
+
Shell.result("brew list -1").split("\n")
|
38
|
+
end
|
39
|
+
|
40
|
+
def read_defaults_value(domain, key)
|
41
|
+
result = Shell.run("defaults read #{domain} '#{key}'")
|
42
|
+
|
43
|
+
result.output if result.success?
|
33
44
|
end
|
34
45
|
end
|
35
46
|
end
|
data/lib/mac_setup/version.rb
CHANGED
data/lib/mac_setup.rb
CHANGED
@@ -3,6 +3,7 @@ require "pathname"
|
|
3
3
|
require "mac_setup/version"
|
4
4
|
require "mac_setup/configuration"
|
5
5
|
require "mac_setup/system_status"
|
6
|
+
require "mac_setup/result"
|
6
7
|
require "mac_setup/shell"
|
7
8
|
require "mac_setup/homebrew_runner"
|
8
9
|
require "mac_setup/secrets"
|
@@ -10,10 +11,13 @@ require "mac_setup/homebrew_installer"
|
|
10
11
|
require "mac_setup/git_repo_installer"
|
11
12
|
require "mac_setup/symlink_path_builder"
|
12
13
|
require "mac_setup/symlink_installer"
|
14
|
+
require "mac_setup/script_installer"
|
15
|
+
require "mac_setup/defaults_installer"
|
13
16
|
require "mac_setup/plugin"
|
14
17
|
require "mac_setup/plugins/keybase"
|
15
18
|
require "mac_setup/plugins/mac_app_store"
|
16
19
|
require "mac_setup/plugins/dotfiles"
|
20
|
+
require "mac_setup/plugins/asdf"
|
17
21
|
|
18
22
|
module MacSetup
|
19
23
|
DEFAULT_DOTFILES_PATH = File.expand_path("~/.dotfiles")
|
@@ -22,13 +26,16 @@ module MacSetup
|
|
22
26
|
INSTALLERS = [
|
23
27
|
GitRepoInstaller,
|
24
28
|
SymlinkInstaller,
|
25
|
-
HomebrewRunner
|
29
|
+
HomebrewRunner,
|
30
|
+
ScriptInstaller,
|
31
|
+
DefaultsInstaller
|
26
32
|
]
|
27
33
|
|
28
34
|
DEFAULT_PLUGINS = [
|
29
35
|
Plugins::MacAppStore,
|
30
36
|
Plugins::Keybase,
|
31
|
-
Plugins::Dotfiles
|
37
|
+
Plugins::Dotfiles,
|
38
|
+
Plugins::Asdf
|
32
39
|
]
|
33
40
|
|
34
41
|
class << self
|
@@ -46,12 +53,15 @@ module MacSetup
|
|
46
53
|
|
47
54
|
GitRepoInstaller.install_repo(config.dotfiles_repo, dotfiles_path)
|
48
55
|
|
56
|
+
Shell.raw("brew update")
|
57
|
+
|
49
58
|
config = Configuration.new(DEFAULT_CONFIG_PATH)
|
50
59
|
plugins(config).each { |plugin| plugin.add_requirements(config) }
|
51
60
|
config.validate!
|
52
61
|
status = SystemStatus.new
|
53
62
|
|
54
63
|
INSTALLERS.each { |installer| installer.run(config, status) }
|
64
|
+
plugins(config).each { |plugin| plugin.run(config, status) }
|
55
65
|
end
|
56
66
|
|
57
67
|
def encrypt
|
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.
|
4
|
+
version: 0.8.5
|
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-
|
11
|
+
date: 2018-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -106,13 +106,16 @@ files:
|
|
106
106
|
- lib/mac_setup/brewfile_installer.rb
|
107
107
|
- lib/mac_setup/command_line_tools_installer.rb
|
108
108
|
- lib/mac_setup/configuration.rb
|
109
|
+
- lib/mac_setup/defaults_installer.rb
|
109
110
|
- lib/mac_setup/git_repo_installer.rb
|
110
111
|
- lib/mac_setup/homebrew_installer.rb
|
111
112
|
- lib/mac_setup/homebrew_runner.rb
|
112
113
|
- lib/mac_setup/plugin.rb
|
114
|
+
- lib/mac_setup/plugins/asdf.rb
|
113
115
|
- lib/mac_setup/plugins/dotfiles.rb
|
114
116
|
- lib/mac_setup/plugins/keybase.rb
|
115
117
|
- lib/mac_setup/plugins/mac_app_store.rb
|
118
|
+
- lib/mac_setup/result.rb
|
116
119
|
- lib/mac_setup/script_installer.rb
|
117
120
|
- lib/mac_setup/secrets.rb
|
118
121
|
- lib/mac_setup/secrets_installer.rb
|