apt-get command line program in Linux,
you may had used apt-get install,
apt-get update for managment your Linux software,
but how about in Windows?
Welcome!
apt-get command line program in Linux,
you may had used apt-get install,
apt-get update for managment your Linux software,
but how about in Windows?
apt-get.
It allows you to install, upgrade, configure, and uninstall Windows software.
For example, just simplly type choco install PROGRAM_NAME in command line,
choco will automatelly install the program that you need.
private static void Main(string[] args) which in file src/chocolatey.console/Program.cs.
public sealed class Program
{
// ReSharper disable InconsistentNaming
private static void Main(string[] args)
// ReSharper restore InconsistentNaming
{
try
{
add_assembly_resolver();
string loggingLocation = ApplicationParameters.LoggingLocation;
//no file system at this point
if (!Directory.Exists(loggingLocation)) Directory.CreateDirectory(loggingLocation);
......
After do some variables and directories checking,
the argument of command input will pass to ConfigurationBuilder.set_up_configuration(args,config,container,license,warning => {warnings.Add(warning);});)
This function will parse argument, configurate file path and set environment values.
public static void set_up_configuration(IList args, ChocolateyConfiguration config, Container container, ChocolateyLicense license, Action notifyWarnLoggingAction)
{
var fileSystem = container.GetInstance();
var xmlService = container.GetInstance();
var configFileSettings = get_config_file_settings(fileSystem, xmlService);
// must be done prior to setting the file configuration
add_or_remove_licensed_source(license, configFileSettings);
set_file_configuration(config, configFileSettings, fileSystem, notifyWarnLoggingAction);
ConfigurationOptions.reset_options();
set_global_options(args, config, container);
set_environment_options(config);
EnvironmentSettings.set_environment_variables(config);
// must be done last for overrides
set_licensed_options(config, license, configFileSettings);
// save all changes if there are any
set_config_file_settings(configFileSettings, xmlService, config);
set_hash_provider(config, container);
}
Following, a run() function which belong to src\chocolatey\infrastructure.app\runners\ConsoleApplication.cs will handle the input command
......
AssemblyFileExtractor.extract_all_resources_to_relative_directory(fileSystem, Assembly.GetAssembly(typeof(ChocolateyResourcesAssembly)), ApplicationParameters.InstallLocation, folders, ApplicationParameters.ChocolateyFileResources);
var application = new ConsoleApplication();
application.run(args, config, container);
}
catch (Exception ex)
{
if (ApplicationParameters.is_debug_mode_cli_primitive())
......
The next run() function (src\chocolatey\infrastructure.app\runners\GenericRunner.cs) will be called and continue to execute the input command
......
commandArgs.Add(arg);
}
var runner = new GenericRunner();
runner.run(config, container, isConsole: true, parseArgs: command =>
{
ConfigurationOptions.parse_arguments_and_update_configuration(
commandArgs,
config,
......
The seecond run() function invokes find_command(config, container, isConsole, parseArgs);
and gets an instance which ontains run(chocolatey.infrastructure.app.configuration.ChocolateyConfiguration configuration)
chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs. This run() function is specifit for install command
Continuing the install command, get_script_for_action() function will be called for determining which power shell script should be used.
private string get_script_for_action(PackageResult packageResult, CommandNameType command)
{
var file = "chocolateyInstall.ps1";
switch (command)
{
case CommandNameType.uninstall:
file = "chocolateyUninstall.ps1";
break;
case CommandNameType.upgrade:
file = "chocolateyBeforeModify.ps1";
break;
}
......
Another core file is Nuget.Core. Nuget is a Microsoft platform package manager.
Yes, Chocolatey is using Nuget.Core to connect packages source server to get and unzip .nupkg
......
<add key="proxyUser" value="" />
<add key="proxyPassword" value="" />
</config>
<sources>
<source id="chocolatey" value="https://chocolatey.org/api/v2/" />
</sources>
<features>
<feature name="checksumFiles" enabled="true" />
<feature name="autoUninstaller" enabled="false" />
......
<id>, <version>, <description>, and <authors>
The following is a basic vlv.nuspec for VLC Media Player
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>vlc</id>
<version>2.2.4.20161210</version>
......
<authors>VideoLAN Organization</authors>
<description>
......
</description>
......
</metadata>
</package>
Now switch to file chocolateyInstall.ps1. The core code is very simple.
In src\chocolatey\infrastructure.app\templates, you will find our more detail of chocolateyInstall.ps1
$packageArgs = @{
packageName = 'packagename'
fileType = 'msi'
url = 'https://example.com/where.to.download.32bit.msi'
url64bit = 'https://example.com/where.to.download.64bit.msi'
......
}
Install-ChocolateyPackage @packageArgs
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- jnuget.users.xml -->
<users>
<user name="admin" password="1234">
<role>jnuget-admin</role>
</user>
</users>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- jnuget.config.xml -->
<options>
<storages>
<storage class="ru.aristar.jnuget.sources.ClassicPackageSource" indexed="false" storageName="DefaultSource" public="true" canPush="true" canDelete="true">
<properties>
<property name="folderName" value="${nuget.home}/Packages/"/>
</properties>
</storage>
</storages>
</options>