]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
95iscsi: Fix network setup code for iscsi
authorKairui Song <kasong@redhat.com>
Sun, 23 Jun 2019 12:22:34 +0000 (20:22 +0800)
committerHarald Hoyer <harald@hoyer.xyz>
Fri, 19 Jul 2019 14:12:47 +0000 (16:12 +0200)
- The network script and config could be in
  "/etc/sysconfig/network-scripts", so try look for network config in
  all possible path.

- The regex used for sed is not working, so fix it too.

- Make bootproto a local variable

Signed-off-by: Kairui Song <kasong@redhat.com>
modules.d/95iscsi/module-setup.sh

index 8b224be31c1ffce30606d017ab88451beb160cf1..2a7616cd922b945716aa1207f3d077aab9fb9a01 100755 (executable)
@@ -74,6 +74,7 @@ install_iscsiroot() {
     local devpath=$1
     local scsi_path iscsi_lun session c d conn host flash
     local iscsi_session iscsi_address iscsi_port iscsi_targetname iscsi_tpgt
     local devpath=$1
     local scsi_path iscsi_lun session c d conn host flash
     local iscsi_session iscsi_address iscsi_port iscsi_targetname iscsi_tpgt
+    local bootproto
 
     scsi_path=${devpath%%/block*}
     [ "$scsi_path" = "$devpath" ] && return 1
 
     scsi_path=${devpath%%/block*}
     [ "$scsi_path" = "$devpath" ] && return 1
@@ -121,8 +122,14 @@ install_iscsiroot() {
     local_address=$(ip -o route get to $iscsi_address | sed -n 's/.*src \([0-9a-f.:]*\).*/\1/p')
     ifname=$(ip -o route get to $iscsi_address | sed -n 's/.*dev \([^ ]*\).*/\1/p')
 
     local_address=$(ip -o route get to $iscsi_address | sed -n 's/.*src \([0-9a-f.:]*\).*/\1/p')
     ifname=$(ip -o route get to $iscsi_address | sed -n 's/.*dev \([^ ]*\).*/\1/p')
 
-    #follow ifcfg settings for boot protocol
-    bootproto=$(sed -n "/BOOTPROTO/s/BOOTPROTO='\([[:alpha:]]*6\?\)4\?'/\1/p" /etc/sysconfig/network/ifcfg-$ifname)
+    # follow ifcfg settings for boot protocol
+    for _path in \
+        "/etc/sysconfig/network-scripts/ifcfg-$ifname" \
+        "/etc/sysconfig/network/ifcfg-$ifname" \
+    ; do
+        [ -f "$_path" ] && bootproto=$(sed -n "s/BOOTPROTO='\?\([[:alpha:]]*6\?\)4\?/\1/p" "$_path")
+    done
+
     if [ $bootproto ]; then
         printf 'ip=%s:%s ' ${ifname} ${bootproto}
     else
     if [ $bootproto ]; then
         printf 'ip=%s:%s ' ${ifname} ${bootproto}
     else