#2323 Issue closed: 58-start-dhclient.sh executes code even when USE_DHCLIENT=no

Labels: bug, fixed / solved / done

gozora opened issue at 2020-01-29 19:44:

Hello guys,

In system-setup.d/58-start-dhclient.sh we have following code:

https://github.com/rear/rear/blob/ed61745b98048b59e1990be591210d6a324e485a/usr/share/rear/skel/default/etc/scripts/system-setup.d/58-start-dhclient.sh#L4

Which just simply checks if USE_DHCLIENT is empty or not, so if one uses USE_DHCLIENT=no, content of script will be executed regardless.

I've found similar problem here as well:

https://github.com/rear/rear/blob/ed61745b98048b59e1990be591210d6a324e485a/usr/share/rear/rescue/GNU/Linux/310_network_devices.sh#L111

So again, if one have explicit USE_DHCLIENT=no set (and empty USE_STATIC_NETWORKING), his network configuration in ReaR recovery system will be skipped.

Since comment in default.conf states (allows both Yes/No values):

https://github.com/rear/rear/blob/ed61745b98048b59e1990be591210d6a324e485a/usr/share/rear/conf/default.conf#L2571-L2574

I think that mentioned conditions should be changed to something like:

[[ -z "$USE_DHCLIENT" ||  $USE_DHCLIENT =~ [fF]$|[nN]$|[nN][oO]$|[fF][aA][lL][sS][eE]$|0$ ]]

resp:

[[ "\$USE_DHCLIENT" =~ [tT]\$|[yY]\$|[yY][eE][sS]\$|[tT][rR][uU][eE]\$|1\$ && -z "\$USE_STATIC_NETWORKING" ]] && return

What do you think?

V.

jsmeix commented at 2020-01-30 10:22:

Sigh!
This is just another legacy code part of the old "binary" variables handling
https://github.com/rear/rear/blob/master/usr/share/rear/conf/default.conf#L27
that needs to be made fail-safe and (as side-effect) more user-friendly.

In system setup skel scripts we can use the is_true and is_false
functions because we source lib/global-functions.sh in
https://github.com/rear/rear/blob/master/usr/share/rear/skel/default/etc/scripts/system-setup.d/00-functions.sh#L30
(and etc/scripts/system-setup.d/00-functions.sh is sourced
by etc/scripts/system-setup which is run by PID1/init/systemd).

For an example where is_true and read_and_strip_file are used see
https://github.com/rear/rear/blob/master/usr/share/rear/skel/default/etc/scripts/system-setup.d/55-migrate-network-devices.sh#L266
and
https://github.com/rear/rear/blob/master/usr/share/rear/skel/default/etc/scripts/system-setup.d/55-migrate-network-devices.sh#L105

jsmeix commented at 2020-01-30 10:31:

By the way via

# cd rear.github.master
# find usr/sbin/rear usr/share/rear/ -type f | xargs grep 'USE_DHCLIENT' | grep -v ': *#' | less

I found

usr/share/rear/rescue/GNU/Linux/310_network_devices.sh:[[ ! -z "\$USE_DHCLIENT" && -z "\$USE_STATIC_NETWORKING" ]] && return
usr/share/rear/rescue/GNU/Linux/350_routing.sh:[[ ! -z "\$USE_DHCLIENT" && -z "\$USE_STATIC_NETWORKING" ]] && return

i.e.
https://github.com/rear/rear/blob/master/usr/share/rear/rescue/GNU/Linux/310_network_devices.sh#L111
and
https://github.com/rear/rear/blob/master/usr/share/rear/rescue/GNU/Linux/350_routing.sh#L37
which write same kind of conditions into
the generated system setup scripts

network_devices_setup_script=$ROOTFS_DIR/etc/scripts/system-setup.d/60-network-devices.sh

and

network_routing_setup_script=$ROOTFS_DIR/etc/scripts/system-setup.d/62-routing.sh

gozora commented at 2020-01-30 11:34:

Hello @jsmeix,

In system setup skel scripts we can use the is_true and is_false
functions because we source lib/global-functions.sh in

This makes things bit easier. Thanks for "heads up!"

I'll prepare PR (hopefully) soon!

V.


[Export of Github issue for rear/rear.]