55import shutil
66import sys
77from pathlib import Path
8+ from subprocess import Popen , PIPE
89
910
1011def file_content (paths ):
@@ -21,25 +22,25 @@ def file_content(paths):
2122nic = args [1 ]
2223
2324etc = Path (os .sep , "etc" )
24- rcconf = etc / "rc.conf"
25- rcconflocal = etc / "rc.conf.local"
25+ rc_conf = etc / "rc.conf"
26+ rc_conf_local = etc / "rc.conf.local"
2627wpa_supplicant = etc / "wpa_supplicant.conf"
2728
28- rcconf_paths = [rcconf ]
29+ rc_conf_paths = [rc_conf ]
2930
30- if rcconflocal .exists ():
31- rcconf_paths .append (rcconflocal )
31+ if rc_conf_local .exists ():
32+ rc_conf_paths .append (rc_conf_local )
3233
33- rcconf_content = file_content (rcconf_paths )
34+ rc_conf_content = file_content (rc_conf_paths )
3435
35- notnics_regex = "(enc|lo|fwe|fwip|tap|plip|pfsync|pflog|ipfw|tun|sl|faith|" \
36+ not_nics_regex = "(enc|lo|fwe|fwip|tap|plip|pfsync|pflog|ipfw|tun|sl|faith|" \
3637 "ppp|bridge|wg|wlan)[0-9]+|vm-[a-z]+"
3738
3839# wifi_driver_regex is taken from devd.conf wifi-driver-regex
39- wifi_driver_regex = "(ath|bwi|bwn|ipw|iwlwifi|iwi|iwm|iwn|malo|mwl|otus|" \
40+ wifi_driver_regex = "(ath|ath[0-9]+k| bwi|bwn|ipw|iwlwifi|iwi|iwm|iwn|malo|mwl|mt79 |otus|" \
4041 "ral|rsu|rtw|rtwn|rum|run|uath|upgt|ural|urtw|wpi|wtap|zyd)[0-9]+"
4142
42- if re .search (notnics_regex , nic ):
43+ if re .search (not_nics_regex , nic ):
4344 exit (0 )
4445
4546if re .search (wifi_driver_regex , nic ):
@@ -48,14 +49,22 @@ def file_content(paths):
4849 shutil .chown (wpa_supplicant , user = "root" , group = "wheel" )
4950 wpa_supplicant .chmod (0o765 )
5051 for wlanNum in range (0 , 9 ):
51- if f'wlan{ wlanNum } ' not in rcconf_content :
52- break
53- if f'wlans_{ nic } =' not in rcconf_content :
54- with rcconf .open ('a' ) as rc :
55- rc .writelines (f'wlans_{ nic } ="wlan{ wlanNum } "\n ' )
56- rc .writelines (f'ifconfig_wlan{ wlanNum } ="WPA DHCP"\n ' )
52+ if f'wlan{ wlanNum } ' not in rc_conf_content :
53+ if f'wlans_{ nic } =' not in rc_conf_content :
54+ with rc_conf .open ('a' ) as rc :
55+ rc .writelines (f'wlans_{ nic } ="wlan{ wlanNum } "\n ' )
56+ rc .writelines (f'ifconfig_wlan{ wlanNum } ="WPA DHCP"\n ' )
57+ Popen (f'/etc/pccard_ether { nic } startchildren' , shell = True )
58+
5759else :
58- if f'ifconfig_{ nic } =' not in rcconf_content :
59- with rcconf .open ('a' ) as rc :
60+ if f'ifconfig_{ nic } =' not in rc_conf_content :
61+ with rc_conf .open ('a' ) as rc :
6062 rc .writelines (f'ifconfig_{ nic } ="DHCP"\n ' )
61- os .system (f'/etc/pccard_ether { nic } startchildren' )
63+ Popen ('/etc/pccard_ether {nic} startchildren' , shell = True )
64+ else :
65+ Popen (
66+ f'service netif start { nic } ; '
67+ f'service dhclient start { nic } ; '
68+ f'service routing restart' ,
69+ shell = True
70+ )
0 commit comments