#!/bin/bash
#
# Disable the WiFi network connection.

# Exit on first failure.
set -e

print_help() {
  cat <<EOF
Usage: ${0##*/} [--help]
Disable the WiFi network connection.
  --help   Optional. Display this help and exit.
EOF
}

# Parse command-line arguments.
while (( "$#" > 0 )); do
  case "$1" in
    --help)
      print_help
      exit
      ;;
    *)
      >&2 echo "Unknown flag/argument: $1"
      >&2 echo "Use the '--help' flag for more information"
      exit 1
      ;;
  esac
done

# Echo commands before executing them, by default to stderr.
set -x

# Exit on unset variable.
set -u

# Delete the connection (ignore errors if it doesn't exist). The connection is
# recreated by enable-wifi or enable-wifi-ap when WiFi is re-enabled.
nmcli connection delete 'tinypilot-wlan0' 2>/dev/null || true

# Disable the wireless radio.
nmcli radio wifi off
