wifi 600 B

1234567891011121314151617181920212223242526272829
  1. #!/bin/sh
  2. if ! command -v nmcli > /dev/null 2>&1; then
  3. echo "nmcli not found"
  4. exit 1
  5. fi
  6. if [ -z "$1" ] || [ "$1" = "help" ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
  7. echo "usage: wifi [list|ssid [wpa secret]]"
  8. exit 1
  9. fi
  10. if [ "$1" = "list" ]; then
  11. nmcli dev wifi list
  12. exit 0
  13. fi
  14. # May be the magic ticket
  15. nmcli con add ifname wlan0 type wifi con-name "$1" ssid "$1"
  16. # nmcli con add dev wifi type wifi con-name "$1" ssid "$1"
  17. if [ ! -z "$2" ]; then
  18. nmcli con modify "$1" wifi-sec.key-mgmt wpa-psk
  19. nmcli con modify "$1" wifi-sec.psk "$2"
  20. fi
  21. nmcli con up "$1"