From f143ddd5841b76c72360ec62ee61164969331761 Mon Sep 17 00:00:00 2001 From: Miroslav Koskar Date: Fri, 15 Nov 2013 20:07:27 +0100 Subject: [PATCH] Set SSID and PASSPHRASE values from standard input - SSID is the first line - PASSPHRASE is the second line example: echo -e 'MyAccessPoint\nMyPassPhrase' | create_ap wlan0 eth0 --- create_ap | 51 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/create_ap b/create_ap index 5bd9b40..c560812 100755 --- a/create_ap +++ b/create_ap @@ -25,6 +25,8 @@ usage() { echo "Examples:" echo " $(basename $0) wlan0 eth0 MyAccessPoint MyPassPhrase" echo " $(basename $0) -n wlan0 MyAccessPoint MyPassPhrase" + echo " echo -e 'MyAccessPoint\nMyPassPhrase' | $(basename $0) wlan0 eth0" + echo " echo -e 'MyAccessPoint\nMyPassPhrase' | $(basename $0) -n wlan0" } get_macaddr() { @@ -88,24 +90,41 @@ while :; do esac done -if [[ $SHARE_INTERNET -eq 1 ]]; then - if [[ $# -ne 3 && $# -ne 4 ]]; then - usage - exit 1 - fi - INTERNET_IFACE=$2 - SSID=$3 - PASSPHRASE=$4 -else - if [[ $# -ne 2 && $# -ne 3 ]]; then - usage - exit 1 - fi - SSID=$2 - PASSPHRASE=$3 +if [[ $# -lt 1 ]]; then + usage + exit 1 fi WIFI_IFACE=$1 +if tty -s; then + if [[ $SHARE_INTERNET -eq 1 ]]; then + if [[ $# -ne 3 && $# -ne 4 ]]; then + usage + exit 1 + fi + INTERNET_IFACE=$2 + SSID=$3 + PASSPHRASE=$4 + else + if [[ $# -ne 2 && $# -ne 3 ]]; then + usage + exit 1 + fi + SSID=$2 + PASSPHRASE=$3 + fi +else + if [[ $SHARE_INTERNET -eq 1 ]]; then + if [[ $# -ne 2 ]]; then + usage + exit 1 + fi + INTERNET_IFACE=$2 + fi + read SSID + read PASSPHRASE +fi + if [[ $(id -u) -ne 0 ]]; then echo "You must run it as root." exit 1 @@ -133,7 +152,7 @@ if [[ -n "$PASSPHRASE" ]]; then [[ "$WPA_VERSION" == "1+2" || "$WPA_VERSION" == "2+1" ]] && WPA_VERSION=3 cat << EOF >> $CONFDIR/hostapd.conf wpa=${WPA_VERSION} -wpa_passphrase=$4 +wpa_passphrase=$PASSPHRASE wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP