From c3cb01fa7af64f4dc8177db8610573e42a0e1763 Mon Sep 17 00:00:00 2001 From: Laura Rodriguez Date: Mon, 5 Feb 2024 13:12:01 -0500 Subject: [PATCH] Add Chocolatey files. --- nuspec/chocolatey/okta-aws-cli.nuspec | 25 ++++++ nuspec/chocolatey/tools/chocolateyinstall.ps1 | 31 ++++++++ .../chocolatey/tools/chocolateyuninstall.ps1 | 78 +++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 nuspec/chocolatey/okta-aws-cli.nuspec create mode 100644 nuspec/chocolatey/tools/chocolateyinstall.ps1 create mode 100644 nuspec/chocolatey/tools/chocolateyuninstall.ps1 diff --git a/nuspec/chocolatey/okta-aws-cli.nuspec b/nuspec/chocolatey/okta-aws-cli.nuspec new file mode 100644 index 0000000..a3c3eb7 --- /dev/null +++ b/nuspec/chocolatey/okta-aws-cli.nuspec @@ -0,0 +1,25 @@ + + + + + okta-aws-cli + 2.0.1 + Okta, Inc. + Okta AWS CLI (Install) + Okta + https://github.com/okta/okta-aws-cli/tree/master/nuspec/chocolatey + https://github.com/okta/okta-aws-cli + https://cdn.brandfolder.io/R30ALRIS/at/mtg52xxxcr939z2ns8jrg3mz/Okta_Aura_CMYK_Black.png + 2024-Present Okta, Inc. + https://github.com/okta/okta-aws-cli/blob/master/LICENSE.md + true + okta-aws-cli okta aws cli oauth oauth2 + A CLI for having Okta as the IdP for AWS CLI operations + A CLI for having Okta as the IdP for AWS CLI operations + https://github.com/okta/okta-aws-cli/releases + + + + + + diff --git a/nuspec/chocolatey/tools/chocolateyinstall.ps1 b/nuspec/chocolatey/tools/chocolateyinstall.ps1 new file mode 100644 index 0000000..39da834 --- /dev/null +++ b/nuspec/chocolatey/tools/chocolateyinstall.ps1 @@ -0,0 +1,31 @@ + +$ErrorActionPreference = 'Stop' +$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" +$url = 'https://github.com/okta/okta-aws-cli/releases/download/v2.0.1/okta-aws-cli_2.0.1_windows_386.zip' + +$packageArgs = @{ + packageName = $env:ChocolateyPackageName + unzipLocation = $toolsDir + url = $url + checksum = 'F05862D42BF14133EFA88C9F77C0AB942858CA0FFDE980D0615395E8E48FD4D6' + checksumType = 'sha256' +} + +Install-ChocolateyZipPackage @packageArgs + + + + + + + + + + + + + + + + + diff --git a/nuspec/chocolatey/tools/chocolateyuninstall.ps1 b/nuspec/chocolatey/tools/chocolateyuninstall.ps1 new file mode 100644 index 0000000..cbc0f9b --- /dev/null +++ b/nuspec/chocolatey/tools/chocolateyuninstall.ps1 @@ -0,0 +1,78 @@ +# IMPORTANT: Before releasing this package, copy/paste the next 2 lines into PowerShell to remove all comments from this file: +# $f='c:\path\to\thisFile.ps1' +# gc $f | ? {$_ -notmatch "^\s*#"} | % {$_ -replace '(^.*?)\s*?[^``]#.*','$1'} | Out-File $f+".~" -en utf8; mv -fo $f+".~" $f + +## NOTE: In 80-90% of the cases (95% with licensed versions due to Package Synchronizer and other enhancements), +## AutoUninstaller should be able to detect and handle registry uninstalls without a chocolateyUninstall.ps1. +## See https://docs.chocolatey.org/en-us/choco/commands/uninstall +## and https://docs.chocolatey.org/en-us/create/functions/uninstall-chocolateypackage + +## If this is an MSI, ensure 'softwareName' is appropriate, then clean up comments and you are done. +## If this is an exe, change fileType, silentArgs, and validExitCodes + +$ErrorActionPreference = 'Stop' # stop on all errors +$packageArgs = @{ + packageName = $env:ChocolateyPackageName + softwareName = 'okta-aws-cli*' #part or all of the Display Name as you see it in Programs and Features. It should be enough to be unique + fileType = 'EXE_MSI_OR_MSU' #only one of these: MSI or EXE (ignore MSU for now) + # MSI + silentArgs = "/qn /norestart" + validExitCodes= @(0, 3010, 1605, 1614, 1641) # https://msdn.microsoft.com/en-us/library/aa376931(v=vs.85).aspx + # OTHERS + # Uncomment matching EXE type (sorted by most to least common) + #silentArgs = '/S' # NSIS + #silentArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-' # Inno Setup + #silentArgs = '/s' # InstallShield + #silentArgs = '/s /v"/qn"' # InstallShield with MSI + #silentArgs = '/s' # Wise InstallMaster + #silentArgs = '-s' # Squirrel + #silentArgs = '-q' # Install4j + #silentArgs = '-s -u' # Ghost + # Note that some installers, in addition to the silentArgs above, may also need assistance of AHK to achieve silence. + #silentArgs = '' # none; make silent with input macro script like AutoHotKey (AHK) + # https://community.chocolatey.org/packages/autohotkey.portable + #validExitCodes= @(0) #please insert other valid exit codes here +} + +[array]$key = Get-UninstallRegistryKey -SoftwareName $packageArgs['softwareName'] + +if ($key.Count -eq 1) { + $key | % { + $packageArgs['file'] = "$($_.UninstallString)" #NOTE: You may need to split this if it contains spaces, see below + + if ($packageArgs['fileType'] -eq 'MSI') { + # The Product Code GUID is all that should be passed for MSI, and very + # FIRST, because it comes directly after /x, which is already set in the + # Uninstall-ChocolateyPackage msiargs (facepalm). + $packageArgs['silentArgs'] = "$($_.PSChildName) $($packageArgs['silentArgs'])" + + # Don't pass anything for file, it is ignored for msi (facepalm number 2) + # Alternatively if you need to pass a path to an msi, determine that and + # use it instead of the above in silentArgs, still very first + $packageArgs['file'] = '' + } else { + # NOTES: + # - You probably will need to sanitize $packageArgs['file'] as it comes from the registry and could be in a variety of fun but unusable formats + # - Split args from exe in $packageArgs['file'] and pass those args through $packageArgs['silentArgs'] or ignore them + # - Ensure you don't pass double quotes in $file (aka $packageArgs['file']) - otherwise you will get "Illegal characters in path when you attempt to run this" + # - Review the code for auto-uninstaller for all of the fun things it does in sanitizing - https://github.com/chocolatey/choco/blob/bfe351b7d10c798014efe4bfbb100b171db25099/src/chocolatey/infrastructure.app/services/AutomaticUninstallerService.cs#L142-L192 + } + + Uninstall-ChocolateyPackage @packageArgs + } +} elseif ($key.Count -eq 0) { + Write-Warning "$packageName has already been uninstalled by other means." +} elseif ($key.Count -gt 1) { + Write-Warning "$($key.Count) matches found!" + Write-Warning "To prevent accidental data loss, no programs will be uninstalled." + Write-Warning "Please alert package maintainer the following keys were matched:" + $key | % {Write-Warning "- $($_.DisplayName)"} +} + +## OTHER POWERSHELL FUNCTIONS +## https://docs.chocolatey.org/en-us/create/functions +#Uninstall-ChocolateyZipPackage $packageName # Only necessary if you did not unpack to package directory - see https://docs.chocolatey.org/en-us/create/functions/uninstall-chocolateyzippackage +#Uninstall-ChocolateyEnvironmentVariable - https://docs.chocolatey.org/en-us/create/functions/uninstall-chocolateyenvironmentvariable +#Uninstall-BinFile # Only needed if you used Install-BinFile - see https://docs.chocolatey.org/en-us/create/functions/uninstall-binfile +## Remove any shortcuts you added in the install script. +