public override bool Execute()
        {
            this.Log.LogMessage(
                MessageImportance.High,
                "Creating DEB package '{0}' from folder '{1}'",
                this.DebPath,
                this.PublishDir);

            using (var targetStream = File.Open(this.DebPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                using (var tarStream = File.Open(this.DebTarPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                {
                    ArchiveBuilder archiveBuilder = new ArchiveBuilder()
                    {
                        Log = this.Log,
                    };

                    var archiveEntries = archiveBuilder.FromDirectory(
                        this.PublishDir,
                        this.AppHost,
                        this.Prefix,
                        this.Content);

                    archiveEntries.AddRange(archiveBuilder.FromLinuxFolders(this.LinuxFolders));
                    EnsureDirectories(archiveEntries);

                    archiveEntries = archiveEntries
                                     .OrderBy(e => e.TargetPathWithFinalSlash, StringComparer.Ordinal)
                                     .ToList();

                    TarFileCreator.FromArchiveEntries(archiveEntries, tarStream);
                    tarStream.Position = 0;

                    // Prepare the list of dependencies
                    List <string> dependencies = new List <string>();

                    if (this.DebDependencies != null)
                    {
                        var debDependencies = this.DebDependencies.Select(d => d.ItemSpec).ToArray();

                        dependencies.AddRange(debDependencies);
                    }

                    if (this.DebDotNetDependencies != null)
                    {
                        var debDotNetDependencies = this.DebDotNetDependencies.Select(d => d.ItemSpec).ToArray();

                        dependencies.AddRange(debDotNetDependencies);
                    }

                    // Prepare the list of recommended dependencies
                    List <string> recommends = new List <string>();

                    if (this.DebRecommends != null)
                    {
                        recommends.AddRange(this.DebRecommends.Select(d => d.ItemSpec));
                    }

                    // XZOutputStream class has low quality (doesn't even know it's current position,
                    // needs to be disposed to finish compression, etc),
                    // So we are doing compression in a separate step
                    using (var tarXzStream = File.Open(this.DebTarXzPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                        using (var xzStream = new XZOutputStream(tarXzStream))
                        {
                            tarStream.CopyTo(xzStream);
                        }

                    using (var tarXzStream = File.Open(this.DebTarXzPath, FileMode.Open, FileAccess.Read, FileShare.None))
                    {
                        var pkg = DebPackageCreator.BuildDebPackage(
                            archiveEntries,
                            this.PackageName,
                            this.Description,
                            this.Maintainer,
                            this.Version,
                            !string.IsNullOrWhiteSpace(this.DebPackageArchitecture) ? this.DebPackageArchitecture : GetPackageArchitecture(this.RuntimeIdentifier),
                            this.CreateUser,
                            this.UserName,
                            this.InstallService,
                            this.ServiceName,
                            this.Prefix,
                            this.Section,
                            this.Priority,
                            this.Homepage,
                            this.PreInstallScript,
                            this.PostInstallScript,
                            this.PreRemoveScript,
                            this.PostRemoveScript,
                            dependencies,
                            recommends,
                            null);

                        DebPackageCreator.WriteDebPackage(
                            archiveEntries,
                            tarXzStream,
                            targetStream,
                            pkg);
                    }

                    this.Log.LogMessage(
                        MessageImportance.High,
                        "Created DEB package '{0}' from folder '{1}'",
                        this.DebPath,
                        this.PublishDir);

                    return(true);
                }
        }
示例#2
0
        public static void HandlerItem(bool dev, PublishDirInfo item)
        {
            var debPath = GetPackPath(dev, item, FileEx.DEB);
            //var debTarPath = GetPackPath(item, FileEx.DEB_TAR);
            var debTarXzPath = GetPackPath(dev, item, FileEx.DEB_TAR_XZ);

            using var targetStream = File.Open(debPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None);
            //using var tarStream = File.Open(debTarPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None);
            using var tarStream = new MemoryStream();

            ArchiveBuilder2 archiveBuilder2 = new()
            {
                Log = TaskLoggingHelper.Instance,
            };
            ArchiveBuilder archiveBuilder = archiveBuilder2;

            var archiveEntries = archiveBuilder.FromDirectory(
                item.Path,
                Constants.HARDCODED_APP_NAME,
                LinuxPackConstants.Prefix,
                Array.Empty <ITaskItem>());

            LinuxPackConstants.AddFileNameDesktop(archiveBuilder2, archiveEntries);

            //archiveEntries.AddRange(archiveBuilder.FromLinuxFolders(this.LinuxFolders));
            DebTask.EnsureDirectories(archiveEntries);

            archiveEntries = archiveEntries
                             .OrderBy(e => e.TargetPathWithFinalSlash, StringComparer.Ordinal)
                             .ToList();

            TarFileCreator.FromArchiveEntries(archiveEntries, tarStream);
            tarStream.Position = 0;

            // Prepare the list of dependencies
            List <string> dependencies = new List <string>();

            if (item.DeploymentMode == DeploymentMode.FDE)
            {
                dependencies.Add(LinuxPackConstants.aspnetcore_runtime_6_0);
            }

            //if (this.DebDependencies != null)
            //{
            //    var debDependencies = this.DebDependencies.Select(d => d.ItemSpec).ToArray();

            //    dependencies.AddRange(debDependencies);
            //}

            //if (this.DebDotNetDependencies != null)
            //{
            //    var debDotNetDependencies = this.DebDotNetDependencies.Select(d => d.ItemSpec).ToArray();

            //    dependencies.AddRange(debDotNetDependencies);
            //}

            // Prepare the list of recommended dependencies
            List <string> recommends = new List <string>();

            //if (this.DebRecommends != null)
            //{
            //    recommends.AddRange(this.DebRecommends.Select(d => d.ItemSpec));
            //}

            // XZOutputStream class has low quality (doesn't even know it's current position,
            // needs to be disposed to finish compression, etc),
            // So we are doing compression in a separate step
            using (var tarXzStream = File.Open(debTarXzPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                using (var xzStream = new XZOutputStream(tarXzStream, XZOutputStream.DefaultThreads, XZOutputStream.DefaultPreset, true))
                {
                    tarStream.CopyTo(xzStream);
                }

            using (var tarXzStream = File.Open(debTarXzPath, FileMode.Open, FileAccess.Read, FileShare.None))
            {
                var pkg = DebPackageCreator.BuildDebPackage(
                    archiveEntries,
                    LinuxPackConstants.PackageName,
                    LinuxPackConstants.Description,
                    LinuxPackConstants.DebMaintainer,
                    Utils.GetVersion(dev),
                    DebTask.GetPackageArchitecture(item.Name),
                    LinuxPackConstants.CreateUser,
                    LinuxPackConstants.UserName,
                    LinuxPackConstants.InstallService,
                    LinuxPackConstants.ServiceName,
                    LinuxPackConstants.Prefix,
                    //LinuxPackConstants.DebSection,
                    "utils",
                    LinuxPackConstants.DebPriority,
                    LinuxPackConstants.DebHomepage,
                    LinuxPackConstants.PreInstallScript,
                    LinuxPackConstants.PostInstallScript,
                    LinuxPackConstants.PreRemoveScript,
                    LinuxPackConstants.PostRemoveScript,
                    dependencies,
                    recommends,
                    null !);

                DebPackageCreator.WriteDebPackage(
                    archiveEntries,
                    tarXzStream,
                    targetStream,
                    pkg);
            }

            File.Delete(debTarXzPath);
        }