summaryrefslogtreecommitdiffstats
path: root/public/.local/bin/network_control.sh
blob: 4dc4b3865b8bfccc5b40b493d71f9f86699f4991 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash

signal=30

# signal dwmblocks to update network block
send_signal() {
    pkill -RTMIN+$signal dwmblocks
}

toggle_wifi() {
    status=$(nmcli radio wifi)

    if [ "$status" = "enabled" ]; then
        nmcli radio wifi off
    else
        nmcli radio wifi on
    fi
}

# This one is hard because it requires root, and the VPN interface name
# 2 ways to toggle, using systemctl, or wg-quick(1)
# This one might be better controled through a `dmenu` script.
toggle_vpn() {
    :
}

toggle_network_quarantine() {
    # Check the status of all wireless devices
    if rfkill list | grep -q "Soft blocked: no"; then
        # not all blocked
        rfkill block all
    else
        # all blocked
        rfkill unblock all
    fi
}

# WIP
toggle_bluetooth() {
    :
}

case $1 in
    wifitoggle) toggle_wifi ;;
    vpntoggle) toggle_vpn ;;
    bluetoothtoggle) toggle_bluetooth ;;
    isolatetoggle) toggle_network_quarantine ;;
    *)
        echo "invalid option :)"
        ;;
esac

send_signal