netconfig.sh: fix error setting up file /etc/iproute2/rt_tables in case old table entries are present.

This commit is contained in:
Christoph 2022-01-21 03:17:35 +01:00
parent 99ac83a6a8
commit 06aba72983

View File

@ -278,6 +278,45 @@ while ! $configured && [ $_try_number -lt $max_attempts ] ; do
let number_rt_table="$number_rt_table+100" let number_rt_table="$number_rt_table+100"
prio=0 prio=0
## - Delete routing table $rt_name if exists, but not matches $number_rt_table
## -
if $(grep $rt_name /etc/iproute2/rt_tables > /dev/null 2>&1) ; then
if ! $(grep -E "^$number_rt_table\s+$rt_name" /etc/iproute2/rt_tables > /dev/null 2>&1) ; then
echo "" >> $log_file
echo "## - Delete routing table \"$rt_name\" in file /etc/iproute2/rt_tables" >> $log_file
echo "## -" >> $log_file
echo "sed -i \"/$rt_name/d" /etc/iproute2/rt_tables\" >> $log_file
sed -i "/$rt_name/d" /etc/iproute2/rt_tables > /dev/null 2>&1
fi
fi
## - Delete routing table $number_rt_table if exists, but not matches $rt_name
## -
if $(grep -E "^$number_rt_table" /etc/iproute2/rt_tables > /dev/null 2>&1) ; then
if ! $(grep -E "^$number_rt_table\s+$rt_name" /etc/iproute2/rt_tables > /dev/null 2>&1) ; then
echo "" >> $log_file
echo "## - Delete routing table \"$number_rt_table\" in file /etc/iproute2/rt_tables" >> $log_file
echo "## -" >> $log_file
echo "sed -i \"/$number_rt_table/d" /etc/iproute2/rt_tables\" >> $log_file
sed -i "/$number_rt_tablei/d" /etc/iproute2/rt_tables > /dev/null 2>&1
fi
fi
## - Delete routing table number $number_rt_table not matching $rt_name
## -
if $(grep -E "$number_rt_table\s+[^(${rt_name})]" /etc/iproute2/rt_tables > /dev/null 2>&1) ; then
echo "" >> $log_file
echo "## - Delete routing table number $number_rt_table not matching $rt_name" >> $log_file
echo "## -" >> $log_file
echo "sed -i \"/${number_rt_table}\s\+[^(${rt_name})]/d\" /etc/iproute2/rt_tables" >> $log_file
sed -i "/${number_rt_table}\s\+[^(${rt_name})]/d" /etc/iproute2/rt_tables > /dev/null 2>&1
fi
## - Add new routing table to /etc/iproute2/rt_tables ## - Add new routing table to /etc/iproute2/rt_tables
## - if not yet exists ## - if not yet exists