This repository has been archived by the owner on Aug 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdev_env.rb
213 lines (172 loc) · 4.67 KB
/
dev_env.rb
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
dep "dev-env" do
requires "zsh as shell",
"code-folder",
"dotfiles",
"npm-libs",
"default-node-env-4",
"default-ruby-env-2.2.0",
"mongodb-service-installed",
"rust",
"dev colour picker",
"secrets",
"klipbookrc",
"proselint.pip",
"aws-vault"
end
#
# Env
#
dep "zsh as shell", :username do
username.default!(shell("whoami"))
requires "zsh.managed", "zshenv fixed"
met? { shell("sudo su - '#{username}' -c 'echo $SHELL'") == which("zsh") }
meet { sudo("chsh -s '#{which('zsh')}' #{username}") }
end
dep "zshenv fixed" do
on :osx do
met? { !"/etc/zshenv".p.exists? && "/etc/zprofile".p.exists? }
meet {
shell "sudo mv /etc/zshenv /etc/zprofile"
}
end
end
dep "code-folder" do
requires "project.dir",
"scripts directory is linked",
"explorations.dir"
end
dep "code.dir" do
path "~/code"
end
dep "project.dir" do
requires "code.dir"
path "~/code/projects"
end
dep "scripts directory is linked" do
requires "code.dir"
met? { "~/code/scripts".p.readlink == "/Users/#{shell("whoami")}/Dropbox/Code/scripts" }
meet { shell "ln -s ~/Dropbox/Code/scripts ~/code/scripts" }
end
dep "explorations.dir" do
requires "code.dir"
path "~/code/explorations"
end
dep "dotfiles.repo" do
source "https://github.com/grassdog/dotfiles"
path "~/.dotfiles"
end
# TODO Migrate these rake tasks into deps
dep "dotfiles" do
requires "dotfiles.repo"
met? { "~/.zshrc".p.readlink == "/Users/#{shell("whoami")}/.dotfiles/zshrc" }
meet {
cd "~/.dotfiles" do
shell "rake bootstrap"
end
}
end
dep "pow" do
met? {
"~/Library/Application Support/Pow/Current".p.exists?
}
meet {
shell "curl get.pow.cx | sh"
}
end
dep "rust" do
met? { shell? "rustc" }
meet {
log_shell "Installing Rust. This takes a while.", "curl -sSf https://static.rust-lang.org/rustup.sh | sh"
}
end
dep "aws-vault", :version do
version.default!("3.2.0")
met? { in_path? "aws-vault" }
meet {
path = "/usr/local/bin/aws-vault"
shell "wget -q -O #{path} https://github.com/99designs/aws-vault/releases/download/#{version}/aws-vault-Darwin-x86_64 && chmod 755 #{path}"
}
end
dep "mongodb-service-installed" do
requires "mongodb-launchagents-linked",
"mongodb-launchctl-loaded"
end
dep "mongodb-launchagents-linked" do
requires "mongodb.managed"
met? { "~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist".p.exist? }
meet {
shell "ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents"
}
end
dep "mongodb-launchctl-loaded" do
met? {
!shell("launchctl list").split("\n").grep(/homebrew\.mxcl\.mongodb/).empty?
}
meet {
shell "launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist"
}
end
# TODO Add dep to create ssh dir and chmod 700
# TODO Add dep to create ssh config
dep 'ssh keys generated', :ssh_dir, :ssh_password do
ssh_dir.ask("Where do you keep your ssh keys").default!('~/.ssh')
ssh_password.ask("Passphase to encrypt your SSH key")
met? {
(ssh_dir / 'id_rsa.pub').exists? && (ssh_dir / 'id_rsa').exists?
}
meet {
shell "ssh-keygen -t rsa -N #{ ssh_password } -f #{ ssh_dir }/id_rsa"
}
after {
shell "/usr/bin/ssh-add -K"
}
end
dep "github has my public key", :github_username, :github_password do
requires "ssh keys generated"
def github_api
"https://api.github.com"
end
def public_key
shell("cat ~/.ssh/id_rsa.pub")
end
def hostname
shell("hostname")
end
met? {
raw_shell("ssh -T [email protected] 2>&1").stdout["successfully authenticated"]
}
meet {
github_username.ask("What is your github username")
github_password.ask("What is your github password")
auth = "#{github_username}:#{github_password}"
args = "{\"title\": \"#{hostname}\", \"key\": \"#{public_key}\"}"
shell "curl -u '#{auth}' -d '#{args}' #{github_api}/user/keys"
}
end
dep "read_only file", :file, :contents do
met? {
file.p.exist? && shell("stat #{file}")["-rw-------"]
}
meet {
shell "echo #{contents} > #{file}"
shell "chmod 600 #{file}"
}
end
# Colour pickers
dep "colorpickers.dir" do
path "~/Library/ColorPickers"
end
dep "dev colour picker", template: "file" do
requires "colorpickers.dir"
source "http://download.panic.com/picker/developercolorpicker.zip"
name "DeveloperColorPicker.colorPicker"
target "~/Library/ColorPickers/DeveloperColorPicker.colorPicker"
end
# Insert \\n at prompt to inject newlines
dep "secrets" do
requires "read_only file".with(file: "~/.secrets")
end
dep "klipbookrc" do
requires "read_only file".with(file: "~/.klipbookrc")
end
dep 'proselint.pip'