-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
118 lines (104 loc) · 3.32 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
require 'tmpdir'
################################################################################
# Constants and helpers
################################################################################
LOCAL_BIN_PATH = "#{ENV['HOME']}/.local/bin".freeze
PREFERRED_SHELL = 'zsh'.freeze
INSTALL_TASKS = %w[packages links shell].freeze
UBUNTU = `which lsb_release` && $CHILD_STATUS.to_i.zero?
RECENT_UBUNTU = UBUNTU && `lsb_release -rs`.chomp.to_i >= 18
CODING_FONT = RECENT_UBUNTU ? 'fonts-firacode' : ''
PACKAGES = %W[
#{CODING_FONT} #{PREFERRED_SHELL} autojump build-essential exuberant-ctags
libpython-dev libpython2.7-dev libpython3-dev molly-guard silversearcher-ag
ssh tmux
].join(' ')
##
# Each key corresponds to a file in the +files+ directory, and each value is the
# destination of the symlink.
#
MAPPINGS = {
'agignore' => '~/.agignore',
'bin' => '~/bin',
'compton.conf' => '~/.config/compton.conf',
'dircolors' => '~/.dircolors',
'gitconfig' => '~/.gitconfig',
'gitignore_global' => '~/.gitignore_global',
'nvim' => %w[~/.config/nvim ~/.vim],
'nvim/init.vim' => '~/.vimrc',
'postman.desktop' => '~/.local/share/applications/postman.desktop',
'tmux.conf' => '~/.tmux.conf',
'zim/style.conf' => '~/.config/zim/style.conf',
'zsh' => '~/.zsh',
'zsh/zshrc.zsh' => '~/.zshrc'
}.freeze
##
# Symlinks +src+ file or directory to +target+
#
def link_file(source, target)
source = "#{pwd}/files/#{source}"
target = File.expand_path target
rm_rf target
FileUtils.mkdir_p File.dirname(target)
ln_s source, target
end
################################################################################
# Tasks
################################################################################
task default: :update_and_install
desc "Create local bin directory at #{LOCAL_BIN_PATH}"
task :local_bin do
mkdir_p LOCAL_BIN_PATH
end
desc "Run these tasks in order: #{INSTALL_TASKS.join(' ')}"
task install: INSTALL_TASKS
desc 'Symlink config files to appropriate locations'
task :links do
MAPPINGS.each do |source, target|
if target.is_a? Array
target.each do |targetlet|
link_file source, targetlet
end
else
link_file source, target
end
end
end
desc 'Install packages'
task :packages do
sh <<-SH
if (which dpkg &>/dev/null && which apt-get &>/dev/null); then
dpkg --status #{PACKAGES} >/dev/null && exit 0
sudo apt-get update
sudo apt-get install --yes --quiet #{PACKAGES}
fi
SH
end
desc 'Set preferred shell'
task shell: :packages do
sh <<-SH
grep $USER.\*$(which #{PREFERRED_SHELL}) /etc/passwd >/dev/null ||
sudo chsh -s $(which #{PREFERRED_SHELL}) $USER
SH
end
# Because this may update the Rakefile, we depend on the update task, then we
# actually exec a call to rake in the shell.
desc '[Default] Update repository and run install task'
task update_and_install: :update do
exec 'rake install' if $CHILD_STATUS.to_i.zero?
end
desc 'Update repository'
task :update do
sh <<-SH
git fetch --prune
git pull --rebase --recurse-submodules origin master
SH
end
desc 'Update all plugins to latest origin/master/HEAD'
task :update_plugins do
sh <<-SH
git submodule foreach '
git checkout master
git pull --force origin master'
SH
end