wiki:interface_renaming_scripts
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
wiki:interface_renaming_scripts [2018/06/19 11:06] – walkeradmin | wiki:interface_renaming_scripts [2018/07/31 08:26] – walkeradmin | ||
---|---|---|---|
Line 40: | Line 40: | ||
Now execute the file using the following syntax: | Now execute the file using the following syntax: | ||
\\ | \\ | ||
- | ./ | + | ./ |
\\ | \\ | ||
\\ | \\ | ||
Line 148: | Line 148: | ||
===The Scripts=== | ===The Scripts=== | ||
\\ | \\ | ||
- | store_macaddr_mapping | + | <color #ed1c24>store_macaddr_mapping</ |
\\ | \\ | ||
< | < | ||
Line 200: | Line 200: | ||
</ | </ | ||
- | rename_network_interfaces.sh | + | <color #ed1c24>rename_network_interfaces.sh</ |
\\ | \\ | ||
+ | < | ||
+ | #!/bin/bash | ||
+ | # this script is based on infos got from blog page: | ||
+ | # http:// | ||
+ | |||
+ | # exit at first error | ||
+ | set -o errexit | ||
+ | |||
+ | IP_INTERFACES=" | ||
+ | MACADDR_ANCHOR=" | ||
+ | NET_NAME_TEMPLATE=" | ||
+ | |||
+ | CSV_FILE= | ||
+ | |||
+ | NETWORK_SCRIPT_DIR="/ | ||
+ | NETWORK_BACKUP_DIR="/ | ||
+ | NETWORK_SCRIPT_TEMPLATE=' | ||
+ | DEVICE="< | ||
+ | ONBOOT=yes | ||
+ | NETBOOT=yes | ||
+ | BOOTPROTO=dhcp | ||
+ | TYPE=Ethernet | ||
+ | # HWADDR key is mandatory to use custom interface name: do not delete it | ||
+ | HWADDR=< | ||
+ | ' | ||
+ | |||
+ | function show_help() { | ||
+ | cat <<- EOF | ||
+ | Update network interfaces names. A csv file with the expected mapping can be given as arg. | ||
+ | --csv Csv file containing < | ||
+ | --help|-h | ||
+ | |||
+ | EOF | ||
+ | } | ||
+ | |||
+ | while [ $# -gt 0 ] ; do | ||
+ | case $1 in | ||
+ | --csv) CSV_FILE=" | ||
+ | --help|-h) show_help; | ||
+ | *) if ! [ -z " | ||
+ | esac | ||
+ | done | ||
+ | |||
+ | echo "*** Getting macaddr to register ***" | ||
+ | macaddr_list=$($IP_INTERFACES | grep " | ||
+ | |||
+ | if ! [ -z " | ||
+ | echo "*** Using $CSV_FILE for network interface mapping ***" | ||
+ | ! [ -d " | ||
+ | for old_script_file in $(find $NETWORK_SCRIPT_DIR -maxdepth 1 -name " | ||
+ | echo -e " | ||
+ | mv -f " | ||
+ | done | ||
+ | while read interface_data | ||
+ | do | ||
+ | [ -z " | ||
+ | interface_name=$(echo " | ||
+ | mac_addr=$(echo " | ||
+ | [ -z " | ||
+ | [ -z " | ||
+ | | ||
+ | # check that given mac addr exist | ||
+ | if ! echo " | ||
+ | echo " | ||
+ | exit 1 | ||
+ | fi | ||
+ | echo -e " | ||
+ | echo " | ||
+ | sed -i " | ||
+ | sed -i " | ||
+ | done < " | ||
+ | |||
+ | else | ||
+ | echo "*** Using default naming (${NET_NAME_TEMPLATE}x) for network interface mapping ***" | ||
+ | ! [ -d " | ||
+ | cnt=0 | ||
+ | for old_script_file in $(find $NETWORK_SCRIPT_DIR -maxdepth 1 -name " | ||
+ | echo -e " | ||
+ | mv -f " | ||
+ | done | ||
+ | for mac_addr in ${macaddr_list[*]}; | ||
+ | mac_addr=$(echo " | ||
+ | echo -e " | ||
+ | echo " | ||
+ | sed -i " | ||
+ | sed -i " | ||
+ | cnt=$(( cnt + 1 )) | ||
+ | done | ||
+ | fi | ||
+ | |||
+ | echo "*** Please check consistency of generated files in directory $NETWORK_SCRIPT_DIR ***" | ||
+ | |||
+ | |||
+ | </ | ||
+ | \\ | ||
+ | \\ | ||
wiki/interface_renaming_scripts.txt · Last modified: 2023/03/09 22:35 by 127.0.0.1