/
dependencies_step.cr
76 lines (66 loc) · 2.47 KB
/
dependencies_step.cr
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
module MStrap
module Steps
# Runnable as `mstrap dependencies`, the Dependencies step runs [`strap.sh`](https://github.com/MikeMcQuaid/strap/)
# and installs software from any available `Brewfile`s.
class DependenciesStep < Step
def self.description
"Basic machine bootstrapping with strap.sh, hub, and brew bundle."
end
def self.requires_mstrap?
false
end
def self.requires_shell_restart?
true
end
def bootstrap
set_strap_env!
strap_sh
load_profile!
brew_bundle
end
private def set_strap_env!
ENV["STRAP_GIT_NAME"] = user.name
ENV["STRAP_GIT_EMAIL"] = user.email
ENV["STRAP_GITHUB_USER"] = user.github
end
private def strap_sh
logn "==> Running strap.sh"
unless cmd "bash #{MStrap::Paths::STRAP_SH_PATH} #{MStrap.debug? ? "--debug" : ""}"
logc "Uhh oh, something went wrong in strap.sh-land. Check above or in #{MStrap::Paths::LOG_FILE}."
end
success "Finished running strap.sh"
set_brew_env_if_not_set
end
private def brew_bundle
logn "==> Installing dependencies from Brewfile (may take a while): "
config.profile_configs.each do |profile_config|
brewfile_path = File.join(profile_config.dir, "Brewfile")
if File.exists?(brewfile_path)
log "--> Installing dependencies from Brewfile from profile '#{profile_config.name})': "
unless cmd "brew bundle --file=#{brewfile_path} #{MStrap.debug? ? "--verbose" : ""}"
logc "Uhh oh, something went wrong in homebrewland. Check above or in #{MStrap::Paths::LOG_FILE}."
end
success "OK"
end
end
end
private def load_profile!
log "--> Reloading profile: "
config.reload!
success "OK"
end
private def set_brew_env_if_not_set
{% if flag?(:linux) %}
# Needed on initial run to continue
unless cmd("brew --version", quiet: true)
ENV["HOMEBREW_PREFIX"] = MStrap::Paths::HOMEBREW_PREFIX
ENV["HOMEBREW_CELLAR"] = "#{MStrap::Paths::HOMEBREW_PREFIX}/Cellar"
ENV["HOMEBREW_REPOSITORY"] = "#{MStrap::Paths::HOMEBREW_PREFIX}/Homebrew"
path = ENV["PATH"]
ENV["PATH"] = "#{MStrap::Paths::HOMEBREW_PREFIX}/bin:#{MStrap::Paths::HOMEBREW_PREFIX}/sbin:#{path}"
end
{% end %}
end
end
end
end