--- netcfg 2006-09-26 13:15:13.000000000 +0300 +++ netcfg.new 2006-09-26 13:14:45.000000000 +0300 @@ -9,6 +9,7 @@ PROFILE_DIR="/etc/network-profiles" STATE_DIR="/var/run/net" +LAST_DIR="/var/lib/net" version() { @@ -22,6 +23,7 @@ echo "usage: netcfg [options] " echo " netcfg --stop " echo " netcfg --menu [--timeout ]" + echo " netcfg --last" echo " netcfg --stopall" echo echo "options:" @@ -102,7 +104,7 @@ # Re-read the profile (stop_profile might have overwritten our settings) unset DESCRIPTION INTERFACE IFOPTS unset IWOPTS WIFI_INTERFACE WIFI_WAIT USEWPA WPAOPTS - unset GATEWAY HOSTNAME DOMAIN DNS1 DNS2 + unset GATEWAY HOSTNAME DOMAIN SEARCH UP DNS1 DNS2 . $PROFILE_DIR/$1 # Configure wireless settings, if necessary @@ -173,16 +175,34 @@ : >/etc/resolv.conf [ $? -ne 0 ] && stat_fail && return [ "$DOMAIN" ] && echo "domain $DOMAIN" >>/etc/resolv.conf + [ "$SEARCH" ] && echo "search $SEARCH" >>/etc/resolv.conf [ "$DNS1" ] && echo "nameserver $DNS1" >>/etc/resolv.conf [ "$DNS2" ] && echo "nameserver $DNS2" >>/etc/resolv.conf fi + if [ "$UP" ]; then + $UP|true + fi + # Save the info in /var/run so we can shut it down later mkdir -p $STATE_DIR cp $PROFILE_DIR/$1 $STATE_DIR/$INTERFACE + # Save current profile + mkdir -p $LAST_DIR + rm -f $LAST_DIR/* + cp $PROFILE_DIR/$1 $LAST_DIR/$1 stat_done } +last_profile() +{ + fn=`ls -1 $LAST_DIR` + if [ -f "$LAST_DIR/$fn" ];then + PROFILE=$(basename $fn) + start_profile $PROFILE + fi +} + menu() { if [ "`ls $PROFILE_DIR 2>/dev/null | grep -v ^template$`" = "" -o ! -d $PROFILE_DIR ]; then @@ -254,11 +274,6 @@ # Begin # -if [ "`id -u`" != "0" ]; then - echo "This script should be run as root." - exit 1 -fi - # Parse command line MODE="profile" CHECK=0 @@ -270,6 +285,8 @@ --version) MODE="ver" ;; --help) MODE="usage" ;; --menu) MODE="menu" ;; + --last) MODE="last" ;; + -l) MODE="last" ;; --stopall) MODE="stopall" ;; --stop) MODE="stop" shift @@ -291,10 +308,18 @@ # Figure out what we're doing... [ "$MODE" = "ver" ] && version [ "$MODE" = "usage" ] && usage + +# other stuff must be run as root +if [ "`id -u`" != "0" ]; then + echo "This option recuire root" + exit 1 +fi + [ "$MODE" = "profile" ] && start_profile $PROFILE [ "$MODE" = "stop" ] && stop_profile $IFACE [ "$MODE" = "stopall" ] && stop_all [ "$MODE" = "menu" ] && menu +[ "$MODE" = "last" ] && last_profile exit 0