chocolatey / cChoco

Community resource to manage Chocolatey
Apache License 2.0
154 stars 99 forks source link

Latest install.ps1 breaks cChocoInstaller DSC resource #181

Closed bozho closed 10 months ago

bozho commented 10 months ago

Checklist

What You Are Seeing?

Hi,

I am unable to find source code for install.ps1 script, so I decided to post here. Please point me to the right repo if this is not the correct one.

We're using cChoco DSC module v2.5.0 (the latest one) to install Chocolatey and manage packages. As of today (or the last few days), it looks like the official install script (https://community.chocolatey.org/install.ps1) doesn't work with cChocoInstaller DSC resource.

When the resource runs on a new machine with no Chocolatey installed, the resource runs the official script, which aborts with the warning about Chocolatey being installed:

WARNING: An existing Chocolatey installation was detected. Installation will not continue. This script will not
overwrite existing installations.
If there is no Chocolatey installation at 'C:\ProgramData\chocolatey', delete the folder and attempt the installation
again.

Please use choco upgrade chocolatey to handle upgrades of Chocolatey itself.
If the existing installation is not functional or a prior installation did not complete, follow these steps:
 - Backup the files at the path listed above so you can restore your previous installation if needed.
 - Remove the existing installation manually.
 - Rerun this installation script.
 - Reinstall any packages previously installed, if needed (refer to the lib folder in the backup).

Once installation is completed, the backup folder is no longer needed and can be deleted.

I had a look at the code for both cChocoInstaller and install.ps1 script and there seems to be a bit of a clash in logic: cChocoInstaller resource will create an empty installation dir in Install-Chocolatey cmdlet before executing install.ps1.

However, Test-ChocolateyInstalled cmdlet in the install.ps1 script will return $true if the install directory exists, even if it's empty (at the time of this writing, lines 322-330, the else clause).

Ideally, both projects could be patched to avoid this kind of issue in the future: there's no need for cChocoInstaller to create an empty install directory (the installer script is supposed to do that). And the install script should be ok with the install directory existing if it's empty (the one corner case here would be if there are two concurrent install scripts running on the system and we get into a bit of a race condition).

What is Expected?

cChocoInstaller resource to install Chocolatey on a fresh system.

How Did You Get This To Happen?

  1. Provision a new Windows machine or uninstall Chocolatey.
  2. Run DSC configuration with cChocoInstaller DSC resource.
  3. Observe it fail.

System Details

Installed Packages

none

Output Log

WARNING: An existing Chocolatey installation was detected. Installation will not continue. This script will not
overwrite existing installations.
If there is no Chocolatey installation at 'C:\ProgramData\chocolatey', delete the folder and attempt the installation
again.

Please use choco upgrade chocolatey to handle upgrades of Chocolatey itself.
If the existing installation is not functional or a prior installation did not complete, follow these steps:
 - Backup the files at the path listed above so you can restore your previous installation if needed.
 - Remove the existing installation manually.
 - Rerun this installation script.
 - Reinstall any packages previously installed, if needed (refer to the lib folder in the backup).

Once installation is completed, the backup folder is no longer needed and can be deleted.


### Additional Context

_No response_
pauby commented 10 months ago

This is in the wrong repository (this repository is for Chocolatey CLI) so I 've transferred it over. It is also a duplicate of #179