You are not logged in.

#1 2020-04-11 06:28:34

IntrepidAntslayer
Member
Registered: 2020-04-06
Posts: 7

Networking script won't connect to wifi

tI have a networking script I have that I want to run to choose whether to statically or dynamically connect to a wifi network using netctl. The static and dynamic netctl profiles were literally just copied and pasted from /etc/netctl/examples and I added the SSIDs and passwords so I'm fairly confident they aren't the problem. Here's the script:

#! /bin/sh

echo "getting the profile..."
# gets the profile

if [[ $1 == "s" ]]; then
        file=/etc/netctl/mhome-static
elif [[ $1 == "d" ]]; then
         file=/etc/netctl/mhome-dynamic
elif [[ $1 == "stop" ]]; then
        echo "shutting down internet connection now"
        ip link set wlan0 down > /dev/null 2> /dev/null
        exit
else
        file=0
fi

# if invalid options prints this
if [[ $file == "0" ]]; then
        echo "You didn't provide the right options dummy"
        echo "syntax: autonet [s/static | d/dynamic]"
        exit
fi

# starts the interface
echo "starting the interface..."
ip link set wlan0 up > /dev/null 2> /dev/null
# stops/starts DHCP based on static/dynamic option
echo "stopping systemd-networkd..."
systemctl stop systemd-networkd > /dev/null 2> /dev/null
systemctl disable systemd-networkd > /dev/null 2> /dev/null
if [[ $1 == "s" ]]; then
        echo "stopping dhcp..."
        systemctl stop dhcpcp.service > /dev/null 2> /dev/null
        systemctl disable dhcpcp.service > /dev/null 2> /dev/null
else
        echo "starting dhcp..."
        systemctl start dhcpcp.service > /dev/null 2> /dev/null
        systemctl enable dhcpcp.service > /dev/null 2> /dev/null
fi

echo "starting the netctl profile"
netctl enable $file > /dev/null 2> /dev/null
netctl start $file > /dev/null 2> /dev/null

Thank you, any help is appreciated

Offline

#2 2020-04-11 10:59:43

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,911

Re: Networking script won't connect to wifi

You're mixing ip commands, systemd-networkd , dhcpcd and netctl .

netctl is intended to be a full network manager and is perfectly capable of bringing interfaces up or down, start a dhcp client etc.

I suggest you check man netctl and figure out which commands you need to switch to / choose one of those profiles manually .
Then you'll understand what commands you should put in that script (chance is high you won't feel the need to script this anymore)

You may also want to check what happens when you
start a service
enable a service
stop a service
disable a service


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

Board footer

Powered by FluxBB