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