dotfiles

Cem's Dotfiles
git clone git://git.ckyln.com/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

wpa_add_network (818B)


      1 #!/bin/sh
      2 
      3 if [ "$(tty)" = "not a tty" ]; then
      4 	getvalue() { VALUE="$(dmenu -p "$1")" ;}
      5 	prompt() { [ "$(printf "No\\nYes" | dmenu -i -p "$1")" = "Yes" ] ;}
      6 	printf "tty"
      7 else
      8 	getvalue() {
      9 		printf "$1 "
     10 		read VALUE
     11 	}
     12 	prompt() {
     13 		printf "$1\ny/n: "
     14 		read ans
     15 		case "$ans" in
     16 			[Yy]*) return 0 ;;
     17 			*) return 1 ;;
     18 		esac
     19 	}
     20 fi
     21 
     22 [ -z "$1" ] && getvalue "Please enter the ssid:" && SSID="$VALUE"
     23 [ -z "$SSID" ] && exit 1
     24 
     25 if prompt "Is the network password protected?" ; then
     26 	getvalue "Enter the password:"
     27 	PASSWORD="$VALUE"
     28 	[ -z "$PASSWORD" ] && exit 1
     29 	wpa_passphrase "$SSID" "$PASSWORD" | sudo tee -a /etc/wpa_supplicant/wpa_supplicant.conf
     30 else
     31 	printf "network={\n        ssid=$SSID\n        keymgmt=NONE\n        priority=-999\n        }\n" | \
     32 		sudo tee -a /etc/wpa_supplicant/wpa_supplicant.conf
     33 fi