-
Notifications
You must be signed in to change notification settings - Fork 9
/
install_programs.ps1
67 lines (53 loc) · 1.42 KB
/
install_programs.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
$packageListName = 'package_list.json'
$programs = (Get-Content -Raw -Path $packageListName | ConvertFrom-Json).list
$listOk = @()
$someFailed = $false
$choice = $null
function startProccess{
Write-Output "`nChecking packages...`n"
foreach($i in $programs){
$result = choco find $i
if($result.Length -gt 2){
$listOk = $listOk + $i
$i + ' - ok'
}else{
$someFailed = $true
$i + ' - failed'
}
}
Write-Output "`n"
if($someFailed){
Write-Warning "Failed to find some packages"
while ($choice -notmatch "[y|n]"){
$choice = Read-Host "Wish to continue? (y/n):"
}
}
$hasUserAccepted = $null -eq $continue -or $continue -eq 'y'
if($hasUserAccepted){
startInstallation
}
else{
Write-Error "Verify your package list and try again"
}
}
function progressBar{
param($percent)
Write-Progress -Activity 'Installation in progress' -PercentComplete $percent
}
function install{
param($item)
choco install $item -y --acceptlicense --force
}
function startInstallation{
try{
Write-Output "Starting installation `n"
for ($i = 1; $i -le $listOk.length; $i++){
progressBar(($i/$listOk.length*100))
install($listOk[$i - 1])
}
}
catch{
Write-Error "Failure to install packages"
}
}
startProccess