Skip to content

Commit

Permalink
Package install scripts instead of installer (#58)
Browse files Browse the repository at this point in the history
* feat: Package as script support

Fixed #50
  • Loading branch information
svrooij authored May 2, 2024
1 parent fa54cb6 commit 8fecb33
Show file tree
Hide file tree
Showing 12 changed files with 314 additions and 69 deletions.
23 changes: 21 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"cwd": "${fileDirname}"
},
{
"name": ".NET Core Launch (console)",
"name": ".NET Core Package Microsoft SQL Server Management Studio",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "dotnet: build-cli",
Expand All @@ -21,7 +21,26 @@
"args": [
"package",
"Microsoft.SQLServerManagementStudio",
"--package-folder", "C:\\tools\\packages"
"--package-folder", "C:\\tools\\packages",
"--package-script",
"--installer-context", "system"
],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Create Index",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "dotnet: build-cli",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/WingetIntune.Cli/bin/Debug/net8.0/WingetIntune.Cli.dll",
"args": [
"generate-index",
"--output-path", "C:\\tools\\packages\\index.json",
"--update-csv", "C:\\tools\\packages\\updates.csv"
],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
Expand Down
2 changes: 2 additions & 0 deletions src/Svrooij.WinTuner.CmdLets/Commands/GetWtWin32Apps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public override async Task ProcessRecordAsync(CancellationToken cancellationToke
CurrentVersion = app.CurrentVersion,
SupersededAppCount = app.SupersededAppCount,
SupersedingAppCount = app.SupersedingAppCount,
InstallerContext = app.InstallerContext,
Architecture = app.Architecture,
LatestVersion = version,
});
}
Expand Down
39 changes: 39 additions & 0 deletions src/Svrooij.WinTuner.CmdLets/Commands/NewWtWingetPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,39 @@ public class NewWtWingetPackage : DependencyCmdlet<Startup>
HelpMessage = "The folder to store temporary files in")]
public string? TempFolder { get; set; } = Path.Combine(Path.GetTempPath(), "wintuner");

/// <summary>
/// Pick this architecture
/// </summary>
[Parameter(
Mandatory = false,
Position = 4,
ValueFromPipeline = true,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Pick this architecture")]
public WingetIntune.Models.Architecture Architecture { get; set; } = WingetIntune.Models.Architecture.Unknown;

/// <summary>
/// The installer context
/// </summary>
[Parameter(
Mandatory = false,
Position = 5,
ValueFromPipeline = true,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The installer context")]
public WingetIntune.Models.InstallerContext InstallerContext { get; set; } = WingetIntune.Models.InstallerContext.System;

/// <summary>
/// Package as script
/// </summary>
[Parameter(
Mandatory = false,
Position = 6,
ValueFromPipeline = true,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Package WinGet script, instead of the actual installer. Helpful for installers that don't really work with WinTuner.")]
public bool? PackageScript { get; set; }

[ServiceDependency]
private ILogger<NewWtWingetPackage> logger;

Expand Down Expand Up @@ -102,6 +135,12 @@ public override async Task ProcessRecordAsync(CancellationToken cancellationToke
TempFolder!,
PackageFolder,
packageInfo,
new WingetIntune.Models.PackageOptions
{
Architecture = Architecture,
InstallerContext = InstallerContext,
PackageScript = PackageScript ?? false
},
cancellationToken: cancellationToken);

WriteObject(package);
Expand Down
72 changes: 72 additions & 0 deletions src/Svrooij.WinTuner.CmdLets/Svrooij.WinTuner.CmdLets.dll-Help.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,42 @@
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName, ByValue)" position="named" aliases="none">
<maml:name>Architecture</maml:name>
<maml:description>
<maml:para>Pick this architecture</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">Architecture</command:parameterValue>
<dev:type>
<maml:name>Architecture</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName, ByValue)" position="named" aliases="none">
<maml:name>InstallerContext</maml:name>
<maml:description>
<maml:para>The installer context</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">InstallerContext</command:parameterValue>
<dev:type>
<maml:name>InstallerContext</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName, ByValue)" position="named" aliases="none">
<maml:name>PackageScript</maml:name>
<maml:description>
<maml:para>Package WinGet script, instead of the actual installer. Helpful for installers that don't really work with WinTuner.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">Boolean</command:parameterValue>
<dev:type>
<maml:name>Boolean</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:syntaxItem>
</command:syntax>
<command:parameters>
Expand Down Expand Up @@ -1340,6 +1376,42 @@
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName, ByValue)" position="named" aliases="none">
<maml:name>Architecture</maml:name>
<maml:description>
<maml:para>Pick this architecture</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">Architecture</command:parameterValue>
<dev:type>
<maml:name>Architecture</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName, ByValue)" position="named" aliases="none">
<maml:name>InstallerContext</maml:name>
<maml:description>
<maml:para>The installer context</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">InstallerContext</command:parameterValue>
<dev:type>
<maml:name>InstallerContext</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName, ByValue)" position="named" aliases="none">
<maml:name>PackageScript</maml:name>
<maml:description>
<maml:para>Package WinGet script, instead of the actual installer. Helpful for installers that don't really work with WinTuner.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">Boolean</command:parameterValue>
<dev:type>
<maml:name>Boolean</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:parameters>
<command:inputTypes>
<command:inputType>
Expand Down
48 changes: 47 additions & 1 deletion src/Svrooij.WinTuner.CmdLets/docs/New-WtWingetPackage.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Create intunewin file from Winget installer

