#!/bin/bash . /etc/init.d/functions.sh MAX_TRIES=50 preup() { if [ "${IFACE}" = "wlan0" ]; then sudo killall dhcpcd 2>/dev/null lsmod \ | grep -q iwl4965 \ && sudo modprobe -r iwl4965 \ && einfo "Reloading iwl4965 kernel module" sleep 1 sudo modprobe iwl4965 fi # Remember to return 0 on success return 0 } postdown() { if [ "${IFACE}" = "wlan0" ]; then lsmod | grep -q iwl4965 && modprobe -r iwl4965 mac80211 fi } for ((i=1; i<=MAX_TRIES; i++)); do ebegin "Try $i" IFACE="wlan0" preup if sudo /etc/init.d/net.wlan0 restart 2>&1 \ | grep -v -e err -e 'Operation not supported'; then eend $? break fi eend 1 done