addwpa (1179B)
1 #!/bin/rc 2 3 cfile = /etc/wpa_supplicant/wpa_supplicant.conf 4 efile = /tmp/$pid.errors 5 6 fn sigexit { 7 if (!~ $havex11 1) { 8 stty echo 9 } 10 if (test -f $efile) { 11 rm -f $efile 12 } 13 } 14 15 if (!~ $DISPLAY ()) { 16 havex11 = 1 17 } else { 18 havex11 = 0 19 } 20 21 if (!~ `{id -u} 0) { 22 if (~ $havex11 1) { 23 echo Accept | dmenu -p 'Give me root, not this stupid ' ^ `{whoami} ^ ' user!' >/dev/null 24 } else { 25 printf 'Give me root, not this stupid %s user!\n' `{whoami} >[1=2] 26 } 27 exit 1 28 } 29 30 echo Scanning for SSIDs... 31 networks = `{net/scan} 32 if (~ $havex11 1) { 33 choices = `{echo $networks | tr ' ' '\n' | dmenu -i -p 'SSID:'} 34 } else { 35 echo $^networks 36 printf 'SSID: ' 37 choices = `{head -n 1} 38 } 39 40 for (ssid in $choices) { 41 if (~ $havex11 1) { 42 pass = `$nl{dmenu -i -p $ssid ^ ' password:' </dev/null} 43 } else { 44 stty -echo 45 printf '%s password: ' $ssid 46 pass = `$nl{head -n 1} 47 printf '\n' 48 stty echo 49 } 50 conf = `''{wpa_passphrase $ssid $pass >[2]$efile} 51 if (!~ $bqstatus 0) { 52 if (~ $havex11 1) { 53 echo Accept | dmenu -p `''{cat $efile} >/dev/null 54 } else { 55 cat $efile >[1=2] 56 } 57 exit 1 58 } 59 printf '%s' $conf | grep -v '#psk' >[1=2] 60 echo Writing to $cfile 61 printf '%s' $conf >> $cfile 62 }