-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
193 lines (153 loc) · 4.55 KB
/
Copy pathRakefile
File metadata and controls
193 lines (153 loc) · 4.55 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
require 'mkmf'
SRC_DIR = File.dirname(File.expand_path(__FILE__))
module OS
def self.mac?
(/darwin/ =~ RUBY_PLATFORM) != nil
end
def self.linux?
not self.mac?
end
def self.archlinux?
File.exist? '/etc/arch-release'
end
end
# 実行ファイルやファイルが存在するならtrue
def exist?(path)
return true if find_executable path
return true if File.exist?(File.expand_path path)
false
end
class Array
def without_comments(sep = '#')
self
.map(&:chomp)
.map { |line| line.split(sep, 2).fetch(0, '') }
.map(&:strip)
.reject { |line| line.empty? }
end
end
desc 'Setup all'
task setup: [:'mac:setup', :'linux:setup', :'anyenv:setup', :'rust:install'] do
end
namespace :rust do
desc 'Install rustup'
task :install do
next if exist? '~/.cargo'
sh 'curl https://sh.rustup.rs -sSf | sh'
end
end
namespace :anyenv do
desc 'Setup anyenv and envs, envs-plugins'
task :setup do
next if exist? "~/.anyenv"
sh 'git clone https://github.com/riywo/anyenv ~/.anyenv'
sh 'mkdir -p ~/.anyenv/envs'
sh 'mkdir -p $(anyenv root)/plugins'
sh 'git clone https://github.com/znz/anyenv-update.git $(anyenv root)/plugins/anyenv-update'
sh 'anyenv install -s rbenv'
sh 'anyenv install -s pyenv'
sh 'anyenv install -s ndenv'
sh "git clone https://github.com/pyenv/pyenv-virtualenv.git $(anyenv root)/envs/pyenv/plugins/pyenv-virtualenv"
end
desc 'Install ruby versions by rbenv'
task rbenv: [:setup] do
sh 'rbenv install -s 2.5.1'
sh 'rbenv global 2.5.1'
sh 'gem install bundler'
end
desc 'Install python versions by pyenv'
task pyenv: [:setup] do
sh 'pyenv install -s 2.7.15'
sh 'pyenv virtualenv 2.7.15 neovim2'
sh 'pyenv shell neovim2; pip install neovim'
sh 'pyenv install -s 3.6.5'
sh 'pyenv virtualenv 3.6.5 neovim3'
sh 'pyenv shell neovim3; pip install neovim'
sh 'pyenv global 3.6.5'
end
desc 'Install nodejs versions by ndenv'
task ndenv: [:setup] do
sh 'ndenv install -s v10.1.0'
sh 'ndenv global v10.1.0'
end
desc 'Install language versions and packages'
task packages: [:rbenv, :pyenv, :ndenv]
end
namespace :mac do
desc 'Mac full setup'
task setup: [:'brew:setup', :'mas:setup']
namespace :brew do
desc 'Install brew'
task :install do
next unless OS.mac?
next if exist? 'brew'
sh '/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"'
end
desc 'Tap brew packages'
task tap: [:install, 'Brewrepos'] do
next unless OS.mac?
repos = File.readlines('Brewrepos').without_comments
repos.each do |repo|
sh "brew tap #{repo}"
end
end
desc 'Install brew packages'
task packages: [:tap, 'Brewfile', 'Caskfile'] do
next unless OS.mac?
installed_app = `brew list`.split("\n").map { |app| app.split(' ')[0] }
packages = File.readlines('Brewfile').without_comments
packages = packages - installed_app
packages.each do |package|
sh "brew install #{package}"
end
installed_app = `brew cask list`.split("\n").map { |app| app.split(' ')[0] }
packages = File.readlines('Caskfile').without_comments
packages = packages - installed_app
packages.each do |package|
sh "brew cask install #{package}"
end
end
desc 'Brew full setup'
task setup: [:install, :packages]
end
namespace :mas do
desc 'Install mas(=Mac AppStore) command line tool'
task install: [:'mac:brew:install'] do
next unless OS.mac?
next if exist? 'mas'
sh "brew install mas"
end
desc 'Install mas(=Mac AppStore) packages'
task packages: [:install, 'Masfile'] do
next unless OS.mac?
# MasfileからアプリのIDを抽出
apps = File.readlines('Masfile').without_comments
# インストール済みのアプリを抽出し、カットする
installed_app = `mas list`.split("\n").map { |app| app.split(' ')[0] }
install_app = apps - installed_app
install_app.map do |app|
sh "mas install #{app}"
end
end
desc 'MAS(=Mac AppStore) full setup'
task setup: [:install, :packages]
end
end
namespace :linux do
desc 'Linux full setup'
task setup: [:'yaourt:setup']
namespace :yaourt do
desc 'Install yaourt packages'
task packages: ['Yaourtfile'] do
next unless OS.archlinux?
installed_app = `yaourt -Qq`.split("\n").map { |app| app.split(' ')[0] }
packages = File.readlines('Yaourtfile').without_comments
packages = packages - installed_app
packages.each do |package|
sh "yaourt -S --noconfirm #{package}"
end
end
desc 'Yaourt full setup'
task setup: [:packages]
end
end