-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.ps1
128 lines (106 loc) · 3.56 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
<#
.Synopsis
Install Serghei's dotfiles.
.DESCRIPTION
Used for one-line PC setup. Includes package installs, system setup, etc.
Performs the following tasks, in order:
1. Install and configure Chocolatey
2. Install defined Chocolatey packages
3. Install package to auto-update all Chocolately packages via Windows Scheduled Tasks
4. Install PSDepend for package management
5. Determine PowerShell modules to install and import
6. Install and import modules based on list in #5
7. Install defined Winget packages
.PARAMETER ChocoPackages
List of Chocolatey packages to install if missing
.PARAMETER WingetPackages
List of Winget packages to install if missing
#>
# Windows 10/11 Setup Script.
# Run this script in PowerShell.
[CmdletBinding()]
param (
[String[]]$ChocoPackages = @(
'bonjour',
'curl',
'SQLite',
'uninstalltool'
),
[String[]]$WingetPackages = @(
'calibre.calibre',
'CPUID.CPU-Z',
'Microsoft.WindowsTerminal',
'JanDeDobbeleer.OhMyPosh',
'Microsoft.dotnet',
'Microsoft.dotnetRuntime.6-x64',
'Docker.DockerDesktop',
'Microsoft.VisualStudioCode',
'vim.vim',
'Git.Git',
'GitHub.cli',
'Ghisler.TotalCommander',
'GnuPG.Gpg4win',
'DBBrowserForSQLite.DBBrowserForSQLite',
'Python.Python.3',
'GoLang.Go'
)
)
# Package Management
Write-Host 'Configuring Chocolatey...' -ForegroundColor Magenta
if (-not (Get-Command -Name choco -ErrorAction SilentlyContinue)) {
# Allow downloads
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force -Verbose
# Install Chocolatey
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest 'https://chocolatey.org/install.ps1' -UseBasicParsing | Invoke-Expression -Verbose
# Auto confirm package installations (no need to pass -y)
choco feature enable -n allowGlobalConfirmation -y
refreshenv
}
function Test-ChocolateyPackageInstalled {
<#
.LINK
https://octopus.com/docs/runbooks/runbook-examples/routine/installing-software-chocolatey
#>
Param (
[Parameter(Mandatory)]
[string]$Package
)
Process {
if (Test-Path -Path $env:ChocolateyInstall) {
$packageInstalled = Test-Path -Path "$env:ChocolateyInstall\lib\$Package"
} else {
Write-Host "Can't find a chocolatey install directory..."
}
return $packageInstalled
}
}
$missing_packages = [System.Collections.ArrayList]::new()
foreach ($package in $ChocoPackages) {
if (-not (Test-ChocolateyPackageInstalled($package))) {
$missing_packages.Add($package)
}
}
if ($missing_packages) {
& choco install $missing_packages
}
# Keep packages up to date
if (-not (Test-ChocolateyPackageInstalled('choco-upgrade-all-at'))) {
& choco install choco-upgrade-all-at --params "'/WEEKLY:yes /DAY:SUN /TIME:01:00'" --force
}
# Add commonly used modules (this must be done first)
Install-Module PSDepend -Scope CurrentUser
Import-Module PSDepend
Write-Host 'Installing PowerShell modules...' -ForegroundColor Magenta
Invoke-PSDepend -Path "$PSScriptRoot\requirements.psd1" -Import -Force
# Install defined Winget packages
Write-Host 'Installing Winget packages...' -ForegroundColor Magenta
$pkgList = winget list
foreach ($package in $WingetPackages) {
if ($pkgList | Select-String -Pattern $package.Replace('+', '\+') -Quiet) {
Write-Host "Package $package is already installed" -ForegroundColor Green
} else {
Write-Host "Installing $package" -ForegroundColor Yellow
winget install --exact --id $package
}
}