2 # --- T2-COPYRIGHT-NOTE-BEGIN ---
3 # T2 SDE: package/*/rocknet/rocknet.sh
4 # Copyright (C) 2004 - 2024 The T2 SDE Project
6 # This Copyright note is generated by scripts/Create-CopyPatch,
7 # more information can be found in the files COPYING and README.
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License version 2.
11 # --- T2-COPYRIGHT-NOTE-END ---
14 rocknet_base
="/lib/network"
15 rocknet_config
="/etc/conf"
16 rocknet_tmp_base
="/var/run/rocknet"
18 [ -d $rocknet_tmp_base ] || mkdir
-p $rocknet_tmp_base
20 unset code_snipplets_idx code_snipplets_dat code_snipplets_counter
21 declare -a code_snipplets_idx
='()'
22 declare -a code_snipplets_dat
='()'
23 code_snipplets_counter
=0
29 if [ "$3" != "up" -a "$3" != "down" ]; then
30 echo "Usage: $0 { profile | default } { interface | auto } { up | down }"
34 if [ ! -f $rocknet_config/network
]; then
35 echo "Configuration file \"$rocknet_config/network\" missing."
43 pmatched
=0 # some profile matched ?
44 imatched
=0 # some interface matched ?
47 # addcode mode major-priority minor-priority code1
50 [ "$mode" != "$1" ] && return
51 [ "$ignore" -gt 0 ] && return
52 if [ "$1" = "up" ]; then udo
="+"; else udo
="-"; fi
53 code_snipplets_idx
[code_snipplets_counter
]="`
54 printf '%04d.%04d.%04d' $((5000$udo$2)) $((5000$udo$lineno)) \
55 $((5000$udo$3))` $code_snipplets_counter"
56 code_snipplets_dat
[code_snipplets_counter
]="$4"
57 ((code_snipplets_counter
++))
64 [ "$ignore" -gt 0 ] && return 0
66 eval "isfirst_$1='return 1'"
82 # register / unregister active interfaces for user input validation
86 echo -n "${1}," >> $rocknet_tmp_base/active-interfaces
90 active_interfaces
="`cat $rocknet_tmp_base/active-interfaces 2>/dev/null`"
91 active_interfaces
="${active_interfaces//${1},/}"
92 echo -n "$active_interfaces" > $rocknet_tmp_base/active-interfaces
95 for x
in $rocknet_base/*.sh
; do .
"$x"; done
98 while read cmd para
; do
100 if [ -n "$cmd" ]; then
102 para
="$(echo "$para" | sed 's,[\*\?],\\&,g')"
103 if declare -f public_
$cmd > /dev
/null
; then
104 # optimization: Only execute commands when they are
105 # inside an unignored interface section ...
106 if [ $cmd = "interface" ]; then
109 elif [ $ignore -eq 0 -o $global -gt 0 ]; then
113 error
"Unknown statement in config file: $cmd"
116 done < <(sed 's,\(^\|[ \t]\)#.*$,,' < $rocknet_config/network
)
118 while read id1 id2
; do
119 if [ "$rocknet_debug" = 1 ]; then
120 echo ">> $id1 -> $id2: ${code_snipplets_dat[id2]}"
122 eval "${code_snipplets_dat[id2]}"
124 for x
in "${code_snipplets_idx[@]}"; do echo "$x"
128 if [ "$pmatched" = 0 -a "$profile" != "default" ]; then
129 error
"Unknown profile: '$profile'"
132 if [ "$imatched" = 0 ]; then
133 error
"Unknown interface for profile: '$interface'"