-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoinstall
333 lines (279 loc) · 11.9 KB
/
autoinstall
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
<#
Script: Ruby Package Management
Created By: Joel Dezenzio
Date: 12/23/2013
Installs the following apps:
7zip
7zip.commandline
NuGet.commandline
NuGet Package Explorer
Uru
Ruby 32-bit
Ruby Devkit
MySQL
Git
Installs the following gems:
mysql2
rails
Installation:
* Right-click and open PowerShell and run as administrator
* Type Set-ExecutionPolicy unrestricted
* Accept via yes
* Close and reopen PowerShell as an administrator
* Install using the following in PowerShell (copy/paste):
START http://boxstarter.org/package/nr/url?https://raw.github.com/elricstorm/wrails/master/autoinstall
#>
# == SET PATHS
$tools = 'C:\tools'
$tools_bin = 'C:\tools\bin'
$tools_downloads = 'C:\tools\downloads'
$git_bin = ${env:ProgramFiles(x86)} + '\Git\bin'
$git_cmd = ${env:ProgramFiles(x86)} + '\Git\cmd'
$ruby_bin = 'C:\tools\bin\ruby\bin'
$env:HOME = $env:USERPROFILE
$env:GEM_HOME = $env:HOME + '\.gems'
$env:GEM_PATH = $env:GEM_HOME + "\bin"
$full_path = ';' + $tools_bin + ';' + $git_bin + ';' + $git_cmd + ';' + $ruby_bin + ';' + $env:GEM_HOME + ';' + $env:GEM_PATH
[Environment]::SetEnvironmentVariable("PATHEXT",$env:PATHEXT + ";.RB;.RBW", "User")
[Environment]::SetEnvironmentVariable("HOME",$env:USERPROFILE, "User")
[Environment]::SetEnvironmentVariable("GEM_HOME",$env:GEM_HOME, "User")
[Environment]::SetEnvironmentVariable("GEM_PATH",$env:GEM_PATH, "User")
[Environment]::SetEnvironmentVariable("PATH",$env:path + $full_path, "User")
$env:Path += $full_path
clear
# set variables
Write-Host "Installing and Updating Dependencies" -ForegroundColor yellow
Write-Host "=================================="
Write-Host "";Write-Host ""
# 7zip
cinst 7zip
cinst 7zip.commandline
# NuGet Commandline
cinst nuget.commandline
# NuGet Package Explorer
cinst NugetPackageExplorer
Start-Sleep 2
Write-Host "Dependendies Completed.";Write-Host ""
Write-Host "Installing Ruby Package Management" -ForegroundColor yellow
Write-Host "=================================="
Write-Host "";Write-Host ""
# Add an environment path variable
Function ADD-TO-PATH {
param([parameter(Mandatory=$True,ValueFromPipeline=$True,Position=0)][String[]]$AddedFolder)
# See if a new folder has been supplied.
IF (!$AddedFolder) {
return write-host ‘No Folder Supplied. $ENV:PATH Unchanged’ -ForegroundColor Cyan
}
# See if the new folder exists on the file system.
IF (!(TEST-PATH $AddedFolder)) {
return write-host $AddedFolder ‘does not Exist, and cannot be added to the $ENV:PATH’ -ForegroundColor Cyan
}
# See if the new Folder is already in the path.
IF ($ENV:PATH | Select-String -SimpleMatch $AddedFolder) {
return write-host $AddedFolder ‘already listed in $ENV:PATH’ -ForegroundColor Cyan
}
Start-Sleep 1
[Environment]::SetEnvironmentVariable("PATH",$env:path + ";" + $AddedFolder,"User")
write-host $AddedFolder 'has been added to the $ENV:PATH for User' -ForegroundColor Green
}
# Prompt to see if an install is needed for something function
function Install-NeededFor {
# Install-NeededFor 'PackageName'
param([string] $packageName = '',[bool] $defaultAnswer = $true)
if ($packageName -eq '') {return $false}
$yes = '6'
$no = '7'
$msgBoxTimeout='-1'
$defaultAnswerDisplay = 'Yes'
$buttonType = 0x4;
if (!$defaultAnswer) { $defaultAnswerDisplay = 'No'; $buttonType= 0x104;}
$answer = $msgBoxTimeout
try {
$timeout = 5
$question = "Do you need to install $($packageName)? Defaults to `'$defaultAnswerDisplay`' after $timeout seconds"
$msgBox = New-Object -ComObject WScript.Shell
$answer = $msgBox.Popup($question, $timeout, "Install $packageName", $buttonType)
} catch {}
if ($answer -eq $yes -or ($answer -eq $msgBoxTimeout -and $defaultAnswer -eq $true)) {
write-host "Installing $packageName >>>" -ForegroundColor Yellow
return $true
}
write-host "Not installing $packageName" -ForegroundColor Cyan
return $false
}
# Create a directory function
function CREATE-Directory {
param($sName, $sDestination)
Write-Host "Attempting to create" $sName "directory >>>" -ForegroundColor Yellow
$check_path = Test-Path $sDestination
if ($check_path) {
Write-Host $sName "directory already exists, bypassing..." -ForegroundColor cyan
} else {
New-Item -ItemType directory -Path $sDestination
Write-Host "Created" $sName "directory." -ForegroundColor green
}
Write-Host ""
}
# Download a file via URI function
function URI-DownloadFile {
param($sName, $sSource, $sDestination)
Write-Host "Beginning to download" $sName ">>>" -ForegroundColor Yellow
$check_path = Test-Path $sDestination
if ($check_path) {
Write-Host $sName "already Downloaded, bypassing..." -ForegroundColor cyan
} else {
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($sSource, $sDestination)
Write-Host $sName "download completed." -ForegroundColor green
}
Write-Host ""
}
# == CREATE TOOLS DIRECTORY
$tools_name = "tools"
CREATE-Directory -sName $tools_name -sDestination $tools
$tools_bin_name = "tools/bin"
CREATE-Directory -sName $tools_bin_name -sDestination $tools_bin
$tools_downloads_name = "tools/downloads"
CREATE-Directory -sName $tools_downloads_name -sDestination $tools_downloads
$gems_name = ".gems"
CREATE-Directory -sName $gems_name -sDestination $env:GEM_HOME
# URU
if (Install-NeededFor 'URU') {
# == DOWNLOAD URU
$uru_name = "URU"
$uru_source = "https://bitbucket.org/jonforums/uru/downloads/uru-0.7.3-windows-x86.7z"
# $uru_source = "https://bitbucket.org/jonforums/uru/downloads/uru-0.7.0-windows-x86.7z"
$uru_destination = $tools_downloads + '\uru-0.7.0-windows-x86.7z'
URI-DownloadFile -sName $uru_name -sSource $uru_source -sDestination $uru_destination
# == INSTALL URU
$uruBuild = Test-Path "C:\tools\bin\uru_rt.exe"
$uruExe = "C:\tools\bin\uru_rt.exe"
$uruArguments = "admin install"
Write-Host "Beginning to install URU >>>" -ForegroundColor Yellow
start-sleep 1
if ($uruBuild) {
Write-Host "URU already installed, bypassing..." -ForegroundColor Cyan
} else {
start-sleep 1
Start-Process "7za" -ArgumentList "x -o`"$tools_bin`" -y `"$uru_destination`"" -Wait
Write-Host "URU install completed." -ForegroundColor green;Write-Host ""
# Configure URU
start-sleep 1
cd $tools_bin
Write-Host "Configuring URU."
Start-Process $uruExe $uruArguments
}
Write-Host ""
}
# Ruby
if (Install-NeededFor 'RUBY') {
# == DOWNLOAD RUBY
$ruby_name = "Ruby"
$ruby_source = "http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.0.0-p353.exe"
$ruby_destination = $tools_downloads + '\rubyinstaller-2.0.0-p353.exe'
URI-DownloadFile -sName $ruby_name -sSource $ruby_source -sDestination $ruby_destination
# == INSTALL RUBY
$rubyBuild = Test-Path "C:\tools\bin\ruby\bin\ruby.exe"
Write-Host "Beginning to install Ruby >>>" -ForegroundColor Yellow
start-sleep 1
if ($rubyBuild) {
Write-Host "Ruby already installed, bypassing..." -ForegroundColor Cyan
} else {
CREATE-Directory -sName "Ruby" -sDestination "C:\tools\bin\ruby"
Write-Host "Installing Ruby >>>" -ForegroundColor Yellow
start-sleep 1
Start-Process $ruby_destination -ArgumentList "/silent /dir=`"C:\tools\bin\ruby`"" -Wait
Write-Host "Ruby install completed." -ForegroundColor green;Write-Host ""
$env:Path += ";" + $ruby_bin
Start-Sleep 1
cd $tools_bin
$uruAddArgs = " admin add C:\tools\bin\ruby\bin --tag system"
Start-Process $uruExe $uruAddArgs -Wait
}
Write-Host ""
}
# Ruby DevKit
if (Install-NeededFor 'Ruby DevKit') {
# == DOWNLOAD RUBY DEVKIT
$rubydev_name = "DevKit"
$rubydev_source = "http://cdn.rubyinstaller.org/archives/devkits/DevKit-mingw64-32-4.7.2-20130224-1151-sfx.exe"
$rubydev_destination = $tools_downloads + '\DevKit-mingw64-32-4.7.2-20130224-1151-sfx.exe'
URI-DownloadFile -sName $rubydev_name -sSource $rubydev_source -sDestination $rubydev_destination
# == INSTALL RUBY DEVKIT
$rubydevBuild = Test-Path "C:\tools\bin\devkit\dk.rb"
Write-Host "Beginning to install DevKit >>>" -ForegroundColor Yellow
start-sleep 1
if ($rubydevBuild) {
Write-Host "DevKit already installed, bypassing..." -ForegroundColor Cyan
} else {
CREATE-Directory -sName "DevKit" -sDestination "C:\tools\bin\devkit"
Write-Host "Installing DevKit >>>" -ForegroundColor Yellow
start-sleep 1
Start-Process "7za" -ArgumentList "x -o`"C:\tools\bin\devkit`" -y `"$rubydev_destination`"" -Wait
Write-Host "DevKit install completed." -ForegroundColor green;Write-Host ""
Write-Host "Begin DevKit configuration >>>" -ForegroundColor yellow;
$env:Path += ";C:\tools\bin\devkit"
$devkitPath = "c:\tools\bin\devkit"
cd $devkitPath
Start-Process "ruby" -ArgumentList "dk.rb init" -Wait
start-sleep 1
Start-Process "ruby" -ArgumentList "dk.rb install" -Wait
Write-Host "DevKit configuration completed." -ForegroundColor green;Write-Host ""
}
Write-Host ""
}
Write-Host "Ruby Package Management Completed.";Write-Host ""
# MySQL
if (Install-NeededFor 'MySql') {
# == INSTALL MYSQL
$mysqlBuild = Test-Path "C:\tools\mysql"
Write-Host "Beginning to install MySQL >>>" -ForegroundColor Yellow
Start-Sleep 1
if ($mysqlBuild) {
Write-Host "MySQL already installed, bypassing..." -ForegroundColor Cyan
} else {
cinst mysql-32bit
$env:Path += ";C:\tools\mysql-32bit\current\bin"
start-sleep 1
# Configure mysql root and password
Write-Host "Configuring mysql user (root) and password (Passw0rd!)" -ForegroundColor Cyan
Start-Process "mysqladmin" -ArgumentList "-u root password Passw0rd!" -Wait
# cmd /c start powershell -command {mysqladmin -u root password Passw0rd!}
}
$dllmysql = Test-Path "C:\tools\bin\ruby\bin\libmysql.dll"
if ($dllmysql) {
# do nothing
} else {
# Copy libmysql.dll into ruby\bin
Write-Host "Copying libmysql.dll into current ruby bin" -ForegroundColor Cyan
Copy-Item -Path C:\tools\mysql-32bit\current\lib\libmysql.dll -Destination c:\tools\bin\ruby\bin
}
}
# GIT
if (Install-NeededFor 'Git') {
cinst git
Write-Host "Git installed." -ForegroundColor Green;Write-Host ""
}
# Mysql2 Gem
if (Install-NeededFor 'MySQL2.Gem') {
# install mysql2 gem
Write-Host "Installing mysql2 gem" -ForegroundColor Cyan
Start-Process "gem" -ArgumentList "install --platform=ruby mysql2 -- --with-mysql-lib=C:\tools\mysql-32bit\current\lib --with-mysql-include=C:\tools\mysql-32bit\current\include" -Wait
Write-Host "mysql2 gem installed." -ForegroundColor Green;Write-Host ""
}
# Rails Gem
if (Install-NeededFor 'Rails Gem') {
# install mysql2 gem
Write-Host "Installing Rails gem" -ForegroundColor Cyan
Start-Process "gem" -ArgumentList "install rails" -Wait
Write-Host "Rails installed." -ForegroundColor Green;Write-Host ""
}
<#
Additonal Notes:
If you need to uninstall all gems you can run the command below in PowerShell:
gem list | %{$_.split(' ')[0]} | %{gem uninstall -Iax $_ }
If you need to view all chocolatey packages without additional information use this function and call "mychoc":
function mychoc {cver all -localonly|%{$_.split(' ')[0]}|%{if($_ -ceq 'name' -Or $_ -ceq '----' -Or $_ -ceq 'Reading' -Or $_ -ceq ''){}else{write-host $_ -ForegroundColor Cyan}}}
If you need to uninstall all chocolatey packages use the following function and then call "cunall"
function cunall {cver all -localonly|%{$_.split(' ')[0]}|%{if($_ -ceq 'name' -Or $_ -ceq '----' -Or $_ -ceq 'Reading' -Or $_ -ceq ''){}else{cuninst $_}}}
#>