public void BuildDebPackageWithScriptsTest()
        {
            List <ArchiveEntry> entries = new List <ArchiveEntry>()
            {
                new ArchiveEntry()
                {
                    TargetPath        = "/usr/bin/demo",
                    FileSize          = 1024,
                    Md5Hash           = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F },
                    RemoveOnUninstall = true
                },

                new ArchiveEntry()
                {
                    TargetPath        = "/opt/local/test",
                    FileSize          = 4096,
                    Md5Hash           = new byte[] { 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F },
                    RemoveOnUninstall = true
                }
            };

            var pkg = DebPackageCreator.BuildDebPackage(
                entries,
                "demo",
                "Demo Package",
                "Demo User",
                "1.0.0",
                "x86-64",
                createUser: true,
                userName: "******",
                installService: true,
                serviceName: "demoservice",
                prefix: "/opt/local",
                section: null,
                priority: null,
                homepage: null,
                preInstallScript: "echo 'Hello from pre install'",
                postInstallScript: "echo 'Hello from post install'",
                preRemoveScript: "echo 'Hello from pre remove'",
                postRemoveScript: "echo 'Hello from post remove'",
                additionalDependencies: null,
                recommends: null,
                additionalMetadata: null);

            Assert.Equal(@"/usr/sbin/groupadd -r demouser 2>/dev/null || :
/usr/sbin/useradd -g demouser -s /sbin/nologin -r demouser 2>/dev/null || :
echo 'Hello from pre install'
", pkg.PreInstallScript, ignoreLineEndingDifferences: true);
            Assert.Equal(@"systemctl daemon-reload
systemctl enable --now demoservice.service
echo 'Hello from post install'
", pkg.PostInstallScript, ignoreLineEndingDifferences: true);
            Assert.Equal(@"systemctl --no-reload disable --now demoservice.service
echo 'Hello from pre remove'
", pkg.PreRemoveScript, ignoreLineEndingDifferences: true);
            Assert.Equal(@"/bin/rm -rf /usr/bin/demo
/bin/rm -rf /opt/local/test
echo 'Hello from post remove'
", pkg.PostRemoveScript, ignoreLineEndingDifferences: true);
        }
        public void BuildDebPackageWithRecommendsTest()
        {
            List <ArchiveEntry> entries = new List <ArchiveEntry>();
            var recommends = new string[]
            {
                "usbmuxd"
            };

            var pkg = DebPackageCreator.BuildDebPackage(
                entries,
                "demo",
                "Demo Package",
                "Demo User",
                "1.0.0",
                "x86-64",
                createUser: false,
                userName: null,
                installService: false,
                serviceName: null,
                prefix: "/opt/local",
                section: null,
                priority: null,
                homepage: null,
                preInstallScript: null,
                postInstallScript: null,
                preRemoveScript: null,
                postRemoveScript: null,
                additionalDependencies: null,
                recommends: recommends,
                additionalMetadata: null);

            Assert.NotNull(pkg.ControlFile);
            Assert.Equal("usbmuxd", pkg.ControlFile["Recommends"]);
        }
        public void BuildDebPackageWithDependenciesTest()
        {
            List <ArchiveEntry> entries = new List <ArchiveEntry>();
            var dependencies            = new string[]
            {
                "libc6",
                "libcurl3 | libcurl4",
                "libgcc1",
                "libgssapi-krb5-2",
                "liblttng-ust0",
                "libssl0.9.8 | libssl1.0.0 | libssl1.0.1 | libssl1.0.2",
                "libstdc++6",
                "libunwind8",
                "libuuid1",
                "zlib1g",
                "libicu52 | libicu53 | libicu54 | libicu55 | libicu56 | libicu57 | libicu58 | libicu59"
            };

            var pkg = DebPackageCreator.BuildDebPackage(
                entries,
                "demo",
                "Demo Package",
                "Demo User",
                "1.0.0",
                "x86-64",
                createUser: false,
                userName: null,
                installService: false,
                serviceName: null,
                prefix: "/opt/local",
                section: null,
                priority: null,
                homepage: null,
                preInstallScript: null,
                postInstallScript: null,
                preRemoveScript: null,
                postRemoveScript: null,
                additionalDependencies: dependencies,
                recommends: null,
                additionalMetadata: null);

            Assert.NotNull(pkg.ControlFile);
            Assert.Equal("libc6, libcurl3 | libcurl4, libgcc1, libgssapi-krb5-2, liblttng-ust0, libssl0.9.8 | libssl1.0.0 | libssl1.0.1 | libssl1.0.2, libstdc++6, libunwind8, libuuid1, zlib1g, libicu52 | libicu53 | libicu54 | libicu55 | libicu56 | libicu57 | libicu58 | libicu59", pkg.ControlFile["Depends"]);
            Assert.False(pkg.ControlFile.ContainsKey("Recommends"));
        }
        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);
                }
        }
        public void BuildDebPackageTest()
        {
            List <ArchiveEntry> entries = new List <ArchiveEntry>()
            {
                new ArchiveEntry()
                {
                    TargetPath = "/usr/bin/demo",
                    FileSize   = 1024,
                    Md5Hash    = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }
                },

                new ArchiveEntry()
                {
                    TargetPath = "/opt/local/test",
                    FileSize   = 4096,
                    Md5Hash    = new byte[] { 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }
                }
            };

            var pkg = DebPackageCreator.BuildDebPackage(
                entries,
                "demo",
                "Demo Package",
                "Demo User",
                "1.0.0",
                "x86-64",
                createUser: false,
                userName: null,
                installService: false,
                serviceName: null,
                prefix: "/opt/local",
                section: null,
                priority: null,
                homepage: null,
                preInstallScript: null,
                postInstallScript: null,
                preRemoveScript: null,
                postRemoveScript: null,
                additionalDependencies: null,
                additionalMetadata: null);

            Assert.NotNull(pkg.Md5Sums);
            Assert.Null(pkg.ControlExtras);
            Assert.NotNull(pkg.ControlFile);

            Assert.Equal(2, pkg.Md5Sums.Count);
            Assert.Equal(6, pkg.ControlFile.Count);

            Assert.Equal("000102030405060708090a0b0c0d0e0f", pkg.Md5Sums["usr/bin/demo"]);
            Assert.Equal("0f0e0d0c0b0a090808090a0b0c0d0e0f", pkg.Md5Sums["opt/local/test"]);

            Assert.Equal("demo", pkg.ControlFile["Package"]);
            Assert.Equal("1.0.0", pkg.ControlFile["Version"]);
            Assert.Equal("x86-64", pkg.ControlFile["Architecture"]);
            Assert.Equal("Demo User", pkg.ControlFile["Maintainer"]);
            Assert.Equal("Demo Package", pkg.ControlFile["Description"]);
            Assert.Equal("5", pkg.ControlFile["Installed-Size"]);

            Assert.Equal(new Version(2, 0), pkg.PackageFormatVersion);
            Assert.Null(pkg.PostInstallScript);
            Assert.Null(pkg.PostRemoveScript);
            Assert.Null(pkg.PreInstallScript);
            Assert.Null(pkg.PreRemoveScript);
        }
Exemplo n.º 6
0
        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();
                    var            archiveEntries = archiveBuilder.FromDirectory(
                        this.PublishDir,
                        this.Prefix,
                        this.Content);

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

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

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

                    // Prepare the list of dependencies
                    PackageDependency[] dependencies = Array.Empty <PackageDependency>();

                    if (this.DebDependencies != null)
                    {
                        dependencies = this.DebDependencies.Select(
                            d => new PackageDependency
                        {
                            Name    = d.ItemSpec,
                            Version = d.GetVersion()
                        }).ToArray();
                    }

                    // 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))
                    {
                        DebPackageCreator.BuildDebPackage(
                            archiveEntries,
                            tarXzStream,
                            this.PackageName,
                            this.Description,
                            this.Maintainer,
                            this.Version,
                            "amd64",
                            this.CreateUser,
                            this.UserName,
                            this.InstallService,
                            this.ServiceName,
                            this.Prefix,
                            dependencies,
                            null,
                            targetStream);
                    }

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

                    return(true);
                }
        }
Exemplo n.º 7
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);
        }