public List <string> Packages() { var packages = _processRunner.ReadShell("apt-cache pkgnames", new RunnerOptions { Env = new Dictionary <string, string> { { "APT_CONFIG", _aptDirectoryPrepService.AptConfigFile }, { "DEBIAN_FRONTEND", "noninteractive" }, { "DEBCONF_NONINTERACTIVE_SEEN", "true" }, { "LC_ALL", "C" }, { "LANGUAGE", "C" }, { "LANG", "C" } } }); return(packages.Split(Environment.NewLine).Where(x => !string.IsNullOrEmpty(x)).ToList()); }
private List <AptRepo> GetRepositories(Image image = null) { if (image == null) { image = GetImage(); } return(image.Repositories.SelectMany(x => { var result = new List <AptRepo> { x }; if (x.IncludeSourcePackages && !x.Source) { result.Add(new AptRepo(x.Trusted, x.Uri, x.Distribution, true, x.Components.ToArray())); } return result; }).Select(x => { // Let's detect if we have a relative path to a local repo. // if we detect "file:../somewhere", we need to resolve that path, relative to // the images.json files. if (x.Uri.StartsWith("file:")) { var path = x.Uri.Substring("file:".Length); if (Path.IsPathRooted(path)) { // Absolute paths don't need to be changed. return x; } var absolutePath = _processRunner.ReadShell($"readlink -f {path}", new RunnerOptions { WorkingDirectory = _workspaceConfig.RootDirectory }).TrimEnd(Environment.NewLine.ToArray()); if (string.IsNullOrEmpty(absolutePath)) { throw new Exception($"Unknown file path for apt repo: {path}"); } return new AptRepo(x.Trusted, $"file:{absolutePath}", x.Distribution, x.Source, x.Components.ToArray()); } return x; }).ToList()); }
public List <string> Extract(string debFile, string directory, bool useSudo) { var output = _processRunner.ReadShell($"dpkg -X {debFile} {directory}", new RunnerOptions { UseSudo = useSudo, Env = new Dictionary <string, string> { { "LC_ALL", "C" } } }); return(output.Split(Environment.NewLine).Where(x => !string.IsNullOrEmpty(x)).ToList()); }
public Dictionary <string, AptVersion> SimulateInstall(Dictionary <string, AptVersion> packages) { var result = new Dictionary <string, AptVersion>(); var output = _processRunner.ReadShell($"apt-get install -s -y {string.Join(" ", packages.Select(x => x.Value.ToCommandParameter(x.Key)))}", new RunnerOptions { Env = new Dictionary <string, string> { { "APT_CONFIG", _aptDirectoryPrepService.AptConfigFile }, { "DEBIAN_FRONTEND", "noninteractive" }, { "DEBCONF_NONINTERACTIVE_SEEN", "true" }, { "LC_ALL", "C" }, { "LANGUAGE", "C" }, { "LANG", "C" } } }); using (var streamReader = new StringReader(output)) { var line = streamReader.ReadLine(); while (line != null) { var match = Regex.Match(line, @"Inst (\S*) \((\S*)(.*)\[(\S*)\]\)"); if (match.Success) { var packageName = match.Groups[1].Captures[0].Value; var version = match.Groups[2].Captures[0].Value; var architecture = match.Groups[4].Captures[0].Value; result.Add(packageName, new AptVersion(version, architecture)); } line = streamReader.ReadLine(); } } return(result); }