-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
75 lines (63 loc) · 2.81 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
desc "link all files their correct locations"
task :link do
puts " == AutoLinking all files with _* prefix to their ~/.* location. =="
Dir.glob("_*") do |filename|
newFilename = filename.gsub(/^_/, "~/.")
puts " * Ensuring #{filename} linked to #{newFilename}"
s_link(filename, newFilename)
end
puts " -- Done AutoLinking."
puts " == AutoLinking all XDG_CONFIG/ with their $XDG_CONFIG_HOME/ location. =="
Dir.glob("XDG_CONFIG/*") do |filename|
xdgDir = ENV["XDG_CONFIG_HOME"] != nil ? ENV["XDG_CONFIG_HOME"] : "~/.config/"
unless xdgDir[-1] == "/"
xdgDir = xdgDir+"/"
end
unless File.directory?(xdgDir)
FileUtils.mkdir_p(xdgDir)
end
newFilename = xdgDir+filename.gsub(/XDG_CONFIG\//, "")
puts " * Ensuring #{filename} linked to #{newFilename}"
s_link(filename, newFilename)
end
puts " -- Done AutoLinking XDG_CONFIG."
puts " == Handling manual links... =="
# Link in my own ZSH theme.
s_link("joshproehl.zsh-theme", "~/.oh-my-zsh/custom/joshproehl.zsh-theme")
puts " -- Done Linking."
end
# Create a symbolic link from the source to the target.
def s_link(source_path, target_path)
target_file = File.expand_path(target_path)
# If the target file exists we don't really want to destroy it...
if File.exists?(target_file) and not File.symlink?(target_file)
puts " ! Stashing your previous #{target_path} as #{target_path}.pre-mdf-bootstrap"
mv(target_file, File.expand_path("#{target_path}.pre-mdf-bootstrap"))
end
if File.symlink?(target_file) and File.readlink(target_file).to_s != File.expand_path(source_path).to_s
puts " ! Existing symlink appears to point to incorrect file, moving it to #{target_file}.pre-mdf-bootstrap"
# Make a new link with the .old extension, pointing to the old target
ln_s(File.readlink(target_file), File.expand_path("#{target_path}.pre-mdf-bootstrap"))
# Now we can get rid of the original target file to make room for the new link
rm(target_file)
end
# At this point either the target file is the symlink we want,
# or something weird happened and we don't want to replace it.
unless File.exists?(target_file)
# Counts on the fact that ln_s outputs "puts" the command for the user to see.
ln_s(File.expand_path(source_path), target_file)
end
end
desc "Init and update all git submodules"
task :submodule_update do
puts " == Setting up submodules =="
`git submodule update --init --recursive`
puts " -- Done with (recursive) submodule update"
end
task :submodule_cleanup do
puts " == Cleaning up submodules =="
`git submodule foreach --recursive git reset --hard HEAD && git clean -fxd`
puts " -- Done cleaning submodules"
end
desc "Run this to perform all necessary tasks to setting up a completely new instance."
task :bootstrap => [ :submodule_update, :link ]