Git init
[external/ifupdown.git] / debian / upgrade-from-0.5.x.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 my %doneifaces = ();
6 my @orig = ();   # original interfaces file
7 my $line;
8
9 while($line = <STDIN>) {
10         if ($line =~ m/^\s*#/) {
11                 push @orig, $line;
12                 next;
13         }
14
15         my $tmp;
16         while ($line =~ m/\\\n$/ and $tmp = <>) {
17                 $line .= $tmp;
18         }
19         push @orig, $line;
20 }
21
22 my $out = "";
23 my $block = "";
24 my $auto = "";
25 for my $x (@orig) {
26         my $y = $x;
27         $y =~ s/^\s*//s;
28         $y =~ s/\\\n//sg;
29         $y =~ s/\s*$//s;
30
31         if ($y =~ m/^scheme\b/) {
32                 print STDERR "Schemes cannot be automatically converted\n";
33                 exit(1);
34         }
35         if ($y =~ m/^auto\b/) {
36                 print STDERR "File seems to already be converted\n";
37                 exit(1);
38         }
39
40         if ($y =~ m/^iface\b/s) {
41                 $out .= $auto . $block;
42                 $block = $x;
43                 if ($y =~ m/^iface\s+(\S+)/s && ! $doneifaces{$1}++ ) {
44                         $auto = "# automatically added when upgrading\n";
45                         $auto .= "auto $1\n";
46                 } else {
47                         $auto = "";
48                 }
49                 next;
50         }
51
52         if ($y =~ m/^noauto/) {
53                 $auto = "";
54                 my $spaces = $x;
55                 $spaces =~ s/\S.*$//s;
56                 $block .= $spaces . "# noauto (removed on upgrade)\n";
57                 next;
58         }
59
60         $block .= $x;
61 }
62
63 $out .= $auto . $block;
64
65 print $out;