tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / workbench / network / stacks / AROSTCP / dhcp / contrib / 3.0b1-lease-convert
blob7c930902cccc6c04312f16a59ea16a1506f5ba3b
1 #!/usr/bin/perl
3 # Start Date: Mon, 26 Mar 2001 14:24:09 +0200
4 # Time-stamp: <Monday, 26 March 2001 16:09:44 by brister>
5 # File: leaseconvertor.pl
6 # RCSId: $Id: 3.0b1-lease-convert,v 1.1.1.1 2005/12/07 10:50:32 sonic_amiga Exp $
8 # Description: Convert 3.0b1 to 3.0b2/final lease file format
11 require 5.004;
13 my $rcsID =<<'EOM';
14 $Id: 3.0b1-lease-convert,v 1.1.1.1 2005/12/07 10:50:32 sonic_amiga Exp $
15 EOM
17 use strict;
19 my $revstatement =<<'EOS';
20 switch (ns-update (delete (1, 12, ddns-rev-name, null))) {
21 case 0:
22 unset ddns-rev-name;
23 break;
25 EOS
27 my $fwdstatement =<<'EOS';
28 switch (ns-update (delete (1, 1, ddns-fwd-name, leased-address))) {
29 case 0:
30 unset ddns-fwd-name;
31 break;
33 EOS
36 if (@ARGV && $ARGV[0] =~ m!^-!) {
37 usage();
42 # read stdin and write stdout.
43 while (<>) {
44 if (! /^lease\s/) {
45 print;
46 } else {
47 my $lease = $_;
48 while (<>) {
49 $lease .= $_;
50 # in a b1 file we should only see a left curly brace on a lease
51 # lines. Seening it anywhere else means the user is probably
52 # running a b2 or later file through this.
53 # Ditto for a 'set' statement.
54 if (m!\{! || m!^\s*set\s!) {
55 warn "this doesn't look like a 3.0b1 file. Ignoring rest.\n";
56 print $lease;
57 dumpRestAndExit();
60 last if m!^\}\s*$!;
63 # $lease contains all the lines for the lease entry.
64 $lease = makeNewLease($lease);
65 print $lease;
71 sub usage {
72 my $prog = $0;
73 $prog =~ s!.*/!!;
75 print STDERR <<EOM;
76 usage: $prog [ file ]
78 Reads from the lease file listed on the command line (or stdin if not filename
79 given) and writes to stdout. Converts a 3.0b1-style leases file to a 3.0b2
80 style (for ad-hoc ddns updates).
81 EOM
83 exit (0);
88 # takes a string that's the lines of a lease entry and converts it, if
89 # necessary to a b2 style lease entry. Returns the new lease in printable form.
90 sub makeNewLease {
91 my ($lease) = @_;
93 my $convertedfwd;
94 my $convertedrev;
95 my $newlease = "";
96 foreach (split "\n", $lease) {
97 if (m!^(\s+)(ddns-fwd-name|ddns-rev-name)\s+(\"[^\"]+\"\s*;)!) {
98 $newlease .= $1 . "set " . $2 . " = " . $3 . "\n";
100 # If there's one of them, then it will always be the -fwd-. There
101 # may not always be a -rev-.
102 $convertedfwd++;
103 $convertedrev++ if ($2 eq "ddns-rev-name");
104 } elsif (m!^\s*\}!) {
105 if ($convertedfwd) {
106 $newlease .= "\ton expiry or release {\n";
107 $newlease .= $revstatement if $convertedrev;
108 $newlease .= $fwdstatement;
109 $newlease .= "\t on expiry or release;\n\t}\n";
111 $newlease .= "}\n";
112 } else {
113 $newlease .= $_ . "\n";
117 return $newlease;
121 sub dumpRestAndExit {
122 while (<>) {
123 print;
125 exit (0);