Skip to content

Instantly share code, notes, and snippets.

@sahal
Last active December 30, 2023 03:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sahal/78eaa73d07ac74de3aa22a889f90fe71 to your computer and use it in GitHub Desktop.
Save sahal/78eaa73d07ac74de3aa22a889f90fe71 to your computer and use it in GitHub Desktop.
netctl wifi restart script

restart-wifi.sh

I use this script because netctl is kinda annoying to use otherwise.

Change Wifi Device state

I've been turning off my wifi device using ip as follows:

ip link set wlp58s0 down

where wlp58s0 is my wifi device.

Use

To use set the first parameter to a wifi name with a configuration already set and placed in /etc/netctl

e.g.

$ sudo cat /etc/netctl/cplwifi
[sudo] password for sahal: 
Description='Automatically generated profile by wifi-menu'
Interface=wlp58s0
Connection=wireless
Security=none
ESSID=CPLWIFI
IP=dhcp

$ restart-wifi.sh cplwifi

Tags

arch linux netctl wifi ip

#!/usr/bin/env bash
set -u
set -e
# sudo ip link set wlp58s0 down
#
export WIFI_NAME="${1:-unset}"
if [[ "${WIFI_NAME:-unset}" == "unset" ]]; then
echo "Set a wifi name as the first positional parameter"
exit 1
fi
sudo systemctl stop "netctl@${WIFI_NAME:-unset}.service"
sleep 4s
sudo systemctl start "netctl@${WIFI_NAME:-unset}.service"
sleep 4s
sudo systemctl status "netctl@${WIFI_NAME:-unset}.service"
watch 'ip a'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment