wifi: Make more user-friendly
This commit is contained in:
parent
097d53807d
commit
ee4e45905a
5 changed files with 65 additions and 30 deletions
|
|
@ -1,9 +1,6 @@
|
|||
#!/usr/bin/env nix-shell
|
||||
#! nix-shell -i python3
|
||||
#! nix-shell -p python3 python3Packages.pyaml
|
||||
|
||||
"""
|
||||
Exports Wi-Fi networks configuration stored in pass into a format readable by Nix.
|
||||
Exports Wi-Fi networks configuration stored in pass
|
||||
into a format readable by Nix.
|
||||
"""
|
||||
|
||||
# TODO EAP ca_cert=/etc/ssl/... probably won't work. Example fix:
|
||||
|
|
@ -11,7 +8,6 @@ Exports Wi-Fi networks configuration stored in pass into a format readable by Ni
|
|||
# url = "https://letsencrypt.org/certs/isrgrootx1.pem";
|
||||
# sha256 = "sha256:1la36n2f31j9s03v847ig6ny9lr875q3g7smnq33dcsmf2i5gd92";
|
||||
# }
|
||||
# TODO Very ugly, can probably do better
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
|
|
@ -22,10 +18,9 @@ import yaml
|
|||
|
||||
# passpy doesn't handle encoding properly, so doing this with calls
|
||||
|
||||
PASSWORD_STORE = os.path.expanduser("~/.local/share/pass")
|
||||
PASSWORD_STORE = os.environ["PASSWORD_STORE_DIR"]
|
||||
SUBFOLDER = "wifi"
|
||||
SEPARATE_PASSWORDS = False
|
||||
# TODO Find a way to make then env file available at whatever time it is needed
|
||||
SEPARATE_PASSWORDS = True
|
||||
|
||||
|
||||
class Password:
|
||||
|
|
@ -41,7 +36,7 @@ class Password:
|
|||
# return self.path.split("/")[-1].upper()
|
||||
m = hashlib.sha256()
|
||||
m.update(self.path.encode())
|
||||
return m.hexdigest().upper()
|
||||
return "p" + m.hexdigest().upper()
|
||||
|
||||
def val(self) -> str:
|
||||
return self.content
|
||||
|
|
@ -148,7 +143,9 @@ for path in list_networks():
|
|||
if psk:
|
||||
network["psk"] = psk.key()
|
||||
if data:
|
||||
raise NotImplementedError(f"{path}: Unhandled non-auth extra: {data}")
|
||||
raise NotImplementedError(
|
||||
f"{path}: Unhandled non-auth extra: {data}"
|
||||
)
|
||||
else:
|
||||
if data:
|
||||
network["auth"] = format_wpa_supplicant_conf(data)
|
||||
|
|
@ -164,8 +161,4 @@ with open("wireless_networks.json", "w") as fd:
|
|||
with open("wireless_networks.env", "w") as fd:
|
||||
if SEPARATE_PASSWORDS:
|
||||
for k, v in Password.vars().items():
|
||||
print(f"{k}={v}", file=fd)
|
||||
|
||||
print("Now, execute:")
|
||||
print("sudo mv -f wireless_networks.* /etc/keys")
|
||||
print("rb")
|
||||
print(f'{k}="{v}"', file=fd)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue