scripts

random scripts
git clone https://git.parazyd.org/scripts
Log | Files | Refs

newifi (567B)


      1 #!/bin/sh
      2 
      3 usage() {
      4 	printf "usage: %s [essid] [bssid] [psk]\n" "$(basename $0)"
      5 	exit 1
      6 }
      7 
      8 wpasup=/etc/wpa_supplicant/wpa_supplicant.conf
      9 
     10 essid="$1"
     11 bssid="$2"
     12 psk="$3"
     13 
     14 [ -n "$essid" ] || usage
     15 [ -n "$bssid" ] || usage
     16 
     17 printf "[essid]: %s\n[bssid]: %s\n[psk]:   %s\n" \
     18 	"$essid" "$bssid" "$psk"
     19 
     20 if [ -n "$psk" ]; then
     21 	cat <<EOF | sudo tee -a $wpasup
     22 
     23 network={
     24 	ssid="${essid}"
     25 	disabled=0
     26 	bssid=${bssid}
     27 	psk="${psk}"
     28 }
     29 EOF
     30 else
     31 	cat <<EOF | sudo tee -a $wpasup
     32 
     33 network={
     34 	ssid="${essid}"
     35 	disabled=0
     36 	bssid=${bssid}
     37 	auth_alg=OPEN
     38 	key_mgmt=NONE
     39 }
     40 EOF
     41 fi