[LEDE-DEV] [PATCH 1/2] base-files: also generate configs when current is empty (FS#193)

Koen Vandeputte koen.vandeputte at ncentric.com
Fri Sep 30 00:48:22 PDT 2016


If a config does not exist, an empty file is created to store the newly
generated one.

- If a powercut happens during generation, it is not stored
- UCI commit does NOT store the generated configs to file on 1st clean
boot

If such a case happens, an empty file exists and it is never
regenerated again, causing some daemons to fail starting
(NTPD, logread, ..)

Fix this by also generating new configs if the current one is empty.
Also fixes this print during boot: "Failed to connect to ubus"

Signed-off-by: Koen Vandeputte <koen.vandeputte at ncentric.com>
---
 package/base-files/files/bin/board_detect    | 4 ++--
 package/base-files/files/bin/config_generate | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/package/base-files/files/bin/board_detect b/package/base-files/files/bin/board_detect
index f9640f0..441db6a 100755
--- a/package/base-files/files/bin/board_detect
+++ b/package/base-files/files/bin/board_detect
@@ -4,11 +4,11 @@ CFG=$1
 
 [ -n "$CFG" ] || CFG=/etc/board.json
 
-[ -d "/etc/board.d/" -a ! -f "$CFG" ] && {
+[ -d "/etc/board.d/" -a ! -s "$CFG" ] && {
 	for a in `ls /etc/board.d/*`; do
 		[ -x $a ] || continue;
 		$(. $a)
 	done
 }
 
-[ -f "$CFG" ] || return 1
+[ -s "$CFG" ] || return 1
diff --git a/package/base-files/files/bin/config_generate b/package/base-files/files/bin/config_generate
index 80ed61b..80e5c9f 100755
--- a/package/base-files/files/bin/config_generate
+++ b/package/base-files/files/bin/config_generate
@@ -4,8 +4,8 @@ CFG=/etc/board.json
 
 . /usr/share/libubox/jshn.sh
 
-[ -f $CFG ] || /bin/board_detect || exit 1
-[ -f /etc/config/network -a -f /etc/config/system ] && exit 0
+[ -s $CFG ] || /bin/board_detect || exit 1
+[ -s /etc/config/network -a -s /etc/config/system ] && exit 0
 
 generate_static_network() {
 	uci -q batch <<-EOF
@@ -401,7 +401,7 @@ generate_gpioswitch() {
 json_init
 json_load "$(cat ${CFG})"
 
-if [ ! -f /etc/config/network ]; then
+if [ ! -s /etc/config/network ]; then
 	touch /etc/config/network
 	generate_static_network
 
@@ -412,7 +412,7 @@ if [ ! -f /etc/config/network ]; then
 	for key in $keys; do generate_switch $key; done
 fi
 
-if [ ! -f /etc/config/system ]; then
+if [ ! -s /etc/config/system ]; then
 	touch /etc/config/system
 	generate_static_system
 
-- 
2.7.4




More information about the Lede-dev mailing list