Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gozora opened this issue Jan 29, 2020 · 3 comments · Fixed by #2325
Closed

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

gozora opened this issue Jan 29, 2020 · 3 comments · Fixed by #2325
Assignees
Labels
bug The code does not do what it is meant to do fixed / solved / done
Milestone

Comments

@gozora
Copy link
Member

gozora commented Jan 29, 2020

Hello guys,

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

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:

[[ ! -z "\$USE_DHCLIENT" && -z "\$USE_STATIC_NETWORKING" ]] && return

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):

# Say "y", "Yes", etc, to enable or "n", "No" etc. to disable the DHCP client protocol or leave empty to autodetect.
# When enabled, lets the rescue/recovery system run dhclient to get an IP address
# instead of using the same IP address as the original system:
USE_DHCLIENT=

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.

@gozora gozora added bug The code does not do what it is meant to do discuss / RFC labels Jan 29, 2020
@gozora gozora self-assigned this Jan 29, 2020
@jsmeix
Copy link
Member

jsmeix commented Jan 30, 2020

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 jsmeix added this to the ReaR v2.6 milestone Jan 30, 2020
@jsmeix
Copy link
Member

jsmeix commented Jan 30, 2020

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
Copy link
Member Author

gozora commented Jan 30, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The code does not do what it is meant to do fixed / solved / done
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants