File: interfaces2ifcfg.pl

package info (click to toggle)
openswan 1%3A2.4.6%2Bdfsg.2-1.1%2Betch2
  • links: PTS
  • area: main
  • in suites: etch
  • size: 25,000 kB
  • ctags: 16,877
  • sloc: ansic: 121,112; sh: 19,782; xml: 9,699; asm: 4,422; perl: 4,087; makefile: 3,367; tcl: 713; exp: 657; yacc: 396; pascal: 328; lex: 289; sed: 265; awk: 124; lisp: 3
file content (61 lines) | stat: -rwxr-xr-x 1,535 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/perl

$interfaces=$ARGV[0];
$networkscriptdir=$ARGV[1];

open(INTERFACES,"$interfaces") || die "interfaces: $interfaces $!\n";

chdir($networkscriptdir) || die "Can not chdir to $networkscriptdir: $!\n";

$stanza=0;

while(<INTERFACES>) {
  next if (/^\#/);
  chop;

  if($stanza) {
    if(/^\s*address\s*([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)/) {
      print IFCFG "IPADDR=$1\n";
      next;
    } elsif(/^\s*network\s*([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)/) {
      print IFCFG "NETMASK=$1\n";
      next;
    } elsif(/^\s*netmask\s*([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)/) {
      print IFCFG "NETMASK=$1\n";
      next;
    } elsif(/^\s*broadcast\s*([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)/) {
      print IFCFG "BROADCAST=$1\n";
      next;
    } elsif(/^\s*gateway\s*([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)/) {
      print IFCFG "GATEWAY=$1\n";
      print IFCFG "GATEWAYDEV=$device\n";
    } elsif(/^\s*up\s*route\s*add\s*-(.*)/) {
      open(STATICROUTES, ">>../static-routes") || die "can not open ../static-routes: $!\n";
      print STATICROUTES "$device $1\n";
      close(STATICROUTES);
    } elsif(/iface/) {
      close(IFCFG);
      $stanza=0;
    } elsif(/^$/) {
      close(IFCFG);
      $stanza=0;
      next;
    } else {
      print STDERR "ignoring command $_\n";
    }
  }

  if(!$stanza) {
    #print "Processing $_\n";
    if(/\s*iface (.*) inet static/) {
      $device=$1;
      $stanza=1;
      open(IFCFG, ">ifcfg-$device") || die "Can not open ifcfg-$device: $!\n";
      print IFCFG "ONBOOT=yes\n";
    }
  }
}