summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authortequa2019-07-25 20:41:37 +0200
committertequa2019-07-25 20:41:37 +0200
commit3b92739becd24f6c9765adc6a26da5b5cc1f853d (patch)
treef67803561a29669a923b3bebbc368cced6098195
parentdce3d73e28d4f2d013e5351d231c3fded6b61ade (diff)
downloadaur-3b92739becd24f6c9765adc6a26da5b5cc1f853d.tar.gz
wait improved by polling -> 0.2
-rw-r--r--.SRCINFO6
-rw-r--r--PKGBUILD6
-rw-r--r--wifi.hook71
3 files changed, 65 insertions, 18 deletions
diff --git a/.SRCINFO b/.SRCINFO
index b2bae111023e..c9542007588a 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -1,7 +1,7 @@
pkgbase = mkinitcpio-wifi
pkgdesc = mkinitcpio hook to enable wifi remote access
- pkgver = 0.1
- pkgrel = 2
+ pkgver = 0.2
+ pkgrel = 1
url = https://aur.archlinux.org/packages/mkinitcpio-wifi/
install = mkinitcpio-wifi.install
arch = any
@@ -12,7 +12,7 @@ pkgbase = mkinitcpio-wifi
optdepends = mkinitcpio-netconf
source = wifi.hook
source = wifi.install
- sha256sums = e70a34a0a2ecf0d0d46308105b4be5dd8f245d32bac6e4a429fed35f433037bb
+ sha256sums = 6739959b5aedaf9a43352d264d1630ee48b13aa371b7f0c900c672981cde8800
sha256sums = 64dd1704fec9eee158f39ab6e6fe24b08cd76d9cc5c657fe0c08ed1f7962a599
pkgname = mkinitcpio-wifi
diff --git a/PKGBUILD b/PKGBUILD
index 581ea1236f6d..e08f867fb13d 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -1,7 +1,7 @@
# Maintainer: tequa
pkgname=mkinitcpio-wifi
-pkgver=0.1
-pkgrel=2
+pkgver=0.2
+pkgrel=1
pkgdesc="mkinitcpio hook to enable wifi remote access"
arch=(any)
license=('GPL')
@@ -11,7 +11,7 @@ optdepends=(mkinitcpio-netconf)
install="mkinitcpio-wifi.install"
source=('wifi.hook'
'wifi.install')
-sha256sums=('e70a34a0a2ecf0d0d46308105b4be5dd8f245d32bac6e4a429fed35f433037bb'
+sha256sums=('6739959b5aedaf9a43352d264d1630ee48b13aa371b7f0c900c672981cde8800'
'64dd1704fec9eee158f39ab6e6fe24b08cd76d9cc5c657fe0c08ed1f7962a599')
package() {
diff --git a/wifi.hook b/wifi.hook
index ee582191eec7..775a1bca2a82 100644
--- a/wifi.hook
+++ b/wifi.hook
@@ -1,31 +1,78 @@
#!/usr/bin/ash
+check_net_device () {
+ ip link show $1 > /dev/null 2>&1
+}
+
+poll_net_device () {
+ local device=$1 seconds=${2//[!0-9]}
+
+ [ "${seconds:-x}" = x ] && seconds=10
+
+ check_net_device $device && return 0
+
+ msg "Waiting $seconds seconds for network device $device ..." >&2
+ while ! check_net_device $device && [ "$seconds" -gt 0 ]; do
+ sleep 1
+ seconds=$(( seconds - 1 ))
+ done
+
+ check_net_device $device
+}
+
+check_wpa_supplicant_done () {
+ grep "CTRL-EVENT-CONNECTED" $1 > /dev/null
+}
+
+poll_wpa_completion () {
+ local logfile=$1 seconds=${2//[!0-9]}
+
+ [ "${seconds:-x}" = x ] && seconds=10
+
+ check_wpa_supplicant_done $logfile && return 0
+
+ msg "Waiting $seconds seconds for wpa_supplicant ..." >&2
+ while ! check_wpa_supplicant_done $logfile && [ "$seconds" -gt 0 ]; do
+ sleep 1
+ seconds=$(( seconds - 1 ))
+ done
+
+ check_wpa_supplicant_done $logfile
+}
+
run_hook ()
{
- # sleep a couple of seconds so wlan0 is setup by kernel
- sleep 3
+ local device="wlan0"
+ local logfile="/tmp-wpa-supplicant-log"
- echo "Starting wifi"
+ # wait for wlan-device
+ poll_net_device $device 15
- # set wlan0 to up
- ip link set wlan0 up
+ msg "Starting wifi"
+
+ # set wlan-device to up
+ ip link set $device up || return 1
# assocciate with wifi network
- wpa_supplicant -B -D nl80211,wext -i wlan0 -c /etc/wpa_supplicant/initcpio.conf
+ wpa_supplicant -B -D nl80211,wext -i $device -c /etc/wpa_supplicant/initcpio.conf -f $logfile
- # sleep a couple of seconds so that wpa_supplicant finishes connecting
- sleep 5
+ # wait for wpa_supplicant
+ poll_wpa_completion $logfile 15
- # wlan0 should now be connected and ready to be assigned an ip by the net hook
+ # wlan-device should now be connected and ready to be assigned an ip by the net hook
}
run_cleanuphook ()
{
+ local device="wlan0"
+ local logfile="/tmp-wpa-supplicant-log"
+
# kill wpa_supplicant running in the background
killall wpa_supplicant
- # set wlan0 link down
- ip link set wlan0 down
+ # set wlan-device link down
+ ip link set $device down
- # wlan0 should now be fully disconnected from the wifi network
+ # wlan-device should now be fully disconnected from the wifi network
+ rm $logfile
}