summaryrefslogtreecommitdiff
path: root/src/extras/rule_generator/write_net_rules
diff options
context:
space:
mode:
Diffstat (limited to 'src/extras/rule_generator/write_net_rules')
-rw-r--r--src/extras/rule_generator/write_net_rules102
1 files changed, 51 insertions, 51 deletions
diff --git a/src/extras/rule_generator/write_net_rules b/src/extras/rule_generator/write_net_rules
index 437979241f..bcea4b09dc 100644
--- a/src/extras/rule_generator/write_net_rules
+++ b/src/extras/rule_generator/write_net_rules
@@ -33,9 +33,9 @@
# debug, if UDEV_LOG=<debug>
if [ -n "$UDEV_LOG" ]; then
- if [ "$UDEV_LOG" -ge 7 ]; then
- set -x
- fi
+ if [ "$UDEV_LOG" -ge 7 ]; then
+ set -x
+ fi
fi
RULES_FILE='/etc/udev/rules.d/70-persistent-net.rules'
@@ -43,42 +43,42 @@ RULES_FILE='/etc/udev/rules.d/70-persistent-net.rules'
. /lib/udev/rule_generator.functions
interface_name_taken() {
- local value="$(find_all_rules 'NAME=' $INTERFACE)"
- if [ "$value" ]; then
- return 0
- else
- return 1
- fi
+ local value="$(find_all_rules 'NAME=' $INTERFACE)"
+ if [ "$value" ]; then
+ return 0
+ else
+ return 1
+ fi
}
find_next_available() {
- raw_find_next_available "$(find_all_rules 'NAME=' "$1")"
+ raw_find_next_available "$(find_all_rules 'NAME=' "$1")"
}
write_rule() {
- local match="$1"
- local name="$2"
- local comment="$3"
-
- {
- if [ "$PRINT_HEADER" ]; then
- PRINT_HEADER=
- echo "# This file was automatically generated by the $0"
- echo "# program, run by the persistent-net-generator.rules rules file."
- echo "#"
- echo "# You can modify it, as long as you keep each rule on a single"
- echo "# line, and change only the value of the NAME= key."
- fi
-
- echo ""
- [ "$comment" ] && echo "# $comment"
- echo "SUBSYSTEM==\"net\", ACTION==\"add\"$match, NAME=\"$name\""
- } >> $RULES_FILE
+ local match="$1"
+ local name="$2"
+ local comment="$3"
+
+ {
+ if [ "$PRINT_HEADER" ]; then
+ PRINT_HEADER=
+ echo "# This file was automatically generated by the $0"
+ echo "# program, run by the persistent-net-generator.rules rules file."
+ echo "#"
+ echo "# You can modify it, as long as you keep each rule on a single"
+ echo "# line, and change only the value of the NAME= key."
+ fi
+
+ echo ""
+ [ "$comment" ] && echo "# $comment"
+ echo "SUBSYSTEM==\"net\", ACTION==\"add\"$match, NAME=\"$name\""
+ } >> $RULES_FILE
}
if [ -z "$INTERFACE" ]; then
- echo "missing \$INTERFACE" >&2
- exit 1
+ echo "missing \$INTERFACE" >&2
+ exit 1
fi
# Prevent concurrent processes from modifying the file at the same time.
@@ -89,49 +89,49 @@ choose_rules_file
# the DRIVERS key is needed to not match bridges and VLAN sub-interfaces
if [ "$MATCHADDR" ]; then
- match="$match, DRIVERS==\"?*\", ATTR{address}==\"$MATCHADDR\""
+ match="$match, DRIVERS==\"?*\", ATTR{address}==\"$MATCHADDR\""
fi
if [ "$MATCHDRV" ]; then
- match="$match, DRIVERS==\"$MATCHDRV\""
+ match="$match, DRIVERS==\"$MATCHDRV\""
fi
if [ "$MATCHDEVID" ]; then
- match="$match, ATTR{dev_id}==\"$MATCHDEVID\""
+ match="$match, ATTR{dev_id}==\"$MATCHDEVID\""
fi
if [ "$MATCHID" ]; then
- match="$match, KERNELS==\"$MATCHID\""
+ match="$match, KERNELS==\"$MATCHID\""
fi
if [ "$MATCHIFTYPE" ]; then
- match="$match, ATTR{type}==\"$MATCHIFTYPE\""
+ match="$match, ATTR{type}==\"$MATCHIFTYPE\""
fi
if [ -z "$match" ]; then
- echo "missing valid match" >&2
- unlock_rules_file
- exit 1
+ echo "missing valid match" >&2
+ unlock_rules_file
+ exit 1
fi
basename=${INTERFACE%%[0-9]*}
match="$match, KERNEL==\"$basename*\""
if [ "$INTERFACE_NAME" ]; then
- # external tools may request a custom name
- COMMENT="$COMMENT (custom name provided by external tool)"
- if [ "$INTERFACE_NAME" != "$INTERFACE" ]; then
- INTERFACE=$INTERFACE_NAME;
- echo "INTERFACE_NEW=$INTERFACE"
- fi
+ # external tools may request a custom name
+ COMMENT="$COMMENT (custom name provided by external tool)"
+ if [ "$INTERFACE_NAME" != "$INTERFACE" ]; then
+ INTERFACE=$INTERFACE_NAME;
+ echo "INTERFACE_NEW=$INTERFACE"
+ fi
else
- # if a rule using the current name already exists, find a new name
- if interface_name_taken; then
- INTERFACE="$basename$(find_next_available "$basename[0-9]*")"
- # prevent INTERFACE from being "eth" instead of "eth0"
- [ "$INTERFACE" = "${INTERFACE%%[ \[\]0-9]*}" ] && INTERFACE=${INTERFACE}0
- echo "INTERFACE_NEW=$INTERFACE"
- fi
+ # if a rule using the current name already exists, find a new name
+ if interface_name_taken; then
+ INTERFACE="$basename$(find_next_available "$basename[0-9]*")"
+ # prevent INTERFACE from being "eth" instead of "eth0"
+ [ "$INTERFACE" = "${INTERFACE%%[ \[\]0-9]*}" ] && INTERFACE=${INTERFACE}0
+ echo "INTERFACE_NEW=$INTERFACE"
+ fi
fi
write_rule "$match" "$INTERFACE" "$COMMENT"