-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.rb
73 lines (63 loc) · 2.53 KB
/
install.rb
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
require 'open-uri'
require 'sqlite3'
require 'mkmf'
# For installing and configure macOS systems
class MacosFirstInstall
def dbconnect
@db = SQLite3::Database.open 'macos_install.db'
@db.results_as_hash = true
@tap = @db.execute("select * from software WHERE method='tap'")
@core = @db.execute("select * from software WHERE method='core'")
@cask = @db.execute("select * from software WHERE method='cask'")
@mas = @db.execute("select * from software WHERE method='mas'")
@gem = @db.execute("select * from software WHERE method='gem'")
end
def preinstall
@pretap = @tap.each.map { |package| 'brew tap ' + package['name'] }
@precore = @core.each.map { |package| 'brew install ' + package['name'] unless system('brew ls --versions ' + package['name']) }
@precask = @cask.each.map { |package| 'brew cask install ' + package['name'] unless system('brew cask ls --versions ' + package['name']) }
@premas = @mas.each.map { |package| 'mas install ' + package['name'] }
@pregem = @gem.each.map { |package| 'gem install ' + package['name'] }
end
def install
@precore.compact.each { |command| system command }
@precask.compact.each { |command| system command }
@premas.compact.each { |command| system command }
@pregem.compact.each { |command| system command }
system('curl -L https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh')
system('git clone https://github.com/zsh-users/zsh-completions ~/.oh-my-zsh/custom/plugins/zsh-completions')
system('curl -L https://iterm2.com/misc/install_shell_integration.sh | bash')
end
def cleanup
system('brew cleanup')
end
def main
dbconnect
preinstall
install
cleanup
end
end
class MacOSConfig
def dbconnect
@db = SQLite3::Database.open 'macos_install.db'
@db.results_as_hash = true
@defaults = @db.execute("select * from config WHERE method='defaults'")
@systemsetup = @db.execute("select * from config WHERE method='systemsetup'")
end
def preconfig
@predefaults = @defaults.each.map { |config| [config['method'], 'write', config['domain'], config['key'], '-' + config['keytyp'], config['keyvalue']].join(' ') }
@presystemsetup = @systemsetup.each.map { |config| [config['method'], '-' + config['key'], config['keyvalue']].join(' ') }
end
def config
@predefaults.each { |command| system command }
@presystemsetup.each { |command| system command }
end
def main
dbconnect
preconfig
config
end
end
MacosFirstInstall.new.main
MacOSConfig.main