#2436 Issue closed: OPALPBA: COPY_AS_IS_EXCLUDE+=( "$REAR_DIR_PREFIX" ) could be insufficient

Labels: enhancement, fixed / solved / done, minor bug

jsmeix opened issue at 2020-06-23 10:33:

@OliverO2

by chance from plain looking at the code I noticed the following:

rear/build/OPALPBA/Linux-i386/095_exclude_non_essential_files.sh contains
https://github.com/rear/rear/blob/master/usr/share/rear/build/OPALPBA/Linux-i386/095_exclude_non_essential_files.sh#L16

# ReaR
COPY_AS_IS_EXCLUDE+=( "$REAR_DIR_PREFIX" )

but "$REAR_DIR_PREFIX" is only set in usr/sbin/rear
if rear is running from a git checkout
https://github.com/rear/rear/blob/master/usr/sbin/rear#L78

# Find out if we're running from checkout
REAR_DIR_PREFIX=""
readonly SCRIPT_FILE="$( readlink -f $( type -p "$0" || echo "$0" ) )"
if test "$SCRIPT_FILE" != "$( readlink -f /usr/sbin/$PROGRAM )" ; then
    REAR_DIR_PREFIX=${SCRIPT_FILE%/usr/sbin/$PROGRAM}
fi

so in particular when rear is running from an installed RPM package
"$REAR_DIR_PREFIX" is empty so that

COPY_AS_IS_EXCLUDE+=( "$REAR_DIR_PREFIX" )

won't exclude anything as far as I see from plain looking at the code.

According to how "$REAR_DIR_PREFIX" is used in the code
(find usr/share/rear/ -type f | xargs grep 'REAR_DIR_PREFIX')
I think what should work in any case to exclude ReaR is

COPY_AS_IS_EXCLUDE+=( "$SHARE_DIR" "$CONFIG_DIR" "$VAR_DIR" "$LOG_DIR" )

cf.
https://github.com/rear/rear/blob/master/usr/sbin/rear#L86

# Program directories - they must be set here. Everything else is then dynamic.
# Not yet readonly here because they are set via the /etc/rear/rescue.conf file
# in the recovery system that is sourced by the rear command in recover mode
# and CONFIG_DIR can also be changed via '-c' command line option:
SHARE_DIR="$REAR_DIR_PREFIX/usr/share/rear"
CONFIG_DIR="$REAR_DIR_PREFIX/etc/rear"
VAR_DIR="$REAR_DIR_PREFIX/var/lib/rear"
LOG_DIR="$REAR_DIR_PREFIX/var/log/rear"

and
https://github.com/rear/rear/blob/master/usr/sbin/rear#L501

# Now SHARE_DIR CONFIG_DIR VAR_DIR LOG_DIR and KERNEL_VERSION should be set to a fixed value:
readonly SHARE_DIR CONFIG_DIR VAR_DIR LOG_DIR KERNEL_VERSION

OliverO2 commented at 2020-06-24 16:18:

@jsmeix
Thanks for pointing this out. Will look at this one next week, too.

OliverO2 commented at 2020-06-30 18:26:

@jsmeix
Thank you for catching this and explaining the underlying mechanism in detail. My new PR deals with the issue (and others) as far as reasonable for me. As my testing has shown, not every copy can be avoided via COPY_AS_IS_EXCLUDE. Some parts are hardcoded differently. For example, excluding $CONFIG_DIR that way has no effect. The PR works around this limitation.

With the PR's changes, rear mkopalpba and rear mkrescue run pretty silent over here. The latter still produces this output:

Symlink '/lib/modules/5.4.0-39-generic/build' -> '/usr/src/linux-headers-5.4.0-39-generic' refers to a non-existing directory on the recovery system.
It will not be copied by default. You can include '/usr/src/linux-headers-5.4.0-39-generic' via the 'COPY_AS_IS' configuration variable.

This is due to the way usr/share/rear/build/GNU/Linux/400_copy_modules.sh works when configured with MODULES=( 'all_modules' ). No big deal for me.

jsmeix commented at 2020-07-02 13:06:

With https://github.com/rear/rear/pull/2448 merged this issue is fixed.

@OliverO2
thank you for your continuous adaptions and improvements of the
TCG Opal 2-compliant Self-Encrypting Disks support in ReaR!

OliverO2 commented at 2020-07-02 13:20:

@jsmeix
As always, thank you for the excellent cooperation!


[Export of Github issue for rear/rear.]