-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.ps1
102 lines (77 loc) · 3.15 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
<#
.SYNOPSIS
Automates the installation or updating of packages using winget, choco, scoop, or executes custom scripts.
.DESCRIPTION
This script reads a list of packages and scripts from a packages file and installs them using the specified package manager.
It supports winget, choco, scoop, and custom scripts. The script determines the execution context (admin or user) based on current privileges.
.PARAMETER PackagesFile
Optional path to the packages file. If not specified, it uses the path from the configuration file.
.PARAMETER ConfigFile
Optional path to the configuration file. If not specified, it defaults to './config.yaml'.
.PARAMETER Incremental
When specified, the script will process only changed lines from the packages file compared to the last successful run.
.PARAMETER PackageLine
Optional single line for package installation. When specified, only this package will be installed.
.PARAMETER Help
Displays this help message.
.EXAMPLE
.\InstallPackages.ps1
Runs the script using the default configuration and packages files.
.EXAMPLE
.\InstallPackages.ps1 -PackagesFile ".\my_packages.txt" -ConfigFile ".\my_config.yaml"
Runs the script using the specified packages and configuration files.
.EXAMPLE
.\InstallPackages.ps1 -Incremental
Runs the script in incremental mode, only processing changed packages.
.EXAMPLE
.\InstallPackages.ps1 -PackageLine "example-package"
Installs only the specified package.
#>
param (
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[string]$PackagesFile,
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[string]$ConfigFile = ".\config.yaml",
[Parameter(Mandatory = $false, HelpMessage = "Runs in incremental mode.")]
[switch]$Incremental,
[Parameter(Mandatory = $false, HelpMessage = "Single package to install.")]
[string]$PackageLine,
[Parameter(Mandatory = $false, HelpMessage = "Displays help information.")]
[switch]$Help
)
if ($Help) {
Get-Help -Detailed $MyInvocation.MyCommand.Path
exit
}
# Import necessary libraries
$libraryPath = Join-Path $PSScriptRoot "libraries"
. "$libraryPath\PowerShell.ps1"
. "$libraryPath\Config.ps1"
. "$libraryPath\Install.ps1"
# Ensure PowerShell 7+
if (-not (Test-PowerShell7 -VerboseCheck)) {
Write-Error "This script requires PowerShell 7 or later."
exit
}
# Load configuration
$configFilePath = if ($ConfigFile) { Resolve-Path -Path $ConfigFile } else { "$PSScriptRoot\config.yaml" }
$config = Load-ConfigFromYaml -ConfigFilePath $configFilePath
# Resolve packages file path
$packagesFilePath = if ($PackagesFile) { Resolve-Path -Path $PackagesFile } else { $config.packages.package_file_path }
# Execute installation logic
try {
if ($PackageLine) {
# Install only the specified package line
Write-Output "Installing package: $PackageLine"
Install-Package $PackageLine
} else {
# Install all packages from the packages file
Write-Output "Installing all packages from: $packagesFilePath"
Install-AllPackages -PackagesFilePath $packagesFilePath -Incremental:$Incremental
}
} catch {
Write-Error "An error occurred during installation: $_"
exit 1
}