-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmacos
executable file
·113 lines (89 loc) · 3.42 KB
/
macos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env ruby
require 'fileutils'
require 'yaml'
class Config
PERSONAL = 'personal'
WORK = 'work'
attr_reader :config_dir, :config_path, :settings
def initialize
@config_dir = File.join(Dir.home, '.config')
@config_path = File.join(config_dir, 'new-machine-bootstrap.yml')
if File.exist?(config_path)
@settings = YAML.load_file config_path
else
FileUtils.mkdir_p config_dir
print "\nIs this machine for work (w) or personal (p) use? "
work_or_personal = STDIN.gets.chomp
exit 1 unless %w(w p).include? work_or_personal
@settings = {}
settings['use'] = work_or_personal == 'p' ? PERSONAL : WORK
File.open(config_path, 'w') { |f| f.write settings.to_yaml }
end
end
def personal?
settings['use'] == PERSONAL
end
def work?
settings['use'] == WORK
end
end
module Provision
def self.binary_installed?(binary)
system("command -v #{binary} >/dev/null 2>&1")
end
def self.brew(brew_package)
return if system("brew list #{brew_package} >/dev/null 2>&1")
run_command "brew install #{brew_package}"
end
def self.update_project(project_name, remote: 'github.com')
project_dir = File.join(Dir.home, 'projects', project_name)
if File.exist? project_dir
puts "\nUpdating #{project_name}\n"
run_command "cd #{project_dir} && git pull"
puts "\nDone updating #{project_name}\n"
else
puts "\nCloning #{project_name}\n"
run_command "git clone git@#{remote}:f1sherman/#{project_name}.git #{project_dir}"
puts "\nDone cloning #{project_name}\n"
end
end
def self.run_command(command)
puts "$ #{command}"
success = system command
return if success
puts "\nReceived exit status #{$?.exitstatus}, quitting..."
exit 1
end
end
filevault_status = %x(fdesetup status)
unless filevault_status == "FileVault is On.\n"
puts 'It looks like FileVault is not turned on. Before doing anything else please enable FileVault and ensure that it has completed.'
exit
end
ssh_public_key = File.join(Dir.home, '.ssh', 'id_rsa.pub')
unless File.exist? ssh_public_key
puts %q(No ssh key found. You'll now have a chance to generate a key if you'd like. If you'd rather generate it manually or copy it from somewhere, answer "n" at this prompt and restart this script after you've added it.)
print "\nWould you like to generate an ssh key now (y/n)? "
exit unless STDIN.gets.chomp == "y"
require 'io/console'
print "\nEnter ssh passphrase:"
ssh_passphrase = STDIN.noecho(&:gets)
Provision.run_command %Q(ssh-keygen -N "#{ssh_passphrase}" -f ~/.ssh/id_rsa)
puts 'Your ssh key has been generated. Add the below public key to bitbucket and github and press any key to continue...'
puts File.read ssh_public_key
STDIN.getch
end
config = Config.new
Provision.run_command 'softwareupdate --all --install --force'
unless Provision.binary_installed? 'brew'
Provision.run_command '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'
end
Provision.run_command 'brew upgrade'
Provision.brew 'ansible'
Provision.update_project 'new-machine-bootstrap'
Provision.run_command 'cd ~/projects/new-machine-bootstrap && bin/provision'
if config.personal?
Provision.update_project 'home-network-provisioning', remote: 'bitbucket.org'
Provision.run_command 'cd ~/projects/home-network-provisioning && bin/provision --limit localhost'
end
Provision.run_command 'brew cleanup'