Developing lightweight computation at the DSG edge

qmp_autoconf 2.55 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/sh /etc/rc.common
#    Copyright (C) 2011 Fundacio Privada per a la Xarxa Oberta, Lliure i Neutral guifi.net
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License along
#    with this program; if not, write to the Free Software Foundation, Inc.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
#    The full GNU General Public License is included in this distribution in
#    the file called "COPYING".

START=99
22
23
STOP=99
SERVICE_DAEMONIZE=1
24
25
26
27
CONTROL_FILE="/qmp_configured"
QMP_DIR="/etc/qmp"
QMP_KEY="/tmp/qmp_key"

28
29
30
31
32
33
log() {
	echo "$@" > /dev/console
	echo "$@"
	echo "$@" > /tmp/qmp_autoconf.log
}

34
configure() {
35
	log Starting qmp configuration...
36

37
38
39
40
	log Waiting 10 seconds to be sure all is configured
	sleep 10
	
	log [Configuring wireless]
41
42

	#Generating default wifi configuration
43
44
45
	country="$(uci get qmp.wireless.country 2>/dev/null)"
	country="${country:-00}"

46
	mv /etc/config/wireless /tmp/wireless.old
47
48
	wifi detect | sed s/"disabled 1"/"country $country"/g > /etc/config/wireless
	/etc/init.d/network reload
49

50
51
52
	#To be sure channel is set...
	iw reg set $country || iw reg set 00
	
53
54
55
56
57
	#Configuring wifi using QMP
	. $QMP_DIR/qmp_wireless.sh
	qmp_configure_wifi_initial
	qmp_configure_wifi

58
59
60
	#Reloading network to avoid problems with next functions
	/etc/init.d/network reload
	
61
62
63
64
65
66
	#Configuring networking
	echo "[Configuring networking]"
	. $QMP_DIR/qmp_functions.sh
	qmp_configure
	#echo "Update hostname for: '$QMP_HOSTNAME'"
	#echo "$QMP_HOSTNAME" > /proc/sys/kernel/hostname
67

68
	touch "$CONTROL_FILE"
69
	[ -f "$CONTROL_FILE" ] && reboot || log CRITICAL, cannot write file $CONTROL_FILE
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
}

#This function is executed in each boot
startup() {
	# Set HostName
	. $QMP_DIR/qmp_functions.sh
	qmp_set_hosts

	# Start/Stop netserver
	$QMP_DIR/qmp_control.sh apply_netserver

	# Generate current qmp key
	logread | md5sum | awk '{print $1}' > $QMP_KEY
}

start() {
	if [ ! -f "$CONTROL_FILE" ]; then
		configure
	else
89
		log QMP configured. Remove $CONTROL_FILE to force reconfiguration
90
	fi
91
92

	startup
93
94
95
}

stop() {
96
	log Nothing to do
97
98
99
100
101
102
}

restart() {
	stop
	start
}