[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Network setup program



Hi all,

I don't know if there is already a network setup program for The HURD.
I've written this script that will configure the network with settrans
and modify the hostname and the dns. It's in perl.
If anybody want to try it...
Please, comment me if there is any error/missign features.
I'll will add a little hosts editor and a more complex dns setup (this
only allows now one dns server).

I've written this because I don't like using settrans with a long line...

Thanks.

----------------------------------------
Juli-Manel Merino Vidal
jmmv@mail.com - http://jmmv.cjb.net
----------------------------------------
        >>> Running Debian/GNU Linux 2.2
#!/bin/perl
# netconfig
# By Juli-Manel Merino Vidal
# Copyright (c) 1999, GNU General Public License
# Please, read http://www.gnu.org/copyleft/gpl.html

# Utility to configure the network under The HURD.

$| = 1;
$hn_file = "/etc/hostname";
$dns_file = "/etc/resolv.conf";
$hosts_file = "/etc/hosts";

print "Network setup\n";
print "-------------\n";
print "This script could damage your network configuration!\n";
print "Please, be sure you are NOT using more than ONE nameserver. If not, ";
print "this script\nwill broke $dns_file.\n\n";

# --------------------
#  READ INITIAL SETUP
# --------------------
print "Reading setup...";
open HN, $hn_file;
$hn_old = <HN>;
chop $hn_old if $hn_old =~ /\n/;
close HN;
open DNS, $dns_file;
while (<DNS>) {
	if (/search[ \t](.*)/) {
		$domain_old = $1;
	}
	if (/nameserver[ \t](.*)/) {
		$dns_old = $1;
		last;
	}
}
close DNS;
open HOSTS, $hosts_file;
$hosts_lines = 0;
while (<HOSTS>) {
	chop if /\n$/;
	$hosts[$hosts_lines] = $_;
	$hosts_lines++;
}
close HOSTS;
# I don't know how to retrive the following data, so set it up by default.
$int_old = "eth0";
$add_old = "192.168.1.1";
$gtw_old = "192.168.1.1";
$msk_old = "255.255.255.0";
$domain_new = $domain_old;
print " done.\n";

# --------------
#  GET NEW DATA
# --------------
print "Local host name ($hn_old): ";
$hn_new = <>;
chop $hn_new;
if ($hn_new eq "") { $hn_new = $hn_old; }

print "Interface ($int_old): ";
$int_new = <>;
chop $int_new;
if ($int_new eq "") { $int_new = $int_old; }

print "Address ($add_old): ";
$add_new = <>;
chop $add_new;
if ($add_new eq "") { $add_new = $add_old; }

print "Gateway ($gtw_old): ";
$gtw_new = <>;
chop $gtw_new;
if ($gtw_new eq "") { $gtw_new = $gtw_old; }

print "Netmask ($msk_old): ";
$msk_new = <>;
chop $msk_new;
if ($msk_new eq "") { $msk_new = $msk_old; }

print "DNS ($dns_old): ";
$dns_new = <>;
chop $dns_new;
if ($dns_new eq "") { $dns_new = $dns_old; }

# --------------
#  CONFIRMATION
# --------------
print "\n-> The following line will be added/replaced to $hosts_file:\n";
print "->  127.0.0.1\tlocalhost\t$hn_new\n";
print "-> I'll also call settrans to set network parameters and I'll modify\n";
print "-> $hn_file.\n";

print "UPDATE CONFIGURATION (Y/n) ? ";
$_ = <>;
chop $_;
if ($_ eq "n") { 
	print "Setup cancelled!\n\n";
	exit; 
} 

# --------------
#  UPDATE SETUP
# --------------
print "Updating files...";
open HN, ">$hn_file";
print HN "$hn_new";
close HN;
open DNS, ">$dns_file";
print DNS "search $domain_new\n";
print DNS "nameserver $dns_new";
close DNS;
open HOSTS, ">$hosts_file";
for ($line = 0; $line < $hosts_lines; $line++) {
	if ($hosts[$line] =~ /127.0.0.1/) { 
		$hosts[$line] = "127.0.0.1\tlocalhost\t$hn_new";
	}
	print HOSTS "$hosts[$line]\n";
}
close HOSTS;
print " done.\n";
print "Calling settrans...";
`settrans -fg /servers/socket/2 /hurd/pfinet --interface=$int_new --address=$add_new --gateway=$gtw_new --netmask=$msk_new`;
print " done.\n";
print "Setup complete!\n\n";

Reply to: