1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: package/*/rocknet/stone_mod_network.sh
3 # Copyright (C) 2004 - 2024 The T2 SDE Project
4 # Copyright (C) 1998 - 2003 ROCK Linux 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 ---
13 # [MAIN] 20 network Network Configuration
16 ### DYNAMIC NEW-STYLE CONFIG ###
18 export rocknet_base
="/lib/network" # export needed for subshells ...
19 export rocknet_config
="/etc/conf/network"
22 gui_edit
"Edit file $1" "$1"
35 [ "$1" = "" ] && readit
=1
36 while read netcmd para
38 if [ -n "$netcmd" ]; then
39 netcmd
="${netcmd//-/_}"
40 para
="$( echo "$para" | sed 's,[\*\?],\\&,g' )"
41 if [ "$netcmd" = "interface" ]; then
42 prof
="$( echo "$para" | sed 's,[(),],_,g' )"
43 [ "$prof" = "$1" ] && readit
=1 || readit
=0
45 interfaces
="$interfaces $prof"
47 if [ $readit = 1 ]; then
48 tags
[$i]="$netcmd $para"
52 done < <( sed 's,\(^\|[ \t]\)#.*$,,' < $rocknet_config )
56 for (( i
=0 ; $i < ${#tags[@]} ; i
=i
+1 )) ; do
57 local netcmd
="${tags[$i]}"
58 [ "$netcmd" ] ||
continue
59 [ $1 = 0 ] && [[ "$netcmd" != interface
* ]] && \
70 [ "$1" = "" ] && passit
=0
72 echo -n > $rocknet_config.new
74 while read netcmd para
; do
75 [ "$netcmd" ] ||
continue
76 netcmd
="${netcmd//-/_}"
77 para
="$( echo "$para" | sed 's,[\*\?],\\&,g' )"
79 # when we reached the matching section dump the
81 if [ $passit = 0 -a $dumped = 0 ]; then
82 write_tags
$globals >> $rocknet_config.new
86 # if we reached a new interface section maybe change
88 if [ "$netcmd" = "interface" ]; then
89 prof
="$( echo "$para" | sed 's,[(),],_,g' )"
90 [ "$prof" = "$1" ] && passit
=0 || passit
=1
92 # write out a separating newline
93 echo "" >> $rocknet_config.new
98 # just pass the line thru?
99 if [ $passit = 1 ]; then
100 [ $globals = 0 -a "$netcmd" != "interface" ] && \
101 echo -en "\t" >> $rocknet_config.new
102 echo "$netcmd $para" >> $rocknet_config.new
104 done < <( cat $rocknet_config )
106 # if the config file was empty, for an not yet present or last
107 # we had no change to match the existing position - so write them
109 [ $globals = 0 ] && echo "" >> $rocknet_config.new
110 [ "$1" ] && globals
=0
111 [ $dumped = 0 ] && write_tags
$globals >> $rocknet_config.new
113 mv $rocknet_config{.new
,}
119 gui_input
"Set new value for tag '$name'" \
132 if [ "$tta" = "" ]; then
133 cmd
="gui_menu add_tag 'Add tag of from module'"
135 while read module
; do
136 cmd
="$cmd "$module" module='$module'"
137 done < <( cd $rocknet_base/ ; grep public_
* |
sed -e \
138 's/\.sh//' -e 's/:.*//' |
sort -u )
142 cmd
="gui_menu add_tag 'Add tag of type'"
144 cmd
="$cmd "$tag" 'tta=$tag'"
145 done < <( cd $rocknet_base/ ; grep -h public_
$module.sh \
146 |
sed -e 's/public_\([^(]*\).*/\1/' |
sort )
167 cmd
="gui_menu if_edit 'Configure interface ${1//_/ }'"
168 for (( i
=0 ; $i < ${#tags[@]} ; i
=i
+1 )) ; do
169 [ "${tags[$i]}" ] ||
continue
170 cmd
="$cmd '${tags[$i]}' 'edit_tag $i'"
173 cmd
="$cmd '' '' 'Add new tag' 'add_tag'"
174 cmd
="$cmd 'Delete this interface/profile' 'del_interface $1 && quit=1'"
176 # tiny hack since gui_menu return 0 or 1 depending on the exec
177 # status of e.g. dialog - and thus a del_interface && false
180 eval "$cmd" || quit
=1
189 gui_input
"The new interface name (and profile)" \
192 tags
[0]="interface $if"
194 if gui_yesno
"Use DHCP to obtain the configuration?"; then
197 add_tag
"ip 192.168.5.1/24"
198 add_tag
"gw 192.168.5.1"
199 add_tag
"nameserver 192.168.5.1"
210 ### STATIC OLD-STYLE CONFIG ###
213 old1
="$HOSTNAME" old2
="$HOSTNAME.$DOMAINNAME" old3
="$DOMAINNAME"
214 if [ $1 = HOSTNAME
]; then
215 gui_input
"Set a new hostname (without domain part)" \
218 gui_input
"Set a new domainname (without host part)" \
221 new
="$HOSTNAME.$DOMAINNAME $HOSTNAME"
223 echo "$HOSTNAME" > /etc
/hostname
; hostname
"$HOSTNAME"
225 #ip="`echo $IPADDR | sed 's,[/ ].*,,'`"
226 #if grep -q "^$ip\\b" /etc/hosts; then
228 # sed -e "/^$ip\\b/ s,\\b$old2\\b[ ]*,,g" \
229 # -e "/^$ip\\b/ s,\\b$old1\\b[ ]*,,g" \
230 # -e "/^$ip\\b/ s,[ ]\\+,&$new ," < /etc/hosts > $tmp
231 # cat $tmp > /etc/hosts ; rm -f $tmp
233 # echo -e "$ip\\t$new" >> /etc/hosts
236 if [ $1 = DOMAINNAME
]; then
238 grep -vx "search $old3" /etc
/resolv.conf
> $tmp
239 [ -n "$DOMAINNAME" ] && echo "search $DOMAINNAME" >> $tmp
240 cat $tmp > /etc
/resolv.conf
246 gui_input
"Set a new (space seperated) list of DNS Servers" "$DNSSRV" "DNSSRV"
247 DNSSRV
="`echo $DNSSRV`" ; [ -z "$DNSSRV" ] && DNSSRV
="none"
249 tmp
="`mktemp`" ; grep -v '^nameserver\b' /etc
/resolv.conf
> $tmp
250 for x
in $DNSSRV ; do
251 [ "$x" != "none" ] && echo "nameserver $x" >> $tmp
253 cat $tmp > /etc
/resolv.conf
257 HOSTNAME
="`hostname`"
258 DOMAINNAME
="`hostname -d 2> /dev/null`"
261 grep '^nameserver ' /etc
/resolv.conf |
tr '\t' ' ' |
tr -s ' ' | \
262 sed 's,^nameserver *\([^ ]*\),DNSSRV="$DNSSRV \1",' > $tmp
263 DNSSRV
='' ; .
$tmp ; DNSSRV
="`echo $DNSSRV`"
264 [ -z "$DNSSRV" ] && DNSSRV
="none" ; rm -f $tmp
270 # read global section and interface list ...
273 p_interfaces
=$
(ip
-o link |
274 sed -n '/link\/ether/ s/[^:]*: \([^:]*\):.*/\1/p')
276 if [ $first_run = 1 ]; then
278 # check if a section for the interface is already present
279 for x
in $p_interfaces ; do
280 if [[ $interfaces != *$x* ]]; then
281 if gui_yesno
"Unconfigured interface $x detected. \
282 Do you want to create an interface section?"; then
290 cmd
="gui_menu network 'Network Configuration - Select an item to
293 WARNING: This script tries to adapt /etc/conf/network and /etc/hosts
294 according to your changes. Changes only take affect the next time
295 rocknet is executed.'"
297 cmd
="$cmd 'Static hostname: $HOSTNAME' 'set_name HOSTNAME'"
298 cmd
="$cmd 'Static domainname: $DOMAINNAME' 'set_name DOMAINNAME'"
299 cmd
="$cmd 'Static DNS-Server: $DNSSRV' 'set_dns' '' ''"
301 for (( i
=0 ; $i < ${#tags[@]} ; i
=i
+1 )); do
302 cmd
="$cmd '${tags[$i]}' 'edit_global_tag $i'"
304 cmd
="$cmd 'Add new global tag' 'add_global_tag' '' ''"
306 for if in $interfaces; do
307 cmd
="$cmd 'Edit interface ${if//_/ }' 'edit_if $if'"
310 cmd
="$cmd 'Add new interface/profile' 'add_interface' '' ''"
312 cmd
="$cmd 'Configure runlevels for network service'"
313 cmd
="$cmd '$STONE runlevel edit_srv network'"
314 cmd
="$cmd '(Re-)Start network init script'"
315 cmd
="$cmd '$STONE runlevel restart network'"
318 cmd
="$cmd 'View/Edit /etc/resolv.conf file' 'edit /etc/resolv.conf'"
319 cmd
="$cmd 'View/Edit /etc/hosts file' 'edit /etc/hosts'"
320 cmd
="$cmd 'View/Edit $rocknet_config file' 'edit $rocknet_config'"