OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / freeswan / testing / utils / interfaces2ifcfg.pl
1 #!/usr/bin/perl
2
3 $interfaces=$ARGV[0];
4 $networkscriptdir=$ARGV[1];
5
6 open(INTERFACES,"$interfaces") || die "interfaces: $interfaces $!\n";
7
8 chdir($networkscriptdir) || die "Can not chdir to $networkscriptdir: $!\n";
9
10 $stanza=0;
11
12 while(<INTERFACES>) {
13   next if (/^\#/);
14   chop;
15
16   if($stanza) {
17     if(/^\s*address\s*([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)/) {
18       print IFCFG "IPADDR=$1\n";
19       next;
20     } elsif(/^\s*network\s*([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)/) {
21       print IFCFG "NETMASK=$1\n";
22       next;
23     } elsif(/^\s*netmask\s*([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)/) {
24       print IFCFG "NETMASK=$1\n";
25       next;
26     } elsif(/^\s*broadcast\s*([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)/) {
27       print IFCFG "BROADCAST=$1\n";
28       next;
29     } elsif(/^\s*gateway\s*([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)/) {
30       print IFCFG "GATEWAY=$1\n";
31       print IFCFG "GATEWAYDEV=$device\n";
32     } elsif(/^\s*up\s*route\s*add\s*-(.*)/) {
33       open(STATICROUTES, ">>../static-routes") || die "can not open ../static-routes: $!\n";
34       print STATICROUTES "$device $1\n";
35       close(STATICROUTES);
36     } elsif(/iface/) {
37       close(IFCFG);
38       $stanza=0;
39     } elsif(/^$/) {
40       close(IFCFG);
41       $stanza=0;
42       next;
43     } else {
44       print STDERR "ignoring command $_\n";
45     }
46   }
47
48   if(!$stanza) {
49     #print "Processing $_\n";
50     if(/\s*iface (.*) inet static/) {
51       $device=$1;
52       $stanza=1;
53       open(IFCFG, ">ifcfg-$device") || die "Can not open ifcfg-$device: $!\n";
54       print IFCFG "ONBOOT=yes\n";
55     }
56   }
57 }
58
59       
60     
61