#!/bin/sh
#Barry Kauler, May 2012, license GPL3 (ref: /usr/share/doc/legal)
#this code is taken out of /etc/rc.d/rc.sysinit
#called from /usr/bin/xwin, if file /tmp/simple_network_setup/network_default_reconnect_required_flag exists.
#that 'flag' file is created in /usr/sbin/hostname-set, if the hostname was changed and the network connection brought down.

#100227 choose default network tool...
DEFAULTCONNECT="`cat /usr/local/bin/defaultconnect | tail -n 1 | tr -s " " | cut -f 2 -d " "`"
[ "`grep 'gprs' /usr/local/bin/defaultconnect`" != "" ] && DEFAULTCONNECT='pgprs-connect'
[ "$DEFAULTCONNECT" = "gkdial" ] && DEFAULTCONNECT="pupdial" #for older pups.
NETCHOICE="$DEFAULTCONNECT"	#101007 shinobar
case $DEFAULTCONNECT in
 Pwireless2)
  NETCHOICE='Pwireless2'
 ;;
 net-setup.sh)
  NETCHOICE='net-setup.sh'
 ;;
 net_wiz_classic)
  NETCHOICE='net_wiz_classic'
 ;;
 sns)
  NETCHOICE='sns'
 ;;
 connectwizard) #try determine which tool was used to setup networking... 101007
  if [ -s /etc/simple_network_setup/connections ];then #100306
   NETCHOICE='sns'
  else
   CHECKOLDWIZ="`ls -1 /etc/*[0-9]mode 2>/dev/null`" #ex: eth0mode, wlan0mode.
   if [ "$CHECKOLDWIZ" != "" -a -d /usr/local/net_setup ];then
    NETCHOICE='net_wiz_classic'
   else
    CHECKNEWWIZ="`ls -1 /etc/network-wizard/network/interfaces 2>/dev/null`"
    if [ "$CHECKNEWWIZ" != "" ];then
     NETCHOICE='net-setup.sh'
    else
     [ -f /usr/local/Pwireless2/interface ] && NETCHOICE='Pwireless2' #100304
    fi
   fi
  fi
 ;;
esac
[ -f /etc/init.d/Pwireless2 ] && chmod 644 /etc/init.d/Pwireless2 #prevent jemimah's script from running. 100304 100513
case $NETCHOICE in
 Pwireless2)
  #this only sets up interface 'lo'...
  /etc/rc.d/rc.network_basic
  #jemimah's script is in /etc/init.d/Pwireless2
  chmod 755 /etc/init.d/Pwireless2 #make executable so it will run.
  #i want to run it right now, as a separate process (rc.services will ignore it)...
  /etc/init.d/Pwireless2 start &
 ;;
 net-setup.sh)
  /etc/rc.d/rc.network &
 ;;
 net_wiz_classic)
  #note, old wizard is located in /usr/local/net_setup.
  /usr/local/net_setup/etc/rc.d/rc.network &
 ;;
 sns) #100306
  /etc/rc.d/rc.network_basic #this only sets up interface 'lo'.
  /usr/local/simple_network_setup/rc.network &
 ;;
 connectwizard) #101007 shinobar
  #100628 shinobar: launch rc.network if eth0 is usable
  RCNETWORK=/etc/rc.d/rc.network_basic #this only sets up interface 'lo'.
  # eth0 usable?
  if /sbin/ifconfig eth0 &>/dev/null ;then
    if [ -x /etc/rc.d/rc.network ]; then
      RCNETWORK=/etc/rc.d/rc.network
    elif [ -e /etc/init.d/Pwireless2 ]; then
      chmod 755 /etc/init.d/Pwireless2
    fi
  fi
  $RCNETWORK &
 ;;
 *) #101007 shinobar
   /etc/rc.d/rc.network_basic &
 ;;
esac
