1

I have some code/macros that are used inside scriptlets, but they need to run slightly differently depending on which scriptlet they're in. It's easy enough to distinguish triggers from not triggers by checking $1 and $2, so more specifically all i need to know is whether I'm installing (inside %pre, %post, %triggerin) or uninstalling (%preun, %postun, %triggerun). For an upgrade, i would first be running install scriplets and then some uninstall scriplets.

I just need to be able to detect install phase or uninstall phase from a scriplet. Either using macro or bash script. Turns out this is vastly more difficult than I imagined, and I've dug through the rpm source code and even built-in lua interpreter: no dice.

Obviously i could just put a "stage=triggerin" or similar into each scriplet, but I'm trying to do it without having to manually modify each scriptlet i have, with the exception of creating some kind of defines at the top of my SPEC that hook the scriptlets.

One attempt i made was to create a very intricate parameterized macro called scriplet_hook() that i would call multiple times at the start of the whole SPEC to "hook" each scriplet, overwriting the scriplet name with a define that attempted to append something to it (bash code or macro) that would mark the stage once the parser gets there or once the bash script is running, but dealing with preserving the scriplet arguments (-p /bin/sh for example) turned out to be too difficult.

I've used the built-in lua interpreter to recursively dump all the tables recursively (_G) and examine the contents, besides a table for patches / sources and the rpm extension that grants a few functions, there's nothing there.

Any ideas?

David Davidson
  • 318
  • 3
  • 12
  • I'm fairly sure the only way you're going to get that is what you already rejected - a call-site argument. – Aaron D. Marasco Sep 23 '22 at 00:10
  • 1
    I got close, i remembered that you can pass the interpreter parameters: %scriplet -p '/bin/sh -c "param=1 /bin/sh $0 $@"' so i pass any value i want to my scriptlet scripts. THIS WORKS! Except: trigger scriptlets are not allowed to pass arguments to their interpreter, fails on build. So it works except for triggers. Again stumped. – David Davidson Sep 23 '22 at 04:11
  • Tricky - I like it! I think it's answer-worthy. – Aaron D. Marasco Sep 23 '22 at 21:27

0 Answers0