From 982aa6ecb23d28a01d8f42eaa9053f0478e5664d Mon Sep 17 00:00:00 2001 From: Tw93 Date: Sat, 21 Mar 2026 19:19:57 +0800 Subject: [PATCH] fix(windows): bypass installer execution policy Refs #612 --- README.md | 10 +++++----- RELEASE.md | 2 +- install.ps1 | 14 +++++++------- quick-install.ps1 | 18 +++++++++++++++++- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index e64deb2..36cb74b 100644 --- a/README.md +++ b/README.md @@ -59,10 +59,10 @@ git clone --branch windows https://github.com/tw93/Mole.git $installDir cd $installDir # Run the installer in place (keeps .git for mo update) -.\install.ps1 -InstallDir $installDir -AddToPath +powershell -ExecutionPolicy Bypass -File .\install.ps1 -InstallDir $installDir -AddToPath # Optional: Create Start Menu shortcut -.\install.ps1 -InstallDir $installDir -AddToPath -CreateShortcut +powershell -ExecutionPolicy Bypass -File .\install.ps1 -InstallDir $installDir -AddToPath -CreateShortcut ``` Run: @@ -280,10 +280,10 @@ Custom scan paths can be configured with `mo purge --paths`. ```powershell # Install to custom location from a cloned windows branch -.\install.ps1 -InstallDir C:\Tools\Mole -AddToPath +powershell -ExecutionPolicy Bypass -File .\install.ps1 -InstallDir C:\Tools\Mole -AddToPath # Create Start Menu shortcut -.\install.ps1 -InstallDir C:\Tools\Mole -AddToPath -CreateShortcut +powershell -ExecutionPolicy Bypass -File .\install.ps1 -InstallDir C:\Tools\Mole -AddToPath -CreateShortcut # Refresh the source channel later mo update @@ -292,7 +292,7 @@ mo update ### Uninstall ```powershell -.\install.ps1 -Uninstall +powershell -ExecutionPolicy Bypass -File .\install.ps1 -Uninstall ``` ## Configuration diff --git a/RELEASE.md b/RELEASE.md index 66b9d83..249203e 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -370,7 +370,7 @@ Expand-Archive release/mole-1.0.0-x64.zip -DestinationPath test-install # Test installation cd test-install/mole-1.0.0-x64 -.\install.ps1 +powershell -ExecutionPolicy Bypass -File .\install.ps1 # Verify mole works mole --version diff --git a/install.ps1 b/install.ps1 index e74bdbe..70c312f 100644 --- a/install.ps1 +++ b/install.ps1 @@ -98,7 +98,7 @@ function Show-InstallerHelp { $c = $script:Colors Write-Host " $($c.Green)USAGE:$($c.NC)" Write-Host "" - Write-Host " .\install.ps1 [options]" + Write-Host " powershell -ExecutionPolicy Bypass -File .\install.ps1 [options]" Write-Host "" Write-Host " $($c.Green)OPTIONS:$($c.NC)" Write-Host "" @@ -118,19 +118,19 @@ function Show-InstallerHelp { Write-Host " $($c.Green)EXAMPLES:$($c.NC)" Write-Host "" Write-Host " $($c.Gray)# Install with defaults$($c.NC)" - Write-Host " .\install.ps1" + Write-Host " powershell -ExecutionPolicy Bypass -File .\install.ps1" Write-Host "" Write-Host " $($c.Gray)# Install and add to PATH$($c.NC)" - Write-Host " .\install.ps1 -AddToPath" + Write-Host " powershell -ExecutionPolicy Bypass -File .\install.ps1 -AddToPath" Write-Host "" Write-Host " $($c.Gray)# Custom install location$($c.NC)" - Write-Host " .\install.ps1 -InstallDir C:\Tools\Mole -AddToPath" + Write-Host " powershell -ExecutionPolicy Bypass -File .\install.ps1 -InstallDir C:\Tools\Mole -AddToPath" Write-Host "" Write-Host " $($c.Gray)# Full installation$($c.NC)" - Write-Host " .\install.ps1 -AddToPath -CreateShortcut" + Write-Host " powershell -ExecutionPolicy Bypass -File .\install.ps1 -AddToPath -CreateShortcut" Write-Host "" Write-Host " $($c.Gray)# Uninstall$($c.NC)" - Write-Host " .\install.ps1 -Uninstall" + Write-Host " powershell -ExecutionPolicy Bypass -File .\install.ps1 -Uninstall" Write-Host "" } @@ -403,7 +403,7 @@ powershell.exe -ExecutionPolicy Bypass -NoLogo -NoProfile -Command "& '%MOLE_DIR Write-Host " & `"$InstallDir\mole.ps1`"" Write-Host "" Write-Host " Or add to PATH with:" - Write-Host " .\install.ps1 -AddToPath" + Write-Host " powershell -ExecutionPolicy Bypass -File .\install.ps1 -AddToPath" } Write-Host "" diff --git a/quick-install.ps1 b/quick-install.ps1 index bfaf9d8..5477bff 100644 --- a/quick-install.ps1 +++ b/quick-install.ps1 @@ -80,6 +80,18 @@ function Invoke-GitCommand { } } +function Get-PowerShellCommand { + if (Get-Command powershell.exe -ErrorAction SilentlyContinue) { + return "powershell.exe" + } + + if (Get-Command pwsh -ErrorAction SilentlyContinue) { + return "pwsh" + } + + throw "PowerShell executable not found" +} + # Main installation try { Write-Host "" @@ -150,7 +162,11 @@ try { Write-Step "Running installer..." Write-Host "" - & (Join-Path $InstallDir "install.ps1") -InstallDir $InstallDir -AddToPath + $powerShellCommand = Get-PowerShellCommand + & $powerShellCommand -NoLogo -NoProfile -ExecutionPolicy Bypass -File (Join-Path $InstallDir "install.ps1") -InstallDir $InstallDir -AddToPath + if ($LASTEXITCODE -ne 0) { + throw "Installer exited with code $LASTEXITCODE" + } Write-Host "" Write-Success "Installation complete!"