iwd_passphrase 884 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/bin/sh
  2. #
  3. # Simple script to generate iwd network files.
  4. [ "$1" ] || {
  5. printf '%s\n' "usage: printf pass | ${0##*/} ssid" >&2
  6. exit 1
  7. }
  8. # Read the password from 'stdin'.
  9. read -r pass; [ "$pass" ] || exit 1
  10. # Consider all characters as single-byte.
  11. export LC_CTYPE=C
  12. # The SSID appears verbatim in the name if it contains
  13. # only alphanumeric characters, spaces, underscores or
  14. # minus signs. Otherwise it is encoded as an equal sign
  15. # followed by the lower-case hex encoding of the name.
  16. case $1 in
  17. *[!A-Za-z0-9_' '-]*)
  18. ssid="=$(printf %s "$1" | od -vA n -t x1 | tr -d '\n ')"
  19. ;;
  20. *)
  21. ssid=$1
  22. ;;
  23. esac
  24. printf '%s\n\n' "Save this output to /var/lib/iwd/$ssid.psk" >&2
  25. printf '[Security]\n'
  26. printf 'Passphrase=%s\n' "$pass"
  27. printf '\nTIP: You can use this output directly as the\n' >&2
  28. printf ' help messages are printed to stderr.\n' >&2