#1320 Issue closed: Enhance "pure additive" scripts sourcing with "additive plus replacing" scripts sourcing

Labels: enhancement, won't fix / can't fix / obsolete

jsmeix opened issue at 2017-04-20 09:51:

Currently the SourceStage function works based on
pure "additive thinking", cf.
https://github.com/rear/rear/pull/1311#issuecomment-295276076
and
https://github.com/rear/rear/pull/1311#issuecomment-295266258

It goes from very generic (default)
to distro & version OR distro & arch specific
(e.g. RedHatEnterpriseServer/7 OR RedHatEnterpriseServer/i386)
with several steps in between.

The idea is to put each script in a "as generic as possible" place.

But the current way makes it impossible to
have a generic default script (that works in most cases)
but use a more specific script INSTEAD of the default script
in special cases because currently the SourceStage function
would run both the default script AND the specific script.

Hereby I suggest to enhance the SourceStage function
to do "additive plus replacing" script sourcing as follows:

The basic idea is that for one task, one script name is used.
I.e. same task <=> same script name.

The SourceStage function will not source two sctipts with
the same script name (without the leading script number)
which exist in one stage (i.e. in the stage directory hierarchy).

When there are several scripts in the stage directory hierarchy
with same script name (regardless of the leading script number)
the SourceStage function will source the script in the most
specific directory of the stage directory hierarchy.

See the following example why the leading script number
is ignored to check if two scripts implement the same task.

Example:

Assume during the 'finalize' stage
the task is to rebuild the initrd/initramfs.

The script name (without number) is 'rebuild_initramfs'.

Then the default script could be e.g.
usr/share/rear/finalize/default/170_rebuild_initramfs.sh

Additionally for special cases there could be scripts like
usr/share/rear/finalize/Debian/170_prepare_rebuild_initramfs.sh
usr/share/rear/finalize/Debian/180_rebuild_initramfs.sh
usr/share/rear/finalize/Fedora/ppc64/500_rebuild_initramfs.sh
usr/share/rear/finalize/SUSE_LINUX/ppc64/200_install_yaboot.sh
usr/share/rear/finalize/SUSE_LINUX/ppc64/500_rebuild_initramfs.sh

In the default case only
usr/share/rear/finalize/default/170_rebuild_initramfs.sh
would be run.

For Debian only
usr/share/rear/finalize/Debian/180_rebuild_initramfs.sh
would be run after
usr/share/rear/finalize/Debian/170_prepare_rebuild_initramfs.sh
was run.

For Fedora on ppc64 only
usr/share/rear/finalize/Fedora/ppc64/500_rebuild_initramfs.sh
would be run.

For SUSE_LINUX on ppc64 only
usr/share/rear/finalize/SUSE_LINUX/ppc64/500_rebuild_initramfs.sh
would be run after
usr/share/rear/finalize/SUSE_LINUX/ppc64/200_install_yaboot.sh
was run.

This way the pure "additive" part still works as before
plus a "replacing" part only when scripts have same name.

schlomo commented at 2017-04-20 10:30:

I once even tried to code that and it became too complex.

To keep things simple I would suggest that the replacement happens only if the entire script name including the number is identical. In the log file we should then also write something to that effect.

jsmeix commented at 2017-04-20 11:29:

@schlomo
meanwhile I think it is probably not really needed to
exclude the script number because when in special cases
some additional scripts should be run before,
those additional scripts can have smaller numbers.

In this case my initial example would become:

Assume during the 'finalize' stage
the task is to rebuild the initrd/initramfs.
The script name with number is '500_rebuild_initramfs'.

Then the default script could be e.g.
usr/share/rear/finalize/default/500_rebuild_initramfs.sh

Additionally for special cases there could be scripts like
usr/share/rear/finalize/Debian/490_prepare_rebuild_initramfs.sh
usr/share/rear/finalize/Debian/500_rebuild_initramfs.sh
usr/share/rear/finalize/Fedora/ppc64/500_rebuild_initramfs.sh
usr/share/rear/finalize/SUSE_LINUX/ppc64/200_install_yaboot.sh
usr/share/rear/finalize/SUSE_LINUX/ppc64/500_rebuild_initramfs.sh

The advantage when for one same task
one same script name with same number is used
is that it avoids confusion between what is run by default
versus what is run in special cases.

The 'do something' task will be always implemented
in a 123_do_something.sh script.


[Export of Github issue for rear/rear.]