forked from mroth/bootslap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
121 lines (106 loc) · 3.92 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
require 'rake'
verbose false
#########################################
# Global vars and setup
#########################################
$home = ENV['HOME']
$installers = "#{$home}/.dothome/installers"
if File.expand_path(File.dirname( __FILE__ )) != "#{$home}/.dothome"
abort "For this to work, we should be located in ~/.dothome"
end
#########################################
# Global methods
#########################################
# A common pattern for my scripts. Check if a specific directory exists. If not,
# clone it from a git repository. But first, recursively create any parent directories
# for the path.
def subdir_clone( directory, name, git_repo )
if not File.directory? "#{directory}/#{name}"
FileUtils.mkdir_p directory
sh "git clone #{git_repo} '#{directory}/#{name}'"
end
end
#########################################
# Default task
#########################################
task :default => [ 'dotfiles:install' ]
task :bootstrap => [
'dotfiles:install',
'homebrew:install',
'git:install',
'python:install',
'ruby:install',
'node:install',
'zsh:install',
'vim:install'
#'textmate:install', #should be no longer needed with textmate2.. or at least needs to be updated
#'solarized:install', #TODO: janus handles this now? not for apple color picker tho
#'bitly:install' #TODO: update to mermanify script before reactivating
]
task :update => [
'dotfiles:install',
'homebrew:brew_upgrade',
'ruby:rvm_update',
'node:npm_update',
'vim:janus_update',
'git:update_scmbreeze'
]
#########################################
# Main dotfiles installer
#########################################
namespace :dotfiles do
desc "install dotfiles"
task :install do
FileList["#{$home}/.dothome/dotfiles/*"].each do |file|
base = File.basename(file)
target = File.join($home, ".#{base}")
src = ".dothome/dotfiles/#{base}"
next if %w[README.md Rakefile].include? base
next if not File.file? file
if File.symlink? target and (File.readlink(target) == src)
puts "*** ~/.#{base} already symlinked properly" #lets not spam on this now since this will be a prereq for a lot of things
elsif File.symlink? target
#symlinked but to the wrong place (e.g. I moved directory structure for bootstrapper)
#just resymlink to repair
puts "+++ symlink moved, re-linking ~/.#{base}"
FileUtils.ln_s(src, target, :force => true)
elsif File.exist? target
puts "!!! backing up existing ~/.#{base} to ~/.#{base}.old "
FileUtils.mv(target,"#{target}.old")
puts "+++ linking ~/.#{base}"
File.symlink(src, target)
else
puts "+++ linking ~/.#{base}"
File.symlink(src, target)
end
end
end
desc "uninstall dotfiles, restoring whatever existed before"
task :uninstall do
abort "...not implemented yet, sorry!"
#TODO: remove symlinks
#TODO: restore .old files if they exist
end
end
# desc "setup dirs"
# task :dirs do |t|
# %w[tmp src].each do |d|
# if not File.directory? "#{$home}/#{d}"
# puts "dir ~/#{d}"
# FileUtils.mkpath "#{$home}/#{d}"
# end
# end
# end
# desc "setup mac stuff"
# task :mac do |t|
# if RUBY_PLATFORM.include?("darwin")
#
# # hide unixy stuff from finder
# sh "chflags hidden ~/var ~/tmp ~/bin"
#
# # graphite, won't take effect until apps are restarted
# # in theory you could send a NSControlTintDidChangeNotification but that's too much work
# sh "defaults write -g AppleAquaColorVariant -int 6"
#
# end
# end