Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If the scripts happen to be paths that exist load them #93

Merged
merged 1 commit into from
Sep 5, 2023

Conversation

jtk18
Copy link
Contributor

@jtk18 jtk18 commented Aug 23, 2023

This is an attempt to resolve issue 86. This way if the script is a path, we can load that into the RPM instead of relying on installing the script manually.

@jtk18
Copy link
Contributor Author

jtk18 commented Aug 31, 2023

Here are the changes I did to the Cargo.toml for testing

diff --git a/Cargo.toml b/Cargo.toml
index 2c7a834..ee51db3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -29,3 +29,4 @@ assets = [
     { source = "LICENSE", dest = "/usr/share/doc/cargo-generate-rpm/LICENSE", doc = true, mode = "0644" },
     { source = "README.md", dest = "/usr/share/doc/cargo-generate-rpm/README.md", doc = true, mode = "0644" }
 ]
+pre_install_script = "pre.sh"

Here's the bash script I made:

[root@me cargo-generate-rpm]# cat pre.sh
#!/bin/bash

echo "THIS WORKS"

Here's it working and the files included.

[root@me repos]# rpm -i cargo-generate-rpm-0.12.1-1.x86_64.rpm
THIS WORKS
[root@me repos]# rpm -qlp cargo-generate-rpm-0.12.1-1.x86_64.rpm
/usr/bin/cargo-generate-rpm
/usr/share/doc/cargo-generate-rpm/LICENSE
/usr/share/doc/cargo-generate-rpm/README.md

Please LMK if you need anything else or would like any changes. I was thinking about making a macro if you think that would be better.

Thank you!

@cat-in-136 cat-in-136 added the enhancement New feature or request label Sep 2, 2023
@cat-in-136
Copy link
Owner

@jtk18 Thank you for new feature implementation.

Two issues.

  1. workspace consideration

Your code lacks consideration of workspace. It is appropriate to check the relative path from the package base as well as the current directory base for the file path base, as like the asset does.

When the option -p specified, first, the asset file source shall be treated as a relative path from the current directory. If not found, it shall be treated as a relative path from the directory of the package. If both not found, cargo generate-rpm shall fail with an error.

You can see this process at the bottom of the generate_expanded_path() function in file_info.rs.

  1. README update

This is very trivial, but please update README.md. Short concise changes are enough. For example, optional string or file path of xxxx_install_script.

@cat-in-136 cat-in-136 linked an issue Sep 2, 2023 that may be closed by this pull request
This is an attempt to resolve issue 86. This way if the script is a path,
we can load that into the RPM instead of relying on installing the script manually.
@jtk18
Copy link
Contributor Author

jtk18 commented Sep 3, 2023

Thanks for pointing out the issues. I think this change covers it, but I wasn't sure since I don't have a workspace project to test on. This change works w/ the previous testing I had done and if the asset isn't a path.

Please LMK if I missed anything or you'd like changes. Thank you!

@cat-in-136
Copy link
Owner

There is small incompatibility in case of specifying just shell script of post_install_script = "/usr/share/foobar/postinst". But this change is accept because we can easily resolve like as following:

post_install_script = "/usr/share/foobar/postinst $*"

or

post_install_script = """
/usr/share/foobar/postinst
"""

@cat-in-136 cat-in-136 merged commit 01a8182 into cat-in-136:master Sep 5, 2023
1 check passed
@cat-in-136
Copy link
Owner

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Script parameters should accept path to files, not script intself
2 participants