-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ps1
52 lines (48 loc) · 2.03 KB
/
utils.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
function global:Test-WingetPackageInstalled([string] $package_id) {
$package = winget list --id "$package_id"
$package = [string]::Join(" ", $package) # La commande renvoie un tableau de string, évite le foreach
if ($package.Contains("$package_id")) {
return $true
} else {
return $false
}
}
function global:Install-WingetPackage([string] $package_id, [bool] $verbose = $true) {
if (-Not (Test-WingetPackageInstalled $package_id)) {
Write-Host -ForegroundColor Yellow "Installation du package - ID: $package_id"
winget install --accept-package-agreements --accept-source-agreements "$package_id"
Invoke-RefreshEnv
Write-Host -ForegroundColor Yellow "Installation terminée"
} elseif ($verbose) {
"Package $package_id already installed"
}
}
function global:Test-ChocoPackageInstalled([string] $package_id) {
$packages = choco list -lo -r --exact $package_id
if ($null -eq $packages) {
return $false
} else {
return $true
}
}
function global:Install-ChocoPackage([string] $package_id, [bool] $verbose = $true) {
if (-Not (Test-ChocoPackageInstalled $package_id)) {
Write-Host -ForegroundColor Yellow "Installation du package - ID: $package_id"
choco install --no-progress -y -r $package_id
Invoke-RefreshEnv
Write-Host -ForegroundColor Yellow "Installation terminée"
} elseif ($verbose) {
"Package $package_id already installed"
}
}
function global:Invoke-GitClone([string] $repo, [string] $path = '.') {
Install-WingetPackage "Git.Git" $false
$git_tmp = "$path/tmpgit"
New-Item -Path $git_tmp -ItemType Container
git clone $repo $git_tmp
Copy-Item -Path "$git_tmp/*" -Destination $path -Force
Remove-Item -Path $git_tmp -Recurse -Force
}
function global:Invoke-RefreshEnv() {
$env:Path = [System.Environment]::ExpandEnvironmentVariables([System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User"))
}