Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/sh
filename=${0##*/}
usage()
{
cat<<EOF
Usage:
$filename <iface>
EOF
}
_iface_restart()
{
local iface="$1"
local module="$2"
echo "inerface: $iface"
echo "module: $module"
echo "==== reload start ===="
sudo -s <<EOF
echo "interface down: $iface"
ifconfig $iface down
echo "module remove: $module"
modprobe --remove $module
sleep 1
echo "module probe: $module"
modprobe $module
sleep 1
echo "interface up: $iface"
ifconfig $iface up
echo "==== reload done ===="
EOF
}
main()
{
iface="${1}"
if [ -z "$iface" ]; then
usage
exit 1
fi
module="$(basename $(readlink -f /sys/class/net/$iface/device/driver 2>/dev/null) 2>/dev/null)"
if [ -z "$module" ]; then
echo "Error: no module found" 1>&2
exit 1
fi
_iface_restart "$iface" "$module"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment