Skip to content

Commit 765a0ca

Browse files
authoredFeb 27, 2025··
Update install-aishell.ps1 to allow user to specify version to install (#345)
- Make packaging throw on Linux/macOS when the command `chmod` cannot be found - Update `install-aishell.ps1` to allow user to specify version to install. When version is not specified, the latest release will be installed.
1 parent b6b9c18 commit 765a0ca

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed
 

‎tools/packaging/packaging.psm1

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ function New-TarballPackage
155155

156156
$permission = Get-ChildItem $executable | ForEach-Object UnixFileMode
157157
Write-Verbose "File permission: $permission" -Verbose
158+
} else {
159+
throw "Failed to create the package because the application 'chmod' cannot be found"
158160
}
159161

160162
if (Get-Command -Name tar -CommandType Application -ErrorAction Ignore) {

‎tools/scripts/install-aishell.ps1

+46-7
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33

44
#Requires -Version 7.4.6
55

6+
[CmdletBinding(DefaultParameterSetName = "Install")]
67
param(
7-
[Parameter(HelpMessage = "Specify this parameter to uninstall AI Shell")]
8+
[Parameter(HelpMessage = "Specify the version to install, e.g. 'v1.0.0-preview.2'", ParameterSetName = "Install")]
9+
[ValidatePattern("^v\d+\.\d+\.\d+(-\w+\.\d{1,2})?$")]
10+
[string] $Version,
11+
12+
[Parameter(HelpMessage = "Specify this parameter to uninstall AI Shell", ParameterSetName = "Uninstall")]
813
[switch] $Uninstall
914
)
1015

@@ -13,6 +18,7 @@ $Script:MacInstallationLocation = "/usr/local/AIShell"
1318
$Script:WinInstallationLocation = "$env:LOCALAPPDATA\Programs\AIShell"
1419
$Script:InstallLocation = $null
1520
$Script:PackageURL = $null
21+
$Script:ModuleVersion = $null
1622

1723
function Resolve-Environment {
1824
if ($PSVersionTable.PSVersion -lt [version]"7.4.6") {
@@ -22,19 +28,41 @@ function Resolve-Environment {
2228
throw "Sorry, this install script is only compatible with Windows and macOS. If you want to install on Linux, please download the package directly from the GitHub repo at aka.ms/AIShell-Repo."
2329
}
2430

25-
($platShortName, $platFullName, $pkgExt, $location) = if ($IsWindows) {
31+
($platShortName, $platFullName, $pkgExt, $Script:InstallLocation) = if ($IsWindows) {
2632
'win', 'Windows', 'zip', $Script:WinInstallationLocation
2733
} else {
2834
'osx', 'macOS', 'tar.gz', $Script:MacInstallationLocation
2935
}
3036

37+
if ($Uninstall) {
38+
return
39+
}
40+
3141
$architecture = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString()
3242
if ($architecture -notin @('X86', 'X64', 'Arm64')) {
3343
throw "AI Shell doesn't support the $architecture architecture on $platFullName."
3444
}
3545

36-
$Script:InstallLocation = $location
37-
$Script:PackageURL = "https://github.com/PowerShell/AIShell/releases/download/v1.0.0-preview.1/AIShell-1.0.0-preview.1-${platShortName}-$($architecture.ToLower()).${pkgExt}"
46+
$tags = (Invoke-RestMethod -Uri "https://api.github.com/repos/PowerShell/AIShell/tags" -ErrorAction Stop).name
47+
if ($Version -and $Version -notin $tags) {
48+
throw "The specified version '$Version' doesn't exist. Available versions are: $($tags -join ', ')"
49+
}
50+
51+
$tagToUse = [string]::IsNullOrEmpty($Version) ? $tags[0] : $Version
52+
$appVersion = $tagToUse.TrimStart('v')
53+
54+
$Script:PackageURL = "https://github.com/PowerShell/AIShell/releases/download/${tagToUse}/AIShell-${appVersion}-${platShortName}-$($architecture.ToLower()).${pkgExt}"
55+
56+
$dashIndex = $appVersion.IndexOf('-')
57+
$Script:ModuleVersion = if ($dashIndex -eq -1) {
58+
## The mapping between module version and the app version is not clear yet.
59+
throw "Not implemented for stable releases."
60+
} else {
61+
$previewLabel = $appVersion.Substring($dashIndex + 1)
62+
$previewDigit = $previewLabel.Substring($previewLabel.LastIndexOf('.') + 1)
63+
$patchDotIndex = $appVersion.LastIndexOf('.', $dashIndex)
64+
$appVersion.Substring(0, $patchDotIndex) + ".$previewDigit-" + $previewLabel.Replace('.', '')
65+
}
3866
}
3967

4068
function Install-AIShellApp {
@@ -148,6 +176,16 @@ function Uninstall-AIShellApp {
148176
Join-String -Separator ';'
149177
[Environment]::SetEnvironmentVariable("Path", $newUserPath, [EnvironmentVariableTarget]::User)
150178
}
179+
180+
# Update the process-scope Path env variables to remove AIShell.
181+
$procPath = $env:Path
182+
if ($procPath.Contains($destination)) {
183+
Write-Host "Removing AI Shell app from the process-scope Path environment variable ..."
184+
$newProcPath = $procPath.Split(';', [StringSplitOptions]::RemoveEmptyEntries -bor [StringSplitOptions]::TrimEntries) |
185+
Where-Object { $_ -ne $destination } |
186+
Join-String -Separator ';'
187+
$env:Path = $newProcPath
188+
}
151189
} else {
152190
sudo rm -rf $destination
153191
if ($LASTEXITCODE -ne 0) {
@@ -167,8 +205,9 @@ function Uninstall-AIShellApp {
167205

168206
function Install-AIShellModule {
169207
if ($IsWindows) {
170-
Write-Host "Installing the PowerShell module 'AIShell' ..."
171-
Install-PSResource -Name AIShell -Repository PSGallery -Prerelease -TrustRepository -ErrorAction Stop -WarningAction SilentlyContinue
208+
$modVersion = $Script:ModuleVersion
209+
Write-Host "Installing the PowerShell module 'AIShell' $modVersion ..."
210+
Install-PSResource -Name AIShell -Repository PSGallery -Prerelease -TrustRepository -Version $modVersion -ErrorAction Stop -WarningAction SilentlyContinue
172211
} else {
173212
Write-Host -ForegroundColor Yellow "Currently the AIShell PowerShell module will only work in iTerm2 terminal and still has limited support but if you would like to test it, you can install it with 'Install-PSResource -Name AIShell -Repository PSGallery -Prerelease'."
174213
Write-Host -ForegroundColor Yellow "The AI Shell app has been added to your path, please run 'aish' to use the standalone experience."
@@ -205,5 +244,5 @@ if ($Uninstall) {
205244
Install-AIShellModule
206245

207246
$message = $IsWindows ? "'Start-AIShell'" : "'aish'"
208-
Write-Host "`nInstallation succeeded. To learn more about AI Shell please visit https://aka.ms/AIShell-Docs. To get started please run $message to start AI Shell." -ForegroundColor Green
247+
Write-Host "`nInstallation succeeded.`nTo learn more about AI Shell please visit https://aka.ms/AIShell-Docs.`nTo get started please run $message to start AI Shell." -ForegroundColor Green
209248
}

0 commit comments

Comments
 (0)
Please sign in to comment.