[LEDE-DEV] [RFC 05/12] base-files: support hostname and ntp servers through board.d

Jo-Philipp Wich jo at mein.io
Tue May 31 07:24:51 PDT 2016


Add support for specifying hostname and NTP servers via /etc/board.d/ scripts.

Signed-off-by: Jo-Philipp Wich <jo at mein.io>

diff --git a/package/base-files/files/bin/config_generate b/package/base-files/files/bin/config_generate
index aaaac59..6fea2d8 100755
--- a/package/base-files/files/bin/config_generate
+++ b/package/base-files/files/bin/config_generate
@@ -220,6 +220,50 @@ generate_switch() {
 	json_select ..
 }
 
+
+generate_static_system() {
+	uci -q batch <<-EOF
+		delete system. at system[0]
+		add system system
+		set system. at system[-1].hostname='lede'
+		set system. at system[-1].timezone='UTC'
+		set system. at system[-1].ttylogin='0'
+
+		delete system.ntp
+		set system.ntp='timeserver'
+		set system.ntp.enabled='1'
+		set system.ntp.enable_server='0'
+		add_list system.ntp.server='0.openwrt.pool.ntp.org'
+		add_list system.ntp.server='1.openwrt.pool.ntp.org'
+		add_list system.ntp.server='2.openwrt.pool.ntp.org'
+		add_list system.ntp.server='3.openwrt.pool.ntp.org'
+	EOF
+
+	if json_is_a system object; then
+		json_select system
+			local hostname
+			if json_get_var hostname hostname; then
+				uci -q set "system. at system[-1].hostname=$hostname"
+			fi
+
+			if json_is_a ntpserver array; then
+				local keys key
+				json_get_keys keys ntpserver
+				json_select ntpserver
+					uci -q delete "system.ntp.server"
+
+					for key in $keys; do
+						local server
+						if json_get_var server "$key"; then
+							uci -q add_list "system.ntp.server=$server"
+						fi
+					done
+				json_select ..
+			fi
+		json_select ..
+	fi
+}
+
 generate_rssimon() {
 	local key="$1"
 	local cfg="rssid_$key"
@@ -375,6 +419,9 @@ for key in $keys; do generate_network $key; done
 json_get_keys keys switch
 for key in $keys; do generate_switch $key; done
 
+
+generate_static_system
+
 json_get_keys keys rssimon
 for key in $keys; do generate_rssimon $key; done
 
diff --git a/package/base-files/files/lib/functions/uci-defaults.sh b/package/base-files/files/lib/functions/uci-defaults.sh
index c51a6da..e688588 100755
--- a/package/base-files/files/lib/functions/uci-defaults.sh
+++ b/package/base-files/files/lib/functions/uci-defaults.sh
@@ -591,6 +591,26 @@ ucidef_add_button() {
 	json_select ..
 }
 
+ucidef_set_hostname() {
+	local hostname="$1"
+
+	json_select_object system
+		json_add_string hostname "$hostname"
+	json_select ..
+}
+
+ucidef_set_ntpserver() {
+	local server
+
+	json_select_object system
+		json_select_array ntpserver
+			for server in "$@"; do
+				json_add_string "" "$server"
+			done
+		json_select ..
+	json_select ..
+}
+
 board_config_update() {
 	json_init
 	[ -f ${CFG} ] && json_load "$(cat ${CFG})"
-- 
2.1.4




More information about the Lede-dev mailing list