mac_setup 0.7.1 → 0.7.2
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/exe/mac_setup +1 -0
- data/lib/mac_setup/git_repo_installer.rb +58 -19
- data/lib/mac_setup/secrets.rb +98 -30
- data/lib/mac_setup/secrets_installer.rb +4 -5
- data/lib/mac_setup/system_status.rb +12 -0
- data/lib/mac_setup/version.rb +1 -1
- data/lib/mac_setup.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f57f9af7d99a2694983bf5d0b09a700eae37b249
|
4
|
+
data.tar.gz: 06f8d752ef6a7103c1b829d98a5d0e140dd44739
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5ecd9dd676671ea407cd222aca03577a1fa11c670a62edd600619c77dd171020531d3632b4d1a4465ad6f989a53fc0ab9c67b66e3b50435cee9ed986813a204
|
7
|
+
data.tar.gz: 4110cb066e342f2b4f048b8d6609143cec308eb59789bc04231dc1602cc55a0466540280f87ae315f5d869b0d49652a3bb49ae8c6b3773fda9ad09d8562d14f5
|
data/exe/mac_setup
CHANGED
@@ -2,6 +2,8 @@ require_relative "shell"
|
|
2
2
|
|
3
3
|
module MacSetup
|
4
4
|
class GitRepoInstaller
|
5
|
+
attr_reader :repo, :install_path, :tracking_key, :status
|
6
|
+
|
5
7
|
def self.run(config, _status)
|
6
8
|
repos = config.git_repos
|
7
9
|
return if repos.none?
|
@@ -10,39 +12,76 @@ module MacSetup
|
|
10
12
|
|
11
13
|
repos.each do |repo_and_path|
|
12
14
|
repo, install_path = repo_and_path.to_a.flatten
|
13
|
-
|
15
|
+
new(repo, File.expand_path(install_path)).install_or_update
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
|
-
def self.install_repo(repo, install_path)
|
19
|
+
def self.install_repo(repo, install_path, tracking_key: nil, status: nil)
|
20
|
+
new(repo, install_path, tracking_key: tracking_key, status: status).install_or_update
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(repo, install_path, tracking_key: nil, status: nil)
|
24
|
+
@repo = repo
|
25
|
+
@install_path = install_path
|
26
|
+
@tracking_key = tracking_key
|
27
|
+
@status = status
|
28
|
+
end
|
29
|
+
|
30
|
+
def install_or_update
|
18
31
|
if Dir.exist?(install_path)
|
19
|
-
MacSetup.log
|
20
|
-
update_repo(install_path)
|
21
|
-
end
|
32
|
+
MacSetup.log("#{repo} Already Installed. Updating") { update }
|
22
33
|
else
|
23
|
-
MacSetup.log
|
24
|
-
url = expand_url(repo)
|
25
|
-
Shell.run(%(git clone --recursive #{url} "#{install_path}"))
|
26
|
-
end
|
34
|
+
MacSetup.log("Installing #{repo}") { install }
|
27
35
|
end
|
28
36
|
end
|
29
37
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
+
private
|
39
|
+
|
40
|
+
def install
|
41
|
+
clone_repo
|
42
|
+
track_install
|
43
|
+
end
|
44
|
+
|
45
|
+
def update
|
46
|
+
unless can_update?
|
47
|
+
puts "\nCan't update. Unstaged changes in #{install_path}"
|
48
|
+
return
|
49
|
+
end
|
50
|
+
|
51
|
+
in_install_path do
|
52
|
+
Shell.run("git fetch")
|
53
|
+
track_update
|
54
|
+
Shell.run("git merge origin && git submodule update --init --recursive")
|
38
55
|
end
|
39
56
|
end
|
40
57
|
|
41
|
-
def
|
58
|
+
def clone_repo
|
59
|
+
Shell.run(%(git clone --recursive #{repo_url} "#{install_path}"))
|
60
|
+
end
|
61
|
+
|
62
|
+
def can_update?
|
42
63
|
Shell.run("git status --porcelain").empty?
|
43
64
|
end
|
44
65
|
|
45
|
-
def
|
66
|
+
def track_install
|
67
|
+
return unless tracking_key
|
68
|
+
|
69
|
+
in_install_path do
|
70
|
+
status.git_changes(tracking_key, Shell.run("git ls-files").split("\n"))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def track_update
|
75
|
+
return unless tracking_key
|
76
|
+
|
77
|
+
status.git_changes(tracking_key, Shell.run("git diff --name-only origin").split("\n"))
|
78
|
+
end
|
79
|
+
|
80
|
+
def in_install_path
|
81
|
+
Dir.chdir(install_path) { yield }
|
82
|
+
end
|
83
|
+
|
84
|
+
def repo_url
|
46
85
|
repo =~ %r{^[^/]+/[^/]+$} ? "https://github.com/#{repo}.git" : repo
|
47
86
|
end
|
48
87
|
end
|
data/lib/mac_setup/secrets.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
module MacSetup
|
2
2
|
class Secrets
|
3
|
+
CRYPTO_LIB = "openssl"
|
3
4
|
CIPHER = "aes-256-cbc"
|
4
5
|
PLAINTEXT_EXT = "priv"
|
5
6
|
CIPHERTEXT_EXT = "crypt"
|
6
7
|
|
7
|
-
attr_reader :
|
8
|
+
attr_reader :files, :password
|
8
9
|
|
9
|
-
def self.encrypt(
|
10
|
-
new(
|
10
|
+
def self.encrypt(dir_or_files)
|
11
|
+
new(filter_files(dir_or_files, PLAINTEXT_EXT)).encrypt
|
11
12
|
end
|
12
13
|
|
13
|
-
def self.decrypt(
|
14
|
-
new(
|
14
|
+
def self.decrypt(dir_or_files)
|
15
|
+
new(filter_files(dir_or_files, CIPHERTEXT_EXT)).decrypt
|
15
16
|
end
|
16
17
|
|
17
18
|
def self.encrypted?(file)
|
@@ -24,50 +25,117 @@ module MacSetup
|
|
24
25
|
file.sub(/\.#{PLAINTEXT_EXT}$/, "")
|
25
26
|
end
|
26
27
|
|
27
|
-
def
|
28
|
-
|
28
|
+
def self.filter_files(dir_or_files, extension)
|
29
|
+
if dir_or_files.is_a?(Array)
|
30
|
+
dir_or_files.select { |file| file.to_s.end_with?(extension) }
|
31
|
+
else
|
32
|
+
Dir.glob("#{File.expand_path(dir_or_files)}/**/*.#{extension}")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def initialize(files)
|
37
|
+
@files = files
|
29
38
|
end
|
30
39
|
|
31
40
|
def encrypt
|
32
|
-
|
33
|
-
files = Dir.glob("#{dir}/**/*.#{PLAINTEXT_EXT}")
|
34
|
-
do_crypt(files, from: PLAINTEXT_EXT, to: CIPHERTEXT_EXT, overwrite: true)
|
41
|
+
do_crypt("encrypt") { encrypt_files }
|
35
42
|
end
|
36
43
|
|
37
44
|
def decrypt
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
unless Shell.success?(command + %W(-in #{files.first}))
|
43
|
-
puts "Wrong password!"
|
44
|
-
exit 1
|
45
|
-
end
|
45
|
+
if files.any?
|
46
|
+
MacSetup.log "Decrypting files:"
|
47
|
+
else
|
48
|
+
MacSetup.log "No files to decrypt. Skipping"
|
46
49
|
end
|
50
|
+
|
51
|
+
list_files
|
52
|
+
get_password
|
53
|
+
decrypt_files
|
47
54
|
end
|
48
55
|
|
49
56
|
private
|
50
57
|
|
51
|
-
def do_crypt(
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
58
|
+
def do_crypt(type)
|
59
|
+
if files.any?
|
60
|
+
MacSetup.log "#{titleized(type)}ing files:"
|
61
|
+
list_files
|
62
|
+
get_password
|
63
|
+
yield
|
64
|
+
else
|
65
|
+
MacSetup.log "No files to #{type}. Skipping"
|
66
|
+
end
|
67
|
+
end
|
56
68
|
|
57
|
-
|
58
|
-
|
69
|
+
def titleized(str)
|
70
|
+
char, rest = str.split("", 2)
|
71
|
+
char.upcase + rest
|
72
|
+
end
|
59
73
|
|
60
|
-
|
74
|
+
def list_files
|
75
|
+
files.each { |file| puts " #{MacSetup.shorten_path(file)}" }
|
76
|
+
end
|
61
77
|
|
78
|
+
def get_password
|
79
|
+
@password = Shell.password
|
80
|
+
end
|
81
|
+
|
82
|
+
def encrypt_files
|
62
83
|
files.each do |file|
|
63
|
-
target_path = file.sub(/#{
|
64
|
-
|
65
|
-
|
84
|
+
target_path = file.sub(/#{PLAINTEXT_EXT}$/, CIPHERTEXT_EXT)
|
85
|
+
do_encrypt(file, target_path)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def decrypt_files
|
90
|
+
if password_correct?
|
91
|
+
do_decrypt
|
92
|
+
else
|
93
|
+
puts "Wrong Password!"
|
94
|
+
get_password
|
95
|
+
decrypt_files
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def password_correct?
|
100
|
+
Shell.success?(decrypt_command(files.first, files.first.sub(/#{CIPHERTEXT_EXT}$/, PLAINTEXT_EXT)))
|
101
|
+
end
|
102
|
+
|
103
|
+
def do_decrypt
|
104
|
+
files.each { |file| decrypt_file(file) }
|
105
|
+
end
|
106
|
+
|
107
|
+
def decrypt_file(file, log: true)
|
108
|
+
target_path = file.sub(/#{CIPHERTEXT_EXT}$/, PLAINTEXT_EXT)
|
109
|
+
command = -> { Shell.run(decrypt_command(file, target_path)) }
|
110
|
+
|
111
|
+
if log
|
112
|
+
MacSetup.log "Decrypting #{raw_file_path(file)}", &command
|
113
|
+
else
|
114
|
+
command.call
|
66
115
|
end
|
67
116
|
end
|
68
117
|
|
118
|
+
def do_encrypt(file, target_path)
|
119
|
+
MacSetup.log "Encrypting #{raw_file_path(file)}" do
|
120
|
+
Shell.run(encrypt_command(file, target_path))
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def encrypt_command(file, target_path)
|
125
|
+
%W(openssl enc -aes-256-cbc -k testme -in #{file} -out #{target_path})
|
126
|
+
end
|
127
|
+
|
128
|
+
def decrypt_command(file, target_path)
|
129
|
+
%W(openssl enc -aes-256-cbc -k testme -d -in #{file} -out #{target_path})
|
130
|
+
end
|
131
|
+
|
69
132
|
def base_command(password)
|
70
|
-
%W(
|
133
|
+
%W(#{CRYPTO_LIB} enc -#{CIPHER} -k #{password})
|
134
|
+
end
|
135
|
+
|
136
|
+
def raw_file_path(file)
|
137
|
+
raw_file = file.sub(/\.#{CIPHERTEXT_EXT}|#{PLAINTEXT_EXT}$/, "")
|
138
|
+
MacSetup.shorten_path(raw_file)
|
71
139
|
end
|
72
140
|
end
|
73
141
|
end
|
@@ -9,13 +9,12 @@ module MacSetup
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def run
|
12
|
-
|
13
|
-
Secrets.decrypt(
|
12
|
+
install_crypto
|
13
|
+
Secrets.decrypt(@status.git_changes(:dotfiles))
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
|
18
|
-
Shell.run("brew install openssl") unless @status.installed_formulas.include?("openssl")
|
16
|
+
def install_crypto
|
17
|
+
Shell.run("brew install #{SECRETS::CRYPTO_LIB}") unless @status.installed_formulas.include?(CRYPTO_LIB)
|
19
18
|
end
|
20
19
|
end
|
21
20
|
end
|
@@ -2,6 +2,10 @@ require_relative "shell"
|
|
2
2
|
|
3
3
|
module MacSetup
|
4
4
|
class SystemStatus
|
5
|
+
def initialize
|
6
|
+
@git_changes = Hash.new { |hash, key| hash[key] = [] }
|
7
|
+
end
|
8
|
+
|
5
9
|
def installed_taps
|
6
10
|
@installed_taps ||= get_taps
|
7
11
|
end
|
@@ -10,6 +14,14 @@ module MacSetup
|
|
10
14
|
@installed_formulas ||= get_formulas
|
11
15
|
end
|
12
16
|
|
17
|
+
def git_changes(key, changes = nil)
|
18
|
+
if changes
|
19
|
+
@git_changes[key] = changes
|
20
|
+
else
|
21
|
+
@git_changes[key]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
13
25
|
private
|
14
26
|
|
15
27
|
def get_taps
|
data/lib/mac_setup/version.rb
CHANGED
data/lib/mac_setup.rb
CHANGED
@@ -27,7 +27,7 @@ module MacSetup
|
|
27
27
|
config = Configuration.new(File.expand_path(config_path))
|
28
28
|
status = SystemStatus.new
|
29
29
|
|
30
|
-
GitRepoInstaller.install_repo(config.dotfiles_repo, DOTFILES_PATH)
|
30
|
+
GitRepoInstaller.install_repo(config.dotfiles_repo, DOTFILES_PATH, status: status, track: :dotfiles)
|
31
31
|
config.reload!
|
32
32
|
INSTALLERS.each { |installer| installer.run(config, status) }
|
33
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.7.
|
4
|
+
version: 0.7.2
|
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-
|
11
|
+
date: 2017-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|