-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
102 lines (84 loc) · 2.5 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
require 'rake'
# This is a good idea that holman@ had
#
# https://raw.github.com/holman/dotfiles/master/Rakefile
#
# I changed a few things, tho. I checked in his and then added my changes. For posterity.
#
task :update => [:pull, :brewup, :link, :install] do
# nop
end
task :brewup do
system "brew cleanup"
system "brew update"
system "brew upgrade"
system "brew autoremove"
system "brew cleanup"
end
task :pull do
system "git pull"
end
desc "Calls any install.sh scripts"
task :install do
scripts = Dir.glob('./*/install.sh').sort
scripts.each do |script|
puts script
system script
end
end
desc "Hook our dotfiles into system-standard positions."
task :link do
linkables = Dir.glob('*/**{.symlink}')
skip_all = false
overwrite_all = false
backup_all = false
linkables.each do |linkable|
overwrite = false
backup = false
file = linkable.split('/').last.split('.symlink').last
target = "#{ENV["HOME"]}/.#{file}"
if File.exists?(target) || File.symlink?(target)
link_dest = "#{`pwd`.chomp}/#{linkable}" # probably rubyish way to do this
already_done = File.symlink?(target) and File.readlink(target) == link_dest
if already_done
next
end
unless skip_all || overwrite_all || backup_all || already_done
puts "File already exists: #{target}"
puts ""
puts `ls -l "#{target}"`
puts ""
puts "what do you want to do?"
puts "[s]kip, [S]kip all, [o]verwrite, [O]verwrite all, [b]ackup, [B]ackup all, [q]uit"
puts ""
case STDIN.gets.chomp
when 'o' then overwrite = true
when 'b' then backup = true
when 'O' then overwrite_all = true
when 'B' then backup_all = true
when 'S' then skip_all = true
when /q|Q/ then exit 0
when 's' then next
end
end
FileUtils.rm_rf(target) if overwrite || overwrite_all
`mv "$HOME/.#{file}" "$HOME/.#{file}.backup"` if backup || backup_all
end
`ln -s "$PWD/#{linkable}" "#{target}"`
end
end
task :uninstall do
Dir.glob('**/*.symlink').each do |linkable|
file = linkable.split('/').last.split('.symlink').last
target = "#{ENV["HOME"]}/.#{file}"
# Remove all symlinks created during installation
if File.symlink?(target)
FileUtils.rm(target)
end
# Replace any backups made during installation
if File.exists?("#{ENV["HOME"]}/.#{file}.backup")
`mv "$HOME/.#{file}.backup" "$HOME/.#{file}"`
end
end
end
task :default => 'update'