-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev-setup.ps1
90 lines (67 loc) · 1.87 KB
/
dev-setup.ps1
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
#Requires -RunAsAdministrator
function Create-Directory
{
param ([string]$path)
if ( (Test-Path $path) -Eq $False)
{
New-Item -ItemType Directory -Path $path | Out-Null
}
}
function Is-Choco-Package-Installed
{
param ([string]$pkg)
return ($installedPackages | Where-Object { $_.ToLower().StartsWith($pkg) }) -Ne $Null
}
function Refresh-Path
{
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
}
#!
$downloadDir = "$HOME\tmp_download"
$toolsDir = "$HOME\tools"
Create-Directory $downloadDir
Create-Directory $toolsDir
# Install Chocolatey
if((Get-Command -Name choco.exe -ErrorAction SilentlyContinue) -Eq $null)
{
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
}
$installedPackages = (powershell choco list -lo)
$packages = (Get-Content dev-packages.json) | ConvertFrom-Json
ForEach($pkg in $packages.packages)
{
$name = $pkg.name;
$refreshPath = ($pkg.refreshPath -Eq $True)
$commands = ($pkg.additionalCommands)
$params = ($pkg.params)
$includePreRelease = $pkg.pre
if(-Not (Is-Choco-Package-Installed $name))
{
$chocoInstall = "choco install $name"
$chocoParams = "-y --force"
if($params -Ne $Null)
{
$chocoParams = "$chocoParams --params $params"
}
if($includePreRelease -Eq $True)
{
$chocoParams = "$chocoParams --pre"
}
# ensure we force evalutation of any PS variables used in params (e.g $home)
Invoke-Expression "$chocoInstall $chocoParams"
if($refreshPath -Eq $True)
{
Refresh-Path
}
if(-Not ($commands -Eq $Null))
{
ForEach($cmd in $commands)
{
Invoke-Expression $cmd
}
}
}
}
# Upgrade any existing packages
powershell choco upgrade all -y