summaryrefslogtreecommitdiff
path: root/dot/local
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2018-06-12 16:56:06 -0400
committerAndrew Cady <d@jerkface.net>2018-06-12 17:07:12 -0400
commiteb3f50f27412c06f5efd2dc4788ed38b4809dda4 (patch)
treec3aa54c7f2422629912ef0f44d110af0ba4ae282 /dot/local
parenta0d05150e5279ddb39fd981553f244706588f922 (diff)
wifi restarting scripts
Diffstat (limited to 'dot/local')
-rwxr-xr-xdot/local/bin/hard-restart-wifi23
-rwxr-xr-xdot/local/bin/restart-linux-device53
2 files changed, 76 insertions, 0 deletions
diff --git a/dot/local/bin/hard-restart-wifi b/dot/local/bin/hard-restart-wifi
new file mode 100755
index 0000000..78f7144
--- /dev/null
+++ b/dot/local/bin/hard-restart-wifi
@@ -0,0 +1,23 @@
1#!/bin/sh
2
3default_dev='wlan0=funston'
4
5die() { printf 'Error: %s\n' "$*" >&2; exit 1; }
6
7with_pwd_path()
8{
9 local PATH="$PATH":.
10 "$@"
11}
12
13[ $(id -u) = 0 ] || die "you are not root."
14
15restart=$(with_pwd_path which restart-linux-device) || die "command 'restart-linux-device' is not available."
16
17dev=${1:-$default_dev}
18rawdev=${dev%=*}
19
20[ "$VERBOSE" ] && set -x
21$restart $rawdev
22ifdown --force $rawdev # It's not clear to me why this is necessary, but it is.
23ifup $dev
diff --git a/dot/local/bin/restart-linux-device b/dot/local/bin/restart-linux-device
new file mode 100755
index 0000000..e1cd41f
--- /dev/null
+++ b/dot/local/bin/restart-linux-device
@@ -0,0 +1,53 @@
1#!/bin/bash
2
3# Thanks, ericwoud
4# https://ubuntuforums.org/showthread.php?t=2339439&page=2&p=13585921#post13585921
5
6warn() { printf 'Error: %s\n' "$*" >&2; }
7
8with_rescan_remove()
9{
10 local devname="$1" dev f hw_path rescan remove
11 shift
12
13 case "$devname" in
14 */*)
15 dev=/sys/class/$devname ;;
16 *)
17 for f in /sys/class/*/"$devname"; do
18 dev=$f
19 break
20 done
21 ;;
22 esac
23 [ "$dev" -a -d "$dev" ] || { warn "device not found: $devname"; return 1; }
24
25 hw_path=$(dirname $(dirname $(realpath "$(dirname "$dev")/$(readlink "$dev")")))
26
27 rescan=$(dirname "$hw_path")/rescan
28 remove="$hw_path"/remove
29
30 if [ ! -e "$rescan" -a -e "$hw_path"/../pci_bus ]; then
31 local p=$(dirname "$hw_path")/
32 rescan=$p/pci_bus/${p#*/pci}/rescan
33 fi
34
35 [ -e "$rescan" ] || { warn "sysfs special file not found: $rescan"; return 1; }
36 [ -e "$remove" ] || { warn "sysfs special file not found: $remove"; return 1; }
37
38 "$@" "$rescan" "$remove"
39}
40
41restart()
42{
43 local rescan="$1" remove="$2"
44 printf 1 > "$remove" || { warn "kernel remove failed"; return 2; }
45 printf 1 > "$rescan" || { warn "kernel rescan failed"; return 3; }
46
47 for ((i=0; i<100; ++i)); do
48 [ -e "$remove" ] && break
49 sleep 0.05
50 done
51}
52
53with_rescan_remove "$1" restart