-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstall.ps1
262 lines (201 loc) · 10 KB
/
Install.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
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
#Retirer la réstriction d'execution de code powershell
# Set-ExecutionPolicy Unrestricted -Force
# Pour revenire au répertoire de base
$Back = $PWD
Set-Location "$env:USERPROFILE\Get-Drivers"
$scriptDir = "$env:USERPROFILE\Get-Drivers"
# Vérifier si le chemin du répertoire du script est déjà présent dans le PATH
if (-Not ($env:PATH -split ";" -contains $scriptDir)) {
if ($Host.Runspace.IsRunspacePushed -and (-not $Host.Runspace.IsRunAsAdministrator >$null)) {
Write-Host "La session n'est pas en mode administrateur." -ForegroundColor Red
Write-Host "Executer le script en Administrateur pour ajouter le chemin du programme" -ForegroundColor Magenta
} else {
Write-Host "La session est en mode administrateur." -ForegroundColor Magenta
Write-Host "Ajout du répertoire au PATH..." -ForegroundColor Yellow
# Ajouter le répertoire au PATH pour le compte machine
$env:PATH += ";$scriptDir"
[System.Environment]::SetEnvironmentVariable("PATH", $env:PATH, "Machine")
Write-Host "Le répertoire a été ajouté au PATH." -ForegroundColor Green
}
}
winget --version 2>$null
if (!$?) {
Write-Host "Winget n'est pas installé !"
Write-Host "Téléchargement" -NoNewline
Write-Host "..." -ForegroundColor Cyan
try {
$downloadUrl = 'https://github.com/microsoft/winget-cli/releases/download/v1.5.1881/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle'
$downloadPath = "$env:TEMP\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
# Télécharger le fichier MSIX
Invoke-WebRequest -Uri $downloadUrl -OutFile $downloadPath
# Exécuter l'installation du package MSIX
Add-AppxPackage -Path $downloadPath
Write-Host "Téléchargement réusit !" -ForegroundColor Green
$wingetInstalled = "y"
} catch {
$wingetInstalled = "n"
Write-Host "Erreur de téléchargement !" -ForegroundColor Red
}
} else {
$wingetInstalled = "y"
Write-Host "Winget est installer !" -ForegroundColor Green
}
if (-Not (Test-Path "$env:USERPROFILE\Get-Drivers\Download")) {
New-Item -ItemType Directory -Path "$env:USERPROFILE\Get-Drivers\Download" | Out-Null
Write-Host "Creation du dossier de téléchargement !" -ForegroundColor Green
}
if ($wingetInstalled -eq "y") {
# Vérifier si Python est déjà installé avec Winget
$pythonApp = Winget -Name "Python" -Exact
if (!$?) {
Write-Host "Python n'est pas installé !" -ForegroundColor Red
# Installation de Python avec Winget
winget install "Python" --scope=machine --accept-package-agreements --silent
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH", "User")
} else {
Write-Host "Python est déjà installé." -ForegroundColor Yellow
}
# Vérifier si Git est déjà installé avec Winget
$gitApp = Winget -Name "Git" -Exact
if (!$?) {
Write-Host "Git n'est pas installé !" -ForegroundColor Yellow
# Installation de Git avec Winget
winget install "Git.Git" --scope=machine --accept-package-agreements --silent
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH", "User")
} else {
Write-Host "Git est déjà installé." -ForegroundColor Yellow
}
# Vérification de la version installée de Python
$pythonVersion = & python --version 2>$null
if (!$?) {
Write-Host "Python a été installé avec succès !" -ForegroundColor Green
} else {
Write-Host "Une erreur s'est produite lors de l'installation de Python." -ForegroundColor Red
}
# Vérification de la version installée de Git
$gitVersion = & git --version 2>$null
if (!$?) {
Write-Host "Git a été installé avec succès." -ForegroundColor Green
} else {
Write-Host "Une erreur s'est produite lors de l'installation de Git." -ForegroundColor Red
}
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH", "User")
}
try {
python --version 2>$null
git --version 2>$null
} catch {
$wingetInstalled = "n"
}
if ($wingetInstalled -eq "n") {
Set-Location "$env:USERPROFILE\Get-Drivers\Download"
# Vérifier si Python est déjà installé
$pythonVersion = python --version 2>$null
if (!$?) {
Write-Host "Python est déjà installé. Vérification de la version" -ForegroundColor Green
python --version
}
if (-Not (Test-Path "$env:USERPROFILE\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python311\python.exe")) {
Write-Host "Il y a une erreur d'installation de Python. Veuillez vérifier que le chemin du programme est ajouté à la variable d'environnement 'Path'." -ForegroundColor Red
}
$PYTHON_URL = "https://www.python.org/ftp/python/3.11.4/python-3.11.4-amd64.exe"
$INSTALLER_FILENAME = ".\python_installer.exe"
# Vérifier si le fichier d'installation existe déjà
if (Test-Path $INSTALLER_FILENAME) {
Write-Host "Le fichier d'installation de Python est déjà présent." -ForegroundColor Yellow
} else {
Write-Host "Téléchargement de Python" -NoNewline -ForegroundColor Magenta
Write-Host "..." -ForegroundColor Cyan
Invoke-WebRequest -Uri $PYTHON_URL -OutFile $INSTALLER_FILENAME
}
Write-Host "Installation de Python en cours" -NoNewline -ForegroundColor Magenta
Write-Host "..." -ForegroundColor Cyan
Start-Process -FilePath $INSTALLER_FILENAME -ArgumentList "/passive" -Wait -NoNewWindow
# Mettre à jour le chemin d'accès actuel pour cette session
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH", "User")
if (Test-Path "$env:USERPROFILE\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python311\python.exe") {
$env:PATH = "$env:PATH;$env:USERPROFILE\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python311"
}
Write-Host "Nettoyage" -NoNewline -ForegroundColor Magenta
Write-Host "..." -ForegroundColor Cyan
Remove-Item $INSTALLER_FILENAME
# Vérification de la version installée de Python
$pythonVersion = python --version 2>$null
if (!$?) {
Write-Host "Python a été installé avec succès !" -ForegroundColor Green
} else {
Write-Host "Une erreur s'est produite lors de l'installation de Python." -ForegroundColor Red
}
# Vérifier si Git est déjà installé
$gitVersion = git --version 2>$null
if (!$?) {
if (Test-Path "C:\Program Files\Git") {
Write-Host "Il y a une erreur d'installation de Git. Vérifiez que le chemin du programme est ajouté à la variable d'environnement 'Path'." -ForegroundColor Red
exit
} else {
Write-Host "Git n'est pas installé !" -ForegroundColor Yellow
# Télécharger Git s'il n'existe pas déjà dans le répertoire de sauvegarde
$gitSetupPath = "$env:USERPROFILE\Get-Drivers\Download\GitSetup.exe"
if (-Not (Test-Path $gitSetupPath)) {
Write-Host "Téléchargement de Git..."
Invoke-WebRequest -Uri "https://github.com/git-for-windows/git/releases/download/v2.41.0.windows.3/Git-2.41.0.3-64-bit.exe" -OutFile $gitSetupPath
}
# Installer Git (modifier le nom du fichier téléchargé si nécessaire)
Write-Host "Installation de Git" -NoNewline -ForegroundColor Magenta
Write-Host "..." -ForegroundColor Cyan
Start-Process -FilePath $gitSetupPath -ArgumentList "/SILENT" -Wait
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH", "User")
if (Test-Path "$gitSetupPath") {
Remove-Item $gitSetupPath
}
# Vérifier à nouveau si Git est installé après l'installation
$gitVersion = git --version 2>$null
if (!$?) {
Write-Host "Git a été installé avec succès." -ForegroundColor Green
} else {
Write-Host "Une erreur s'est produite lors de l'installation de Git." -ForegroundColor Red
}
}
} else {
Write-Host "Git est déjà installé avec succès." -ForegroundColor Yellow
}
}
pip --version 2>$null
if (!$?) {
python get-pip.py
Write-Host "PIP est installé !" -ForegroundColor Green
} else {
Write-Host "PIP n'est pas installé !" -ForegroundColor Red
}
pip install --upgrade requests 2>$null
if (!$?) {
Write-Host "Installation de requests" -NoNewline
Write-Host " [OK]" -ForegroundColor Green
} else {
Write-Host "Installation de requests" -NoNewline
Write-Host " [ERREUR]" -ForegroundColor Red
}
pip install --upgrade bs4 2>$null
if (!$?) {
Write-Host "Installation de bs4" -NoNewline
Write-Host " [OK]" -ForegroundColor Green
} else {
Write-Host "Installation de bs4" -NoNewline
Write-Host " [ERREUR]" -ForegroundColor Red
}
pip install --upgrade urljoin 2>$null
if (!$?) {
Write-Host "Installation de urljoin" -NoNewline
Write-Host " [OK]" -ForegroundColor Green
} else {
Write-Host "Installation de urljoin" -NoNewline
Write-Host " [ERREUR]" -ForegroundColor Red
}
if (-Not ($env:PATH -split ";" -contains $scriptDir)) {
Write-Host "Erreur le chemin n'est pas ajoutée corectement !"
} else {
# "Le répertoire est déjà présent dans le PATH."
Write-Host "Vous pouvez appeler la commande 'Get-Drivers' a présent comme une commande native powershell !" -ForegroundColor Green
}
Set-Location "$Back"
exit(0)