mac_setup 0.5.0 → 0.6.0
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 +2 -0
- data/lib/mac_setup/brewfile_installer.rb +6 -0
- data/lib/mac_setup/secrets.rb +73 -0
- data/lib/mac_setup/shell.rb +21 -1
- data/lib/mac_setup/symlink_installer.rb +8 -6
- data/lib/mac_setup/version.rb +1 -1
- data/lib/mac_setup.rb +8 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e838d025ff3bddf2160c37b063735b85094e7ff5
|
4
|
+
data.tar.gz: 6c7d1722bbc01b83955fd73dd040e2b292460b1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4792d51c9b5840513664182570c7de79c667641afba9aa0ac389db988a183705d129146f589214049c2d61a813a666ce5c2abe6322346011b7c51c526ff3f495
|
7
|
+
data.tar.gz: 8708caa2c2c09d0fa8d3be474d9083a616174e93b404d5622418fe7e83b34704a0e79935d928528fec639d9d21fd2d388d67d8c6505d4eadc2da4d51f6caaa20
|
data/exe/mac_setup
CHANGED
@@ -19,6 +19,7 @@ module MacSetup
|
|
19
19
|
tap_bundle
|
20
20
|
sign_in_to_mas
|
21
21
|
install_brewfile
|
22
|
+
install_openssl
|
22
23
|
end
|
23
24
|
|
24
25
|
private
|
@@ -39,6 +40,11 @@ module MacSetup
|
|
39
40
|
Shell.run("brew bundle --global")
|
40
41
|
end
|
41
42
|
|
43
|
+
def install_openssl
|
44
|
+
# Needed for encrypted files
|
45
|
+
Shell.run("brew install openssl")
|
46
|
+
end
|
47
|
+
|
42
48
|
def bundle_already_tapped?
|
43
49
|
status.installed_taps.include?(BUNDLE_TAP)
|
44
50
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module MacSetup
|
2
|
+
class Secrets
|
3
|
+
CIPHER = "aes-256-cbc"
|
4
|
+
PLAINTEXT_EXT = "priv"
|
5
|
+
CIPHERTEXT_EXT = "crypt"
|
6
|
+
|
7
|
+
attr_reader :dir
|
8
|
+
|
9
|
+
def self.encrypt(dir)
|
10
|
+
new(dir).encrypt
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.decrypt(dir)
|
14
|
+
new(dir).decrypt
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.encrypted?(file)
|
18
|
+
file.to_s.end_with?(CIPHERTEXT_EXT)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.strip_extension(file)
|
22
|
+
return file unless file.to_s.end_with?(PLAINTEXT_EXT)
|
23
|
+
|
24
|
+
file.sub(/#{PLAINTEXT_EXT}$/, "")
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(dir)
|
28
|
+
@dir = File.expand_path(dir)
|
29
|
+
end
|
30
|
+
|
31
|
+
def encrypt
|
32
|
+
puts "Encrypting files:"
|
33
|
+
files = Dir.glob("#{dir}/**/*.#{PLAINTEXT_EXT}")
|
34
|
+
do_crypt(files, from: PLAINTEXT_EXT, to: CIPHERTEXT_EXT, overwrite: true)
|
35
|
+
end
|
36
|
+
|
37
|
+
def decrypt
|
38
|
+
puts "Decrypting files:"
|
39
|
+
files = Dir.glob("#{dir}/**/*.#{CIPHERTEXT_EXT}")
|
40
|
+
|
41
|
+
do_crypt(files, from: CIPHERTEXT_EXT, to: PLAINTEXT_EXT, args: "-d") do |command|
|
42
|
+
unless Shell.success?(command + %W(-in #{files.first}))
|
43
|
+
puts "Wrong password!"
|
44
|
+
exit 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def do_crypt(files, options)
|
52
|
+
old_ext = options.fetch(:from)
|
53
|
+
new_ext = options.fetch(:to)
|
54
|
+
overwrite = options.fetch(:overwrite, false)
|
55
|
+
args = Array(options.fetch(:args, []))
|
56
|
+
|
57
|
+
files.each { |file| puts " - #{file}" }
|
58
|
+
command = base_command(Shell.password) + args
|
59
|
+
|
60
|
+
yield command if block_given?
|
61
|
+
|
62
|
+
files.each do |file|
|
63
|
+
target_path = file.sub(/#{old_ext}$/, new_ext)
|
64
|
+
next if !overwrite && File.exist?(target_path)
|
65
|
+
Shell.run(command + %W(-in #{file} -out #{target_path}))
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def base_command(password)
|
70
|
+
%W(openssl enc -#{CIPHER} -k #{password})
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/mac_setup/shell.rb
CHANGED
@@ -1,12 +1,32 @@
|
|
1
|
+
require "shellwords"
|
2
|
+
require "io/console"
|
3
|
+
|
1
4
|
module MacSetup
|
2
5
|
class Shell
|
3
6
|
def self.run(command)
|
4
|
-
`#{command}`
|
7
|
+
`#{sanitize_command(command)}`
|
5
8
|
end
|
6
9
|
|
7
10
|
def self.ask(question)
|
8
11
|
puts question
|
9
12
|
gets.strip
|
10
13
|
end
|
14
|
+
|
15
|
+
def self.password
|
16
|
+
puts "Enter Password"
|
17
|
+
STDIN.noecho(&:gets).strip
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.success?(command)
|
21
|
+
system(sanitize_command(command))
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.sanitize_command(command)
|
25
|
+
if command.respond_to?(:each)
|
26
|
+
Shellwords.join(command)
|
27
|
+
else
|
28
|
+
command
|
29
|
+
end
|
30
|
+
end
|
11
31
|
end
|
12
32
|
end
|
@@ -3,10 +3,12 @@ module MacSetup
|
|
3
3
|
def initialize(options)
|
4
4
|
@source_path = options[:source_path]
|
5
5
|
@file_name = options[:name]
|
6
|
-
@target_path = options[:target_path]
|
6
|
+
@target_path = sanitize_target(options[:target_path])
|
7
7
|
end
|
8
8
|
|
9
9
|
def link
|
10
|
+
return if Secrets.encrypted?(source_path)
|
11
|
+
|
10
12
|
short_sorce_path = MacSetup.shorten_path(source_path)
|
11
13
|
short_target_path = MacSetup.shorten_path(target_path)
|
12
14
|
puts "Linking #{short_sorce_path} to #{short_target_path}..."
|
@@ -31,16 +33,12 @@ module MacSetup
|
|
31
33
|
File.exist?(target_path)
|
32
34
|
end
|
33
35
|
|
34
|
-
def target
|
35
|
-
@target ||= SymlinkTarget.new(target_path)
|
36
|
-
end
|
37
|
-
|
38
36
|
def source_path
|
39
37
|
@source_path ||= File.expand_path(file_name, DOTFILES_PATH)
|
40
38
|
end
|
41
39
|
|
42
40
|
def target_path
|
43
|
-
@target_path ||= File.join(ENV["HOME"], ".#{file_name}")
|
41
|
+
@target_path ||= File.join(ENV["HOME"], ".#{sanitize_target(file_name)}")
|
44
42
|
end
|
45
43
|
|
46
44
|
def file_name
|
@@ -85,6 +83,10 @@ module MacSetup
|
|
85
83
|
def children
|
86
84
|
Dir.entries(source_path).reject { |entry| entry.start_with?(".") }
|
87
85
|
end
|
86
|
+
|
87
|
+
def sanitize_target(file)
|
88
|
+
Secrets.strip_extension(file)
|
89
|
+
end
|
88
90
|
end
|
89
91
|
|
90
92
|
class SymlinkInstaller
|
data/lib/mac_setup/version.rb
CHANGED
data/lib/mac_setup.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "mac_setup/version"
|
2
2
|
require "mac_setup/configuration"
|
3
3
|
require "mac_setup/system_status"
|
4
|
+
require "mac_setup/secrets"
|
4
5
|
require "mac_setup/command_line_tools_installer"
|
5
6
|
require "mac_setup/homebrew_installer"
|
6
7
|
require "mac_setup/git_repo_installer"
|
@@ -13,16 +14,17 @@ module MacSetup
|
|
13
14
|
DOTFILES_PATH = File.expand_path("~/.dotfiles")
|
14
15
|
|
15
16
|
INSTALLERS = [
|
16
|
-
|
17
|
+
GitRepoInstaller,
|
17
18
|
BrewfileInstaller,
|
18
19
|
ServicesInstaller,
|
19
|
-
|
20
|
+
SymlinkInstaller,
|
20
21
|
ScriptInstaller
|
21
22
|
]
|
22
23
|
|
23
24
|
def self.install(config_path, _options)
|
24
25
|
config = Configuration.new(File.expand_path(config_path))
|
25
26
|
status = SystemStatus.new
|
27
|
+
Secrets.decrypt(DOTFILES_PATH)
|
26
28
|
|
27
29
|
INSTALLERS.each { |installer| installer.run(config, status) }
|
28
30
|
end
|
@@ -30,10 +32,13 @@ module MacSetup
|
|
30
32
|
def self.bootstrap(dotfiles_repo)
|
31
33
|
CommandLineToolsInstaller.run
|
32
34
|
GitRepoInstaller.install_repo(dotfiles_repo, DOTFILES_PATH)
|
33
|
-
SymlinkInstaller.install_dotfile("mac_setup")
|
34
35
|
HomebrewInstaller.run
|
35
36
|
end
|
36
37
|
|
38
|
+
def self.encrypt
|
39
|
+
Secrets.encrypt(DOTFILES_PATH)
|
40
|
+
end
|
41
|
+
|
37
42
|
def self.shorten_path(path)
|
38
43
|
path.sub(/#{ENV['HOME']}/, "~")
|
39
44
|
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.
|
4
|
+
version: 0.6.0
|
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-
|
11
|
+
date: 2017-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- lib/mac_setup/git_repo_installer.rb
|
110
110
|
- lib/mac_setup/homebrew_installer.rb
|
111
111
|
- lib/mac_setup/script_installer.rb
|
112
|
+
- lib/mac_setup/secrets.rb
|
112
113
|
- lib/mac_setup/services_installer.rb
|
113
114
|
- lib/mac_setup/shell.rb
|
114
115
|
- lib/mac_setup/symlink_installer.rb
|