-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
67 lines (61 loc) · 1.71 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
require 'rake'
require 'erb'
require 'socket'
HOSTS_DIR = "hosts"
desc "install the dot files into user's home directory"
task :install, :host do |t, args|
args.with_defaults(:host => Socket.gethostbyname(Socket.gethostname).first)
excludes = %w[Rakefile README.rdoc LICENSE install]
host_dir = File.join(Dir.pwd, HOSTS_DIR, args[:host])
puts "Installing generic config files"
process_dir(Dir.pwd, excludes + [HOSTS_DIR])
if File.exist?(host_dir)
puts "Installing host config files for #{args[:host]}"
process_dir(host_dir, excludes)
end
update_submodules()
end
def process_dir(dir, excludes)
replace_all = false
Dir[File.join(dir, "*")].each do |file|
file_name = File.basename(file)
source = File.expand_path(file)
target = File.join(ENV['HOME'], ".#{file_name}")
next if excludes.include? file_name
if File.exist?(target)
if File.identical?(source, target)
puts "\t- identical ~/.#{file_name}"
elsif replace_all
replace_file(target, source)
else
print "overwrite ~/.#{file}? [ynaq] "
case $stdin.gets.chomp
when 'a'
replace_all = true
replace_file(target, source)
when 'y'
replace_file(target, source)
when 'q'
exit
else
puts "skipping ~/.#{file}"
end
end
else
link_file(source, target)
end
end
end
def update_submodules()
puts "Updating git submodules"
`git submodule update --init`
# add any submodules here if you ever get any
end
def replace_file(target, source)
system %Q{rm -rf target}
link_file(source, target)
end
def link_file(source, target)
puts "\t* linking #{target}"
File.symlink(source, target)
end