forked from cybertk/ckdots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
115 lines (91 loc) · 2.1 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
task default: [:uninstall, :install]
class Installer
@@BASHRC = <<END
#!/bin/sh
#
# NOTE: Do **NOT** edit this file.
# This file is automated generated by cybertk/profile.
# Edit profile/bashrc instead.
CK_BASHRC_DIR="#{File.dirname(__FILE__)}"
# Source bashrc provided by cybertk/profile
. ${CK_BASHRC_DIR}/dots/bashrc
END
def initialize(*args)
@dot_items=[
'vim',
'vimrc',
'gitconfig',
'gitignore',
]
@profiles=[
'.bashrc',
'.bash_profile',
]
end
def install()
# Copy first to make world safe
_backup()
_remove()
_install()
end
def uninstall()
_remove()
# restore_backup()
end
def _install()
@dot_items.each do |item|
puts "Installing .#{item}"
FileUtils.ln_sf File.absolute_path(File.join 'dots', item), File.join(Dir.home, ".#{item}")
end
@profiles.each do |item|
puts "Installing #{item}"
File.open(File.join(Dir.home, item), 'w') do |f|
f.write(@@BASHRC)
end
end
end
def _backup_file(src, dest)
if File.exist? src
puts "Backuping #{src}"
FileUtils.cp_r src, dest
else
puts "Skipping backup #{src}"
end
end
def _backup()
backup_path = File.expand_path "~/ck-dots-backup-#{Time.now.strftime("%Y%m%d-%H%M")}"
puts "Backup to #{backup_path}"
FileUtils.mkdir_p backup_path
# Backup dots
@dot_items.each do |item|
_backup_file File.join(Dir.home, ".#{item}"), backup_path
end
# Backup bashrc and bash_profile
@profiles.each do |item|
_backup_file File.join(Dir.home, item), backup_path
end
end
def _remove()
# Remove unused
@dot_items.each do |item|
item=File.join(Dir.home, ".#{item}")
puts "Removing #{item}"
FileUtils.rm_rf item
end
end
end
task :install do
Installer.new.install()
end
task :uninstall do
Installer.new.uninstall()
end
task :lint do
shs = Dir.glob("**/*.sh")
shs << "profile"
shs << "bin/largest"
sh "shellcheck #{shs.join(' ')}"
end
task :test do
sh "ruby -Ilib:test tests/test_installer.rb"
end