Developing lightweight computation at the DSG edge

Commit 6a9c063f authored by Pau Escrich's avatar Pau Escrich
Browse files

Improve the autoconfiguration system

Make it compatible with OpenWRT BB
parent fd36f16c
...@@ -32,9 +32,8 @@ QMP_KEY="/tmp/qmp_key" ...@@ -32,9 +32,8 @@ QMP_KEY="/tmp/qmp_key"
QMP_LOG="/root/qmp_autoconf.log" QMP_LOG="/root/qmp_autoconf.log"
log() { log() {
echo "$@" > /dev/console echo -e "$@" > /dev/console
echo "$@" echo -e "$@"
echo "$@" >> $QMP_LOG
} }
exechooks() { exechooks() {
...@@ -43,70 +42,65 @@ exechooks() { ...@@ -43,70 +42,65 @@ exechooks() {
qmp_hooks_exec $stage qmp_hooks_exec $stage
} }
stop_services() {
/etc/init.d/dnsmasq stop
/etc/init.d/gwck stop
/etc/init.d/bmx6 stop
/etc/init.d/radvd stop
/etc/init.d/uhttpd stop
}
prepare_wifi() { prepare_wifi() {
finish=0
i=0 i=0
while [ $finish -eq 0 ]; do radios=$(uci show wireless | grep wireless\.radio.*wifi-device -c)
while [ $i -lt $radios ]; do
uci set wireless.radio${i}.disabled="0" 2>/dev/null uci set wireless.radio${i}.disabled="0" 2>/dev/null
uci set wireless.radio${i}.country="$country" 2>/dev/null uci set wireless.radio${i}.country="$country" 2>/dev/null
finish=$?
i=$(($i+1)) i=$(($i+1))
done done
uci commit wireless
uci commit wireless
wifi up wifi up
sleep 10
log WiFi devices: log WiFi devices:
log -------------------------------------------------- log --------------------------------------------------
log $(iwinfo | egrep "ESSID|Mode|Type") log $(iwinfo)
log -------------------------------------------------- log --------------------------------------------------
#To be sure channel is set...
iw reg set $country || iw reg set 00
} }
configure() { configure() {
stop_services
log Redirecting stderr to $QMP_LOG log Redirecting stderr to $QMP_LOG
exec 2>>$QMP_LOG exec 2>>$QMP_LOG 1>&2
log Starting qmp configuration... log Starting qmp configuration...
log Waiting 30 seconds to be sure all is configured log Waiting 10 seconds to be sure all is configured
sleep 30 sleep 10
# Execute birth hooks if it is the first boot of the device # Execute birth hooks if it is the first boot of the device
[ ! -e "$BIRTH_FILE" ] && exechooks birth && touch "$BIRTH_FILE" [ ! -e "$BIRTH_FILE" ] && exechooks birth && touch "$BIRTH_FILE"
# Execute firstboot hooks # Generating default wifi configuration
log "[Executing hooks]"
exechooks firstboot
#Generating default wifi configuration
log "[Configuring wifi]" log "[Configuring wifi]"
country="$(uci get qmp.wireless.country 2>/dev/null)" country="$(uci get qmp.wireless.country 2>/dev/null)"
country="${country:-00}" country="${country:-00}"
log Using countrycode $country log Using countrycode $country
#Configuring wifi using QMP
prepare_wifi prepare_wifi
. $QMP_DIR/qmp_wireless.sh . $QMP_DIR/qmp_wireless.sh
. $QMP_DIR/qmp_functions.sh
log "[Configuring initial system]"
qmp_configure_wifi_initial qmp_configure_wifi_initial
qmp_configure_wifi qmp_configure_wifi
#Reloading network to avoid problems with next functions
log Reloading network log Reloading network
/etc/init.d/network reload /etc/init.d/network reload
if /etc/init.d/gwck enabled sleep 1
then # Configuring networking and everything else
/etc/init.d/gwck restart log "[Configuring full system]"
fi
#Configuring networking
log "[Configuring networking]"
. $QMP_DIR/qmp_functions.sh
qmp_configure_initial qmp_configure_initial
qmp_configure qmp_configure
log Rebooting log Rebooting
touch "$CONTROL_FILE" touch "$CONTROL_FILE"
[ -f "$CONTROL_FILE" ] && reboot || log CRITICAL, cannot write file $CONTROL_FILE [ -f "$CONTROL_FILE" ] && reboot || log CRITICAL, cannot write file $CONTROL_FILE
} }
......
...@@ -267,11 +267,11 @@ qmp_configure_smart_network() { ...@@ -267,11 +267,11 @@ qmp_configure_smart_network() {
} && continue } && continue
# if there is already LAN device and it is not wifi, use as WAN # if there is already LAN device and it is not wifi, use as WAN
[ -z "$wan" ] && wan="$dev" && continue [ -z "$wan" ] && wan="$dev" || {
# else use as LAN and MESH # else use as LAN and MESH
lan="$dev $lan" lan="$dev $lan"
mesh="$dev $mesh" mesh="$dev $mesh"
}
done done
echo "Network devices found:" echo "Network devices found:"
......
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