jdeb icon indicating copy to clipboard operation
jdeb copied to clipboard

Pass variables from jdeb plugin to postinst script

Open swc-kdzekov opened this issue 8 months ago • 6 comments

Hello all,

I'm working on migrating .rpm packaging to .deb for a spring boot service. For that reason I use org.vafer:jdeb:1.5. Most of the feature that were used by the rpm maven plugin were nicely replaced by 'jdeb'. However, I haven't found how to set environmental variables carrying information from the plugin configuration to 'postinst' script. For example: installation path, application name, application version etc. I would like to keep that information in the pom file (where org.vafer:deb is configured), and then use it in postinst script. Could somebody help here on how if that is possible ?

Here is a piece of the maven pom configuration:

`

    <app.version>1.1.1</app.version> <!-- to remove the -SNAPSHOT -->
    <app.name>cyan-phishing</app.name>
    <app.script.name>cyan-phishing-tmp.sh</app.script.name>
    <app.description>CYAN Phishing</app.description>
    <app.dir>phishing</app.dir>
    <app.base.dir>/opt/cyan/${app.dir}/${app.version}</app.base.dir>
    <app.lib.dir>${app.base.dir}/lib</app.lib.dir>
    <app.conf.dir>${app.base.dir}/configuration</app.conf.dir>
    <app.phish.dir>${app.base.dir}/phish_checker</app.phish.dir>
    <app.pid.dir>/var/run/cyan/${app.dir}/${app.version}</app.pid.dir>
    <app.log.dir>/var/log/cyan/${app.dir}/${app.version}</app.log.dir>
    <app.lock.dir>/var/lock/cyan/${app.dir}/${app.version}</app.lock.dir>
    <app.opt.dir>/var/opt/cyan/${app.dir}/</app.opt.dir>
    <app.artifact.prefix>cyan-phishing</app.artifact.prefix>
    <app.user>phishing</app.user>
    <app.group>cyan</app.group>
    <app.required.hosts>phishing-db-cl</app.required.hosts>

    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <jdeb.version>1.5</jdeb.version>

    <deb.jdk.version>jdk1.8</deb.jdk.version>
    <inew.daemon.version>2.0.9</inew.daemon.version>
    <inew.database.manager.version>1.0.2</inew.database.manager.version>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-libs</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/lib</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>jdeb</artifactId>
            <groupId>org.vafer</groupId>
            <version>${jdeb.version}</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>jdeb</goal>
                    </goals>
                    <configuration>
                        <controlDir>${basedir}/src/deb/control</controlDir>
                        <dataSet>
                            <data>
                                <src>${basedir}/src/main/resources/scripts/${app.script.name}</src>
                                <type>file</type>
                                <mapper>
                                    <type>perm</type>
                                    <prefix>${app.base.dir}</prefix>
                                </mapper>
                            </data>
                            <data>
                                <src>${project.build.directory}/lib</src>
                                <type>directory</type>
                                <mapper>
                                    <type>perm</type>
                                    <prefix>${app.base.dir}/lib</prefix>
                                </mapper>
                            </data>
                            <data>
                                <src>src/main/resources/configuration</src>
                                <type>directory</type>
                                <mapper>
                                    <type>perm</type>
                                    <prefix>${app.base.dir}/configuration</prefix>
                                </mapper>
                            </data>
                            <!-- copy the debian jar file in the lib folder -->
                            <data>
                                <src>${project.build.directory}/${project.artifactId}-${project.version}.jar</src>
                                <type>file</type>
                                <mapper>
                                    <type>perm</type>
                                    <prefix>${app.base.dir}/lib</prefix>
                                </mapper>
                            </data>
                        </dataSet>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>`

Best Regards, Konstantin

swc-kdzekov avatar Mar 14 '25 15:03 swc-kdzekov

We are passing the variable resolver into the control builder

https://github.com/tcurdt/jdeb/blob/6d96da832f7bc859479420f65eff1b3179d5b793/src/main/java/org/vafer/jdeb/ControlBuilder.java#L67

The postinst should already be filtered.

https://github.com/tcurdt/jdeb/blob/6d96da832f7bc859479420f65eff1b3179d5b793/src/main/java/org/vafer/jdeb/ControlBuilder.java#L125

The tokens are define here

https://github.com/tcurdt/jdeb/blob/master/src/main/java/org/vafer/jdeb/utils/FilteredFile.java#L29

Does that help?

tcurdt avatar Mar 16 '25 20:03 tcurdt

Thank you for your response! I will have a look.

swc-kdzekov avatar Mar 16 '25 22:03 swc-kdzekov

@tcurdt That is very implementation of the plugin. I'm wondering how to define environmental variables so that I would use them in the pre/post instal scripts?

In rpm maven plugin there is something like < defineStatements > within the configuration where one could define the variables.

swc-kdzekov avatar Mar 17 '25 13:03 swc-kdzekov

@tcurdt That is very implementation of the plugin. I'm wondering how to define environmental variables so that I would use them in the pre/post instal scripts?

You don't really need to. All the Maven properties are by default reusable in generated files. See for example https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-distribution/xwiki-platform-distribution-debian/xwiki-platform-distribution-debian-solr/xwiki-platform-distribution-debian-solr-cores/xwiki-platform-distribution-debian-solr-core-events/src/deb/control/postinst which is simply printing the content of the Maven property defined in a parent pom at https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-distribution/xwiki-platform-distribution-debian/xwiki-platform-distribution-debian-solr/xwiki-platform-distribution-debian-solr-cores/pom.xml#L59.

tmortagne avatar Mar 17 '25 14:03 tmortagne

Alright, this looks more concrete. Thanks!

swc-kdzekov avatar Mar 17 '25 14:03 swc-kdzekov

@swc-kdzekov can this be closed? or is it still a problem?

tcurdt avatar May 18 '25 16:05 tcurdt

no response ... seems to be solved ... closing

tcurdt avatar Nov 03 '25 22:11 tcurdt