Refactored the script by placing the logic of starting and stopping into 
separate functions,
added a switch statement to act on $1, then refactored multiple if statements 
into one line tests.
Check_socket function was extracted to increase the readability of the start 
function.
Created restart functionality by calling stop then start
Added a BEGIN INIT INFO comment section (should be verified for accuracy)
Sourced the rcS default file to use the VERBOSE variable instead of VERBOSITY
Defined WPA_COMMON_CTRL_IFACE = "/var/run/wpa_supplicant" that was previously 
acted upon but not defined.

Signed-off-by: Andrew Wichmann <awichm...@emacinc.com>
---
 .../wpa-supplicant/wpa-supplicant.sh               | 91 +++++++++++++---------
 1 file changed, 54 insertions(+), 37 deletions(-)

diff --git 
a/meta/recipes-connectivity/wpa-supplicant/wpa-supplicant/wpa-supplicant.sh 
b/meta/recipes-connectivity/wpa-supplicant/wpa-supplicant/wpa-supplicant.sh
index 5c9e5d3..3623cbe 100644
--- a/meta/recipes-connectivity/wpa-supplicant/wpa-supplicant/wpa-supplicant.sh
+++ b/meta/recipes-connectivity/wpa-supplicant/wpa-supplicant/wpa-supplicant.sh
@@ -1,72 +1,62 @@
-#!/bin/sh
+#!/bin/sh -e
+### BEGIN INIT INFO
+# Provides:                    wpa_supplicant
+# Required-Start:      $local_fs
+# Required-Stop:       $local_fs
+# Default-Start:       2 3 4 5
+# Default-Stop:                0 1 6
+# Short-Description: A script to start, stop, or restart the wpa_supplicant 
daemon.
+### END INIT INFO
 
 
+IFACE="wlan0"
 WPA_SUP_BIN="/usr/sbin/wpa_supplicant"
 WPA_SUP_PNAME="wpa_supplicant"
 WPA_SUP_PIDFILE="/var/run/wpa_supplicant.$IFACE.pid"
 WPA_SUP_OPTIONS="-B -P $WPA_SUP_PIDFILE -i $IFACE"
+WPA_COMMON_CTRL_IFACE="/var/run/wpa_supplicant"
+IF_WPA_CONF="/etc/wpa_supplicant.conf"
 
-VERBOSITY=0
 
+[ -s "/etc/default/rcS" ] && . "/etc/default/rcS"
 
-if [ -s "$IF_WPA_CONF" ]; then
-       WPA_SUP_CONF="-c $IF_WPA_CONF"
-else
-       exit 0
-fi
+[ ! -s "$IF_WPA_CONF" ] && exit 0
+WPA_SUP_CONF="-c $IF_WPA_CONF"
 
 if [ ! -x "$WPA_SUP_BIN" ]; then
        
-       if [ "$VERBOSITY" = "1" ]; then
-               echo "$WPA_SUP_PNAME: binaries not executable or missing from 
$WPA_SUP_BIN"
-       fi
+       [ "$VERBOSE" = "yes" ] && echo "$WPA_SUP_PNAME: binaries not executable 
or missing from $WPA_SUP_BIN"
        
        exit 1
 fi
 
-if [ "$MODE" = "start" ] ; then
+start() {
        # driver type of interface, defaults to wext when undefined
        if [ -s "/etc/wpa_supplicant/driver.$IFACE" ]; then
                IF_WPA_DRIVER=$(cat "/etc/wpa_supplicant/driver.$IFACE")
        elif [ -z "$IF_WPA_DRIVER" ]; then
                
-               if [ "$VERBOSITY" = "1" ]; then
-                       echo "$WPA_SUP_PNAME: wpa-driver not provided, using 
\"wext\""
-               fi
-               
+               [ "$VERBOSE" = "yes" ] && echo "$WPA_SUP_PNAME: wpa-driver not 
provided, using \"wext\""
+       
                IF_WPA_DRIVER="wext"
        fi
        
        # if we have passed the criteria, start wpa_supplicant
        if [ -n "$WPA_SUP_CONF" ]; then
                
-               if [ "$VERBOSITY" = "1" ]; then
-                       echo "$WPA_SUP_PNAME: $WPA_SUP_BIN $WPA_SUP_OPTIONS 
$WPA_SUP_CONF -D $IF_WPA_DRIVER"
-               fi
-               
+               [ "$VERBOSE" = "yes" ] && echo "$WPA_SUP_PNAME: $WPA_SUP_BIN 
$WPA_SUP_OPTIONS $WPA_SUP_CONF -D $IF_WPA_DRIVER"
+
                start-stop-daemon --start --quiet \
                        --name $WPA_SUP_PNAME --startas $WPA_SUP_BIN --pidfile 
$WPA_SUP_PIDFILE \
                        --  $WPA_SUP_OPTIONS $WPA_SUP_CONF -D $IF_WPA_DRIVER
        fi
+       check_socket
+}
 
-       # if the interface socket exists, then wpa_supplicant was invoked 
successfully
-       if [ -S "$WPA_COMMON_CTRL_IFACE/$IFACE" ]; then
-       
-               if [ "$VERBOSITY" = "1" ]; then
-                       echo "$WPA_SUP_PNAME: ctrl_interface socket located at 
$WPA_COMMON_CTRL_IFACE/$IFACE"
-               fi
-
-               exit 0
-               
-       fi
-       
-elif [ "$MODE" = "stop" ]; then
-
+stop() {
        if [ -f "$WPA_SUP_PIDFILE" ]; then
                
-               if [ "$VERBOSITY" = "1" ]; then
-                       echo "$WPA_SUP_PNAME: terminating $WPA_SUP_PNAME daemon"
-               fi
+               [ "$VERBOSE" = "yes" ] && echo "$WPA_SUP_PNAME: terminating 
$WPA_SUP_PNAME daemon"
                
                start-stop-daemon --stop --quiet \
                        --name $WPA_SUP_PNAME --pidfile $WPA_SUP_PIDFILE
@@ -79,7 +69,34 @@ elif [ "$MODE" = "stop" ]; then
                        rm -f $WPA_SUP_PIDFILE
                fi
        fi
+       exit 0
+}
 
-fi
+check_socket(){
+       # if the interface socket exists, then wpa_supplicant was invoked 
successfully
+       if [ -S "$WPA_COMMON_CTRL_IFACE/$IFACE" ]
+       then
+               [ "$VERBOSE" = "yes" ] && echo "$WPA_SUP_PNAME: ctrl_interface 
socket located at$WPA_COMMON_CTRL_IFACE/$IFACE"
+               exit 0
+       fi
+       exit 1
+}
+
+case "$1" in
+       start)
+               start
+               ;;
+       stop)
+               stop
+               ;;
+       restart)
+               stop
+               start
+               ;;
+       *)
+               echo "Usage: /etc/init.d/wpa_supplicant {start|stop|restart}"
+               exit 1
+
+esac
 
-exit 0
+exit 1
-- 
1.9.1

-- 
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core

Reply via email to