forked from chocolatey/choco
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- completed start-chocolateyprocess(asadmin) - completed assert-checksumvalid(/get-checksumvalid)
- Loading branch information
Showing
26 changed files
with
1,921 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="StringResources\EnvironmentVariables.cs~RF1e9b1f0.TMP" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\chocolatey\chocolatey.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="System.Management.Automation"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>..\..\lib\PowerShell\System.Management.Automation.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
// Copyright © 2017-2019 Chocolatey Software, Inc ("Chocolatey") | ||
// Copyright © 2015-2017 RealDimensions Software, LLC | ||
// | ||
// Chocolatey Professional, Chocolatey for Business, and Chocolatey Architect are licensed software. | ||
// | ||
// ===================================================================== | ||
// End-User License Agreement | ||
// Chocolatey Professional, Chocolatey for Service Providers, Chocolatey for Business, | ||
// and/or Chocolatey Architect | ||
// ===================================================================== | ||
// | ||
// IMPORTANT- READ CAREFULLY: This Chocolatey Software ("Chocolatey") End-User License Agreement | ||
// ("EULA") is a legal agreement between you ("END USER") and Chocolatey for all Chocolatey products, | ||
// controls, source code, demos, intermediate files, media, printed materials, and "online" or electronic | ||
// documentation (collectively "SOFTWARE PRODUCT(S)") contained with this distribution. | ||
// | ||
// Chocolatey grants to you as an individual or entity, a personal, nonexclusive license to install and use the | ||
// SOFTWARE PRODUCT(S). By installing, copying, or otherwise using the SOFTWARE PRODUCT(S), you | ||
// agree to be bound by the terms of this EULA. If you do not agree to any part of the terms of this EULA, DO | ||
// NOT INSTALL, USE, OR EVALUATE, ANY PART, FILE OR PORTION OF THE SOFTWARE PRODUCT(S). | ||
// | ||
// In no event shall Chocolatey be liable to END USER for damages, including any direct, indirect, special, | ||
// incidental, or consequential damages of any character arising as a result of the use or inability to use the | ||
// SOFTWARE PRODUCT(S) (including but not limited to damages for loss of goodwill, work stoppage, computer | ||
// failure or malfunction, or any and all other commercial damages or losses). | ||
// | ||
// The liability of Chocolatey to END USER for any reason and upon any cause of action related to the | ||
// performance of the work under this agreement whether in tort or in contract or otherwise shall be limited to the | ||
// amount paid by the END USER to Chocolatey pursuant to this agreement. | ||
// | ||
// ALL SOFTWARE PRODUCT(S) are licensed not sold. If you are an individual, you must acquire an individual | ||
// license for the SOFTWARE PRODUCT(S) from Chocolatey or its authorized resellers. If you are an entity, you | ||
// must acquire an individual license for each machine running the SOFTWARE PRODUCT(S) within your | ||
// organization from Chocolatey or its authorized resellers. Both virtual and physical machines running the | ||
// SOFTWARE PRODUCT(S) or benefitting from licensed features such as Package Builder or Package | ||
// Internalizer must be counted in the SOFTWARE PRODUCT(S) licenses quantity of the organization. | ||
|
||
namespace Chocolatey.PowerShell | ||
{ | ||
using chocolatey; | ||
using chocolatey.infrastructure.filesystem; | ||
using chocolatey.infrastructure.logging; | ||
using Chocolatey.PowerShell.Helpers; | ||
using System; | ||
using System.Collections; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Management.Automation; | ||
using System.Text; | ||
using System.Threading; | ||
|
||
public abstract class ChocolateyCmdlet : PSCmdlet | ||
{ | ||
private readonly object _lock = new object(); | ||
private readonly Lazy<IFileSystem> _fileSystem = new Lazy<IFileSystem>(() => new DotNetFileSystem()); | ||
private readonly CancellationTokenSource _pipelineStopTokenSource = new CancellationTokenSource(); | ||
|
||
protected CancellationToken PipelineStopToken { get => _pipelineStopTokenSource.Token; } | ||
|
||
protected IFileSystem FileSystem { get => _fileSystem.Value; } | ||
|
||
protected string ErrorId { get => GetType().Name + "Error"; } | ||
|
||
protected override void BeginProcessing() | ||
{ | ||
WriteCmdletCallDebugMessage(); | ||
} | ||
|
||
protected override void EndProcessing() | ||
{ | ||
WriteCmdletCompletionDebugMessage(); | ||
} | ||
|
||
protected override void StopProcessing() | ||
{ | ||
lock (_lock) | ||
{ | ||
_pipelineStopTokenSource.Cancel(); | ||
} | ||
} | ||
|
||
protected void WriteCmdletCallDebugMessage() | ||
{ | ||
var logMessage = new StringBuilder() | ||
.Append("Running ") | ||
.Append(MyInvocation.InvocationName); | ||
|
||
foreach (var param in MyInvocation.BoundParameters) | ||
{ | ||
if (param.Key == "ignoredArguments") | ||
{ | ||
continue; | ||
} | ||
|
||
var paramValue = param.Key.IsEqualTo("SensitiveStatements") || param.Key.IsEqualTo("Password") | ||
? "[REDACTED]" | ||
: param.Value is IList list | ||
? string.Join(" ", list) | ||
: LanguagePrimitives.ConvertTo(param.Value, typeof(string)); | ||
|
||
logMessage.Append($" -{param.Key} '{paramValue}'"); | ||
} | ||
|
||
WriteDebug(logMessage.ToString()); | ||
} | ||
|
||
protected void WriteCmdletCompletionDebugMessage() | ||
{ | ||
WriteDebug($"Finishing '{MyInvocation.InvocationName}'"); | ||
} | ||
|
||
protected string EnvironmentVariable(string environmentVariable) | ||
=> Environment.GetEnvironmentVariable(environmentVariable); | ||
|
||
protected void SetEnvironmentVariable(string variable, string value) | ||
=> Environment.SetEnvironmentVariable(variable, value); | ||
|
||
protected object GetPSVariable(string variable) | ||
=> PowerShellHelper.GetPSVariable(this, variable); | ||
|
||
protected void WriteHost(string message) | ||
=> PowerShellHelper.WriteHost(this, message); | ||
|
||
protected new void WriteDebug(string message) | ||
=> PowerShellHelper.WriteDebug(this, message); | ||
|
||
protected new void WriteVerbose(string message) | ||
=> PowerShellHelper.WriteVerbose(this, message); | ||
|
||
protected new void WriteWarning(string message) | ||
=> PowerShellHelper.WriteWarning(this, message); | ||
|
||
protected string CombinePaths(string parent, params string[] childPaths) | ||
=> PowerShellHelper.CombinePaths(this, parent, childPaths); | ||
|
||
protected void EnsureDirectoryExists(string directory) | ||
=> PowerShellHelper.EnsureDirectoryExists(this, directory); | ||
|
||
protected string GetDirectoryName(string path) | ||
=> PowerShellHelper.GetDirectoryName(this, path); | ||
|
||
protected string GetFileName(string path) | ||
=> PowerShellHelper.GetFileName(this, path); | ||
|
||
protected string GetUnresolvedPath(string path) | ||
=> PowerShellHelper.GetUnresolvedPath(this, path); | ||
|
||
protected string GetCurrentDirectory() | ||
=> PowerShellHelper.GetCurrentDirectory(this); | ||
|
||
protected FileInfo GetFileInfoFor(string path) | ||
=> PowerShellHelper.GetFileInfoFor(this, path); | ||
|
||
protected string GetFullPath(string path) | ||
=> PowerShellHelper.GetFullPath(this, path); | ||
|
||
protected bool ItemExists(string path) | ||
=> PowerShellHelper.ItemExists(this, path); | ||
|
||
protected bool ContainerExists(string path) | ||
=> PowerShellHelper.ContainerExists(this, path); | ||
|
||
protected void CopyFile(string source, string destination, bool overwriteExisting) | ||
=> PowerShellHelper.CopyFile(this, source, destination, overwriteExisting); | ||
|
||
protected void DeleteFile(string path) | ||
=> PowerShellHelper.DeleteFile(this, path); | ||
|
||
protected void SetExitCode(int exitCode) | ||
=> PowerShellHelper.SetExitCode(this, exitCode); | ||
|
||
protected T ConvertTo<T>(object value) | ||
=> PowerShellHelper.ConvertTo<T>(value); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/Chocolatey.PowerShell/Commands/AssertChecksumValidCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
namespace Chocolatey.PowerShell.Commands | ||
{ | ||
using Chocolatey.PowerShell; | ||
using Chocolatey.PowerShell.Helpers; | ||
using Chocolatey.PowerShell.Shared; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Management.Automation; | ||
using System.Management.Automation.Host; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
[Cmdlet(VerbsLifecycle.Assert, "ChecksumValid")] | ||
public class AssertChecksumValidCommand : ChocolateyCmdlet | ||
{ | ||
[Parameter(Mandatory = true, Position = 0)] | ||
[Alias("File", "FilePath")] | ||
public string Path { get; set; } | ||
|
||
[Parameter(Position = 1)] | ||
public string Checksum { get; set; } = string.Empty; | ||
|
||
[Parameter(Position = 2)] | ||
public ChecksumType ChecksumType { get; set; } = ChecksumType.Md5; | ||
|
||
[Parameter(Position = 3)] | ||
[Alias("OriginalUrl")] | ||
public string Url { get; set; } = string.Empty; | ||
|
||
[Parameter(ValueFromRemainingArguments = true)] | ||
public object[] IgnoredArguments { get; set; } | ||
|
||
protected override void EndProcessing() | ||
{ | ||
ChecksumValidator.AssertChecksumValid(this, Path, Checksum, ChecksumType, Url); | ||
base.EndProcessing(); | ||
} | ||
|
||
} | ||
} |
127 changes: 127 additions & 0 deletions
127
src/Chocolatey.PowerShell/Commands/ExpandChocolateyArchive.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
namespace Chocolatey.PowerShell.Commands | ||
{ | ||
using Chocolatey.PowerShell.Helpers; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Management.Automation; | ||
using System.Text; | ||
|
||
[Cmdlet(VerbsData.Expand, "ChocolateyArchive")] | ||
[OutputType(typeof(string))] | ||
public class ExpandChocolateyArchive : ChocolateyCmdlet | ||
{ | ||
/* | ||
.SYNOPSIS | ||
Unzips an archive file and returns the location for further processing. | ||
.DESCRIPTION | ||
This unzips files using the 7-zip command line tool 7z.exe. | ||
Supported archive formats are listed at: | ||
https://sevenzip.osdn.jp/chm/general/formats.htm | ||
.INPUTS | ||
None | ||
.OUTPUTS | ||
Returns the passed in $destination. | ||
.NOTES | ||
If extraction fails, an exception is thrown. | ||
If you are embedding files into a package, ensure that you have the | ||
rights to redistribute those files if you are sharing this package | ||
publicly (like on the community feed). Otherwise, please use | ||
Install-ChocolateyZipPackage to download those resources from their | ||
official distribution points. | ||
Will automatically call Set-PowerShellExitCode to set the package exit code | ||
based on 7-zip's exit code. | ||
.PARAMETER FileFullPath | ||
This is the full path to the zip file. If embedding it in the package | ||
next to the install script, the path will be like | ||
`"$(Split-Path -Parent $MyInvocation.MyCommand.Definition)\\file.zip"` | ||
`File` is an alias for FileFullPath. | ||
This can be a 32-bit or 64-bit file. This is mandatory in earlier versions | ||
of Chocolatey, but optional if FileFullPath64 has been provided. | ||
.PARAMETER FileFullPath64 | ||
Full file path to a 64-bit native installer to run. | ||
If embedding in the package, you can get it to the path with | ||
`"$(Split-Path -parent $MyInvocation.MyCommand.Definition)\\INSTALLER_FILE"` | ||
Provide this when you want to provide both 32-bit and 64-bit | ||
installers or explicitly only a 64-bit installer (which will cause a package | ||
install failure on 32-bit systems). | ||
.PARAMETER Destination | ||
This is a directory where you would like the unzipped files to end up. | ||
If it does not exist, it will be created. | ||
.PARAMETER SpecificFolder | ||
OPTIONAL - This is a specific directory within zip file to extract. The | ||
folder and its contents will be extracted to the destination. | ||
.PARAMETER PackageName | ||
OPTIONAL - This will facilitate logging unzip activity for subsequent | ||
uninstalls | ||
.PARAMETER DisableLogging | ||
OPTIONAL - This disables logging of the extracted items. It speeds up | ||
extraction of archives with many files. | ||
Usage of this parameter will prevent Uninstall-ChocolateyZipPackage | ||
from working, extracted files will have to be cleaned up with | ||
Remove-Item or a similar command instead. | ||
.PARAMETER IgnoredArguments | ||
Allows splatting with arguments that do not apply. Do not use directly. | ||
.EXAMPLE | ||
> | ||
# Path to the folder where the script is executing | ||
$toolsDir = (Split-Path -parent $MyInvocation.MyCommand.Definition) | ||
Get-ChocolateyUnzip -FileFullPath "c:\someFile.zip" -Destination $toolsDir | ||
.LINK | ||
Install-ChocolateyZipPackage | ||
*/ | ||
|
||
[Alias("File", "FileFullPath")] | ||
[Parameter(Position = 0)] | ||
public string Path { get; set; } | ||
|
||
[Alias("UnzipLocation")] | ||
[Parameter(Mandatory = true, Position = 1)] | ||
public string Destination { get; set; } | ||
|
||
[Parameter(Position = 2)] | ||
public string SpecificFolder { get; set; } | ||
|
||
[Parameter(Position = 3)] | ||
public string PackageName { get; set; } | ||
|
||
[Alias("File64", "FileFullPath64")] | ||
[Parameter] | ||
public string Path64 { get; set; } | ||
|
||
[Parameter] | ||
public SwitchParameter DisableLogging { get; set; } | ||
|
||
[Parameter(ValueFromRemainingArguments = true)] | ||
public object[] IgnoredArguments { get; set; } | ||
|
||
protected override void EndProcessing() | ||
{ | ||
var bitnessMessage = string.Empty; | ||
var zipFilePath = Path; | ||
|
||
var architecture = ArchitectureWidth.Get(); | ||
|
||
base.EndProcessing(); | ||
} | ||
} | ||
} |
Oops, something went wrong.