dofiles-win/Documents/PowerShell/verify-state.ps1

31 lines
1.1 KiB
PowerShell
Raw Normal View History

2024-02-02 22:28:57 -04:00
function differences($required, $installed) {
# Args in json format
# Only compare the names of the software
# Format is a json array of objects with a name property
$required_names = $required | ForEach-Object { $_.name }
$installed_names = $installed | ForEach-Object { $_.name }
$diff = Compare-Object $required_names $installed_names
return $diff
}
if (-not (Test-Path "~\scoop\apps.json")) {
Write-Host "Scoop is installed but the apps.json file is missing"
}
2024-02-03 15:30:44 -04:00
scoop export | Out-File "~\scoop\apps.json"
2024-02-02 22:28:57 -04:00
# Diff the installed software with the required software, if there are differences, install the required software
$required = Get-Content "~\scoop\apps.json" | ConvertFrom-Json
$installed = scoop export | ConvertFrom-Json
$differences = differences $required.apps $installed.apps
if ($differences) {
2024-02-03 15:30:44 -04:00
Write-Host "The following software not synced:"
2024-02-02 22:28:57 -04:00
$differences | ForEach-Object { Write-Host $_.InputObject }
$install = Read-Host "Would you like to install the missing software? (y/n)"
if ($install -eq "y") {
# Install the missing software
scoop import "~\scoop\apps.json"
}
else {
Write-Host "The required software is not installed"
}
}