[NCLUG] RH networking scripts

S. Luke Jones luke at frii.com
Mon Oct 29 22:02:21 MST 2001


Mike Loseke wrote:
> Thus spake S. Luke Jones:
> > ... I've come to the conclusion that they're
> > beyond redemption. ...
> 
>  I'm curious as to what issues you're having that would cause you to need
> to replace the scripts provided. True, RedHat has probably over-engineered
> some of their scripts but they work pretty good. They took the SysV init
> method and kind of perverted it, but with current releases they are falling
> more inline with the mainstream (i.e. Solaris). They even have /etc/init.d
> linked to /etc/rc.d/init.d now.

Well, this isn't the time or place to attack the SysV init mechanism.
I dislike the directories-full-of-symlinks ... but I like having a
single script /etc/rc.d/init.d/foo that I can use to start/stop/restart
or get the current status of the "foo" service, without being an
expert user of "foo".

My posting was designed to find out what others do with the RH scripts.
Apparently, people keep them.  By this I meant the stuff in
/etc/sysconfig/network-scripts, not the related stuff in /etc/rc.d/*.

Well. To each his own.

I have an axe to grind: I just took a virgin 10/2001 KRUD machine and
spent several hours trying to set up ppp to connect to frii.  Old-timers
on this list know I'm networking-challenged, and that ppp (and my
personal nemesis, sendmail) have been, uh, topics of my rants in the
past. But in this case I had a working system to start with, and
wvdial is incontestably better (i.e. more idiot-proof) than chat.

The general idea is sound: set a bunch of variables that govern the
behavior of a chunk of code. As a software developer, I approve.

However, the variables don't appear to be documented. What is the
point of having a variable-driven script if you don't document
what the variables are? I can egrep on '[A-Z]+' and get some idea
of what they are, but why not just tell me?

(I am, as I mentioned in that posting, unhappy with how many of
RH's value-add components are undocumented. For example, there's
no man page for netconfig, but that's okay: netconfig is an
undocumented bare-bones ascii tool not to be confused with the
(documented) network configurator.  As another example, the man
page for usernetctl says it wraps ifup and ifdown, which have no
man pages. What a shame: so much effort went into making ifup-eth0
and ifup-ipx and the other ifup-* scripts work alike (it would
appear) only to fail because of the trivial effort required to
document the command line syntax.)

Another reason I asked the "prosumer" RH-admins what they did
was because RH seems to think people administer their systems
using Gnome-based GUI tools. I've always been surprised at how
difficult it is to install a RH system without X and it would
increasingly appear that Gnome will be required too.

As for the scripts themselves, I gave an example of what I
consider poor coding style, but I suppose there is room for
disagreement about these things. I sometimes use && for an
if-block: test -f $file && cat $file || echo no such file: $file
I'd use subroutines a lot more than the authors of these
scripts do. (If they didn't . network-functions I'd wonder if
the authors knew about sh's ability to define functions.) How
many times do they do the same or very similar 2-3 lines of
code where a function could simplify maintenance. But I'd also
use functions to decompose the task at hand into smaller
pieces. As may be: coding styles are like opinions: everybody's
got one.

But then there's plain bad code. To pick a single example:

# grep -n awk ifup-post
30: # replace only the first two nameserver lines; cannot count on awk
84:if [ -f /etc/sysconfig/ipchains -a "`ipchains -L input -n 2>&1 | awk 'END {print NR }'`" -gt 1 ]; then
90:  ns=`awk '/^nameserver / { print $2 }' /etc/resolv.conf`
104:    awk -F: '{print $2 } ' | awk '{ print $1 }'`

The comment on line 30 explains that they do cat | while read
(because awk isn't necessarily installed) and then the rest of
the script uses awk at will. (I can see -- barely -- being
worried about whether or not you've got perl installed, but
awk? And if you don't have awk, what are the odds that you'll
have X? And Gnome?)

I got to wondering whether or not this script would break if
you don't have awk. Well, obviously it will, I mean, will the
install fail if you try to install without awk. So I did

	# rpm -qf /etc/sysconfig/network-scripts/ifup-post
	initscripts-5.84-1
	# rpm -qf /usr/bin/awk
	gawk-3.0.6-1
	# rpm -q --whatrequires gawk | grep initscripts
	initscripts-5.84-1

So in fact, you *can* count on awk and you *don't* have to do
a "cat | while read". The comment on line 30 is broken, and the
code is needlessly arcane. (Assuming that anything compared to
awk could be considered arcane. :-)

Having said that, I now have a confession. While I was doing
the rpm -q this and that, I did a rpm -qil on initscripts and
saw that there are some readme-type files in which the
environment variables *are* documented and the command line
syntax is even partly documented. So I was wrong and RedHat
was right. "Honey, these scripts are *fantastic*." ("That's
odd: Luke never asks for a second initscript at home.")

Well.

Since we've established that people use the RH initscripts
and since I finally roused myself to (locate and) RTFM, my
next question would be, what do you prosumer-types use to
administer your RH initscripts for headless server boxes?

-- 
Luke Jones = luke/vortex/frii/fullstop/com



More information about the NCLUG mailing list