-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRakefile
More file actions
142 lines (118 loc) · 4.03 KB
/
Copy pathRakefile
File metadata and controls
142 lines (118 loc) · 4.03 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# from http://github.com/ryanb/dotfiles/tree/master
#
# Copyright (c) 2008 Ryan Bates
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'rake'
require 'fileutils'
task :default => :install
desc "install the dot files into user's home directory"
task :install do
replace_all = false
Dir['*'].each do |file|
next if %w[Rakefile README LICENSE].include? file
next if FileTest.symlink?(File.join(ENV['HOME'], ".#{file}"))
# handle .local versions; only copy if DNE
if file.match('\.local$')
if !File.exist?(File.join(ENV['HOME'], ".#{file}"))
FileUtils.copy(file, File.join(ENV['HOME'], ".#{file}"))
end
next
end
# handle normal dotfiles
if File.exist?(File.join(ENV['HOME'], ".#{file}"))
if replace_all
replace_file(file)
else
print "overwrite ~/.#{file}? [ynaq] "
case $stdin.gets.chomp
when 'a'
replace_all = true
replace_file(file)
when 'y'
replace_file(file)
when 'q'
exit
else
puts "skipping ~/.#{file}"
end
end
else
link_file(file)
end
end
Rake::Task["vimupdate"].execute
Rake::Task["mac"].execute
end
desc "Install /etc/pam.d/sudo_local from repo template (enables Touch ID for sudo)"
task :sudo_local do
template = File.join(Dir.pwd, "sudo_local.pam")
unless File.exist?(template)
puts "sudo_local template not found at #{template}, skipping."
next
end
puts "Installing /etc/pam.d/sudo_local from #{template} (requires sudo)..."
sh <<~SH
set -e
# Backup existing sudo_local if present
if [ -f /etc/pam.d/sudo_local ]; then
echo "Backing up existing /etc/pam.d/sudo_local to /etc/pam.d/sudo_local.bak"
sudo cp /etc/pam.d/sudo_local /etc/pam.d/sudo_local.bak
fi
# Install our template with proper owner/perm
sudo install -m 444 -o root -g wheel "#{template}" /etc/pam.d/sudo_local
echo "Touch ID sudo config installed at /etc/pam.d/sudo_local."
SH
end
desc "Run macOS-specific things"
task :mac do
unless RUBY_PLATFORM.include?("darwin")
puts "Skipping :mac task – not on macOS (RUBY_PLATFORM=#{RUBY_PLATFORM})"
next
end
Rake::Task["mac_configs"].execute
Rake::Task["sudo_local"].execute
end
desc "Run macOS-specific configuration scripts"
task :mac_configs do
script = File.join(Dir.pwd, "mac.configs")
unless File.exist?(script)
puts "mac.configs not found, skipping macOS config."
next
end
puts "Running macOS config script..."
sh "bash #{script}"
end
desc "VIM/Vundle"
task :vimupdate do
puts "Ensuring vundle is installed..."
sh "[ -d ~/.vim/bundle/Vundle.vim ] || git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim"
puts "Installing/Updating vundles..."
sh "vim '+set nomore' +PluginInstall! +PluginClean +qa"
puts "Done!"
end
def replace_file(file)
system %Q{rm "$HOME/.#{file}"}
link_file(file)
end
def link_file(file)
puts "linking ~/.#{file}"
system %Q{ln -s "$PWD/#{file}" "$HOME/.#{file}"}
end