1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 # T2 SDE: package/.../stone/stone_mod_network.sh
5 # Copyright (C) 2004 - 2008 The T2 SDE Project
6 # Copyright (C) 1998 - 2003 ROCK Linux Project
8 # More information can be found in the files COPYING and README.
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- T2-COPYRIGHT-NOTE-END ---
16 # [MAIN] 20 network Network Configuration
18 ### DYNAMIC NEW-STYLE CONFIG ###
20 export rocknet_base
="/lib/network" # export needed for subshells ...
21 export rocknet_config
="/etc/conf/network"
24 gui_edit
"Edit file $1" "$1"
37 [ "$1" = "" ] && readit
=1
38 while read netcmd para
40 if [ -n "$netcmd" ]; then
41 netcmd
="${netcmd//-/_}"
42 para
="$( echo "$para" | sed 's,[\*\?],\\&,g' )"
43 if [ "$netcmd" = "interface" ] ; then
44 prof
="$( echo "$para" | sed 's,[(),],_,g' )"
45 [ "$prof" = "$1" ] && readit
=1 || readit
=0
47 interfaces
="$interfaces $prof"
49 if [ $readit = 1 ] ; then
50 tags
[$i]="$netcmd $para"
54 done < <( sed 's,\(^\|[ \t]\)#.*$,,' < $rocknet_config )
58 for (( i
=0 ; $i < ${#tags[@]} ; i
=i
+1 )) ; do
59 local netcmd
="${tags[$i]}"
60 [ "$netcmd" ] ||
continue
61 [ $1 = 0 ] && [[ "$netcmd" != interface
* ]] && \
72 [ "$1" = "" ] && passit
=0
74 echo -n > $rocknet_config.new
76 while read netcmd para
; do
78 [ "$netcmd" ] ||
continue
79 netcmd
="${netcmd//-/_}"
80 para
="$( echo "$para" | sed 's,[\*\?],\\&,g' )"
82 # when we reached the matching section dump the
84 if [ $passit = 0 -a $dumped = 0 ] ; then
85 write_tags
$globals >> $rocknet_config.new
89 # if we reached a new interface section maybe change
91 if [ "$netcmd" = "interface" ] ; then
92 prof
="$( echo "$para" | sed 's,[(),],_,g' )"
93 [ "$prof" = "$1" ] && passit
=0 || passit
=1
95 # write out a separating newline
96 echo "" >> $rocknet_config.new
101 # just pass the line thru?
102 if [ $passit = 1 ] ; then
103 [ $globals = 0 -a "$netcmd" != "interface" ] && \
104 echo -en "\t" >> $rocknet_config.new
105 echo "$netcmd $para" >> $rocknet_config.new
107 done < <( cat $rocknet_config )
109 # if the config file was empty, for an not yet present or last
110 # we had no change to match the existing position - so write them
112 [ $globals = 0 ] && echo "" >> $rocknet_config.new
113 [ "$1" ] && globals
=0
114 [ $dumped = 0 ] && write_tags
$globals >> $rocknet_config.new
116 mv $rocknet_config{.new
,}
122 gui_input
"Set new value for tag '$name'" \
135 if [ "$tta" = "" ] ; then
136 cmd
="gui_menu add_tag 'Add tag of from module'"
138 while read module
; do
139 cmd
="$cmd "$module" module='$module'"
140 done < <( cd $rocknet_base/ ; grep public_
* |
sed -e \
141 's/\.sh//' -e 's/:.*//' |
sort -u )
145 cmd
="gui_menu add_tag 'Add tag of type'"
147 cmd
="$cmd "$tag" 'tta=$tag'"
148 done < <( cd $rocknet_base/ ; grep -h public_
$module.sh \
149 |
sed -e 's/public_\([^(]*\).*/\1/' |
sort )
170 cmd
="gui_menu if_edit 'Configure interface ${1//_/ }'"
171 for (( i
=0 ; $i < ${#tags[@]} ; i
=i
+1 )) ; do
172 [ "${tags[$i]}" ] ||
continue
173 cmd
="$cmd '${tags[$i]}' 'edit_tag $i'"
176 cmd
="$cmd '' '' 'Add new tag' 'add_tag'"
177 cmd
="$cmd 'Delete this interface/profile' 'del_interface $1 && quit=1'"
179 # tiny hack since gui_menu return 0 or 1 depending on the exec
180 # status of e.g. dialog - and thus a del_interface && false
183 eval "$cmd" || quit
=1
192 gui_input
"The new interface name (and profile)" \
195 tags
[0]="interface $if"
197 if gui_yesno
"Use DHCP to obtain the configuration?" ; then
200 add_tag
"ip 192.168.5.1/24"
201 add_tag
"gw 192.168.5.1"
202 add_tag
"nameserver 192.168.5.1"
213 ### STATIC OLD-STYLE CONFIG ###
216 old1
="$HOSTNAME" old2
="$HOSTNAME.$DOMAINNAME" old3
="$DOMAINNAME"
217 if [ $1 = HOSTNAME
] ; then
218 gui_input
"Set a new hostname (without domain part)" \
221 gui_input
"Set a new domainname (without host part)" \
224 new
="$HOSTNAME.$DOMAINNAME $HOSTNAME"
226 echo "$HOSTNAME" > /etc
/HOSTNAME
; hostname
"$HOSTNAME"
228 #ip="`echo $IPADDR | sed 's,[/ ].*,,'`"
229 #if grep -q "^$ip\\b" /etc/hosts ; then
231 # sed -e "/^$ip\\b/ s,\\b$old2\\b[ ]*,,g" \
232 # -e "/^$ip\\b/ s,\\b$old1\\b[ ]*,,g" \
233 # -e "/^$ip\\b/ s,[ ]\\+,&$new ," < /etc/hosts > $tmp
234 # cat $tmp > /etc/hosts ; rm -f $tmp
236 # echo -e "$ip\\t$new" >> /etc/hosts
239 if [ $1 = DOMAINNAME
] ; then
241 grep -vx "search $old3" /etc
/resolv.conf
> $tmp
242 [ -n "$DOMAINNAME" ] && echo "search $DOMAINNAME" >> $tmp
243 cat $tmp > /etc
/resolv.conf
249 gui_input
"Set a new (space seperated) list of DNS Servers" "$DNSSRV" "DNSSRV"
250 DNSSRV
="`echo $DNSSRV`" ; [ -z "$DNSSRV" ] && DNSSRV
="none"
252 tmp
="`mktemp`" ; grep -v '^nameserver\b' /etc
/resolv.conf
> $tmp
253 for x
in $DNSSRV ; do
254 [ "$x" != "none" ] && echo "nameserver $x" >> $tmp
256 cat $tmp > /etc
/resolv.conf
260 HOSTNAME
="`hostname`"
261 DOMAINNAME
="`hostname -d 2> /dev/null`"
264 grep '^nameserver ' /etc
/resolv.conf |
tr '\t' ' ' |
tr -s ' ' | \
265 sed 's,^nameserver *\([^ ]*\),DNSSRV="$DNSSRV \1",' > $tmp
266 DNSSRV
='' ; .
$tmp ; DNSSRV
="`echo $DNSSRV`"
267 [ -z "$DNSSRV" ] && DNSSRV
="none" ; rm -f $tmp
273 # read global section and interface list ...
276 p_interfaces
=$
(ip
-o link |
277 sed -n '/link\/ether/ s/[^:]*: \([^:]*\):.*/\1/p')
279 if [ $first_run = 1 ] ; then
281 # check if a section for the interface is already present
282 for x
in $p_interfaces ; do
283 if [[ $interfaces != *$x* ]] ; then
284 if gui_yesno
"Unconfigured interface $x detected. \
285 Do you want to create an interface section?" ; then
293 cmd
="gui_menu network 'Network Configuration - Select an item to
296 WARNING: This script tries to adapt /etc/conf/network and /etc/hosts
297 according to your changes. Changes only take affect the next time
298 rocknet is executed.'"
300 cmd
="$cmd 'Static hostname: $HOSTNAME' 'set_name HOSTNAME'"
301 cmd
="$cmd 'Static domainname: $DOMAINNAME' 'set_name DOMAINNAME'"
302 cmd
="$cmd 'Static DNS-Server: $DNSSRV' 'set_dns' '' ''"
304 for (( i
=0 ; $i < ${#tags[@]} ; i
=i
+1 )) ; do
305 cmd
="$cmd '${tags[$i]}' 'edit_global_tag $i'"
307 cmd
="$cmd 'Add new global tag' 'add_global_tag' '' ''"
309 for if in $interfaces ; do
310 cmd
="$cmd 'Edit interface ${if//_/ }' 'edit_if $if'"
313 cmd
="$cmd 'Add new interface/profile' 'add_interface' '' ''"
315 cmd
="$cmd 'Configure runlevels for network service'"
316 cmd
="$cmd '$STONE runlevel edit_srv network'"
317 cmd
="$cmd '(Re-)Start network init script'"
318 cmd
="$cmd '$STONE runlevel restart network'"
321 cmd
="$cmd 'View/Edit /etc/resolv.conf file' 'edit /etc/resolv.conf'"
322 cmd
="$cmd 'View/Edit /etc/hosts file' 'edit /etc/hosts'"
323 cmd
="$cmd 'View/Edit $rocknet_config file' 'edit $rocknet_config'"