From 52fbd12f0e9dd0327395249382b4b01afc7bea3d Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Tue, 20 Jun 2023 21:10:08 -0700 Subject: [PATCH] Use advanced function for install script Required to use the clean block (interrupt trap) --- install.ps1 | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/install.ps1 b/install.ps1 index 941a204..7fbd6db 100644 --- a/install.ps1 +++ b/install.ps1 @@ -1,14 +1,24 @@ -# Create a temporary working folder -$tempFolder = Join-Path $Env:Temp $(New-Guid) -New-Item -Type Directory -Path $tempFolder | Out-Null +function Install-ArdisUtilities { + begin { + # Create a temporary working folder + $tempFolder = Join-Path $Env:Temp $(New-Guid) + New-Item -Type Directory -Path $tempFolder | Out-Null + } -# Download and extract the repository from GitHub -$zipFile = Join-Path $tempFolder /ArdisUtilities.zip -Invoke-WebRequest 'https://github.com/ardislu/ArdisUtilities/archive/refs/heads/main.zip' -OutFile $zipFile -Expand-Archive $zipFile $tempFolder + process { + # Download and extract the repository from GitHub + $zipFile = Join-Path $tempFolder /ArdisUtilities.zip + Invoke-WebRequest 'https://github.com/ardislu/ArdisUtilities/archive/refs/heads/main.zip' -OutFile $zipFile + Expand-Archive $zipFile $tempFolder -# Import the module from the extraction -Import-Module (Join-Path $tempFolder /ArdisUtilities-main/ArdisUtilities) + # Import the module from the extraction + Import-Module (Join-Path $tempFolder /ArdisUtilities-main/ArdisUtilities) + } -# Clean up the temporary folder -Remove-Item $tempFolder -Force -Recurse + clean { + # Clean up the temporary folder + Remove-Item $tempFolder -Force -Recurse + } +} + +Install-ArdisUtilities -- 2.47.3