forked from bbatsche/LAMP-Setup-Script
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlamp-setup.command
More file actions
executable file
·365 lines (276 loc) · 11.8 KB
/
lamp-setup.command
File metadata and controls
executable file
·365 lines (276 loc) · 11.8 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
#!/usr/bin/env ruby
module Support
extend self
@@repo_path = "~/vagrant-lamp"
@@repo_url = "https://github.com/gocodeup/Codeup-Vagrant-Setup.git"
@@steps = ["start", "xcode", "homebrew", "vagrant_lamp", "git", "sublime", "final"]
def steps
@@steps
end
def repo_path
@@repo_path
end
def repo_url
@@repo_url
end
def git_download(repo_url, local_path)
`git clone #{repo_url} #{local_path} 2>&1`
if IO.readlines("#{local_path}/.git/info/exclude").grep(/^\*$/).empty?
`echo '*' >> #{local_path}/.git/info/exclude`
end
end
def subl_pkg_install(package_path)
`curl -L --silent -o \"#{package_path}/Package Control.sublime-package\" https://sublime.wbond.net/Package%20Control.sublime-package`
end
def brew_install(package, *args)
versions = `brew list #{package} --versions`
options = args.last.is_a?(Hash) ? args.pop : {}
if versions.empty?
`brew install #{package} #{args.join ' '}`
else
`brew upgrade #{package} #{args.join ' '}`
end
end
def pip_install(package, version = nil)
pip_info = `pip show #{package}`
if version
if $?.success?
return if pip_info.match /^Version: #{version}$/
end
system "sudo -H pip install --upgrade '#{package}~=#{version}'"
else
system "sudo -H pip install --upgrade '#{package}'"
end
end
def brew_cask_install(package, *options)
output = `brew cask info #{package}`
return unless output.include? 'Not installed'
system "brew cask install #{package} #{options.join ' '}"
end
def app_path(name)
path = "/Applications/#{name}.app"
["~#{path}", path].each do |full_path|
return full_path if File.directory? full_path
end
return nil
end
def subl_path
["/Applications", "~/Applications"].each do |app_path|
`find #{app_path} -name subl 2>&1`.each_line do |subl_path|
subl_path.chomp!
return subl_path if `\"#{subl_path}\" --version 2>&1`.start_with? 'Sublime Text'
end
end
return nil
end
def app?(name)
!self.app_path(name).nil?
end
def xcode?
`xcode-select --print-path 2>&1`
$?.success?
end
end
module Steps
extend self
def heading(description)
description = "-- #{description} "
description = description.ljust(80, '-')
puts
puts "\e[32m#{description}\e[0m"
end
def block(description)
line = ''
description.split(/ /).each do |word|
if line.length + word.length > 76
puts " #{line}"
line = ''
end
line += "#{word} "
end
puts " #{line}"
puts "\n Press 'Return' to continue."
gets
end
def do_step(name)
case name
when "start"
self.heading "Welcome!"
when "xcode"
self.heading "Setting up Xcode Commandline Tools"
when "homebrew"
self.heading "Setting up Homebrew"
when "vagrant"
self.heading "Setting up Vagrant Box"
when "vagrant_lamp"
self.heading "Checking Out Vagrant LAMP Repository"
when "git"
self.heading "Configuring SSH Keys for Git"
when "final"
self.heading "Final Configuration Steps"
when "sublime"
self.heading "Setting up Sublime Text"
else
raise "Unknown step #{name}"
end
self.send name
end
def start
description = "This script will go through and make sure you have all the tools you need to get started as a Codeup student. "
description+= "At several points through this process, you may be asked for a password; this is normal. "
description+= "Enter the password you use to log in to your computer or otherwise install software normally."
self.block description
end
def xcode
if Support.xcode?
self.block "Xcode commandline tool are already installed, moving on."
else
description = "We need to install some commandline tools for Xcode. When you press 'Return', a dialog will pop up "
description+= "with several options. Click the 'Install' button and wait. Once the process completes, come back here "
description+= "and we will proceed with the next step."
self.block description
`xcode-select --install 2>&1`
while !Support.xcode?
sleep 1
end
end
end
def homebrew
if system("which brew > /dev/null")
description = "Homebrew is already installed. We will check to make sure our other utilities--including Ansible, Vagrant, "
description+= "and VirutalBox--are also set up."
self.block description
`brew update 2>&1`
else
description = "We will now install a tool called 'Homebrew'. This is a package manager we will use to install several "
description+= "other utilities we will be using in the course, including Ansible, Vagrant, and VirtualBox. "
description+= "You will probably be asked for your password a couple of times through this process; "
description+= "when you type it in, your password will not be displayed on the screen. This is normal."
self.block description
system 'ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"'
end
# Install brew cask
`brew tap caskroom/cask 2>&1`
# Install Virtual Box
Support.brew_cask_install "virtualbox" unless Support.app? "VirtualBox"
# Install Vagrant
Support.brew_cask_install "vagrant"
# Install Ansible
Support.brew_install "ansible"
end
def vagrant_lamp
full_repo_path = File.expand_path Support.repo_path
if File.directory?(full_repo_path)
self.block "Looks like our project directory has already been checked out. On to the next step."
else
description = "We will now use Git to download our project directory. This project will set up your Vagrant "
description+= "environment. All of your development in the class will be done inside this Vagrant environment."
self.block description
Support.git_download(Support.repo_url, full_repo_path)
end
description = "We're going to start up the vagrant box with the command 'vagrant up'. If the box hasn't already been downloaded "
description+= "this will grab it and configure the internal settings for it. This could take some considerable time so please "
description+= "be patient. Otherwise, it will simply boot up the box and make sure everything is running."
self.block description
system "cd #{full_repo_path} && vagrant up"
end
def git
key_path = File.expand_path "~/.ssh/id_rsa"
unless File.exists?(key_path) && File.exists?("#{key_path}.pub")
description = "We're now going to generate an SSH public/private key pair. This key is like a fingerprint for you "
description+= "on your laptop. We'll use this key for connecting into GitHub without having to enter a password, and "
description+= "when you ultimately deploy your website to a third party server."
self.block description
description = "We will be putting a comment in the SSH key pair as well. Comments can be used to keep track of different "
description+= "keys on different servers. The comment will be formatted as [your name]@codeup."
self.block description
name = ''
while name.empty?
print " Please type in your name and press 'Return'. "
name = gets.chomp
end
`ssh-keygen -trsa -b2048 -C '#{name}@codeup' -f #{key_path} -N ''`
end
`pbcopy < #{key_path}.pub`
puts " The following is your new SSH key:\n"
puts IO.read(key_path + ".pub")
puts
description = "We've already copied it to the clipboard for you. Now, we are going to take you to the GitHub website "
description+= "where you will add it as one of your keys by clicking the \"Add SSH key\" button and pasting "
description+= "the contents in there."
self.block description
`open https://github.com/settings/ssh`
self.block "We'll continue once you're done."
ssh_config_path = File.expand_path "~/.ssh/config"
if !File.exists? ssh_config_path || IO.readlines(ssh_config_path).grep(/Host\s+192\.168\.77\.77/).empty?
open(ssh_config_path, 'a') do |f|
f.puts "Host 192.168.77.77"
f.puts " StrictHostKeyChecking no"
f.puts " UserKnownHostsFile=/dev/null"
end
end
end
def sublime
subl_path = Support.subl_path
if subl_path.nil?
description = "Looks like Sublime Text hasn't been installed yet. We are going to open your browser to "
description+= "http://www.sublimetext.com, please click the \"Download\" link and copy Sublime Text to "
description+= "your Applications folder."
self.block description
`open http://www.sublimetext.com`
while subl_path.nil?
self.block "Please copy Sublime Text to your Applications folder."
subl_path = Support.subl_path
end
end
`ln -s \"#{subl_path}\" /usr/local/bin/subl 2>&1`
`git config --global core.editor \"subl -n -w\"`
description = "We're going to install the Sublime Text Package Manager. This is a plugin for Sublime that makes "
description+= "it incredibly easy to install other plugins and add functionality to Sublime."
self.block description
support_dir = subl_path[/Sublime Text 2/] || "Sublime Text 3"
package_dir = File.expand_path "~/Library/Application Support/#{support_dir}/Installed Packages"
`mkdir -p \"#{package_dir}\"`
Support.subl_pkg_install package_dir
end
def final
if IO.readlines("/etc/hosts").grep(/192\.168\.77\.77\s+codeup\.dev/).empty?
description = "We need to add an entry to your hosts file so we can easily connect to sites in your Vagrant environment. "
description+= "The hosts file is a shortcut for DNS lookup. We are going to put the domain name 'codeup.dev' in the "
description+= "hosts file and point it into your Vagrant environment, allowing you to connect into it without "
description+= "having to memorize IP addresses or ports. This will require you to again put in your password."
self.block description
system "sudo sh -c \"echo '\n192.168.77.77\tcodeup.dev' >> /etc/hosts\""
end
description = "Now that everything has been configured, we are going to load the codeup.dev site. "
description+= "This is the site landing page running in YOUR vagrant box inside YOUR OWN computer! "
description+= "You should see the Codeup logo as well as some information about PHP. Don't worry too "
description+= "much about what it says for now, we just want to verify that everything is running correctly."
self.block description
`open http://codeup.dev`
description = "Ok! We've gotten everything setup and you should be ready to go! Thanks for taking the time to "
description+= "get your laptop configured and good luck in the class."
self.block description
puts " _____ _____ _ _ "
puts " | __ \\ / __ \\ | | | |"
puts " | | \\/ ___ | / \\/ ___ __| | ___ _ _ _ __ | |"
puts " | | __ / _ \\ | | / _ \\ / _` |/ _ \\ | | | '_ \\| |"
puts " | |_\\ \\ (_) | | \\__/\\ (_) | (_| | __/ |_| | |_) |_|"
puts " \\____/\\___/ \\____/\\___/ \\__,_|\\___|\\__,_| .__/(_)"
puts " | | "
puts " |_| "
end
end
begin
Support.steps.each do |step|
Steps.do_step step
end
rescue => e
puts "Oh no! Looks like something has gone wrong in the process."
puts "Please copy the contents of this window and paste them into an"
puts "eMail to <instructors@codeup.com>."
puts "We're sorry about the inconvenience; we'll get the error resolved as quickly"
puts "as we can and let you know when you may re-run the setup process."
puts "Error: " + e.message
puts e.backtrace.join "\n"
end