From 3b3ea75b7ed0856d810828794dbb12b7ca96f5b8 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Mon, 13 Apr 2015 09:23:56 -0500 Subject: [PATCH 01/22] (GH-237) Remove warning for allowGlobalConfirmation Most folks know they have allowGlobalConfirmation set, this warning doesn't really add to the experience. It's mostly an annoyance for some folks. --- .../builders/ConfigurationBuilder.cs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs index aea4d41cae..a566ea866f 100644 --- a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs +++ b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs @@ -101,20 +101,6 @@ private static void set_file_configuration(ChocolateyConfiguration config, IFile config.CommandExecutionTimeoutSeconds = configFileSettings.CommandExecutionTimeoutSeconds; set_feature_flags(config, configFileSettings); - if (!config.PromptForConfirmation) - { - if (notifyWarnLoggingAction != null) - { - const string logMessage = @" -Config has insecure allowGlobalConfirmation set to true. - This setting lowers the integrity of the security of your system. If - this is not intended, please change the setting using the feature - command. -"; - notifyWarnLoggingAction.Invoke(logMessage); - } - } - // save so all updated configuration items get set to existing config FaultTolerance.try_catch_with_logging_exception( From 1baa1ffaec107fff896cd6a2cf60d52b8908e87a Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Mon, 13 Apr 2015 10:39:10 -0500 Subject: [PATCH 02/22] (GH-160) No admin warning unless command request Do not issue an administrator warning with a pause unless the command being run requests that it may need administrative rights. --- src/chocolatey.console/Program.cs | 25 --------------- .../commands/ChocolateyApiKeyCommand.cs | 5 +++ .../commands/ChocolateyFeatureCommand.cs | 5 +++ .../commands/ChocolateyInstallCommand.cs | 5 +++ .../commands/ChocolateyListCommand.cs | 5 +++ .../commands/ChocolateyNewCommand.cs | 5 +++ .../commands/ChocolateyPackCommand.cs | 5 +++ .../commands/ChocolateyPinCommand.cs | 5 +++ .../commands/ChocolateyPushCommand.cs | 5 +++ .../commands/ChocolateySourceCommand.cs | 5 +++ .../commands/ChocolateyUninstallCommand.cs | 5 +++ .../commands/ChocolateyUnpackSelfCommand.cs | 5 +++ .../commands/ChocolateyUpgradeCommand.cs | 5 +++ .../runners/GenericRunner.cs | 31 ++++++++++++++++++- .../infrastructure/commands/ICommand.cs | 6 ++++ 15 files changed, 96 insertions(+), 26 deletions(-) diff --git a/src/chocolatey.console/Program.cs b/src/chocolatey.console/Program.cs index 67f50cc3f1..ab64b5bf0d 100644 --- a/src/chocolatey.console/Program.cs +++ b/src/chocolatey.console/Program.cs @@ -102,7 +102,6 @@ private static void Main(string[] args) "chocolatey".Log().Debug(() => "{0} is running on {1} v {2}".format_with(ApplicationParameters.Name, config.Information.PlatformType, config.Information.PlatformVersion.to_string())); //"chocolatey".Log().Debug(() => "Command Line: {0}".format_with(Environment.CommandLine)); - warn_when_admin_needs_elevation(config); remove_old_chocolatey_exe(fileSystem); LicenseValidation.validate(fileSystem); @@ -180,30 +179,6 @@ private static void trap_exit_scenarios(ChocolateyConfiguration config) ExitScenarioHandler.SetHandler(); } - private static void warn_when_admin_needs_elevation(ChocolateyConfiguration config) - { - // NOTE: blended options may not have been fully initialized yet - if (!config.PromptForConfirmation) return; - - if (!config.Information.IsProcessElevated && config.Information.IsUserAdministrator) - { - var selection = InteractivePrompt.prompt_for_confirmation(@" -Chocolatey detected you are not running from an elevated command shell - (cmd/powershell). You may experience errors - many functions/packages - require admin rights. Only advanced users should run choco w/out an - elevated shell. When you open the command shell, you should ensure - that you do so with ""Run as Administrator"" selected. - - Do you want to continue?", new[] {"yes", "no"}, "no", requireAnswer: true); - - if (selection.is_equal_to("no")) - { - pause_execution_if_debug(); - Environment.Exit(-1); - } - } - } - private static void remove_old_chocolatey_exe(IFileSystem fileSystem) { try diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyApiKeyCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyApiKeyCommand.cs index 9264bf96c0..cc8fa00867 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyApiKeyCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyApiKeyCommand.cs @@ -127,5 +127,10 @@ public void run(ChocolateyConfiguration configuration) _configSettingsService.set_api_key(configuration); } } + + public bool may_require_admin_access() + { + return true; + } } } \ No newline at end of file diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyFeatureCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyFeatureCommand.cs index 3353fb84af..ee6d060d94 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyFeatureCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyFeatureCommand.cs @@ -120,5 +120,10 @@ public void run(ChocolateyConfiguration configuration) break; } } + + public bool may_require_admin_access() + { + return true; + } } } \ No newline at end of file diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs index c2b8af1969..df9a659400 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs @@ -165,5 +165,10 @@ public void run(ChocolateyConfiguration configuration) { _packageService.install_run(configuration); } + + public bool may_require_admin_access() + { + return true; + } } } \ No newline at end of file diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs index cd5b0af76b..bac6eebea1 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs @@ -109,5 +109,10 @@ public void run(ChocolateyConfiguration configuration) { _packageService.list_run(configuration, logResults: true); } + + public bool may_require_admin_access() + { + return false; + } } } diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyNewCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyNewCommand.cs index fa9bd065ab..2f42b938d2 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyNewCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyNewCommand.cs @@ -143,5 +143,10 @@ public void run(ChocolateyConfiguration configuration) { _templateService.generate(configuration); } + + public bool may_require_admin_access() + { + return false; + } } } \ No newline at end of file diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyPackCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyPackCommand.cs index 4e04db7e97..adfac294f7 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyPackCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyPackCommand.cs @@ -86,5 +86,10 @@ public void run(ChocolateyConfiguration configuration) { _packageService.pack_run(configuration); } + + public bool may_require_admin_access() + { + return false; + } } } diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyPinCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyPinCommand.cs index 4c30d38998..ef000500e3 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyPinCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyPinCommand.cs @@ -165,5 +165,10 @@ public void set_pin(IPackageManager packageManager, ChocolateyConfiguration conf pkgInfo.IsPinned = config.PinCommand.Command == PinCommandType.add; _packageInfoService.save_package_information(pkgInfo); } + + public bool may_require_admin_access() + { + return true; + } } } \ No newline at end of file diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyPushCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyPushCommand.cs index cb36695b79..5de65894f2 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyPushCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyPushCommand.cs @@ -177,5 +177,10 @@ public void run(ChocolateyConfiguration configuration) { _packageService.push_run(configuration); } + + public bool may_require_admin_access() + { + return false; + } } } \ No newline at end of file diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs index eafdcac8f4..773c3b5bbe 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs @@ -139,5 +139,10 @@ public void run(ChocolateyConfiguration configuration) break; } } + + public bool may_require_admin_access() + { + return true; + } } } \ No newline at end of file diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyUninstallCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyUninstallCommand.cs index 2cea4a1408..e1e4134a57 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyUninstallCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyUninstallCommand.cs @@ -130,5 +130,10 @@ public void run(ChocolateyConfiguration configuration) { _packageService.uninstall_run(configuration); } + + public bool may_require_admin_access() + { + return true; + } } } \ No newline at end of file diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyUnpackSelfCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyUnpackSelfCommand.cs index abfc0247f3..49c257fc76 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyUnpackSelfCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyUnpackSelfCommand.cs @@ -104,5 +104,10 @@ public void run(ChocolateyConfiguration configuration) overwriteExisting: configuration.Force, logOutput: true); } + + public bool may_require_admin_access() + { + return true; + } } } \ No newline at end of file diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs index 2f352bad7f..b202eade8d 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs @@ -140,5 +140,10 @@ public virtual void run(ChocolateyConfiguration configuration) { _packageService.upgrade_run(configuration); } + + public bool may_require_admin_access() + { + return true; + } } } \ No newline at end of file diff --git a/src/chocolatey/infrastructure.app/runners/GenericRunner.cs b/src/chocolatey/infrastructure.app/runners/GenericRunner.cs index a30499d330..d0e69fcc78 100644 --- a/src/chocolatey/infrastructure.app/runners/GenericRunner.cs +++ b/src/chocolatey/infrastructure.app/runners/GenericRunner.cs @@ -20,6 +20,7 @@ namespace chocolatey.infrastructure.app.runners using SimpleInjector; using adapters; using attributes; + using commandline; using configuration; using infrastructure.commands; using logging; @@ -49,6 +50,11 @@ public void run(ChocolateyConfiguration config, Container container, bool isCons } else { + if (command.may_require_admin_access()) + { + warn_when_admin_needs_elevation(config); + } + if (parseArgs != null) { parseArgs.Invoke(command); @@ -104,6 +110,29 @@ now be in a bad state. Only official builds are to be trusted. } } } - } + public void warn_when_admin_needs_elevation(ChocolateyConfiguration config) + { + // NOTE: blended options may not have been fully initialized yet + if (!config.PromptForConfirmation) return; + + if (!config.Information.IsProcessElevated && config.Information.IsUserAdministrator) + { + var selection = InteractivePrompt.prompt_for_confirmation(@" +Chocolatey detected you are not running from an elevated command shell + (cmd/powershell). You may experience errors - many functions/packages + require admin rights. Only advanced users should run choco w/out an + elevated shell. When you open the command shell, you should ensure + that you do so with ""Run as Administrator"" selected. + + Do you want to continue?", new[] { "yes", "no" }, "no", requireAnswer: true); + + if (selection.is_equal_to("no")) + { + Environment.Exit(-1); + } + } + } + + } } \ No newline at end of file diff --git a/src/chocolatey/infrastructure/commands/ICommand.cs b/src/chocolatey/infrastructure/commands/ICommand.cs index 1efa93447c..abd958a4d7 100644 --- a/src/chocolatey/infrastructure/commands/ICommand.cs +++ b/src/chocolatey/infrastructure/commands/ICommand.cs @@ -57,5 +57,11 @@ public interface ICommand /// /// The configuration. void run(ChocolateyConfiguration config); + + /// + /// This command may require admin rights + /// + /// + bool may_require_admin_access(); } } \ No newline at end of file From 1c9ce4c8295873b29d8aa1019f724f493aa7dbf7 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Mon, 13 Apr 2015 10:48:13 -0500 Subject: [PATCH 03/22] (GH-169) Do not resolve disabled sources --- .../infrastructure.app/builders/ConfigurationBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs index a566ea866f..413e204221 100644 --- a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs +++ b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs @@ -73,7 +73,7 @@ private static void set_file_configuration(ChocolateyConfiguration config, IFile var configFileSettings = xmlService.deserialize(globalConfigPath); var sources = new StringBuilder(); - foreach (var source in configFileSettings.Sources.or_empty_list_if_null()) + foreach (var source in configFileSettings.Sources.Where(s => !s.Disabled).or_empty_list_if_null()) { sources.AppendFormat("{0};", source.Value); } From 346c050025dc4c51800cc8cd4985d81710c40ebb Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Mon, 13 Apr 2015 10:48:28 -0500 Subject: [PATCH 04/22] (maint) formatting --- .../infrastructure.app/builders/ConfigurationBuilder.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs index 413e204221..169634b13a 100644 --- a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs +++ b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs @@ -89,9 +89,9 @@ private static void set_file_configuration(ChocolateyConfiguration config, IFile } FaultTolerance.try_catch_with_logging_exception( - () => fileSystem.create_directory_if_not_exists(config.CacheLocation), - "Could not create temp directory at '{0}'".format_with(config.CacheLocation), - logWarningInsteadOfError: true); + () => fileSystem.create_directory_if_not_exists(config.CacheLocation), + "Could not create temp directory at '{0}'".format_with(config.CacheLocation), + logWarningInsteadOfError: true); config.ContainsLegacyPackageInstalls = configFileSettings.ContainsLegacyPackageInstalls; if (configFileSettings.CommandExecutionTimeoutSeconds <= 0) From e683783c8dea86537f9c3b493a5d3033fad360d8 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Mon, 13 Apr 2015 10:56:49 -0500 Subject: [PATCH 05/22] (GH-187) Show log file path in messages. When including the message "See the log for details", be sure to include the path to the log file. --- .../services/ChocolateyPackageService.cs | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index 98739afff8..b13f221387 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -241,13 +241,15 @@ public ConcurrentDictionary install_run(ChocolateyConfigu var installFailures = packageInstalls.Count(p => !p.Value.Success); var installWarnings = packageInstalls.Count(p => p.Value.Warning); - this.Log().Warn(() => @"{0}{1} installed {2}/{3} package(s). {4} package(s) failed.{5}{0} See the log for details.".format_with( + this.Log().Warn(() => @"{0}{1} installed {2}/{3} package(s). {4} package(s) failed.{5}{0} See the log for details ({6}).".format_with( Environment.NewLine, ApplicationParameters.Name, packageInstalls.Count(p => p.Value.Success && !p.Value.Inconclusive), packageInstalls.Count, installFailures, - installWarnings == 0 ? string.Empty : "{0} {1} package(s) had warnings.".format_with(Environment.NewLine, installWarnings))); + installWarnings == 0 ? string.Empty : "{0} {1} package(s) had warnings.".format_with(Environment.NewLine, installWarnings), + _fileSystem.combine_paths(ApplicationParameters.LoggingLocation,ApplicationParameters.LoggingFile) + )); if (installWarnings != 0) { @@ -333,12 +335,14 @@ public void upgrade_noop(ChocolateyConfiguration config) if (config.RegularOutput) { var upgradeWarnings = noopUpgrades.Count(p => p.Value.Warning); - this.Log().Warn(() => @"{0}{1} can upgrade {2}/{3} package(s). {4}{0} See the log for details.".format_with( + this.Log().Warn(() => @"{0}{1} can upgrade {2}/{3} package(s). {4}{0} See the log for details ({5}).".format_with( Environment.NewLine, ApplicationParameters.Name, noopUpgrades.Count(p => p.Value.Success && !p.Value.Inconclusive), noopUpgrades.Count, - upgradeWarnings == 0 ? string.Empty : "{0} {1} package(s) had warnings.".format_with(Environment.NewLine, upgradeWarnings))); + upgradeWarnings == 0 ? string.Empty : "{0} {1} package(s) had warnings.".format_with(Environment.NewLine, upgradeWarnings), + _fileSystem.combine_paths(ApplicationParameters.LoggingLocation, ApplicationParameters.LoggingFile) + )); if (upgradeWarnings != 0) { @@ -371,13 +375,15 @@ public ConcurrentDictionary upgrade_run(ChocolateyConfigu var upgradeFailures = packageUpgrades.Count(p => !p.Value.Success); var upgradeWarnings = packageUpgrades.Count(p => p.Value.Warning); - this.Log().Warn(() => @"{0}{1} upgraded {2}/{3} package(s). {4} package(s) failed.{5}{0} See the log for details.".format_with( + this.Log().Warn(() => @"{0}{1} upgraded {2}/{3} package(s). {4} package(s) failed.{5}{0} See the log for details ({6}).".format_with( Environment.NewLine, ApplicationParameters.Name, packageUpgrades.Count(p => p.Value.Success && !p.Value.Inconclusive), packageUpgrades.Count, upgradeFailures, - upgradeWarnings == 0 ? string.Empty : "{0} {1} package(s) had warnings.".format_with(Environment.NewLine, upgradeWarnings))); + upgradeWarnings == 0 ? string.Empty : "{0} {1} package(s) had warnings.".format_with(Environment.NewLine, upgradeWarnings), + _fileSystem.combine_paths(ApplicationParameters.LoggingLocation, ApplicationParameters.LoggingFile) + )); if (upgradeWarnings != 0) { @@ -453,12 +459,14 @@ public ConcurrentDictionary uninstall_run(ChocolateyConfi }); var uninstallFailures = packageUninstalls.Count(p => !p.Value.Success); - this.Log().Warn(() => @"{0}{1} uninstalled {2}/{3} packages. {4} packages failed.{0}See the log for details.".format_with( + this.Log().Warn(() => @"{0}{1} uninstalled {2}/{3} packages. {4} packages failed.{0} See the log for details ({5}).".format_with( Environment.NewLine, ApplicationParameters.Name, packageUninstalls.Count(p => p.Value.Success && !p.Value.Inconclusive), packageUninstalls.Count, - uninstallFailures)); + uninstallFailures, + _fileSystem.combine_paths(ApplicationParameters.LoggingLocation, ApplicationParameters.LoggingFile) + )); if (uninstallFailures != 0) { From 1ffd4e04dc3a89cc0177e9219b13dd5ad85f3a66 Mon Sep 17 00:00:00 2001 From: Christian Rondeau Date: Tue, 31 Mar 2015 22:45:21 -0400 Subject: [PATCH 06/22] (GH-182) Ask before printing ps1 scripts --- .../services/PowershellService.cs | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/chocolatey/infrastructure.app/services/PowershellService.cs b/src/chocolatey/infrastructure.app/services/PowershellService.cs index ef4f79aa9d..aa60a83f1e 100644 --- a/src/chocolatey/infrastructure.app/services/PowershellService.cs +++ b/src/chocolatey/infrastructure.app/services/PowershellService.cs @@ -217,16 +217,19 @@ public bool run_action(ChocolateyConfiguration configuration, PackageResult pack if (!shouldRun) { - this.Log().Info(ChocolateyLoggers.Important, () => " Found '{0}':".format_with(_fileSystem.get_file_name(chocoPowerShellScript))); - this.Log().Info(() => "{0}{1}{0}".format_with(Environment.NewLine, chocoPowerShellScriptContents.escape_curly_braces())); - var selection = InteractivePrompt - .prompt_for_confirmation(@" -Do you want to run the script? - NOTE: If you choose not to run the script, the installation will - fail. - Skip is an advanced option and most likely will never be wanted. -" - , new[] {"yes", "no", "skip"}, "no", requireAnswer: true); + this.Log().Info(ChocolateyLoggers.Important, () => "The package {0} wants to run '{1}'.".format_with(package.Id, _fileSystem.get_file_name(chocoPowerShellScript))); + this.Log().Info(ChocolateyLoggers.Important, () => "Note: If you don't run this script, the installation will fail."); + + var selection = InteractivePrompt.prompt_for_confirmation(@"Do you want to run the script?", new[] {"yes", "no", "print"}, "no", requireAnswer: true); + + if (selection.is_equal_to("print")) + { + this.Log().Info(ChocolateyLoggers.Important, "------ BEGIN SCRIPT ------"); + this.Log().Info(() => "{0}{1}{0}".format_with(Environment.NewLine, chocoPowerShellScriptContents.escape_curly_braces())); + this.Log().Info(ChocolateyLoggers.Important, "------- END SCRIPT -------"); + selection = InteractivePrompt.prompt_for_confirmation(@"Do you want to run this script?", new[] { "yes", "no" }, "no", requireAnswer: true); + } + if (selection.is_equal_to("yes")) shouldRun = true; if (selection.is_equal_to("no")) { From 150220803d58a02bd04bde7586b03e606e0d9807 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Mon, 13 Apr 2015 11:09:39 -0500 Subject: [PATCH 07/22] (GH-186) Uninstall - no prompt for one version If there is only one version installed, uninstall should not prompt for which version to remove. It should just move forward removing that version. --- src/chocolatey/infrastructure.app/services/NugetService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index b39a7c54b6..a3d59068b6 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -797,7 +797,7 @@ public ConcurrentDictionary uninstall_run(ChocolateyConfi } var packageVersionsToRemove = installedPackageVersions.ToList(); - if (!config.AllVersions) + if (!config.AllVersions && installedPackageVersions.Count > 1) { if (config.PromptForConfirmation) { From 900c23a2a3b2b9417165a9e6850783fb3a047607 Mon Sep 17 00:00:00 2001 From: Christian Rondeau Date: Tue, 24 Mar 2015 20:56:34 -0400 Subject: [PATCH 08/22] (GH-185) Remove console prompt default choices --- src/chocolatey/infrastructure.app/runners/GenericRunner.cs | 2 +- .../infrastructure.app/services/ChocolateyPackageService.cs | 2 +- src/chocolatey/infrastructure.app/services/NugetService.cs | 2 +- .../infrastructure.app/services/PowershellService.cs | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/chocolatey/infrastructure.app/runners/GenericRunner.cs b/src/chocolatey/infrastructure.app/runners/GenericRunner.cs index d0e69fcc78..8f86e20931 100644 --- a/src/chocolatey/infrastructure.app/runners/GenericRunner.cs +++ b/src/chocolatey/infrastructure.app/runners/GenericRunner.cs @@ -125,7 +125,7 @@ require admin rights. Only advanced users should run choco w/out an elevated shell. When you open the command shell, you should ensure that you do so with ""Run as Administrator"" selected. - Do you want to continue?", new[] { "yes", "no" }, "no", requireAnswer: true); + Do you want to continue?", new[] { "yes", "no" }, defaultChoice: null, requireAnswer: true); if (selection.is_equal_to("no")) { diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index b13f221387..603ddcf0bc 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -626,7 +626,7 @@ private void rollback_previous_version(ChocolateyConfiguration config, PackageRe var rollback = true; if (config.PromptForConfirmation) { - var selection = InteractivePrompt.prompt_for_confirmation(" Unsuccessful operation for {0}.{1} Do you want to rollback to previous version (package files only)?".format_with(packageResult.Name, Environment.NewLine), new[] { "yes", "no" }, "yes", requireAnswer: true); + var selection = InteractivePrompt.prompt_for_confirmation(" Unsuccessful operation for {0}.{1} Do you want to rollback to previous version (package files only)?".format_with(packageResult.Name, Environment.NewLine), new[] { "yes", "no" }, defaultChoice: null, requireAnswer: true); if (selection.is_equal_to("no")) rollback = false; } diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index a3d59068b6..cf9bc016ed 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -817,7 +817,7 @@ public ConcurrentDictionary uninstall_run(ChocolateyConfi choices.Add(allVersionsChoice); } - var selection = InteractivePrompt.prompt_for_confirmation("Which version of {0} would you like to uninstall?".format_with(packageName), choices, abortChoice, true); + var selection = InteractivePrompt.prompt_for_confirmation("Which version of {0} would you like to uninstall?".format_with(packageName), choices, defaultChoice: null, requireAnswer: true); if (string.IsNullOrWhiteSpace(selection)) continue; if (selection.is_equal_to(abortChoice)) continue; diff --git a/src/chocolatey/infrastructure.app/services/PowershellService.cs b/src/chocolatey/infrastructure.app/services/PowershellService.cs index aa60a83f1e..80d5f10246 100644 --- a/src/chocolatey/infrastructure.app/services/PowershellService.cs +++ b/src/chocolatey/infrastructure.app/services/PowershellService.cs @@ -220,14 +220,14 @@ public bool run_action(ChocolateyConfiguration configuration, PackageResult pack this.Log().Info(ChocolateyLoggers.Important, () => "The package {0} wants to run '{1}'.".format_with(package.Id, _fileSystem.get_file_name(chocoPowerShellScript))); this.Log().Info(ChocolateyLoggers.Important, () => "Note: If you don't run this script, the installation will fail."); - var selection = InteractivePrompt.prompt_for_confirmation(@"Do you want to run the script?", new[] {"yes", "no", "print"}, "no", requireAnswer: true); + var selection = InteractivePrompt.prompt_for_confirmation(@"Do you want to run the script?", new[] {"yes", "no", "print"}, defaultChoice: null, requireAnswer: true); if (selection.is_equal_to("print")) { this.Log().Info(ChocolateyLoggers.Important, "------ BEGIN SCRIPT ------"); this.Log().Info(() => "{0}{1}{0}".format_with(Environment.NewLine, chocoPowerShellScriptContents.escape_curly_braces())); this.Log().Info(ChocolateyLoggers.Important, "------- END SCRIPT -------"); - selection = InteractivePrompt.prompt_for_confirmation(@"Do you want to run this script?", new[] { "yes", "no" }, "no", requireAnswer: true); + selection = InteractivePrompt.prompt_for_confirmation(@"Do you want to run this script?", new[] { "yes", "no" }, defaultChoice: null, requireAnswer: true); } if (selection.is_equal_to("yes")) shouldRun = true; From 8fd6d20963a90af1bf3c3a876500eaf24f6cec7c Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Sun, 19 Apr 2015 21:18:15 -0500 Subject: [PATCH 09/22] (GH-230) Fix Issues with Generate/Remove BinFile - Rename Generate-BinFile to Install-BinFile to remove warnings. - Create an alias Generate-BinFile for Install-BinFile so that existing package scripts are not broken when using the old function name. - Create an alias Add-BinFile for Install-BinFile to be similar to Remove-BinFile. - Rename Remove-BinFile to Uninstall-BinFile to match the rest of the package script names. - Create alias Remove-BinFile to not break existing package scripts. - Fix path and variable issues with both functions. --- .../chocolatey.resources.csproj | 4 ++-- ...nerate-BinFile.ps1 => Install-BinFile.ps1} | 19 ++++++++++++------- ...move-BinFile.ps1 => Uninstall-BinFile.ps1} | 16 ++++++++++------ 3 files changed, 24 insertions(+), 15 deletions(-) rename src/chocolatey.resources/helpers/functions/{Generate-BinFile.ps1 => Install-BinFile.ps1} (87%) rename src/chocolatey.resources/helpers/functions/{Remove-BinFile.ps1 => Uninstall-BinFile.ps1} (83%) diff --git a/src/chocolatey.resources/chocolatey.resources.csproj b/src/chocolatey.resources/chocolatey.resources.csproj index be6e89404c..bbd951ecd9 100644 --- a/src/chocolatey.resources/chocolatey.resources.csproj +++ b/src/chocolatey.resources/chocolatey.resources.csproj @@ -116,8 +116,8 @@ - - + + diff --git a/src/chocolatey.resources/helpers/functions/Generate-BinFile.ps1 b/src/chocolatey.resources/helpers/functions/Install-BinFile.ps1 similarity index 87% rename from src/chocolatey.resources/helpers/functions/Generate-BinFile.ps1 rename to src/chocolatey.resources/helpers/functions/Install-BinFile.ps1 index 5333bbef4c..dae58ee596 100644 --- a/src/chocolatey.resources/helpers/functions/Generate-BinFile.ps1 +++ b/src/chocolatey.resources/helpers/functions/Install-BinFile.ps1 @@ -12,15 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -function Generate-BinFile { +function Install-BinFile { param( [string] $name, [string] $path, [switch] $useStart, [string] $command = '' ) - Write-Debug "Running 'Generate-BinFile' for $name with path:`'$path`'|`$useStart:$useStart|`$command:$command"; + Write-Debug "Running 'Install-BinFile' for $name with path:`'$path`'|`$useStart:$useStart|`$command:$command"; + $nugetPath = [System.IO.Path]::GetFullPath((Join-Path "$helpersPath" '..\')) + $nugetExePath = Join-Path "$nugetPath" 'bin' $packageBatchFileName = Join-Path $nugetExePath "$name.bat" $packageBashFileName = Join-Path $nugetExePath "$name" $packageShimFileName = Join-Path $nugetExePath "$name.exe" @@ -68,16 +70,16 @@ param( } if (Test-Path ($packageShimFileName)) { - Write-Host "Added $packageShimFileName shim pointed to `'$path`'." -ForegroundColor $Note + Write-Host "Added $packageShimFileName shim pointed to `'$path`'." } else { Write-Warning "An error occurred generating shim, using old method." $path = "%DIR%$($path)" $pathBash = $path.Replace("%DIR%..\","`$DIR/../").Replace("\","/") - Write-Host "Adding $packageBatchFileName and pointing to `'$path`'." -ForegroundColor $Note - Write-Host "Adding $packageBashFileName and pointing to `'$path`'." -ForegroundColor $Note + Write-Host "Adding $packageBatchFileName and pointing to `'$path`'." + Write-Host "Adding $packageBashFileName and pointing to `'$path`'." if ($useStart) { - Write-Host "Setting up $name as a non-command line application." -ForegroundColor $Note + Write-Host "Setting up $name as a non-command line application." "@echo off SET DIR=%~dp0% start """" ""$path"" %*" | Out-File $packageBatchFileName -encoding ASCII @@ -100,4 +102,7 @@ exit /b %ERRORLEVEL%" | Out-File $packageBatchFileName -encoding ASCII } } -} \ No newline at end of file +} + +Set-Alias Generate-BinFile Install-BinFile +Set-Alias Add-BinFile Install-BinFile \ No newline at end of file diff --git a/src/chocolatey.resources/helpers/functions/Remove-BinFile.ps1 b/src/chocolatey.resources/helpers/functions/Uninstall-BinFile.ps1 similarity index 83% rename from src/chocolatey.resources/helpers/functions/Remove-BinFile.ps1 rename to src/chocolatey.resources/helpers/functions/Uninstall-BinFile.ps1 index e68c6ad52d..904a180952 100644 --- a/src/chocolatey.resources/helpers/functions/Remove-BinFile.ps1 +++ b/src/chocolatey.resources/helpers/functions/Uninstall-BinFile.ps1 @@ -12,13 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -function Remove-BinFile { +function Uninstall-BinFile { param( [string] $name, [string] $path ) - Write-Debug "Running 'Remove-BinFile' for $name with path:`'$path`'"; + Write-Debug "Running 'Uninstall-BinFile' for $name with path:`'$path`'"; + $nugetPath = [System.IO.Path]::GetFullPath((Join-Path "$helpersPath" '..\')) + $nugetExePath = Join-Path "$nugetPath" 'bin' $packageBatchFileName = Join-Path $nugetExePath "$name.bat" $packageBashFileName = Join-Path $nugetExePath "$name" $packageShimFileName = Join-Path $nugetExePath "$name.exe" @@ -28,7 +30,7 @@ param( Write-Debug "Attempting to remove the batch and bash shortcuts: $packageBatchFileName and $packageBashFileName" if (Test-Path $packageBatchFileName) { - Write-Host "Removing batch file $packageBatchFileName which pointed to `'$path`'." -ForegroundColor $Note + Write-Host "Removing batch file $packageBatchFileName which pointed to `'$path`'." Remove-Item $packageBatchFileName } else { @@ -36,7 +38,7 @@ param( } if (Test-Path $packageBashFileName) { - Write-Host "Removing bash file $packageBashFileName which pointed to `'$path`'." -ForegroundColor $Note + Write-Host "Removing bash file $packageBashFileName which pointed to `'$path`'." Remove-Item $packageBashFileName } else { @@ -45,10 +47,12 @@ param( Write-Debug "Attempting to remove the shim: $packageShimFileName" if (Test-Path $packageShimFileName) { - Write-Host "Removing shim $packageShimFileName which pointed to `'$path`'." -ForegroundColor $Note + Write-Host "Removing shim $packageShimFileName which pointed to `'$path`'." Remove-Item $packageShimFileName } else { Write-Debug "Tried to remove shim $packageShimFileName but it was already removed." } -} \ No newline at end of file +} + +Set-Alias Remove-BinFile Uninstall-BinFile \ No newline at end of file From 039f70a02eb45efd156d5fdbb29ed9a9d6e0bb83 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Sun, 19 Apr 2015 21:19:30 -0500 Subject: [PATCH 10/22] (GH-230) Export all functions and aliases imported Instead of just Exporting the functions imported by helpers path, export all functions and aliases defined, including those imported by community extensions. --- src/chocolatey.resources/helpers/chocolateyInstaller.psm1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/chocolatey.resources/helpers/chocolateyInstaller.psm1 b/src/chocolatey.resources/helpers/chocolateyInstaller.psm1 index cc3f00f924..bfc0a37bbd 100644 --- a/src/chocolatey.resources/helpers/chocolateyInstaller.psm1 +++ b/src/chocolatey.resources/helpers/chocolateyInstaller.psm1 @@ -39,7 +39,7 @@ Get-Item $helpersPath\functions\*.ps1 | ? { -not ($_.Name.Contains(".Tests.")) } | % { . $_.FullName; - Export-ModuleMember -Function $_.BaseName + #Export-ModuleMember -Function $_.BaseName } # load extensions if they exist @@ -48,4 +48,6 @@ if(Test-Path($extensionsPath)) { Write-Debug 'Loading community extensions' #Resolve-Path $extensionsPath\**\*\*.psm1 | % { Write-Debug "Importing `'$_`'"; Import-Module $_.ProviderPath } Get-ChildItem $extensionsPath -recurse -filter "*.psm1" | Select -ExpandProperty FullName | % { Write-Debug "Importing `'$_`'"; Import-Module $_; } -} \ No newline at end of file +} + +Export-ModuleMember -Function * -Alias * \ No newline at end of file From 1635ac62f4f283536ac8c585ae139f86290b92fd Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Mon, 20 Apr 2015 10:50:45 -0500 Subject: [PATCH 11/22] (doc) how to quote values Update how to quote values from wiki --- .../builders/ConfigurationBuilder.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs index 169634b13a..d76d22d8ea 100644 --- a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs +++ b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs @@ -214,10 +214,12 @@ the local options are parsed. * **Use Equals**: You can also include or not include an equals sign `=` between options and values. * **Quote Values**: When you need to quote things, such as when using - spaces, please use single quote marks (`'`). In cmd.exe, you can - also use double double quotes (i.e. `""""yo""""`). This is due to - the hand off to PowerShell - it seems to strip off the outer set of - quotes. TODO: TEST THIS, MAY NOT BE RELEVANT NOW. + spaces, please use apostrophes (`'value'`). In cmd.exe you may be + able to use just double quotes (`""value""`) but in powershell.exe + you may need to either escape the quotes with backticks + (`` `""value`"" ``) or use a combination of double quotes and + apostrophes (`""'value'""`). This is due to the hand off to + PowerShell - it seems to strip off the outer set of quotes. * Options and switches apply to all items passed, so if you are installing multiple packages, and you use `--version=1.0.0`, choco is going to look for and try to install version 1.0.0 of every From 8c8e29e9bb5a07b42a4170f541ad33ef03e9b575 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Mon, 20 Apr 2015 10:53:44 -0500 Subject: [PATCH 12/22] (GH-240)(config) Add machine sources Add the machine sources to the configuration. This will be used when determining credentials to access a source. --- .../configuration/ChocolateyConfiguration.cs | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index f8a163b778..dadd8b4322 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -39,6 +39,7 @@ public ChocolateyConfiguration() ListCommand = new ListCommandConfiguration(); UpgradeCommand = new UpgradeCommandConfiguration(); SourceCommand = new SourcesCommandConfiguration(); + MachineSources = new List(); FeatureCommand = new FeatureCommandConfiguration(); ApiKeyCommand = new ApiKeyCommandConfiguration(); PushCommand = new PushCommandConfiguration(); @@ -67,7 +68,7 @@ private void output_tostring(StringBuilder propertyValues, IEnumerable /// On .NET 4.0, get error CS0200 when private set - see http://stackoverflow.com/a/23809226/18475 /// - public SourcesCommandConfiguration SourceCommand { get; set; } + public SourcesCommandConfiguration SourceCommand { get; set; } + + /// + /// Default Machine Sources Configuration + /// + /// + /// On .NET 4.0, get error CS0200 when private set - see http://stackoverflow.com/a/23809226/18475 + /// + public IList MachineSources { get; set; } /// /// Configuration related specifically to the Feature command @@ -328,6 +337,15 @@ public sealed class SourcesCommandConfiguration public string Password { get; set; } } + [Serializable] + public sealed class MachineSourceConfiguration + { + public string Name { get; set; } + public string Key { get; set; } + public string Username { get; set; } + public string EncryptedPassword { get; set; } + } + [Serializable] public sealed class FeatureCommandConfiguration { From ab711afe0fac93b705b4ed8ce43744e0a2fa5912 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Mon, 20 Apr 2015 10:54:45 -0500 Subject: [PATCH 13/22] (GH-240) pass credentials at runtime Allow passing credentials at runtime to certain commands. --- .../commands/ChocolateyInstallCommand.cs | 6 ++++++ .../infrastructure.app/commands/ChocolateyListCommand.cs | 8 +++++++- .../commands/ChocolateyUpgradeCommand.cs | 6 ++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs index df9a659400..5a517ddd96 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs @@ -74,6 +74,12 @@ public void configure_argument_parser(OptionSet optionSet, ChocolateyConfigurati .Add("n|skippowershell|skip-powershell", "Skip Powershell - Do not run chocolateyInstall.ps1. Defaults to false.", option => configuration.SkipPackageInstallProvider = option != null) + .Add("u=|user=", + "User - used with authenticated feeds. Defaults to empty.", + option => configuration.SourceCommand.Username = option.remove_surrounding_quotes()) + .Add("p=|password=", + "Password - the user's password to the source. Defaults to empty.", + option => configuration.SourceCommand.Password = option.remove_surrounding_quotes()) ; //todo: Checksum / ChecksumType defaults to md5 / package name can be a url / installertype diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs index bac6eebea1..bc3ddf5b92 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs @@ -47,12 +47,18 @@ public void configure_argument_parser(OptionSet optionSet, ChocolateyConfigurati .Add("pre|prerelease", "Prerelease - Include Prereleases? Defaults to false.", option => configuration.Prerelease = option != null) - .Add("p|includeprograms|include-programs", + .Add("i|includeprograms|include-programs", "IncludePrograms - Used in conjunction with LocalOnly, filters out apps chocolatey has listed as packages and includes those in the list. Defaults to false.", option => configuration.ListCommand.IncludeRegistryPrograms = option != null) .Add("a|all|allversions|all-versions", "AllVersions - include results from all versions.", option => configuration.AllVersions = option != null) + .Add("u=|user=", + "User - used with authenticated feeds. Defaults to empty.", + option => configuration.SourceCommand.Username = option.remove_surrounding_quotes()) + .Add("p=|password=", + "Password - the user's password to the source. Defaults to empty.", + option => configuration.SourceCommand.Password = option.remove_surrounding_quotes()) ; //todo exact name } diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs index b202eade8d..04538ad6e9 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs @@ -76,6 +76,12 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon .Add("failonunfound|fail-on-unfound", "Fail On Unfound Packages - If a package is not found in feeds specified, fail instead of warn.", option => configuration.UpgradeCommand.FailOnUnfound = option != null) + .Add("u=|user=", + "User - used with authenticated feeds. Defaults to empty.", + option => configuration.SourceCommand.Username = option.remove_surrounding_quotes()) + .Add("p=|password=", + "Password - the user's password to the source. Defaults to empty.", + option => configuration.SourceCommand.Password = option.remove_surrounding_quotes()) ; } From 155caf9298d669eaedd36bb57a9f2984d35bb825 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Mon, 20 Apr 2015 10:57:26 -0500 Subject: [PATCH 14/22] (GH-171) Use RedirectedHttpClient Instead of the default NuGet HttpClient, the console uses a RedirectedHttpClient by default that resolves the actual address by following redirects. Chocolatey should also use this. --- src/chocolatey/infrastructure.app/nuget/NugetCommon.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs b/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs index efeea9d99c..1081b6a1d0 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs @@ -65,7 +65,7 @@ public static IPackageRepository GetRemoteRepository(ChocolateyConfiguration con } else { - repositories.Add(new DataServicePackageRepository(uri)); + repositories.Add(new DataServicePackageRepository(new RedirectedHttpClient(uri))); } } catch (Exception) From def53bbd1c7a12dea6b8cfcd00fc3a4ca0bfaa5c Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Mon, 20 Apr 2015 11:03:04 -0500 Subject: [PATCH 15/22] (maint) Only warn subcommand list if not empty When setting the subcommand list when the command is not recognized, only provide a warning if the command was not empty. Otherwise you get an annoying message that is unnecessary. --- .../infrastructure.app/commands/ChocolateyFeatureCommand.cs | 2 +- .../infrastructure.app/commands/ChocolateyPinCommand.cs | 2 +- .../infrastructure.app/commands/ChocolateySourceCommand.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyFeatureCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyFeatureCommand.cs index ee6d060d94..d192de8371 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyFeatureCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyFeatureCommand.cs @@ -62,7 +62,7 @@ public void handle_additional_argument_parsing(IList unparsedArguments, Enum.TryParse(unparsedCommand, true, out command); if (command == FeatureCommandType.unknown) { - this.Log().Warn("Unknown command {0}. Setting to list.".format_with(unparsedCommand)); + if (!string.IsNullOrWhiteSpace(unparsedCommand)) this.Log().Warn("Unknown command {0}. Setting to list.".format_with(unparsedCommand)); command = FeatureCommandType.list; } diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyPinCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyPinCommand.cs index ef000500e3..e7a45ad708 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyPinCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyPinCommand.cs @@ -69,7 +69,7 @@ public void handle_additional_argument_parsing(IList unparsedArguments, if (command == PinCommandType.unknown) { - this.Log().Warn("Unknown command {0}. Setting to list.".format_with(unparsedCommand)); + if (!string.IsNullOrWhiteSpace(unparsedCommand)) this.Log().Warn("Unknown command {0}. Setting to list.".format_with(unparsedCommand)); command = PinCommandType.list; } diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs index 773c3b5bbe..9db67cc3b4 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs @@ -71,7 +71,7 @@ public void handle_additional_argument_parsing(IList unparsedArguments, Enum.TryParse(unparsedCommand, true, out command); if (command == SourceCommandType.unknown) { - this.Log().Warn("Unknown command {0}. Setting to list.".format_with(unparsedCommand)); + if (!string.IsNullOrWhiteSpace(unparsedCommand)) this.Log().Warn("Unknown command {0}. Setting to list.".format_with(unparsedCommand)); command = SourceCommandType.list; } From eb1b48b79ba68e8c7fbdb93b80ceb3e2f76d51eb Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Mon, 20 Apr 2015 11:05:11 -0500 Subject: [PATCH 16/22] (GH-240) Add default sources to machine sources When loading up configuration, be sure to set the machine wide sources into the configuration value for machine sources. This way they can be used later. --- .../builders/ConfigurationBuilder.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs index d76d22d8ea..c0a41987d4 100644 --- a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs +++ b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs @@ -82,6 +82,8 @@ private static void set_file_configuration(ChocolateyConfiguration config, IFile config.Sources = sources.Remove(sources.Length - 1, 1).ToString(); } + set_machine_sources(config, configFileSettings); + config.CacheLocation = !string.IsNullOrWhiteSpace(configFileSettings.CacheLocation) ? configFileSettings.CacheLocation : System.Environment.GetEnvironmentVariable("TEMP"); if (string.IsNullOrWhiteSpace(config.CacheLocation)) { @@ -109,6 +111,20 @@ private static void set_file_configuration(ChocolateyConfiguration config, IFile logWarningInsteadOfError: true); } + private static void set_machine_sources(ChocolateyConfiguration config, ConfigFileSettings configFileSettings) + { + foreach (var source in configFileSettings.Sources.Where(s => !s.Disabled).or_empty_list_if_null()) + { + config.MachineSources.Add(new MachineSourceConfiguration + { + Key = source.Value, + Name = source.Id, + Username = source.UserName, + EncryptedPassword = source.Password + }); + } + } + private static void set_feature_flags(ChocolateyConfiguration config, ConfigFileSettings configFileSettings) { config.Features.CheckSumFiles = set_feature_flag(ApplicationParameters.Features.CheckSumFiles, configFileSettings); From 9d71a6bc1c2573d5df0a93aaa8af4c0774c2f695 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Mon, 20 Apr 2015 11:09:42 -0500 Subject: [PATCH 17/22] (GH-240) ChocolateyNugetCredentialProvider When NuGet needs credentials for a source, it was using a default credential provider that needs to use the same format as the NuGet config file. This provides a way to pull those credentials from the Chocolatey stored sources, use the passed in credentials, or prompt for credentials if the user is interactive. --- src/chocolatey/chocolatey.csproj | 1 + .../ChocolateyNugetCredentialProvider.cs | 113 ++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 src/chocolatey/infrastructure.app/nuget/ChocolateyNugetCredentialProvider.cs diff --git a/src/chocolatey/chocolatey.csproj b/src/chocolatey/chocolatey.csproj index b008ab60a3..87f6acf0ec 100644 --- a/src/chocolatey/chocolatey.csproj +++ b/src/chocolatey/chocolatey.csproj @@ -97,6 +97,7 @@ + diff --git a/src/chocolatey/infrastructure.app/nuget/ChocolateyNugetCredentialProvider.cs b/src/chocolatey/infrastructure.app/nuget/ChocolateyNugetCredentialProvider.cs new file mode 100644 index 0000000000..a5a261f225 --- /dev/null +++ b/src/chocolatey/infrastructure.app/nuget/ChocolateyNugetCredentialProvider.cs @@ -0,0 +1,113 @@ +// Copyright © 2011 - Present RealDimensions Software, LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace chocolatey.infrastructure.app.nuget +{ + using System; + using System.Linq; + using System.Net; + using NuGet; + using configuration; + using logging; + + // ReSharper disable InconsistentNaming + + public sealed class ChocolateyNugetCredentialProvider : ICredentialProvider + { + private readonly ChocolateyConfiguration _config; + + public ChocolateyNugetCredentialProvider(ChocolateyConfiguration config) + { + _config = config; + } + + public ICredentials GetCredentials(Uri uri, IWebProxy proxy, CredentialType credentialType, bool retrying) + { + if (uri == null) + { + throw new ArgumentNullException("uri"); + } + if (retrying) + { + this.Log().Warn("Invalid credentials specified."); + } + + if (_config.Sources.TrimEnd('/').is_equal_to(uri.OriginalString.TrimEnd('/'))) + { + if (!string.IsNullOrWhiteSpace(_config.SourceCommand.Username) && !string.IsNullOrWhiteSpace(_config.SourceCommand.Password)) + { + this.Log().Debug("Using passed in credentials"); + + return new NetworkCredential(_config.SourceCommand.Username, _config.SourceCommand.Password); + } + } + + var source = _config.MachineSources.FirstOrDefault(s => + { + var sourceUri = s.Key.TrimEnd('/'); + return sourceUri.is_equal_to(uri.OriginalString.TrimEnd('/')) + && !string.IsNullOrWhiteSpace(s.Username) + && !string.IsNullOrWhiteSpace(s.EncryptedPassword); + }); + + if (source == null) + { + return get_credentials_from_user(uri, proxy, credentialType); + } + + this.Log().Debug("Using saved credentials"); + + return new NetworkCredential(source.Username, NugetEncryptionUtility.DecryptString(source.EncryptedPassword)); + } + + public ICredentials get_credentials_from_user(Uri uri, IWebProxy proxy, CredentialType credentialType) + { + if (!_config.Information.IsInteractive) + { + return CredentialCache.DefaultCredentials; + } + + string message = credentialType == CredentialType.ProxyCredentials ? + "Please provide proxy credentials:" : + "Please provide credentials for: {0}".format_with(uri.OriginalString); + this.Log().Info(ChocolateyLoggers.Important, message); + + Console.Write("User name: "); + string username = Console.ReadLine(); + Console.Write("Password: "); + var password = Console.ReadLine(); + + //todo: set this up as secure + //using (var securePassword = new SecureString()) + //{ + // foreach (var letter in password.to_string()) + // { + // securePassword.AppendChar(letter); + // } + + var credentials = new NetworkCredential + { + UserName = username, + Password = password, + //SecurePassword = securePassword + }; + return credentials; + // } + } + } + + + // ReSharper restore InconsistentNaming +} \ No newline at end of file From c917f75d53bfd0b3215e1d2d52851fec98aecc9b Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Mon, 20 Apr 2015 11:12:21 -0500 Subject: [PATCH 18/22] (GH-240) Set CredentialProvider for NuGet NuGet has an HttpClient that exposes a CredentialProvider. Set that to the ChocolateyNugetCredentialProvider so it is used by NuGet when determining credentials. --- src/chocolatey/infrastructure.app/nuget/NugetCommon.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs b/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs index 1081b6a1d0..0299dc3f2c 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs @@ -54,6 +54,10 @@ public static IPackageRepository GetRemoteRepository(ChocolateyConfiguration con IEnumerable sources = configuration.Sources.Split(new[] {";", ","}, StringSplitOptions.RemoveEmptyEntries); IList repositories = new List(); + + // ensure credentials can be grabbed from configuration + HttpClient.DefaultCredentialProvider = new ChocolateyNugetCredentialProvider(configuration); + foreach (var source in sources.or_empty_list_if_null()) { try From 998bc44116cb3054ac5717fcd4547bcb03db55d6 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Mon, 20 Apr 2015 11:12:33 -0500 Subject: [PATCH 19/22] (maint) formatting --- src/chocolatey/infrastructure.app/nuget/NugetCommon.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs b/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs index 0299dc3f2c..2a45ac5f54 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs @@ -80,7 +80,7 @@ public static IPackageRepository GetRemoteRepository(ChocolateyConfiguration con //todo well that didn't work on failing repos... grrr var repository = new AggregateRepository(repositories) {IgnoreFailingRepositories = true}; - //,ResolveDependenciesVertically = true}; + //repository.ResolveDependenciesVertically = true; if (configuration.Debug) { repository.Logger = nugetLogger; From cdc6b5066af90ac75713a0b00f344d6652764f34 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Mon, 20 Apr 2015 17:52:18 -0500 Subject: [PATCH 20/22] (GH-238) ApiKey source matching intuitive When matching a source versus the passed in source, be a little more intuitive about the source itself by matching without the end `/`. --- .../services/ChocolateyConfigSettingsService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs index f45624b3e9..47f8a410c9 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs @@ -176,7 +176,7 @@ public string get_api_key(ChocolateyConfiguration configuration, Action p.Source.is_equal_to(configuration.Sources)); + var apiKey = configFileSettings.ApiKeys.FirstOrDefault(p => p.Source.TrimEnd('/').is_equal_to(configuration.Sources.TrimEnd('/'))); if (apiKey != null) { apiKeyValue = NugetEncryptionUtility.DecryptString(apiKey.Key).to_string(); From 18bf625494193ce783a974e895b7792192c43eeb Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Mon, 20 Apr 2015 17:52:53 -0500 Subject: [PATCH 21/22] (doc) update changelog/nuspec --- CHANGELOG.md | 29 +++++++++++++++++++++++++++++ nuget/chocolatey/chocolatey.nuspec | 29 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2751efc6d..0689ffb1c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,32 @@ +## [0.9.9.5](https://github.com/chocolatey/choco/issues?q=milestone%3A0.9.9.5+is%3Aclosed) (April 20, 2015) + +### BREAKING CHANGES + + * Renamed short option `p` to `i` for list --include-programs so that `p` could be ubiquitous for password across commands that optionally can pass a password - see [#240](https://github.com/chocolatey/choco/issues/240) + +### BUG FIXES + + * Fix - Secure Sources Not Working - see [#240](https://github.com/chocolatey/choco/issues/240) + * Fix - Generate-BinFile / Remove-BinFile - see [#230](https://github.com/chocolatey/choco/issues/230) + * Fix - cpack should only include files from nuspec - see [#232](https://github.com/chocolatey/choco/issues/232) + * Fix - cpack should leave nupkg in current directory - see [#231](https://github.com/chocolatey/choco/issues/231) + * Fix - Install-PowerShellCommand uses incorrect path - see [#241](https://github.com/chocolatey/choco/issues/241) + * Fix - choco list source with redirects does not resolve - see [#171](https://github.com/chocolatey/choco/issues/171) + * Fix - choco tried to resolve disabled repo - see [#169](https://github.com/chocolatey/choco/issues/169) + * Fix - cpack nuspec results in "The path is not of a legal form" - see [#164](https://github.com/chocolatey/choco/issues/164) + * Fix - cpack hangs on security related issue - see [#160](https://github.com/chocolatey/choco/issues/160) + * Fix - spelling error in "package has been upgradeed successfully" - see [#64](https://github.com/chocolatey/choco/issues/64) + +### IMPROVEMENTS + + * Api Key and Source matching could be more intuitive - see [#228](https://github.com/chocolatey/choco/issues/238) + * Remove warning about allowGlobalConfirmation being enabled - see [#237](https://github.com/chocolatey/choco/issues/237) + * Include log file path when saying 'See the log for details' - see [#187](https://github.com/chocolatey/choco/issues/187) + * Uninstall prompts for version when there is only one installed - see [#186](https://github.com/chocolatey/choco/issues/186) + * Do not offer a default option when prompting for a user choice - see [#185](https://github.com/chocolatey/choco/issues/185) + * Remove the warning note about skipping, and instead show the warning when selecting skip - see [#183](https://github.com/chocolatey/choco/issues/183) + * Do not print PowerShell install/update scripts by default - see [#182](https://github.com/chocolatey/choco/issues/182) + ## [0.9.9.4](https://github.com/chocolatey/choco/issues?q=milestone%3A0.9.9.4+is%3Aclosed) (March 30, 2015) ### BUG FIXES diff --git a/nuget/chocolatey/chocolatey.nuspec b/nuget/chocolatey/chocolatey.nuspec index 92324bb289..c30e27142f 100644 --- a/nuget/chocolatey/chocolatey.nuspec +++ b/nuget/chocolatey/chocolatey.nuspec @@ -40,6 +40,35 @@ In that mess there is a link to the [Helper Reference](https://github.com/chocol See all - https://github.com/chocolatey/choco/blob/master/CHANGELOG.md +## 0.9.9.5 + +### BREAKING CHANGES + + * Renamed short option `p` to `i` for list --include-programs so that `p` could be ubiquitous for password across commands that optionally can pass a password - see [#240](https://github.com/chocolatey/choco/issues/240) + +### BUG FIXES + + * Fix - Secure Sources Not Working - see [#240](https://github.com/chocolatey/choco/issues/240) + * Fix - Generate-BinFile / Remove-BinFile - see [#230](https://github.com/chocolatey/choco/issues/230) + * Fix - cpack should only include files from nuspec - see [#232](https://github.com/chocolatey/choco/issues/232) + * Fix - cpack should leave nupkg in current directory - see [#231](https://github.com/chocolatey/choco/issues/231) + * Fix - Install-PowerShellCommand uses incorrect path - see [#241](https://github.com/chocolatey/choco/issues/241) + * Fix - choco list source with redirects does not resolve - see [#171](https://github.com/chocolatey/choco/issues/171) + * Fix - choco tried to resolve disabled repo - see [#169](https://github.com/chocolatey/choco/issues/169) + * Fix - cpack nuspec results in "The path is not of a legal form" - see [#164](https://github.com/chocolatey/choco/issues/164) + * Fix - cpack hangs on security related issue - see [#160](https://github.com/chocolatey/choco/issues/160) + * Fix - spelling error in "package has been upgradeed successfully" - see [#64](https://github.com/chocolatey/choco/issues/64) + +### IMPROVEMENTS + + * Api Key and Source matching could be more intuitive - see [#228](https://github.com/chocolatey/choco/issues/238) + * Remove warning about allowGlobalConfirmation being enabled - see [#237](https://github.com/chocolatey/choco/issues/237) + * Include log file path when saying 'See the log for details' - see [#187](https://github.com/chocolatey/choco/issues/187) + * Uninstall prompts for version when there is only one installed - see [#186](https://github.com/chocolatey/choco/issues/186) + * Do not offer a default option when prompting for a user choice - see [#185](https://github.com/chocolatey/choco/issues/185) + * Remove the warning note about skipping, and instead show the warning when selecting skip - see [#183](https://github.com/chocolatey/choco/issues/183) + * Do not print PowerShell install/update scripts by default - see [#182](https://github.com/chocolatey/choco/issues/182) + ## 0.9.9.4 ### BUG FIXES From 44eb8e36364f038a98b0fee91a38bcc840c1d5aa Mon Sep 17 00:00:00 2001 From: Brandon H Date: Fri, 27 Mar 2015 22:50:02 -0500 Subject: [PATCH 22/22] (GH-121) Making Uninstall-ChocolateyZipPackage more robust when deleting files that were copied during installation of the Zip package --- .../helpers/functions/UnInstall-ChocolateyZipPackage.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/chocolatey.resources/helpers/functions/UnInstall-ChocolateyZipPackage.ps1 b/src/chocolatey.resources/helpers/functions/UnInstall-ChocolateyZipPackage.ps1 index 7dc5f61f78..ac38766127 100644 --- a/src/chocolatey.resources/helpers/functions/UnInstall-ChocolateyZipPackage.ps1 +++ b/src/chocolatey.resources/helpers/functions/UnInstall-ChocolateyZipPackage.ps1 @@ -10,8 +10,8 @@ # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and -# limitations under the License. - +# limitations under the License. + function UnInstall-ChocolateyZipPackage { <# .SYNOPSIS @@ -50,7 +50,7 @@ param( $zipContentFile $zipContents=get-content $zipContentFile foreach ($fileInZip in $zipContents) { - remove-item "$fileInZip" -ErrorAction SilentlyContinue + remove-item -Path "$fileInZip" -ErrorAction SilentlyContinue -Recurse -Force } } -} \ No newline at end of file +}