Bug 1195850 - installation hooks are not working
installation hooks are not working
Classification: openSUSE
Product: openSUSE Tumbleweed
Classification: openSUSE
Component: Installation
Other Other
: P5 - None : Normal (vote)
: ---
Assigned To: YaST Team
Jiri Srain
Depends on:
  Show dependency treegraph
Reported: 2022-02-11 18:41 UTC by Giacomo Comes
Modified: 2022-02-15 09:57 UTC (History)
3 users (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Note You need to log in before you can comment on or make changes to this bug.
Description Giacomo Comes 2022-02-11 18:41:28 UTC
I'm trying to use hooks as described here:
What I did is to create the file "before_copy_logs_finish_00_test_hook.sh"
and put it in var/lib/YaST2/hooks/installation in the 'root' image that is used at installation time (to be clear like the one that is available in:
At the the end of the installation process, the script before_copy_logs_finish_00_test_hook.sh is supposed to be executed, but that doesn't happen. The log /var/log/YaST2/y2log-1.gz explains why:

[Ruby] modules/Hooks.rb(find_hook_files):193 Found 1 hook files: before_copy_logs_finish_00_comes_hook.sh
[Ruby] modules/Hooks.rb(execute):165 Executing hook 'before_copy_logs_finish'
[Ruby] modules/Hooks.rb(execute):210 Executing hook file '/var/lib/YaST2/hooks/installation/before_copy_logs_finish_00_comes_hook.sh'
[bash] ShellCommand.cc(shellcommand):78 sh: /var/lib/YaST2/hooks/installation/before_copy_logs_finish_00_comes_hook.sh: No such file or directory
[Ruby] modules/Hooks.rb(execute):212 Hook file 'before_copy_logs_finish_00_comes_hook.sh' failed with stderr: sh: /var/lib/YaST/hooks/installation/before_copy_logs_finish_00_comes_hook.sh: No such file or directory

The installer finds the script, but when it is executed it is not there. I suspected a chroot issue and to confirm my suspicion I did the following:
After the installation process started, I moved to tty2 where a shell is available. The command 'ls /var/lib/YaST2/hooks/installation' shows that the hook script is there. then I did: 
  mkdir -p /mnt/var/lib/YaST2/hooks/installation
  cp /var/lib/YaST2/hooks/installation/* /mnt/var/lib/YaST2/hooks/installation
and let the installation process complete.
This time the hook script got executed.
The solution to the problem seemd to be:
1) do not execute the hook scripts in the chroot environment
2) make the hook scripts visible in the chroot environment

I guess the correct solution is number 2.

For the record, the issue exists both in Leap 15.3 and tumbleweed.
Using hooks was a possible solution to fix boo#1195118 bur I guess that's not an option right now.
Comment 1 Ancor Gonzalez Sosa 2022-02-14 14:57:35 UTC
(In reply to Giacomo Comes from comment #0)
> The solution to the problem seemd to be:
> 1) do not execute the hook scripts in the chroot environment
> or
> 2) make the hook scripts visible in the chroot environment
> I guess the correct solution is number 2.

I would say the intended behavior is (1). That is, hooks should always run in the int-sys. It's kind of inconsistent and weird that they run in the inst-sys or in the chroot depending on the phase of installation in which they run.

So my opinion this line contains a bug and the path should not include "target"

Josef (and main father of the creature according to git history), do you agree?
Comment 2 Josef Reidinger 2022-02-14 23:23:50 UTC
well, I think main creator should be christopher and most importantly hooks requester was Lukas if I remember correctly. I think in general it should really be 1. and run only from insts-sys where customer/user can add own hooks. But lets also ask Lukas as requestor of feature ( if I remember correctly )
Comment 3 Lukas Ocilka 2022-02-15 07:54:24 UTC
The main creator was actually Vladimir in 2013 https://github.com/yast/yast-yast2/pull/148

Honestly, we should rather think about the usage and usefulness rather than going back in time.

- First of all, as Giacomo says, he has tried this to solve bug #1195118, but 
  that did not work anyway, so code change would be needed anyway
- Second, a hook-script does not know by itself whether YaST runs chrooted or 
  outside chroot and cannot simply check it, plus it's not documented
- We've already discussed that YaST should check both paths inst-sys and chroot
- Ideally, script should run from within the environment where it's places unless 
  explicitly defined otherwise (in human speech: if you find me at the balcony, I 
  start at the balcony instead of starting at the Moon which I'm just watching 
  with my telescope)

All in all

- Script found in inst-sys should be called in inst-sys (to be fixed)
- Script found in chroot should be called in chroot (to be implemented)