Developing lightweight computation at the DSG edge

Commit a7fd93cd authored by p4u's avatar p4u
Browse files

qmp_autoconf:

	Added LOG to /root/ (preserve after reboot)
    Extend debug output
    Add function to execute hooks (firstboot, anyboot and birth)
    Add preapre_wifi function with rmmod ath9k to solve the first-boot wifi devices detection problem
parent fe92d230
......@@ -22,48 +22,73 @@ START=99
STOP=99
SERVICE_DAEMONIZE=1
CONTROL_FILE="/qmp_configured"
BIRTH_FILE="/etc/qmp/.birth"
QMP_DIR="/etc/qmp"
QMP_KEY="/tmp/qmp_key"
QMP_LOG="/root/qmp_autoconf.log"
log() {
echo "$@" > /dev/console
echo "$@"
echo "$@" > /tmp/qmp_autoconf.log
echo "$@" >> $QMP_LOG
}
boothooks() {
exechooks() {
local stage="$1"
stage=${stage:-anyboot}
local device="$(cat /tmp/sysinfo/board_name)"
local hooksdir="/etc/qmp/hooks/$device"
[ -d "$hooksdir" ] && {
[ -n "$device" ] && [ -d "$hooksdir" ] && {
for h in $hooksdir/*; do
echo "Executing hook: $h"
sh $h boot
sh $h $stage
done
}
}
configure() {
log Redirecting stderr to $QMP_LOG
exec 2>>$QMP_LOG
log Starting qmp configuration...
log Waiting 10 seconds to be sure all is configured
sleep 10
log [Configuring wireless]
# Execute birth hooks if it is the first boot of the device
[ ! -e "$BIRTH_FILE" ] && exechooks birth
#Execute hooks
boothooks
# Execute firstboot hooks
log "[Executing hooks]"
exechooks firstboot
#Generating default wifi configuration
log "[Configuring wifi]"
country="$(uci get qmp.wireless.country 2>/dev/null)"
country="${country:-00}"
log Using countrycode $country
mv /etc/config/wireless /tmp/wireless.old
# Wifi is complicated...
rmmod ath9k
insmod ath9k
sleep 1
# It is a quick hack, because each time ath9k is loaded the phyX counter increases
# and openwrt wifi scripts take it for selectin the wlan name (i.e wlan3)
iw phy | grep Wiphy | awk '{print $2}' | while read d
do
iw phy $d set name qmp0
done
wifi detect | sed s/"disabled 1"/"country $country"/g > /etc/config/wireless
wifi down
wifi up
log WiFi devices:
log --------------------------------------------------
log $(iwinfo | egrep "ESSID|Mode|Type")
log --------------------------------------------------
#To be sure channel is set...
iw reg set $country || iw reg set 00
......@@ -73,26 +98,31 @@ configure() {
qmp_configure_wifi
#Reloading network to avoid problems with next functions
log Reloading network
/etc/init.d/network reload
#Configuring networking
echo "[Configuring networking]"
log "[Configuring networking]"
. $QMP_DIR/qmp_functions.sh
qmp_configure_initial
qmp_configure
#echo "Update hostname for: '$QMP_HOSTNAME'"
#echo "$QMP_HOSTNAME" > /proc/sys/kernel/hostname
log ==================================================
log Rebooting
log ==================================================
touch "$CONTROL_FILE"
[ -f "$CONTROL_FILE" ] && reboot || log CRITICAL, cannot write file $CONTROL_FILE
[ -e "$CONTROL_FILE" ] && reboot || log CRITICAL, cannot write file $CONTROL_FILE
}
#This function is executed in each boot
# This function is executed in each boot
startup() {
# Set HostName
. $QMP_DIR/qmp_functions.sh
qmp_set_hosts
# Run hooks
exechooks anyboot
# Start/Stop netserver
$QMP_DIR/qmp_control.sh apply_netserver
......@@ -101,7 +131,7 @@ startup() {
}
start() {
if [ ! -f "$CONTROL_FILE" ]; then
if [ ! -e "$CONTROL_FILE" ]; then
configure
else
log QMP configured. Remove $CONTROL_FILE to force reconfiguration
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment