From 18fde802fc7633a179a9bb81f16760a94692c54b Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Sat, 18 Dec 2021 22:42:56 +0800
Subject: [PATCH] add wpa_supplicant start script

---
 bsp/rootfs/files/wpa_supplicant.conf |    9 ++++
 bsp/rootfs/files/S30WpaSupplicant    |   33 ++++++++++++++++
 bsp/rootfs/build.sh                  |   30 ++++++++++++++
 3 files changed, 71 insertions(+), 1 deletions(-)

diff --git a/bsp/rootfs/build.sh b/bsp/rootfs/build.sh
index ae47a2e..95a1814 100755
--- a/bsp/rootfs/build.sh
+++ b/bsp/rootfs/build.sh
@@ -20,6 +20,7 @@
 DEF_HOSTNAME=${BOARD}
 
 APT_CONF=extra_apps.json
+PATCH_PATH=${PRJ_PATH}/files
 
 set -u
 set -e
@@ -170,11 +171,38 @@
     fi
 }
 
+function do_buildroot()
+{
+    if [ $ROOTFS != "buildroot" ] ; then
+        return ;
+    fi
+
+    # add vim alias for vim
+    grep "alias vim=" ${ROOTFS_DIR}/etc/profile > /dev/null 2>&1
+    if [ $? != 0 ] ; then
+       echo "alias vim='vi'" >> ${ROOTFS_DIR}/etc/profile
+    fi
+
+    if [ -s ${PATCH_PATH}/S30WpaSupplicant ] ; then
+        cp ${PATCH_PATH}/S30WpaSupplicant ${ROOTFS_DIR}/etc/init.d/
+        chmod a+x ${ROOTFS_DIR}/etc/init.d/S30WpaSupplicant
+    fi
+
+    if [ -s ${PATCH_PATH}/wpa_supplicant.conf ] ; then
+        cp ${PATCH_PATH}/wpa_supplicant.conf ${ROOTFS_DIR}/etc/
+    fi
+
+    printf "\n\n -- modify buildroot rootfs done --\n\n"
+}
+
 function do_modify()
 {
     msg_banner " modify rootfs environment"
 
     set +e
+
+    # modify for buildroot rootfs
+    do_buildroot
 
     # update hostnmae and issue
     echo "Welcome to LingYun IoT Gateway Kit Board GNU/Linux $ROOTFS system, default password '$DEF_PASSWD'." > ${ROOTFS_DIR}/etc/issue
@@ -194,7 +222,7 @@
 
 
     # add ls alias for display with color
-    grep "color=auto" ${ROOTFS_DIR}/etc/profile > /dev/null 2>&1
+    grep "^alias ls=" ${ROOTFS_DIR}/etc/profile > /dev/null 2>&1
     if [ $? != 0 ] ; then
        echo "alias ls='ls --color=auto'" >> ${ROOTFS_DIR}/etc/profile
     fi
diff --git a/bsp/rootfs/files/S30WpaSupplicant b/bsp/rootfs/files/S30WpaSupplicant
new file mode 100755
index 0000000..9f68746
--- /dev/null
+++ b/bsp/rootfs/files/S30WpaSupplicant
@@ -0,0 +1,33 @@
+#!/bin/sh
+#
+# Start the network....
+#
+
+APP_NAME=wpa_supplicant
+CONF_FILE=/etc/wpa_supplicant.conf
+
+case "$1" in
+  start)
+	printf "Starting ${APP_NAME}: "
+	[ -f $CONF_FILE ] || echo "FAIL"
+	start-stop-daemon -S -q -m -b -p /var/run/${APP_NAME}.pid \
+	--exec /usr/sbin/${APP_NAME} \
+	-- -iwlan0 -c ${CONF_FILE}
+	[ $? = 0 ] && echo "OK" || echo "FAIL"
+	;;
+  stop)
+	printf "Stopping ${APP_NAME}: "
+	start-stop-daemon -K -q -p /var/run/${APP_NAME}.pid
+	[ $? = 0 ] && echo "OK" || echo "FAIL"
+	;;
+  restart|reload)
+	"$0" stop
+	"$0" start
+	;;
+  *)
+	echo "Usage: $0 {start|stop|restart}"
+	exit 1
+esac
+
+exit $?
+
diff --git a/bsp/rootfs/files/wpa_supplicant.conf b/bsp/rootfs/files/wpa_supplicant.conf
new file mode 100644
index 0000000..9aed517
--- /dev/null
+++ b/bsp/rootfs/files/wpa_supplicant.conf
@@ -0,0 +1,9 @@
+ctrl_interface=/var/run/wpa_supplicant
+ctrl_interface_group=0
+update_config=1
+ 
+network={
+ scan_ssid=1
+ ssid=""   
+ psk=""
+}

--
Gitblit v1.9.1