#!/bin/sh # Put a Wi-Fi network's PSK on the card's root, for networking.wireless.secretsFile. # The passphrase comes from the desktop keyring and goes no further than wifi_psk.py; # only the PSK goes on the card. To keep it there, once: # secret-tool store --label="Wi-Fi SSID" service wifi ssid SSID set -eu ssid=${1:?usage: wifi-secret.sh SSID MOUNTPOINT} mnt=${2:?usage: wifi-secret.sh SSID MOUNTPOINT} here=$(dirname "$0") sudo mkdir -p "$mnt" mountpoint -q "$mnt" || sudo mount /dev/disk/by-label/NIXOS_SD "$mnt" trap 'sudo umount "$mnt"' EXIT secret-tool lookup service wifi ssid "$ssid" \ | python3 -I "$here/wifi_psk.py" "$ssid" psk \ | sudo install -D -m 640 /dev/stdin "$mnt/etc/wifi-secrets" sudo grep -c '^psk=[0-9a-f]\{64\}$' "$mnt/etc/wifi-secrets"