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
|
#!/usr/bin/env python3
import sys, os
import argparse
import subprocess
import time
parser = argparse.ArgumentParser(
prog='iwctl-re'
)
parser.add_argument(
'--mode',
default='soft',
choices=['soft', 'hard']
)
args = parser.parse_args()
def getSubprocessOutput(command):
return subprocess.run(command, capture_output=True, text=True).stdout.strip()
if args.mode == 'soft':
subprocess.run(['notify-send', 'WLAN Reload', 'Disconnect'])
subprocess.run(['iwctl', 'station', 'wlan0', 'disconnect'])
time.sleep(5)
subprocess.run(['notify-send', 'WLAN Reload', 'Reconnect'])
wlan_passphrase = getSubprocessOutput(['pass', 'router/passphrase'])
wlan_name = getSubprocessOutput(['pass', 'router/name'])
wlan_security = getSubprocessOutput(['pass', 'router/security'])
subprocess.run(['iwctl', '--passphrase', wlan_passphrase, 'station', 'wlan0', 'connect', wlan_name, wlan_security])
elif args.mode == 'hard':
subprocess.run(['notify-send', 'WLAN Reload', 'Restart iwd.service'])
subprocess.run(['sudo', 'systemctl', 'restart', 'iwd.service'])
|