forked from lewagon/data-setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rb
executable file
·212 lines (200 loc) · 4.8 KB
/
build.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/env ruby -wU
CONSTANTS = {
'PYTHON_VERSION' => "3.8.12",
'PYTHON_CHECKER_URL' => "https://raw.githubusercontent.com/lewagon/data-setup/master/checks/python_checker.sh",
'PIP_CHECKER_URL' => "https://raw.githubusercontent.com/lewagon/data-setup/master/checks/pip_check.sh",
'PIP_LOADER_URL' => "https://raw.githubusercontent.com/lewagon/data-setup/master/checks/pip_check.py"
}
# NOTE(ssaunier): This script needs https://github.com/lewagon/setup to be cloned as well
MAC_OS = %w[
intro
setup/zoom
setup/github
setup/macos_apple_silicon
setup/macos_command_line_tools
homebrew
chrome
setup/macos_vscode
vscode_extensions
setup/vscode_liveshare
setup/oh_my_zsh
setup/gh_cli
setup/ssh_key
dotfiles
dotfiles_new_student
dotfiles_new_laptop
dotfiles_new_laptop_heading
dotfiles_new_laptop
osx_python
virtualenv
pip
nbextensions
python_checkup
dbeaver
docker
gcp_cli_setup
gcp_setup
gcp_setup_mid
gcp_setup_end
setup/kitt
setup/macos_slack
setup/slack_settings
kata
].freeze
MAC_OS_KC = %w[
keep_current
python_checkup
].freeze
WINDOWS = %w[
intro
setup/zoom
setup/github
setup/windows_version
setup/windows_virtualization
setup/windows_wsl
setup/windows_ubuntu
chrome
setup/windows_vscode
setup/windows_terminal
vscode_extensions
setup/vscode_liveshare
setup/git
setup/zsh
setup/oh_my_zsh
setup/gh_cli
setup/ssh_key
ubuntu_gcloud
dotfiles
dotfiles_new_student
dotfiles_new_laptop
dotfiles_new_laptop_heading
dotfiles_new_laptop
setup/ssh_agent
ubuntu_python
virtualenv
pip
win_jupyter
nbextensions
python_checkup
dbeaver
setup/windows_settings
win_vs_redistributable
win_docker
gcp_setup
gcp_setup_wsl
gcp_setup_end
setup/kitt
setup/windows_slack
setup/slack_settings
kata
].freeze
WINDOWS_KC = %w[
keep_current
python_checkup
].freeze
LINUX = %w[
intro
setup/zoom
setup/github
setup/ubuntu_vscode
vscode_extensions
setup/vscode_liveshare
setup/git
chrome
setup/zsh
setup/oh_my_zsh
setup/gh_cli
setup/ssh_key
ubuntu_gcloud
dotfiles
dotfiles_new_student
dotfiles_new_laptop
dotfiles_new_laptop_heading
dotfiles_new_laptop
setup/ssh_agent
ubuntu_python
virtualenv
pip
nbextensions
python_checkup
dbeaver
ubuntu_docker
gcp_setup
gcp_setup_linux
gcp_setup_end
setup/kitt
setup/ubuntu_slack
setup/slack_settings
kata
]
LINUX_KC = %w[
keep_current
python_checkup
]
KEEP_CURRENT_SUFFIX = "_keep_current"
filenames = {
"WINDOWS.md" => WINDOWS,
"macOS.md" => MAC_OS,
"LINUX.md" => LINUX,
"WINDOWS#{KEEP_CURRENT_SUFFIX}.md" => WINDOWS_KC,
"macOS#{KEEP_CURRENT_SUFFIX}.md" => MAC_OS_KC,
"LINUX#{KEEP_CURRENT_SUFFIX}.md" => LINUX_KC
}
DEFAULT_SUBS = {
"<CODE_EDITOR>" => "VS Code",
"<CODE_EDITOR_CMD>" => "code"
}
subs = {
"WINDOWS.md" => DEFAULT_SUBS,
"macOS.md" => DEFAULT_SUBS,
"LINUX.md" => DEFAULT_SUBS
}
delimiters = {
"WINDOWS.md" => ["\\$WINDOWS_START\n", "\\$WINDOWS_END\n"],
"macOS.md" => ["\\$MAC_START\n", "\\$MAC_END\n"],
"LINUX.md" => ["\\$LINUX_START\n", "\\$LINUX_END\n"]
}
filenames.each do |filename, partials|
File.open(filename.to_s, "w:utf-8") do |f|
partials.each do |partial|
match_data = partial.match(/setup\/(?<partial>[0-9a-z_]+)/)
if match_data
require 'open-uri'
content = URI.open(File.join("https://raw.githubusercontent.com/lewagon/setup/master", "_partials", "#{match_data[:partial]}.md"))
.string
# replace data-setup repo relative path by setup repo URL
image_paths = content.scan(/\!\[.*\]\((.*)\)/).flatten
image_paths.each { |ip| content.gsub!(ip, "https://github.com/lewagon/setup/blob/master/#{ip}")}
else
file = File.join("_partials", "#{partial}.md")
content = File.read(file, encoding: "utf-8")
end
# retrieve os name
if filename.include? KEEP_CURRENT_SUFFIX
os_name = filename[0..-(KEEP_CURRENT_SUFFIX.length() + 4)] + ".md"
else
os_name = filename
end
# iterate through the patterns to replace in the file depending on the OS
subs[os_name].each do |pattern, replace|
content.gsub!(pattern, replace)
end
# remove the OS dependant blocks
removed_blocks = delimiters.keys - [os_name]
removed_blocks.each do |block|
delimiter_start, delimiter_end = delimiters[block]
pattern = "#{delimiter_start}(.|\n)*?(?<!#{delimiter_end})#{delimiter_end}"
content.gsub!(/#{pattern}/, "")
end
# remove the OS dependant block delimiters
delimiters[os_name].each do |delimiter|
content.gsub!(/#{delimiter}/, "")
end
CONSTANTS.each do |placeholder, value|
content.gsub!("<#{placeholder}>", value)
end
f << content
f << "\n\n"
end
end
end