```
New-WtWingetPackage [-PackageId] <String> [[-PackageFolder] <String>] [[-Version] <String>]
[[-TempFolder] <String>] [-ProgressAction <ActionPreference>] [<CommonParameters>]
[[-TempFolder] <String>] [-Architecture <Architecture>] [-InstallerContext <InstallerContext>]
[-PackageScript <Boolean>] [-ProgressAction <ActionPreference>] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -106,6 +107,51 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -Architecture
Pick this architecture
```yaml
Type: Architecture
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False
```
### -InstallerContext
The installer context
```yaml
Type: InstallerContext
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False
```
### -PackageScript
Package WinGet script, instead of the actual installer. Helpful for installers that don't really work with WinTuner.
```yaml
Type: Boolean
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
Expand Down
11 changes: 9 additions & 2 deletions src/WingetIntune.Cli/Commands/PackageCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ internal class PackageCommand : Command
IsHidden = isHidden,
};

internal static Option<InstallerContext> GetInstallerContextOption(bool isHidden = false) => new Option<InstallerContext>("--installer-context", () => InstallerContext.User, "Installer context to use")
internal static Option<InstallerContext> GetInstallerContextOption(bool isHidden = false) => new Option<InstallerContext>("--installer-context", () => InstallerContext.System, "Installer context to use")
{
IsHidden = isHidden,
};

internal static Option<bool?> GetPackageAsScriptOption(bool isHidden = false) => new Option<bool?>("--package-script", () => null, "Package just a winget script, not the installer itself")
{
IsHidden = isHidden,
};
Expand All @@ -51,6 +56,7 @@ public PackageCommand() : base(name, description)
AddOption(GetPackageFolderOption(isRequired: true));
AddOption(GetArchitectureOption(isHidden: false));
AddOption(GetInstallerContextOption(isHidden: false));
AddOption(GetPackageAsScriptOption(isHidden: false));
AddOption(UseWingetOption);
this.Handler = CommandHandler.Create(HandleCommand);
}
Expand Down Expand Up @@ -88,7 +94,7 @@ private async Task<int> HandleCommand(PackageCommandOptions options, InvocationC
await intuneManager.GenerateInstallerPackage(options.TempFolder,
options.PackageFolder!,
packageInfo,
new PackageOptions { Architecture = options.Architecture, InstallerContext = options.InstallerContext },
new PackageOptions { Architecture = options.Architecture, InstallerContext = options.InstallerContext, PackageScript = options.PackageScript == true },
cancellationToken);

return 0;
Expand All @@ -105,4 +111,5 @@ internal class PackageCommandOptions : WinGetRootCommand.DefaultOptions
public bool UseWinget { get; set; }
public InstallerContext InstallerContext { get; set; }
public Architecture Architecture { get; set; }
public bool? PackageScript { get; set; }
}
4 changes: 3 additions & 1 deletion src/WingetIntune.Cli/Commands/PublishCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public PublishCommand() : base(name, description)
AddOption(new Option<bool>("--auto-update", "Turn on auto update, if assigned as available") { IsHidden = true });
AddOption(PackageCommand.GetArchitectureOption(isHidden: true));
AddOption(PackageCommand.GetInstallerContextOption(isHidden: true));
AddOption(PackageCommand.GetPackageAsScriptOption(isHidden: true));
this.Handler = CommandHandler.Create(HandleCommand);
}

Expand Down Expand Up @@ -78,7 +79,7 @@ private async Task<int> HandleCommand(PublishCommandOptions options, InvocationC
await intuneManager.GenerateInstallerPackage(options.TempFolder,
options.PackageFolder!,
tempInfo,
new PackageOptions { Architecture = options.Architecture, InstallerContext = options.InstallerContext },
new PackageOptions { Architecture = options.Architecture, InstallerContext = options.InstallerContext, PackageScript = options.PackageScript == true },
cancellationToken);
}
packageInfo = tempInfo.Source == PackageSource.Store || options.AutoPackage
Expand Down Expand Up @@ -130,4 +131,5 @@ internal class PublishCommandOptions : WinGetRootCommand.DefaultOptions
public string TempFolder { get; set; }
public InstallerContext InstallerContext { get; set; }
public Architecture Architecture { get; set; }
public bool? PackageScript { get; set; }
}
Loading

0 comments on commit 8fecb33

Please sign in to comment.