-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindows.ps1
89 lines (72 loc) · 2.44 KB
/
windows.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
# Automation Script to streamline local development setup for Windows-based systems
# --- Functions ---
function Install-WithWinget {
param (
[string]$PackageName
)
Write-Host "Installing $PackageName using WinGet..."
$packageInfo = winget show $PackageName
$latestVersion = $packageInfo.Property | Where-Object {$_.Name -eq 'Version'} | Select-Object -ExpandProperty Value
winget install "$PackageName" -v "$latestVersion" -h -e || (
Write-Warning "Failed to install $PackageName with WinGet."
Install-WithChocolatey $PackageName
)
Write-Host "$PackageName installation completed successfully!"
}
function Install-WithChocolatey {
param (
[string]$PackageName
)
# Check if Chocolatey is installed
if (-not (Get-Command choco -ErrorAction SilentlyContinue)) {
Write-Host "Chocolatey not found. Installing..."
Set-ExecutionPolicy Bypass -Scope Process -Force
irm get.chocolatey.org/install.ps1 | iex
}
choco install $PackageName -y || (
Write-Error "Failed to install $PackageName with Chocolatey. Please install manually and rerun script."
exit 1
)
}
function PreUpdate {
Write-Host "Checking for and installing Windows Updates..."
Install-WithWinget Microsoft.Windows.Update
}
function InstallCoreComponents {
Write-Host "Installing core components..."
Install-WithWinget Git.Git
InstallNodeJS
InstallPHP
}
function InstallNodeJS {
Write-Host "Installing Node.js & npm..."
Install-WithWinget OpenJS.NodeJS
}
function InstallPHP {
Write-Host "Installing PHP..."
Install-WithWinget PHP.PHP
}
function InstallComposer {
Write-Host "Installing Composer..."
# Download Composer installer
Invoke-WebRequest -Uri https://getcomposer.org/installer -OutFile composer-setup.php
# Verify installer hash (you'll still need to add hash verification logic here)
# For now, we'll assume the installer is valid
php composer-setup.php --install-dir=$env:ProgramData\ComposerSetup\bin --filename=composer || (
Write-Error "Error installing Composer. Fix and rerun script."
exit 1
)
Write-Host "Composer installation completed successfully!"
}
function Cleanup {
Write-Host "Cleaning up..."
Remove-Item composer-setup.php
}
# --- Main Script ---
PreUpdate
InstallCoreComponents
InstallNodeJS
InstallPHP
InstallComposer
Cleanup
Write-Host "Setup completed successfully!"