fail() { echo "$@" 1>&2; exit 1; }

name=$1
path=""
if [ "${name#/sys}" = "${name}" ]; then
   for p in net block; do
      [ -e "/sys/class/$p/${name}" ] && path="/sys/class/$p/${name}" && break
   done
   [ -n "$path" ] ||  fail "did not find $name. give full /sys/"
else
   path=$name
fi

[ -e "$path" ] || fail "$path not exist"
[ -e "$path/device/driver/unbind" ] || fail "no $path/device/driver/unbind"

device_d=$(cd "$path/device" && /bin/pwd )
devname="${device_d##*/}"
driver_d=$(cd "$path/device/driver" && /bin/pwd)
unbind="$driver_d/unbind"
bind="$driver_d/bind"
echo "devname=$devname device_d=$devdir"
echo "unbind=$unbind bind=$bind"
[ -f "$bind" ] || fail "no $bind"
[ -f "$unbind" ] || fail "no $unbind"

echo "$devname" > "$unbind" || fail "unbind of $devname to $unbind"
echo "$devname" > "$bind" || fail "bind of $devname to $bind failed"