alicelinux

A lightweight musl + clang/llvm + libressl + busybox distro
git clone https://codeberg.org/emmett1/alicelinux
Log | Files | Refs | README | LICENSE

iwd_passphrase (884B)


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