wpa_cli.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/sh
  2. # Copyright 1999-2011 Gentoo Foundation
  3. # Written by Roy Marples <uberlord@gentoo.org>
  4. # Distributed under the terms of the GNU General Public License v2
  5. # Alternatively, this file may be distributed under the terms of the BSD License
  6. if [ -z "$1" -o -z "$2" ]; then
  7. logger -t wpa_cli "Insufficient parameters"
  8. exit 1
  9. fi
  10. INTERFACE="$1"
  11. ACTION="$2"
  12. # Note, the below action must NOT mark the interface down via ifconfig, ip or
  13. # similar. Addresses can be removed, changed and daemons can be stopped, but
  14. # the interface must remain up for wpa_supplicant to work.
  15. if [ -f /etc/parabola-release ]; then
  16. EXEC="/etc/init.d/net.${INTERFACE} --quiet"
  17. else
  18. logger -t wpa_cli "I don't know what to do with this distro!"
  19. exit 1
  20. fi
  21. case ${ACTION} in
  22. CONNECTED)
  23. EXEC="${EXEC} start"
  24. ;;
  25. DISCONNECTED)
  26. # Deactivated, since stopping /etc/init.d/net.wlanX
  27. # stops the network completly.
  28. EXEC="false ${EXEC} stop"
  29. ;;
  30. *)
  31. logger -t wpa_cli "Unknown action ${ACTION}"
  32. exit 1
  33. ;;
  34. esac
  35. # ${EXEC} can use ${IN_BACKGROUND} so that it knows that the user isn't
  36. # stopping the interface and a background process - like wpa_cli - is.
  37. export IN_BACKGROUND=true
  38. logger -t wpa_cli "interface ${INTERFACE} ${ACTION}"
  39. ${EXEC} || logger -t wpa_cli "executing '${EXEC}' failed"