Root/ibrdtnd/files/build-config.sh

1#!/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.timezone" "timezone"
40add_param $CONFFILE "ibrdtn.main.routing" "routing"
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.statistic.type" "statistic_type"
70add_param $CONFFILE "ibrdtn.statistic.interval" "statistic_interval"
71add_param $CONFFILE "ibrdtn.statistic.file" "statistic_file"
72add_param $CONFFILE "ibrdtn.statistic.address" "statistic_address"
73add_param $CONFFILE "ibrdtn.statistic.port" "statistic_port"
74
75add_param $CONFFILE "ibrdtn.discovery.address" "discovery_address"
76add_param $CONFFILE "ibrdtn.discovery.timeout" "discovery_timeout"
77
78add_param $CONFFILE "ibrdtn.security.level" "security_level"
79add_param $CONFFILE "ibrdtn.security.bab_key" "security_bab_default_key"
80add_param $CONFFILE "ibrdtn.security.key_path" "security_path"
81
82
83# iterate through all network interfaces
84iter=0
85netinterfaces=
86while [ 1 == 1 ]; do
87    $UCI -q get "ibrdtn.@network[$iter]" > /dev/null
88    if [ $? == 0 ]; then
89        netinterfaces="${netinterfaces} lan${iter}"
90        add_param $CONFFILE "ibrdtn.@network[$iter].type" "net_lan${iter}_type"
91        add_param $CONFFILE "ibrdtn.@network[$iter].interface" "net_lan${iter}_interface"
92        add_param $CONFFILE "ibrdtn.@network[$iter].port" "net_lan${iter}_port"
93        add_param $CONFFILE "ibrdtn.@network[$iter].discovery" "net_lan${iter}_discovery"
94    else
95        break
96    fi
97    
98    let iter=iter+1
99done
100
101# write list of network interfaces
102echo "net_interfaces =$netinterfaces" >> $CONFFILE
103
104# iterate through all static routes
105iter=0
106while [ 1 == 1 ]; do
107    $UCI -q get "ibrdtn.@static-route[$iter]" > /dev/null
108    if [ $? == 0 ]; then
109        PATTERN=`$UCI -q get "ibrdtn.@static-route[$iter].pattern"`
110        DESTINATION=`$UCI -q get "ibrdtn.@static-route[$iter].destination"`
111        let NUMBER=iter+1
112        echo "route$NUMBER = $PATTERN $DESTINATION" >> $CONFFILE
113    else
114        break
115    fi
116    
117    let iter=iter+1
118done
119
120#iterate through all static connections
121iter=0
122while [ 1 == 1 ]; do
123    $UCI -q get "ibrdtn.@static-connection[$iter]" > /dev/null
124    if [ $? == 0 ]; then
125        let NUMBER=iter+1
126        add_param $CONFFILE "ibrdtn.@static-connection[$iter].uri" "static${NUMBER}_uri"
127        add_param $CONFFILE "ibrdtn.@static-connection[$iter].address" "static${NUMBER}_address"
128        add_param $CONFFILE "ibrdtn.@static-connection[$iter].port" "static${NUMBER}_port"
129        add_param $CONFFILE "ibrdtn.@static-connection[$iter].protocol" "static${NUMBER}_proto"
130        add_param $CONFFILE "ibrdtn.@static-connection[$iter].immediately" "static${NUMBER}_immediately"
131    else
132        break
133    fi
134    
135    let iter=iter+1
136done
137

Archive Download this file



interactive