Hi,
I want to share a script with you I've just created.
You probably all are familiar when creating an base image on a Mac Pro and
image a MacBook Pro with it that the network service names are like
Ethernet 1, Ethernet 2 and FireWire. Ethernet 2 is actually the AirPort
(or Wi-Fi). The script I created renames the service to the hardware port
name if they do not match. After running the script on a MacBook Pro (with
10.6) the result will be: Ethernet, AirPort and FireWire.
#!/bin/bash
# renameNetworkServices.sh
# Script to correct the network services names after imaging a new machine
# Detect new network hardware
networksetup -detectnewhardware
# List all network services and read one by one
networksetup -listallnetworkservices | tail -n +2 | while read service
do
# Check if network service is disabled (note the asterisk)
if [[ ${service} == ** ]]
then
# Remove asterisk from string for renaming service
service=echo ${service} | sed -e 's/.(.*)/1/'
fi
# Use filter to select next line which has the harware port defined
filter=false
# Display network services
networksetup -listnetworkserviceorder | while read serviceorder
do
if [[ ${filter} == true ]]
then
# Grab hardware port
hardwareport=`echo ${serviceorder} | sed -e 's/(Hardware Port:
//;s/, Device:.*//'`
# Check if service name if different
if [[ ${service} != ${hardwareport} ]]
then
# Rename the network service
networksetup -renamenetworkservice "${service}"
"${hardwareport}"
echo -e "Renamed network server "${service}" to
"${hardwareport}""
fi
fi
if [[ ${serviceorder} == *${service} ]]
then
# Got the line with the service. Set the filter to true to
grab the next line which contains the hardware port
filter=true
else
filter=false
fi
done
done
Have fun with it!
Kind Regards,
Martin van Diemen