wpa 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/bash
  2. # Begin services/wpa
  3. # Origianlly based upon lfs-bootscripts-1.12 $NETWORK_DEVICES/if{down,up}
  4. # Written by Armin K. <krejzi at email dot com>
  5. # Call with: IFCONFIG=<filename> /lib/services/wpa <IFACE> <up | down>
  6. #$LastChangedBy: bdubbs $
  7. #$Date: 2016-09-02 23:10:02 -0500 (Fri, 02 Sep 2016) $
  8. . /lib/lsb/init-functions
  9. . $IFCONFIG
  10. CFGFILE=/etc/sysconfig/wpa_supplicant-${IFCONFIG##*.}.conf
  11. PIDFILE=/run/wpa_supplicant/$1.pid
  12. CONTROL_IFACE=/run/wpa_supplicant/$1
  13. case "$2" in
  14. up)
  15. if [ -e ${PIDFILE} ]; then
  16. ps $(cat ${PIDFILE}) | grep wpa_supplicant >/dev/null
  17. if [ "$?" = "0" ]; then
  18. log_warning_msg "\n wpa_supplicant already running on $1."
  19. exit 0
  20. else
  21. rm ${PIDFILE}
  22. fi
  23. fi
  24. if [ ! -e ${CFGFILE} ]; then
  25. log_info_msg "\n wpa_supplicant configuration file ${CFGFILE} not present"
  26. log_failure_msg2
  27. exit 1
  28. fi
  29. # Only specify -C on command line if it is not in CFGFILE
  30. if ! grep -q ctrl_interface ${CFGFILE}; then
  31. WPA_ARGS="-C/run/wpa_supplicant ${WPA_ARGS}"
  32. fi
  33. log_info_msg "\n Starting wpa_supplicant on the $1 interface..."
  34. mkdir -p /run/wpa_supplicant
  35. /sbin/wpa_supplicant -q -B -Dnl80211,wext -P${PIDFILE} \
  36. -c${CFGFILE} -i$1 ${WPA_ARGS}
  37. if [ "$?" != "0" ]; then
  38. log_failure_msg2
  39. exit 1
  40. fi
  41. log_success_msg2
  42. if [ -n "${WPA_SERVICE}" ]; then
  43. if [ ! -e /lib/services/${WPA_SERVICE} -a \
  44. ! -x /lib/services/${WPA_SERVICE} ]; then
  45. log_info_msg "\n Cannot start ${WPA_SERVICE} on $1"
  46. log_failure_msg2
  47. exit 1
  48. fi
  49. IFCONFIG=${IFCONFIG} /lib/services/${WPA_SERVICE} $1 up
  50. fi
  51. ;;
  52. down)
  53. if [ -n "${WPA_SERVICE}" ]; then
  54. if [ ! -e /lib/services/${WPA_SERVICE} -a ! -x /lib/services/${WPA_SERVICE} ]; then
  55. log_warning_msg "\n Cannot stop ${WPA_SERVICE} on $1"
  56. else
  57. IFCONFIG=${IFCONFIG} /lib/services/${WPA_SERVICE} $1 down
  58. fi
  59. fi
  60. log_info_msg "\n Stopping wpa_supplicant on the $1 interface..."
  61. if [ -e ${PIDFILE} ]; then
  62. kill -9 $(cat ${PIDFILE})
  63. rm -f ${PIDFILE} ${CONTROL_IFACE}
  64. evaluate_retval
  65. else
  66. log_warning_msg "\n wpa_supplicant already stopped on $1"
  67. exit 0
  68. fi
  69. ;;
  70. *)
  71. echo "Usage: $0 [interface] {up|down}"
  72. exit 1
  73. ;;
  74. esac
  75. # End services/wpa