Coder Social home page Coder Social logo

Comments (6)

cat-in-136 avatar cat-in-136 commented on July 17, 2024

Generally speaking, TOML can accept "here-document". My app also accept it. Please specify script as follows:

[package.metadata.generate-rpm]
pre_install_script = """
echo some command > /dev/null
echo another command > /dev/null
"""

from cargo-generate-rpm.

ximon18 avatar ximon18 commented on July 17, 2024

Thanks.

And if I want the script to be a file outside of Cargo.toml? I'd rather not put lots of Bash script into my Cargo.toml.

Ximon

Update: Hmm, I suppose I could use the here-doc approach to enable me to both execute and remove a script placed in /tmp/ as a workaround.

from cargo-generate-rpm.

cat-in-136 avatar cat-in-136 commented on July 17, 2024

Like RPM native spec file format, scriptlets shall be written Cargo.toml directly. It is not really intended to be huge scripts with more than hundred lines long.

IMHO, considering the transparency for users, it is better to leave the large script stored in a separated file such as /usr/share/foobar/rpm/install-script.sh so that they can refer to it later.

from cargo-generate-rpm.

ximon18 avatar ximon18 commented on July 17, 2024

Thanks for the advice. I do not want scriptlets in Cargo.toml, I don't want it to become cluttered and to mix purposes and languages together like that. However I hadn't thought about using assets under /usr/share, I will try that as indeed it is good if the scripts invoked are available on the host post (successful or failed) install.

from cargo-generate-rpm.

ximon18 avatar ximon18 commented on July 17, 2024

So we realized that the workaround of specifying a command that runs a script file doesn't work for post_uninstall_script as by the time it is run the script has been removed from disk.

Still not wanting to pollute my Cargo.toml with Bash scripts I'm now trying to see if the new --set-metadata functionality can help here, with:

cargo generate-rpm --set-metadata "post_uninstall_script = \"\"\"$(cat pkg/rpm/postuninst)\"\"\""

This looks fine when the created package is inspected:

$ rpm -qp --scripts target/generate-rpm/routinator-0.12.0-dev-1.x86_64.rpm 
postinstall scriptlet:
/usr/share/routinator/rpm/postinst $*
preuninstall scriptlet:
/usr/share/routinator/rpm/preuninst $*
postuninstall scriptlet:
#!/bin/bash -e
# Script based on the RPM %systemd_postun scriptlet. See:
#   - https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_systemd
#   - https://cgit.freedesktop.org/systemd/systemd/tree/src/core/macros.systemd.in

systemctl daemon-reload >/dev/null 2>&1 || :
if [ $1 -ge 1 ] ; then
    systemctl try-restart routinator.service >/dev/null 2>&1 || :
fi

from cargo-generate-rpm.

cat-in-136 avatar cat-in-136 commented on July 17, 2024

Since it is up to an RPM specification, these scripts should be defined using a multi-string string, such as #17 (comment). Of course, you can use escaped linefeed \n in a basic string instead of raw string in a multi-line basic string (see also: https://toml.io/en/v1.0.0#string ).

from cargo-generate-rpm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.