Skip to content

Commit

Permalink
helpers to start/stop wifi on several distros
Browse files Browse the repository at this point in the history
  • Loading branch information
albfan committed Oct 16, 2022
1 parent b46679d commit 380504b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 79 deletions.
2 changes: 1 addition & 1 deletion res/kill-wpa.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

. miracle-utils.sh

kill_ubuntu_network_manager
kill_network_manager

WPA_PID=$(find_wpa_supplicant_pid)
if [ -n "$WPA_PID" ]
Expand Down
37 changes: 11 additions & 26 deletions res/miracle-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,45 +159,30 @@ function check_debian_distro {
}

#
# ubuntu manager restarts automatically wpa_supplicant
# kills network manager
#
function kill_ubuntu_network_manager {
function kill_network_manager {
echo stopping NetworkManager
if check_ubuntu_distro || check_debian_distro
then
echo stopping NetworkManager
# ubuntu manager restarts automatically wpa_supplicant
sudo service NetworkManager stop
fi
}

#
# arch linux manager restarts automatically wpa_supplicant
#
function kill_archlinux_network_manager {
if check_ubuntu_distro
then
echo stopping NetworkManager
elif check_archlinux_distro
sudo systemctl stop Network.service
else
sudo systemctl stop Network.service
fi
}

#
# start ubuntu manager
# start network manager
#
function start_ubuntu_network_manager {
function start_network_manager {
echo starting NetworkManager
if check_ubuntu_distro || check_debian_distro
then
echo starting NetworkManager
sudo service NetworkManager start
fi
}

#
# start arch linux manager
#
function start_archlinux_network_manager {
if check_archlinux_distro
then
echo starting NetworkManager
elif check_archlinux_distro
sudo systemctl start Network.service
fi
}
54 changes: 2 additions & 52 deletions res/normal-wifi.sh
Original file line number Diff line number Diff line change
@@ -1,57 +1,7 @@
#!/bin/bash

./kill-wpa.sh

. miracle-utils.sh

ETHER_NAMES=$(find_choosable_networknames)

ETHER_COUNT=$(echo "$ETHER_NAMES" | wc -l)

if [ 0 = $ETHER_COUNT ]
then
echo There is no net devices available
exit 1
elif [ 1 = $ETHER_COUNT ]
then
ETHERNAME="$ETHER_NAMES"
elif [ 2 -le $ETHER_COUNT ]
then
echo choose device for normal connection:
QUIT="exit"
select et_name in $ETHER_NAMES $QUIT
do
case $et_name
in
"$QUIT")
exit
;;
"")
if [ "$REPLY" = $QUIT ]
then
exit
else
echo unknow $REPLY
fi
;;
*)
ETHERNAME=$et_name
break
;;
esac
done
fi

# default path for config file
CONFIG_FILE=${1:-/run/network/wpa_supplicant_${ETHERNAME}.conf}


echo starting wpa_supplicant for normal connection
if check_ubuntu_distro || check_debian_distro
then
start_ubuntu_network_manager
sudo wpa_supplicant -B -u -s -O /var/run/wpa_supplicant
else
sudo wpa_supplicant -B -u -P /run/wpa_supplicant_${ETHERNAME}pid -i ${ETHERNAME} -D nl80211 -c$CONFIG_FILE
fi
./kill-wpa.sh

start_network_manager

0 comments on commit 380504b

Please sign in to comment.