Skip to content

Commit

Permalink
added args and help
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymon Ziolkowski authored and Szymon Ziolkowski committed Jun 29, 2023
1 parent 0fef8ba commit bef6053
Showing 1 changed file with 43 additions and 31 deletions.
74 changes: 43 additions & 31 deletions berate_radius.sh
Original file line number Diff line number Diff line change
@@ -1,46 +1,58 @@
#!/bin/sh

PROGNAME="berate_radius"
export LC_ALL=C

PROGNAME="$(basename $0)"

usage() {
echo "Usage: "$PROGNAME" [options] <wifi-interface> [<interface-with-internet>] [<access-point-name> [<passphrase>]]"
echo "Usage: "$PROGNAME" [-h] [--domain example.com] [--radius-password P@ssw0rd] [--radius-client-ip-range 0.0.0.0/0]"
echo
echo "Options:"
echo " -h, --help Show this help"
echo " --version Print version number"
echo " -e <hosts_file> DNS server will take into account additional hosts file"
echo
echo "Useful informations:"
echo " * If you're not using the --no-virt option, then you can create an AP with the same"
echo " interface you are getting your Internet connection."
echo " * You can pass your SSID and password through pipe or through arguments (see examples)."
echo " * On bridge method if the <interface-with-internet> is not a bridge interface, then"
echo " a bridge interface is created automatically."
echo " -h, --help Show this help"
echo " -d, --domain <domain> Domain of the certificate (default: \"example.com\")"
echo " -p, --radius-password <password> Radius client password (default: \"P@ssw0rd\")"
echo " -r, --radius-client-ip-range <ip range> Radius client allowed IP range (default: \"0.0.0.0/0\")"
echo
echo "Examples:"
echo " "$PROGNAME" wlan0 eth0 MyAccessPoint MyPassPhrase"
echo " echo -e 'MyAccessPoint\nMyPassPhrase' | "$PROGNAME" wlan0 eth0"
echo " "$PROGNAME" wlan0 eth0 MyAccessPoint"
echo " echo 'MyAccessPoint' | "$PROGNAME" wlan0 eth0"
echo " "$PROGNAME" wlan0 wlan0 MyAccessPoint MyPassPhrase"
echo " "$PROGNAME" -n wlan0 MyAccessPoint MyPassPhrase"
echo " "$PROGNAME" -m bridge wlan0 eth0 MyAccessPoint MyPassPhrase"
echo " "$PROGNAME" -m bridge wlan0 br0 MyAccessPoint MyPassPhrase"
echo " "$PROGNAME" --driver rtl871xdrv wlan0 eth0 MyAccessPoint MyPassPhrase"
echo " "$PROGNAME" --daemon wlan0 eth0 MyAccessPoint MyPassPhrase"
echo " "$PROGNAME" --stop wlan0"
}

# defaults
PASSWORD=P@ssw0rd
RANGE=0.0.0.0/0
DOMAIN=example.com
export PASSWORD="P@ssw0rd"
export RANGE="0.0.0.0/0"
export DOMAIN="example.com"

GETOPT_ARGS=$(getopt -o hd:p:r: -l "help","domain:","radius-password:","radius-client-ip-range:" -n "$PROGNAME" -- "$@")
[ $? -ne 0 ] && exit 1
eval set -- "$GETOPT_ARGS"

export DOMAIN=wifi.example.com
/hostapd_configs/hostapd.conf.template > /hostapd_configs/hostapd.conf
while :; do
case "$1" in
-h|--help)
usage
exit 0
;;
-d|--domain)
shift
DOMAIN="$1"
shift
;;
-p|--radius-password)
shift
PASSWORD="$1"
shift
;;
-r|--radius-client-ip-range)
shift
RANGE="$1"
shift
;;
--)
shift
break
;;
esac
done

export PASSWORD=P@ssw0rd
export RANGE=0.0.0.0/0
/hostapd_configs/hostapd.conf.template > /hostapd_configs/hostapd.conf
/hostapd_configs/hostapd.radius_client.template > /hostapd_configs/hostapd.radius_client


Expand Down

0 comments on commit bef6053

Please sign in to comment.