-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwithoutChoco.ps1
144 lines (135 loc) · 2.68 KB
/
withoutChoco.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
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
## iex ((New-Object System.Net.WebClient).DownloadString('https://git.io/JRCsv'))
$python = 0
$pipenv = 0
$choco = 0
function downloadPython {
try{
Write-Host -NoNewline "Checking Chocolatey..."
$er = (invoke-expression "choco -v") 2>&1
if ($lastexitcode) {throw $er}
if (!$lastexitcode) {
Write-Host "[Found]"
$choco = 1
return 1
}
}
catch{
Write-Host "[Not Found]"
$choco = 0
return 0
}
}
function checkPython {
try{
Write-Host -NoNewline "Checking Python..."
$er = (invoke-expression "python -V") 2>&1
if ($lastexitcode) {throw $er}
if (!$lastexitcode) {
Write-Host "[Found]"
$python = 1
return 1
}
}
catch{
Write-Host "[Not Found]"
$python = 0
return 0
}
}
function checkPipenv {
try{
Write-Host -NoNewline "Checking Pipenv..."
$er = (invoke-expression "python -m pipenv --version") 2>&1
if ($lastexitcode) {throw $er}
if (!$lastexitcode) {
Write-Host "[Found]"
$pipenv = 1
return 1
}
}
catch{
Write-Host "[Not Found]"
$pipenv = 0
return 0
}
}
function installChocolatey {
try{
Write-Host -NoNewline "Installing Chocolatey..."
$InstallDir='C:\ProgramData\chocolatey'
$env:ChocolateyInstall="$InstallDir"
Set-ExecutionPolicy Bypass -Scope Process -Force;
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
$er = (invoke-expression "choco -v") 2>&1
if ($lastexitcode) {throw $er}
if (!$lastexitcode) {
Write-Host "[Installed]"
$choco = 1
return 1
}
}
catch{
Write-Host "[Not Installed]"
$choco = 0
return 0
}
}
function installPython {
try{
Write-Host -NoNewline "Installing Python..."
$er = (invoke-expression "choco install python --version=3.9.6 -y") 2>&1
if ($lastexitcode) {throw $er}
checkPython
if (!$lastexitcode) {
Write-Host "[Installed]"
refreshenv
$python = 1
return 1
}
}
catch{
Write-Host "[Not Installed]"
$python = 0
return 0
}
}
function installPipenv {
try{
Write-Host -NoNewline "Installing Pipenv..."
$er = (invoke-expression "python -m pip install pipenv") 2>&1
if ($lastexitcode) {throw $er}
if (!$lastexitcode) {
Write-Host "[Installed]"
$pipenv = 1
return 1
}
}
catch{
Write-Host "[Not Installed]"
$pipenv = 0
return 0
}
}
$valuepipenv = checkPipenv
$valuepython = checkPython
$valuechoco = checkChocolatey
if($valuepipenv -eq 0) {
if($valuepython -eq 0) {
if($valuechoco -eq 0) {
$value = installChocolatey
if(($python -eq 0) -and ($value -eq 1)) {
$value = installPython
$value = installPipenv
}
}
else{
$value = installPython
if(($python -eq 1) -and ($value -eq 1)) {
$value = installPipenv
}
}
}
else{
$value = installPipenv
}
}