summaryrefslogtreecommitdiffstats
path: root/.local/bin/wifi
blob: 0a067ab6d848b8708831e950125490d8ad6b0798 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash

# root check
if [ "$EUID" -ne 0 ]; then echo "Please run as root" && exit; fi

# variables
interface=$(ip a | awk -F": " '/wlp/ {print $2}')
runfile=/run/wpa_supplicant/$interface
ping_test=1.1.1.1

# existing connection check
ping -c 1 "$ping_test" && printf "\nAlready connceted!" && exit

# runfile check
if [ -f "$runfile" ] ; then echo Removing Runfile && rm "$runfile" ; fi

# make connection
wpa_supplicant -B -c "/etc/wpa_supplicant/wpa_supplicant.conf" -i "$interface" && dhcpcd "$interface"

# ping test
while true; do sleep 0.8 && ping -c 1 "$ping_test" && printf "\nConnected!" && break; done

exit