-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.ps1
More file actions
146 lines (136 loc) · 5.27 KB
/
setup.ps1
File metadata and controls
146 lines (136 loc) · 5.27 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
<#
.SYNOPSIS
Setup Linux Dev Box
.DESCRIPTION
This script install the requirements of the linux-dev-box.
.PARAMETER ImagePath
Path of the vhd file to mount.
.NOTES
Version: 1.0
Author: Sajal N. Shrestha
Creation Date: 2/24/2020
Purpose/Change: Initial Version
.EXAMPLE
.\setup.ps1
#>
Param (
[Parameter(Mandatory = $False)]
[alias("i")]
[switch]$Install
)
$Script:ValidateOnly = $True
$LogFileName = "setup-linux-dev-box.log"
$Script:CurrentLocation = (Get-Item -Path ".\").FullName
$Script:LogLocation = $Script:CurrentLocation
$Script:LogFile = $Script:LogLocation + "\" + $LogFileName
$Script:InstallLocation = $Script:CurrentLocation
if ($InstallMode) { $Script:ValidateOnly = $False }
$Script:Requirements = @{
vagrant = @{
Name = 'Vagrant'
Version = '2.2.7'
InstallType = 'msi'
URL = 'https://releases.hashicorp.com/vagrant/2.2.7/vagrant_2.2.7_x86_64.msi'
InstallArgs = "/qn /norestart"
}
virutalbox = @{
Name = 'Oracle VM VirtualBox'
Version = '6.0.16'
InstallType = 'exe'
URL = 'https://download.virtualbox.org/virtualbox/6.0.16/VirtualBox-6.0.16-135674-Win.exe'
InstallArgs = (
'-s -l -msiparams REBOOT=ReallySuppress ' +
'ALLUSERS=2 ' +
'VBOX_INSTALLDESKTOPSHORTCUT=0 ' +
'VBOX_INSTALLQUICKLAUNCHSHORTCUT=0 ' +
'VBOX_REGISTERFILEEXTENSIONS=0 '
)
}
}
###############################################################################
# Utility Functions
###############################################################################
# Write Log
function Write-Log {
Param(
[Parameter(Mandatory = $true)]
[String]$Message
)
$timestamp = "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
Write-Output "$timestamp $Message"
Write-Output "$timestamp $Message" | Out-file $Script:LogFile -append
}
# Returns a list of installed application or a given application
function Get-InstalledApp() {
Param(
[Parameter(Mandatory = $false)]
[String]$AppName
)
$Apps = @()
$PATH_32 = 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
$PATH_64 = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
if (Get-Item Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node -ErrorAction SilentlyContinue) {
$Apps += Get-ItemProperty $PATH_64 |
Where-Object DisplayName -ne $null |
Where-Object DisplayName -ne ""
}
$Apps += Get-ItemProperty $PATH_32 |
Where-Object DisplayName -ne $null |
Where-Object DisplayName -ne ""
if ($PSBoundParameters.ContainsKey('AppName')) {
$AppName = $AppName.Split(" ")[0]
$App = $Apps | Where-Object DisplayName -match $AppName | Select-Object -First 1
if ($null -ne $App) {
return $App
}
return $false
}
return $Apps
}
# Installs the requirement of the linux development box.
function Install-Requirements() {
foreach($Requirement in $Script:Requirements.Keys) {
foreach($App in $Script:Requirements[$Requirement]) {
$InstallApp = Get-InstalledApp -AppName $App.Name
if ($InstallApp -eq $false) {
if (-not $Script:ValidateOnly) {
if ($App.URL -like 'https://*' -or $App.URL -like 'http://*') {
Import-Module BitsTransfer
$InstallerFileName = $App.URL.Substring($App.URL.LastIndexOf("/") + 1)
$TempInstallerPath = $Script:CurrentLocation + "\" + $installerFileName
Start-BitsTransfer -Source $App.URL -Destination $Script:CurrentLocation -ErrorVariable Err
if (-not (Test-Path $tempInstallerPath))
{
Write-Log -Message "Failed to download file $InstallerFileName"
return
}
$Installer = $TempInstallerPath
$InstallArgs = $App.InstallArgs
if($App.InstallType -eq 'msi') {
$Installer = "msiexec.exe"
$InstallArgs = "/i $(TempInstallerPath) $($App.InstallArgs)"
}
Write-Log -Message "Starting Installation: $Installer, Argument: $InstallArgs"
Start-Process -FilePath $Installer -ArgumentList $InstallArgs -Wait
if(Get-InstalledApp -AppName $App.Name) {
Write-Log -Message "Install $App.Name $App.Version -> SUCCESS"
}
else {
Write-Log -Message "Install $App.Name $App.Version -> FAILED"
}
}
}
else {
Write-Log -Message "Application $($App.Name) to be installed."
}
}
else {
Write-Log -Message "Application $($App.Name) is already installed."
}
}
}
}
###############################################################################
# Start Configuration
###############################################################################
Install-Requirements