Remove hooks support from PS scripts

This commit is contained in:
Manuel Thalmann 2024-10-12 17:18:19 +02:00
parent d9d1575a19
commit db3955a090
3 changed files with 25 additions and 60 deletions

View file

@ -4,7 +4,6 @@ $null = New-Module {
. "$PSScriptRoot/Scripting.ps1"; . "$PSScriptRoot/Scripting.ps1";
. "$PSScriptRoot/SoftwareManagement.ps1"; . "$PSScriptRoot/SoftwareManagement.ps1";
. "$PSScriptRoot/../../Windows/Scripts/Constants.ps1"; . "$PSScriptRoot/../../Windows/Scripts/Constants.ps1";
. "$PSScriptRoot/../../Windows/Scripts/Hooks.ps1";
. "$PSScriptRoot/../../Windows/Scripts/PowerManagement.ps1"; . "$PSScriptRoot/../../Windows/Scripts/PowerManagement.ps1";
. "$PSScriptRoot/../../Windows/Scripts/Registry.ps1"; . "$PSScriptRoot/../../Windows/Scripts/Registry.ps1";
. "$PSScriptRoot/../../Windows/Scripts/Security.ps1"; . "$PSScriptRoot/../../Windows/Scripts/Security.ps1";
@ -92,23 +91,19 @@ $null = New-Module {
while (-not $initialized) { while (-not $initialized) {
if ($IsWindows) { if ($IsWindows) {
if (-not ((Test-Command "choco") -and (Test-Command "refreshenv"))) { if (-not ((Test-Command "choco") -and (Test-Command "refreshenv"))) {
Invoke-Hook "Install-Chocolatey" -Fallback { # Install chocolatey
# Install chocolatey Write-Host "Installing Chocolatey…";
New-Item -Force $PROFILE; New-Item -Force $PROFILE;
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')); Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'));
Import-Module $env:ChocolateyInstall/helpers/chocolateyProfile.psm1; Import-Module $env:ChocolateyInstall/helpers/chocolateyProfile.psm1;
refreshenv; refreshenv;
};
continue; continue;
} }
if (-not (Test-ChocoPackage "powershell-core")) { if (-not (Test-ChocoPackage "powershell-core")) {
Invoke-Hook "Install-PowerShellCore" -Fallback { Write-Host "Installing PowerShell Core…";
choco install -y powershell-core --install-arguments='"ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL=1 ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 REGISTER_MANIFEST=1 USER_MU=1 ENABLE_MU=1"'; choco install -y powershell-core --install-arguments='"ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL=1 ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 REGISTER_MANIFEST=1 USER_MU=1 ENABLE_MU=1"';
};
Restart-Intermediate; Restart-Intermediate;
return; return;
} }
@ -260,24 +255,24 @@ $null = New-Module {
. "$PSScriptRoot/../../Windows/Software/PinnedItem/Manage.ps1"; . "$PSScriptRoot/../../Windows/Software/PinnedItem/Manage.ps1";
} }
Invoke-Hook "Install-PSModules" -Fallback { Write-Host "Installing PowerShell Modules…";
foreach ($module in (Get-RequiredModules)) {
$parameters = @{ };
if ($module -is [string]) { foreach ($module in (Get-RequiredModules)) {
$module = @($module); $parameters = @{ };
}
if ($module[1]) { if ($module -is [string]) {
$parameters = @("-AllowPrerelease"); $module = @($module);
}
if (-not (Test-PSModule $module[0])) {
sudo pwsh -Command Install-Module -Scope AllUsers -AcceptLicense -Force -AllowClobber $module[0] @parameters;
Import-Module $module[0];
}
} }
};
if ($module[1]) {
$parameters = @("-AllowPrerelease");
}
if (-not (Test-PSModule $module[0])) {
sudo pwsh -Command Install-Module -Scope AllUsers -AcceptLicense -Force -AllowClobber $module[0] @parameters;
Import-Module $module[0];
}
}
if (-not $env:CONFIG_NAME) { if (-not $env:CONFIG_NAME) {
Show-ProfileNamePrompt; Show-ProfileNamePrompt;

View file

@ -7,7 +7,6 @@ using namespace System.Security.Principal;
$null = New-Module { $null = New-Module {
. "$PSScriptRoot/../Scripts/Constants.ps1"; . "$PSScriptRoot/../Scripts/Constants.ps1";
. "$PSScriptRoot/../Scripts/Deployment.ps1"; . "$PSScriptRoot/../Scripts/Deployment.ps1";
. "$PSScriptRoot/../Scripts/Hooks.ps1";
. "$PSScriptRoot/../Scripts/PowerManagement.ps1"; . "$PSScriptRoot/../Scripts/PowerManagement.ps1";
. "$PSScriptRoot/../Scripts/Registry.ps1"; . "$PSScriptRoot/../Scripts/Registry.ps1";
. "$PSScriptRoot/../Scripts/Security.ps1"; . "$PSScriptRoot/../Scripts/Security.ps1";
@ -80,10 +79,7 @@ $null = New-Module {
while (-not (Get-IsFinished)) { while (-not (Get-IsFinished)) {
if (Test-Admin) { if (Test-Admin) {
$null = Import-Module PSWindowsUpdate; $null = Import-Module PSWindowsUpdate;
Update-WindowsInstallation;
Invoke-Hook "Invoke-WindowsUpdate" -Fallback {
Update-WindowsInstallation;
};
if ((Get-WURebootStatus -Silent)) { if ((Get-WURebootStatus -Silent)) {
Restart-Intermediate; Restart-Intermediate;

View file

@ -1,26 +0,0 @@
function Invoke-Hook() {
param(
[string] $Name,
[scriptblock] $Fallback
)
if ($Fallback) {
$scriptBlock = $Fallback;
} else {
$scriptBlock = { };
}
if (Get-Command "$Name" -ErrorAction SilentlyContinue) {
$parameters = {
fallback = $scriptBlock;
};
Write-Host "Running Hook ``$Name``";
& "$Name" @parameters;
} elseif ($Fallback) {
Write-Host "Running Default of Hook ``$Name``";
& $scriptBlock;
} else {
Write-Host "Hook ``$Name``";
}
}