blob: c9a6128cd1eba50ecbc041cacb44a3702e102797 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#!/bin/sh
2#
3# convert uci configuration into daemon specific format
4#
5
6UCI=/sbin/uci
7
8create_file() {
9 echo "# -- DO NOT EDIT THIS FILE --" > $1
10 echo "# automatic generated configuration file for IBR-DTN daemon" >> $1
11 echo "#" >> $1
12}
13
14add_param() {
15 VALUE=`$UCI -q get $2`
16
17 if [ $? == 0 ]; then
18 echo "$3 = $VALUE" >> $1
19 fi
20}
21
22getconfig() {
23 $UCI -q get ibrdtn.$1
24 return $?
25}
26
27if [ "$1" == "--safe-mode" ]; then
28 SAFEMODE=yes
29 CONFFILE=$2
30else
31 SAFEMODE=no
32 CONFFILE=$1
33fi
34
35# create the file and write some header info
36create_file $CONFFILE
37
38add_param $CONFFILE "ibrdtn.main.uri" "local_uri"
39add_param $CONFFILE "ibrdtn.main.routing" "routing"
40add_param $CONFFILE "ibrdtn.main.fragmentation" "fragmentation"
41
42if [ "$SAFEMODE" == "yes" ]; then
43 if [ -n "`getconfig safemode.forwarding`" ]; then
44 add_param $CONFFILE "ibrdtn.safemode.forwarding" "routing_forwarding"
45 else
46 add_param $CONFFILE "ibrdtn.main.forwarding" "routing_forwarding"
47 fi
48
49 if [ -n "`getconfig safemode.maxblock`" ]; then
50 add_param $CONFFILE "ibrdtn.safemode.maxblock" "limit_blocksize"
51 else
52 add_param $CONFFILE "ibrdtn.main.blocksize" "limit_blocksize"
53 fi
54
55 if [ -n "`getconfig safemode.storage`" ]; then
56 add_param $CONFFILE "ibrdtn.safemode.storage" "limit_storage"
57 else
58 add_param $CONFFILE "ibrdtn.storage.limit" "limit_storage"
59 fi
60else
61 add_param $CONFFILE "ibrdtn.main.forwarding" "routing_forwarding"
62 add_param $CONFFILE "ibrdtn.main.blocksize" "limit_blocksize"
63 add_param $CONFFILE "ibrdtn.storage.limit" "limit_storage"
64 add_param $CONFFILE "ibrdtn.storage.blobs" "blob_path"
65 add_param $CONFFILE "ibrdtn.storage.bundles" "storage_path"
66 add_param $CONFFILE "ibrdtn.storage.engine" "storage"
67fi
68
69add_param $CONFFILE "ibrdtn.main.max_predated_timestamp" "limit_predated_timestamp"
70add_param $CONFFILE "ibrdtn.main.limit_lifetime" "limit_lifetime"
71add_param $CONFFILE "ibrdtn.main.foreign_blocksize" "limit_foreign_blocksize"
72
73add_param $CONFFILE "ibrdtn.discovery.address" "discovery_address"
74add_param $CONFFILE "ibrdtn.discovery.timeout" "discovery_timeout"
75add_param $CONFFILE "ibrdtn.discovery.version" "discovery_version"
76add_param $CONFFILE "ibrdtn.discovery.crosslayer" "discovery_crosslayer"
77
78add_param $CONFFILE "ibrdtn.tcptuning.idle_timeout" "tcp_idle_timeout"
79add_param $CONFFILE "ibrdtn.tcptuning.nodelay" "tcp_nodelay"
80add_param $CONFFILE "ibrdtn.tcptuning.chunksize" "tcp_chunksize"
81
82add_param $CONFFILE "ibrdtn.security.level" "security_level"
83add_param $CONFFILE "ibrdtn.security.bab_key" "security_bab_default_key"
84add_param $CONFFILE "ibrdtn.security.key_path" "security_path"
85add_param $CONFFILE "ibrdtn.security.generate_dh" "generate_dh_params"
86
87add_param $CONFFILE "ibrdtn.tls.certificate" "security_certificate"
88add_param $CONFFILE "ibrdtn.tls.key" "security_key"
89add_param $CONFFILE "ibrdtn.tls.trustedpath" "security_trusted_ca_path"
90add_param $CONFFILE "ibrdtn.tls.required" "security_tls_required"
91add_param $CONFFILE "ibrdtn.tls.noencryption" "security_tls_disable_encryption"
92add_param $CONFFILE "ibrdtn.tls.fallback_badclock" "security_tls_fallback_badclock"
93
94add_param $CONFFILE "ibrdtn.timesync.reference" "time_reference"
95add_param $CONFFILE "ibrdtn.timesync.synchronize" "time_synchronize"
96add_param $CONFFILE "ibrdtn.timesync.discovery_announcement" "time_discovery_announcements"
97add_param $CONFFILE "ibrdtn.timesync.sigma" "time_sigma"
98add_param $CONFFILE "ibrdtn.timesync.psi" "time_psi"
99add_param $CONFFILE "ibrdtn.timesync.sync_level" "time_sync_level"
100add_param $CONFFILE "ibrdtn.timesync.time_set_clock" "time_set_clock"
101
102add_param $CONFFILE "ibrdtn.dht.enabled" "dht_enabled"
103add_param $CONFFILE "ibrdtn.dht.port" "dht_port"
104add_param $CONFFILE "ibrdtn.dht.id" "dht_id"
105add_param $CONFFILE "ibrdtn.dht.bootstrap" "dht_bootstrapping"
106add_param $CONFFILE "ibrdtn.dht.nodesfile" "dht_nodes_file"
107add_param $CONFFILE "ibrdtn.dht.enable_ipv4" "dht_enable_ipv4"
108add_param $CONFFILE "ibrdtn.dht.enable_ipv6" "dht_enable_ipv6"
109add_param $CONFFILE "ibrdtn.dht.bind_ipv4" "dht_bind_ipv4"
110add_param $CONFFILE "ibrdtn.dht.bind_ipv6" "dht_bind_ipv6"
111add_param $CONFFILE "ibrdtn.dht.ignore_neighbour_informations" "dht_ignore_neighbour_informations"
112add_param $CONFFILE "ibrdtn.dht.allow_neighbours_to_announce_me" "dht_allow_neighbours_to_announce_me"
113add_param $CONFFILE "ibrdtn.dht.allow_neighbour_announcement" "dht_allow_neighbour_announcement"
114
115
116# iterate through all network interfaces
117iter=0
118netinterfaces=
119netinternet=
120while [ 1 == 1 ]; do
121 $UCI -q get "ibrdtn.@network[$iter]" > /dev/null
122 if [ $? == 0 ]; then
123 netinterfaces="${netinterfaces} lan${iter}"
124 add_param $CONFFILE "ibrdtn.@network[$iter].type" "net_lan${iter}_type"
125 add_param $CONFFILE "ibrdtn.@network[$iter].interface" "net_lan${iter}_interface"
126 add_param $CONFFILE "ibrdtn.@network[$iter].port" "net_lan${iter}_port"
127 if [ "$(uci -q get ibrdtn.@network[$iter].global)" == "yes" ]; then
128 netinternet="${netinternet} $(uci -q get ibrdtn.@network[$iter].interface)"
129 fi
130 else
131 break
132 fi
133
134 let iter=iter+1
135done
136
137# write list of network interfaces
138echo "net_interfaces =$netinterfaces" >> $CONFFILE
139echo "net_internet =${netinternet}" >> $CONFFILE
140
141# iterate through all static routes
142iter=0
143while [ 1 == 1 ]; do
144 $UCI -q get "ibrdtn.@static-route[$iter]" > /dev/null
145 if [ $? == 0 ]; then
146 PATTERN=`$UCI -q get "ibrdtn.@static-route[$iter].pattern"`
147 DESTINATION=`$UCI -q get "ibrdtn.@static-route[$iter].destination"`
148 let NUMBER=iter+1
149 echo "route$NUMBER = $PATTERN $DESTINATION" >> $CONFFILE
150 else
151 break
152 fi
153
154 let iter=iter+1
155done
156
157#iterate through all static connections
158iter=0
159while [ 1 == 1 ]; do
160 $UCI -q get "ibrdtn.@static-connection[$iter]" > /dev/null
161 if [ $? == 0 ]; then
162 let NUMBER=iter+1
163 add_param $CONFFILE "ibrdtn.@static-connection[$iter].uri" "static${NUMBER}_uri"
164 add_param $CONFFILE "ibrdtn.@static-connection[$iter].address" "static${NUMBER}_address"
165 add_param $CONFFILE "ibrdtn.@static-connection[$iter].port" "static${NUMBER}_port"
166 add_param $CONFFILE "ibrdtn.@static-connection[$iter].protocol" "static${NUMBER}_proto"
167 add_param $CONFFILE "ibrdtn.@static-connection[$iter].immediately" "static${NUMBER}_immediately"
168 else
169 break
170 fi
171
172 let iter=iter+1
173done