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
This commit is contained in:
Miroslav Koskar 2013-11-15 20:07:27 +01:00 committed by oblique
parent dc6fe47389
commit f143ddd584

View File

@ -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