-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
109 lines (109 loc) · 3.2 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
require 'rake'
task :install do
main
end
def main
sudo = sudo
if File.exists?("#{ENV["HOME"]}/.vim/vimrc")==true
puts "\nYou already have an existing configuration.\nYou'll need to remove ~/.vim if you want to install.\n\n"
usersymlink(2)
elsif File.exists?("/etc/vim/vimrc")==true
puts "\nYou already have an existing configuration.\nYou'll need to remove /etc/vim if you want to install.\n\n"
usersymlink(1)
else
puts "\nChecking for Git."
checkgit = system "/usr/bin/env git --version | grep version"
if checkgit == true
sudo = sudoornotsudo
if sudo == 1
singleuser
usersymlink(2)
elsif sudo == 2
globalusers
usersymlink(1)
return
elsif sudo == 3
singleuser
usersymlink(2)
else
return
end
else
puts "\n\nGit is not installed!"
puts "Install git and try again.\n\n"
return
end
end
end
def sudoornotsudo
if (`id -urn`.chomp.casecmp("root")||`who am i`.chomp.casecmp("root"))==0
puts "\n\nYou have run this script with root permissions."
puts "If you only wish to have it installed for your current (non-root) user,\nre-run the script under that user without SUDO.\n\n"
puts "That said, would you like to install this VIM configuration for:\n\n"
puts "(r)oot or (g)lobally.\n\n"
response = $stdin.gets
puts ""
if response.chomp.casecmp("R")==0
return 1
elsif response.chomp.casecmp("G")==0
#git clone global
return 2
else
puts "Invalid input. Exiting Script.\n\n"
return 0
end
else
return 3
end
end
def singleuser
puts "Cloning VIM configuration..."
system "/usr/bin/env git clone git://github.com/brandondean/Vim.git ~/.vim"
system "(cd ~/.vim && git submodule init && git submodule update)"
end
def globalusers
if File.exist?("#{ENV["HOME"]}/.vim-tmp/")==true
puts "/etc/vim/ folder already exists. Recreating..."
`rm -rf /etc/vim/`
`mkdir /etc/vim/`
else
`mkdir /etc/vim/`
puts "Created /etc/vim/ folder."
end
puts "Cloning VIM configuration..."
system "/usr/bin/env git clone git://github.com/brandondean/Vim.git /etc/vim/"
system "(cd /etc/vim && git submodule init && git submodule update)"
return
end
def usersymlink(section=0)
if section==1
if File.exist?("/etc/vimrc")==true
puts "/etc/vimrc file already exists.\nPlease remove this file, and try again.\n\n"
else
`ln -s "/etc/vim/vimrc" "/etc/vimrc"`
puts "\n\nEstablished symbolic link of /etc/vimrc\n\n"
end
return
elsif section==2
files = ['vimrc']
# Create dotfile symlinks.
files.each do |file|
target = "#{ENV["HOME"]}/.#{file}"
if File.exist?(target)==true
puts "\n#{file} already exists as #{target}. Please remove this file, and try again."
else
`ln -s "#{ENV["HOME"]}/.vim/#{file}" "#{target}"`
puts "Established symbolic link of .vimrc\n\n"
end
if File.exist?("#{ENV["HOME"]}/.vim-tmp/")==true
puts "Temporary directory already exists.\n\n"
else
`mkdir "#{ENV["HOME"]}/.vim-tmp/"`
puts "Created temp directory for VIM\n\n."
end
end
return
else
return
end
end