forked from skwp/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathRakefile
306 lines (260 loc) · 9.56 KB
/
Rakefile
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
require 'rake'
require 'fileutils'
$is_macos = RUBY_PLATFORM.downcase.include?("darwin")
desc "Hook our dotfiles into system-standard positions."
task :install => [:submodule_init, :submodules] do
puts
puts "======================================================"
puts "Welcome to YADR Installation."
puts "======================================================"
puts
install_homebrew
# this has all the runcoms from this directory.
install_files(Dir.glob('git/*')) if want_to_install?('git configs (color, aliases)')
install_files(Dir.glob('ruby/*')) if want_to_install?('rubygems config (faster/no docs)')
install_files(Dir.glob('ctags/*')) if want_to_install?('ctags config (better js/ruby support)')
install_files(Dir.glob('tmux/*')) if want_to_install?('tmux config')
install_files(Dir.glob('vimify/*')) if want_to_install?('vimification of command line tools')
install_files(Dir.glob('{vim,vimrc}'))
install_files(Dir.glob('zsh/zshrc'))
run %{ ln -nfs ~/.yadr/nvim ~/.config/nvim }
run %{ mkdir -p ~/.config/ranger }
run %{ ln -nfs ~/.yadr/ranger ~/.config/ranger }
run %{ touch ~/.hushlogin }
Rake::Task["install_prezto"].execute
install_fonts
if $is_macos
run %{ ~/.yadr/iTerm2/bootstrap-iterm2.sh }
end
success_msg("installed")
end
task :install_prezto do
if want_to_install?('zsh enhancements & prezto')
install_prezto
end
end
desc 'Updates the installation'
task :update do
Rake::Task["install"].execute
#TODO: for now, we do the same as install. But it would be nice
#not to clobber zsh files
end
task :submodule_init do
unless ENV["SKIP_SUBMODULES"]
run %{ git submodule update --init --recursive }
end
end
desc "Init and update submodules."
task :submodules do
unless ENV["SKIP_SUBMODULES"]
puts "======================================================"
puts "Downloading YADR submodules...please wait"
puts "======================================================"
run %{
cd $HOME/.yadr
git submodule update --recursive
git clean -df
}
puts
end
end
task :default => 'install'
private
def run(cmd)
puts "[Running] #{cmd}"
`#{cmd}` unless ENV['DEBUG']
end
def number_of_cores
if $is_macos
cores = run %{ sysctl -n hw.ncpu }
else
cores = run %{ nproc }
end
puts
cores.to_i
end
def linux_variant
r = { :distro => nil, :family => nil }
if File.exists?('/etc/lsb-release')
File.open('/etc/lsb-release', 'r').read.each_line do |line|
r = { :distro => $1 } if line =~ /^DISTRIB_ID=(.*)/
end
end
if File.exists?('/etc/debian_version')
r[:distro] = 'Debian' if r[:distro].nil?
r[:family] = 'Debian' if r[:variant].nil?
elsif File.exists?('/etc/redhat-release') or File.exists?('/etc/centos-release')
r[:family] = 'RedHat' if r[:family].nil?
r[:distro] = 'CentOS' if File.exists?('/etc/centos-release')
elsif File.exists?('/etc/SuSE-release')
r[:distro] = 'SLES' if r[:distro].nil?
end
return r
end
def install_homebrew
run %{which brew}
unless $?.success?
puts "======================================================"
puts "Installing Homebrew, the OSX package manager...If it's"
puts "already installed, this will do nothing."
puts "======================================================"
if $is_macos
run %{bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"}
else
puts "Running Homebrew 'install.sh' on Linux..."
if ! File.exists?('/home/linuxbrew')
run %{sudo mkdir -p /home/linuxbrew}
run %{sudo chmod 777 /home/linuxbrew}
end
run %{yes | bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"}
puts "Configuring 'brew shellenv' on Linux..."
ENV['HOMEBREW_PREFIX'] = "/home/linuxbrew/.linuxbrew"
ENV['HOMEBREW_CELLAR'] = "/home/linuxbrew/.linuxbrew/Cellar"
ENV['HOMEBREW_REPOSITORY'] = "/home/linuxbrew/.linuxbrew/Homebrew"
ENV['PATH'] = "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:" + ENV['PATH']
ENV['MANPATH'] = "/home/linuxbrew/.linuxbrew/share/man:" + ENV['MANPATH'].to_s
ENV['INFOPATH'] ="/home/linuxbrew/.linuxbrew/share/info:" + ENV['INFOPATH'].to_s
run %{which brew}
unless $?.success?
puts "'brew' is NOT in the path!"
exit 0
end
if linux_variant[:distro] == 'Ubuntu' || linux_variant[:distro] == 'Debian'
# Running on Debian/Ubuntu
run %{sudo apt-get install build-essential}
elsif linux_variant[:family] == 'Redhat'
if linux_variant[:distro] == nil
# Running on Redhat Linux
elsif linux_variant[:distro] == 'Centos'
# Running on Centos Linux
end
end
end
end
puts
puts
puts "======================================================"
puts "Updating Homebrew."
puts "======================================================"
run %{brew update}
puts
puts
puts "======================================================"
puts "Installing Homebrew and other packages..."
puts "======================================================"
if ENV['CI'] then
# A minimal Brewfile to speed up CI Builds
run %{brew bundle install --file=test/Brewfile_ci}
else
run %{brew bundle install}
end
# run %{pip3 install tmuxp}
run %{pip3 install --user neovim} # For NeoVim plugins
run %{pip3 install --user pynvim} # For NeoVim plugins
run %{gem install neovim} # For NeoVim plugins
puts
puts
end
def install_fonts
puts "======================================================"
puts "Installing patched fonts for Powerline/Lightline."
puts "======================================================"
run %{ cp -f $HOME/.yadr/fonts/* $HOME/Library/Fonts } if $is_macos
run %{ mkdir -p ~/.fonts && cp ~/.yadr/fonts/* ~/.fonts && fc-cache -vf ~/.fonts } if !$is_macos
puts
end
def ask(message, values)
puts message
while true
values.each_with_index { |val, idx| puts " #{idx+1}. #{val}" }
selection = STDIN.gets.chomp
if (Float(selection)==nil rescue true) || selection.to_i < 0 || selection.to_i > values.size+1
puts "ERROR: Invalid selection.\n\n"
else
break
end
end
selection = selection.to_i-1
values[selection]
end
def install_prezto
puts
puts "Installing Prezto (ZSH Enhancements)..."
run %{ ln -nfs "$HOME/.yadr/zsh/prezto" "${ZDOTDIR:-$HOME}/.zprezto" }
# The prezto runcoms are only going to be installed if zprezto has never been installed
install_files(Dir.glob('zsh/prezto/runcoms/zlogin'), :symlink)
install_files(Dir.glob('zsh/prezto/runcoms/zlogout'), :symlink)
install_files(Dir.glob('zsh/prezto/runcoms/zpreztorc'), :symlink)
install_files(Dir.glob('zsh/prezto/runcoms/zprofile'), :symlink)
install_files(Dir.glob('zsh/prezto/runcoms/zshenv'), :symlink)
puts
puts "Overriding prezto ~/.zpreztorc with YADR's zpreztorc to enable additional modules..."
run %{ ln -nfs "$HOME/.yadr/zsh/prezto-override/zpreztorc" "${ZDOTDIR:-$HOME}/.zpreztorc" }
run %{ ln -s ~/.zprezto/modules/prompt/external/powerlevel9k/powerlevel9k.zsh-theme ~/.zprezto/modules/prompt/functions/prompt_powerlevel9k_setup }
puts
puts "Creating directories for your customizations"
run %{ mkdir -p $HOME/.zsh.before }
run %{ mkdir -p $HOME/.zsh.after }
run %{ mkdir -p $HOME/.zsh.prompts }
if "#{ENV['SHELL']}".include? 'zsh' then
puts "Zsh is already configured as your shell of choice. Restart your session to load the new settings"
else
puts "Setting zsh as your default shell"
if File.exists?("/usr/local/bin/zsh")
if File.readlines("/private/etc/shells").grep("/usr/local/bin/zsh").empty?
puts "Adding zsh to standard shell list"
run %{ echo "/usr/local/bin/zsh" | sudo tee -a /private/etc/shells }
end
run %{ sudo chsh -s /usr/local/bin/zsh $USER }
elsif File.exists?("/home/linuxbrew/.linuxbrew/bin/zsh")
if File.readlines("/etc/shells").grep("/home/linuxbrew/.linuxbrew/bin/zsh").empty?
puts "Adding zsh to standard shell list"
run %{ echo "/home/linuxbrew/.linuxbrew/bin/zsh" | sudo tee -a /etc/shells }
end
run %{ sudo chsh -s /home/linuxbrew/.linuxbrew/bin/zsh $USER }
else
puts "Falling back to default/system zsh"
run %{ chsh -s /bin/zsh }
end
end
end
def want_to_install? (section)
if ENV["ASK"]=="true"
puts "Would you like to install configuration files for: #{section}? [y]es, [n]o"
STDIN.gets.chomp == 'y'
else
true
end
end
def install_files(files, method = :symlink)
files.each do |f|
file = f.split('/').last
source = "#{ENV["PWD"]}/#{f}"
target = "#{ENV["HOME"]}/.#{file}"
puts "======================#{file}=============================="
puts "Source: #{source}"
puts "Target: #{target}"
if File.exists?(target) && (!File.symlink?(target) || (File.symlink?(target) && File.readlink(target) != source))
puts "[Overwriting] #{target}...leaving original at #{target}.backup..."
run %{ mv "$HOME/.#{file}" "$HOME/.#{file}.backup" }
end
if method == :symlink
run %{ ln -nfs "#{source}" "#{target}" }
else
run %{ cp -f "#{source}" "#{target}" }
end
puts "=========================================================="
puts
end
end
def success_msg(action)
puts ""
puts " _ _ _ "
puts " | | | | | | "
puts " | |___| |_____ __| | ____ "
puts " |_____ (____ |/ _ |/ ___) "
puts " _____| / ___ ( (_| | | "
puts " (_______\_____|\____|_| "
puts ""
puts "YADR has been #{action}. Please restart your terminal and vim."
end