-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Here's a script that turns WiFi on and off on my Dell laptop.  (It works on my 
2-hole desktop as well -- so the complexity.  'slsware' is my domain.)

# Makes sure the primary Ethernet port (ETH0) is up and
# sets a route to rrc through ETH0 (so SSH down there will by happy with the IP 
it gets) and
# sets DNS (/etc/resolv.conf) to the standard slsware values (in 
/etc/resolv.conf.sls)
#
# UP brings up the secondary Ethernet port (ETH1) by DHCP from the 
Frasier_Residents DHCP server,
# removes the ETH0 default route, and replaces it with an ETH1 default
#
# DOWN just puts things back as though there were no ETH1

ETH0_DEFAULT_IP="216.17.134.201"
ETH1_DEFAULT_IP="10.200.184.254"
TRUE="0"
leadingSpace="      "

function cleanUp()
{
        # remove detritus
        sudo rm ifconfig.all ifconfig.status route.status 2>/dev/null
        # set DNS
        sudo cp /etc/resolv.conf.sls /etc/resolv.conf
        # say goodbye
        if [ "$1" != "" ]
        then
                echo ; echo "${leadingSpace}$1"
        fi
        # show routing table
        echo ; echo "${leadingSpace}route:" ; echo
        sudo route
        echo
}

ETH0="lo only"
ETH1=$ETH0
function getInterfaceNameStyle()
{
        # get an 'ifconfig' of all interfaces
        sudo ip a >ifconfig.all

        egrep -q "eth.:" ifconfig.all
        if [ "$?" == "$TRUE" ]
        then
                ETH0="eth0"
                ETH1="wlan0"
                return
        fi

        egrep -q "enp.s" ifconfig.all
        if [ "$?" == "$TRUE" ]
        then
                ETH0="enp6s0"
                ETH1="enp7s0"
                return
        fi

        if [ "$ETH0" == "lo only" ]
        then
                cleanUp "$ETH0"
                exit 0
        fi
}

# are the interfaces in the eth<n> style?
getInterfaceNameStyle

# get current ifconfig status
ip -4 link ls up >ifconfig.status

# is ETH0 up?
egrep -q "${ETH0}:.*UP" ifconfig.status
ETH0_UP=$?
# is ETH1 up?
egrep -q "${ETH1}:.*UP" ifconfig.status
ETH1_UP=$?

# make sure ETH0 is up (it probably is, but...)
if [ "$ETH0_UP" != "$TRUE" ]
then
        echo ; echo "${leadingSpace}bringing up $ETH0" ; echo
        sudo ifup $ETH0
        $ETH0_UP == "$TRUE"
fi

if [ "$1" == "up" ]
then
        # is ETH1 already up?
        if [ "${ETH1_UP}" == "$TRUE" ]
        then
                cleanUp "$ETH1 is already up"
                exit 0
        else
                echo ; echo "${leadingSpace}bringing up $ETH1" ; echo
                # bring up the DHCP interface
                sudo ifup $ETH1
                ip route >route.status
                # remove the ETH0 default route
                sudo ip route del default via $ETH0_DEFAULT_IP dev $ETH0
                # is the wifi default not in the routing table?
                egrep "default.*$ETH1" route.status
                if [ "$?" != "$TRUE" ]
                then
                        # if not, put it in
                        sudo ip route add default via $ETH1_DEFAULT_IP dev $ETH1
                fi
                # remove the ETH1 route to the LAN (there's already one for 
ETH0)
                sudo ip route del 216.17.134.0/24 dev $ETH1
        fi
elif [ "$1" == "down" ]
then
        # is ETH1 already down?
        if [ "$ETH1_UP" != "$TRUE" ]
        then
                cleanUp "$ETH1 is already down"
                exit 0
        else
                sudo ifdown $ETH1
                sudo ip route add default via $ETH0_DEFAULT_IP dev $ETH0
                sudo cp /etc/resolv.conf.sls /etc/resolv.conf
        fi
else
        cleanUp "You forgot to say 'up' or 'down'..."
        exit 0

fi

cleanUp ""


And here's a piece of /etc/network/interfaces:

# wlan0 -- Get DHCP from SSID: Frasier_Residents, PW: <password>
iface wlan0 inet dhcp
        pre-up sudo ip addr flush dev wlan0
        wpa-ssid Frasier_Residents
        wpa-psk <password>


Hope this helps...

--
Glenn English




-----BEGIN PGP SIGNATURE-----
Version: ProtonMail

wsBzBAEBCAAGBQJfxIqdACEJEJ/XhjGCrIwyFiEELKJzD0JScCVjQA2Xn9eG
MYKsjDI02Qf8CkOUUDV1BfSUZhRNT/7Fvp8Fjqqcfy/VXTkuUDCyhBXGCqEh
gQfe+LVlq/HyZkjsDMSQl4qVzZzhETafopVi8MMwXCmcp9eVt37pLeJS+Wyh
k6/CXTqHy2or+TXW2vKtI7mWDlEqHFRlj7E1FkJJpN8WorAbuAhnX2xEGBcf
NzncvyOXsndbbqY3T1pwZFywivH9HiqAPJ4rRyjoBX7XNrv6Q170Icukq30A
y3reL1HRWmPH6JMZ7awiVWMxVe74bLQDlrYP+znwqopwQvEpYsCBP2Gd4lGv
fnUROVW6FvOvPuFEn+eK57KIgQoa/9oLdq4MbnmYEV7oebjrOQe+1w==
=Itjc
-----END PGP SIGNATURE-----

Reply via email to