#!/bin/bash ## Scriptname, version etc app_name=centrino app_version="0.0.1" app_date_start="04.02.04" app_date_lchanged="`date -r "$0" +%d.%m.%y`" test "$app_date_start" = "$app_date_lchanged" && app_date="$app_date_start" || app_date="$app_date_start - $app_date_lchanged" app_title="$app_name v$app_version ($app_date) by M.Hentges (devel@hentges.net)" ## Script configuration need_local_tmp_dir=yes need_global_tmp_dir=no must_be_root=yes tmp_dir="$HOME/.mhentges_data/$app_name" g_tmp_dir="/etc/mhentges_data/$app_name" ## Misc VARs def_script_version="6.00" debug=0 ## Script specific VARs ########################################################################## function die { echo -e "\n\aERR: $1\n" exit 1 } function init { echo "$app_title" if test "$need_local_tmp_dir" = yes -a ! -e "$tmp_dir" then mkdir -p "$tmp_dir" || die "Error: [mkdir -p $tmp_dir] failed!" fi if test "$need_global_tmp_dir" = yes -a ! -e "$g_tmp_dir" then mkdir -p "$g_tmp_dir" || die "Error: [mkdir -p $g_tmp_dir] failed!" fi test "$must_be_root" = yes -a "$UID" != 0 && die "Only root may run this script, sorry." } function parse_args { OLD_IFS="$IFS"; IFS=" " for argument in $1 do case $argument in start) MODE=start;; stop) MODE=stop;; --version|-v) exit 0;; --help|-h) print_help ;; *) die "Unknown option <$argument>" ;; esac done IFS="$OLD_IFS" } function print_help { echo "" echo -e "Syntax: $(basename $0) [options]" echo -e "Options:" echo -e " --version|-v Version anzeigen" echo -e " --help/-h This text" echo -e "" exit 0 } function start { test -z "$MODE" && die "--start / --stop" if test "$MODE" = start then tmp_1=`ifconfig eth0` if ! test -z "$tmp_1" then echo -n "Shutting down eth0..." ifconfig eth0 down && echo "ok" || echo "FAILED" fi tmp_2=`ps ax|grep -v grep|grep dhclient` if ! test -z "$tmp_2" then echo -n "Stopping dhclient..." killall dhclient && echo "ok" || echo "FAILED" fi if (lsmod|grep ndiswrapper) &>/dev/null then echo -n "Unloading ndiswrapper" rmmod ndiswrapper && echo "ok" fi if ! (lsmod|grep ndiswrapper) &>/dev/null then echo -n "Loading ndiswrapper..." modprobe ndiswrapper && echo ok || die "modprobe ndiswrapper failed" fi if ! (iptables -L|grep in_wlan0) &>/dev/null then echo -n "Configuring mhfirewall for wlan0..." /usr/scripts/mhfirewall start wlan0 echo "done" fi test -e /etc/init.d/hostwatch && /usr/scripts/rcstop hostwatch echo "Configuring wlan0" dhclient wlan0 2>&1 |logger -t centrino fi if test "$MODE" = stop then tmp_1=`ifconfig wlan0` if ! test -z "$tmp_1" then echo -n "Shutting down wlan0..." ifconfig wlan0 down && echo ok || echo FAILED fi tmp_2=`ps ax|grep dhclient` if ! test -z "$tmp_2" then echo -n "Stopping dhclient..." killall dhclient && echo ok || echo FAILED fi if (iptables -L|grep in_wlan0) &>/dev/null then echo -n "Removing mhfirewall for wlan0..." /usr/scripts/mhfirewall stop wlan0 echo "done" fi if (lsmod|grep ndiswrapper) &>/dev/null then echo -n "Unloading ndiswrapper" rmmod ndiswrapper && echo "ok" fi echo "Configuring eth0" ifconfig eth0 up dhclient eth0 2>&1 |logger -t centrino test -e /etc/init.d/hostwatch && /usr/scripts/rcstart hostwatch fi } init parse_args "$*" start